diff --git a/packages/babel-core/src/parser/index.ts b/packages/babel-core/src/parser/index.ts index b788b9527d45..08aa59693a10 100644 --- a/packages/babel-core/src/parser/index.ts +++ b/packages/babel-core/src/parser/index.ts @@ -66,7 +66,12 @@ export default function* parser( if (missingPlugin) { err.message = `${filename}: ` + - generateMissingPluginMessage(missingPlugin[0], loc, codeFrame); + generateMissingPluginMessage( + missingPlugin[0], + loc, + codeFrame, + filename, + ); } else { err.message = `${filename}: ${err.message}\n\n` + codeFrame; } diff --git a/packages/babel-core/src/parser/util/missing-plugin-helper.ts b/packages/babel-core/src/parser/util/missing-plugin-helper.ts index 9eb396b94b57..d157389e0604 100644 --- a/packages/babel-core/src/parser/util/missing-plugin-helper.ts +++ b/packages/babel-core/src/parser/util/missing-plugin-helper.ts @@ -318,6 +318,7 @@ export default function generateMissingPluginMessage( column: number; }, codeFrame: string, + filename: string, ): string { let helpMessage = `Support for the experimental syntax '${missingPluginName}' isn't currently enabled ` + @@ -342,5 +343,17 @@ If you want to leave it as-is, add ${syntaxPluginInfo} to the 'plugins' section } } } + + const msgFilename = + filename === "unknown" ? "" : filename; + helpMessage += ` + +If you already added the plugin for this syntax to your config, it's possible that your config \ +isn't being loaded. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded \ +configuration: +\tnpx cross-env BABEL_SHOW_CONFIG_FOR=${msgFilename} ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. +`; return helpMessage; } diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index c00732d98a3d..9a11ac737f03 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -906,23 +906,29 @@ describe("api", function () { }); }); - it("both syntax and transform plugin available", function () { - return new Promise(resolve => { + it("both syntax and transform plugin available", async function () { + const promise = new Promise((resolve, reject) => { transformFile( cwd + "/fixtures/api/parsing-errors/syntax-and-transform/file.js", options, - function (err) { - expect(err.message).toMatch( - "Support for the experimental syntax 'doExpressions' isn't currently enabled (1:2):", - ); - expect(err.message).toMatch( - "Add @babel/plugin-proposal-do-expressions (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-do-expressions) to the " + - "'plugins' section of your Babel config to enable transformation.", - ); - resolve(); - }, + (err, result) => (err ? reject(err) : resolve(result)), ); }); + + await expect(promise).rejects.toThrow(); + + const err = await promise.catch(e => e); + + expect(err.message).toMatch( + "Support for the experimental syntax 'doExpressions' isn't currently enabled (1:2):", + ); + expect(err.message).toMatch( + "Add @babel/plugin-proposal-do-expressions (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-do-expressions) to the " + + "'plugins' section of your Babel config to enable transformation.", + ); + expect(err.message).toMatch( + /You can re-run Babel with the BABEL_SHOW_CONFIG_FOR=(.*?)[\\/]parsing-errors[\\/]syntax-and-transform[\\/]file.js environment variable to show the loaded configuration./, + ); }); }); diff --git a/packages/babel-helper-create-class-features-plugin/src/features.ts b/packages/babel-helper-create-class-features-plugin/src/features.ts index 88ad8777e2ea..2fe2f3907010 100644 --- a/packages/babel-helper-create-class-features-plugin/src/features.ts +++ b/packages/babel-helper-create-class-features-plugin/src/features.ts @@ -94,7 +94,9 @@ export function enableFeature(file: File, feature: number, loose: boolean) { throw new Error( "'loose' mode configuration must be the same for @babel/plugin-transform-class-properties, " + "@babel/plugin-transform-private-methods and " + - "@babel/plugin-transform-private-property-in-object (when they are enabled).", + "@babel/plugin-transform-private-property-in-object (when they are enabled)." + + "\n\n" + + getBabelShowConfigForHint(file), ); } else { resolvedLoose = loose; @@ -118,13 +120,29 @@ export function enableFeature(file: File, feature: number, loose: boolean) { `and @babel/plugin-transform-private-property-in-object (when they are enabled): you can ` + `silence this warning by explicitly adding\n` + `\t["${name}", { "loose": ${resolvedLoose} }]\n` + - `to the "plugins" section of your Babel config.`, + `to the "plugins" section of your Babel config.` + + "\n\n" + + getBabelShowConfigForHint(file), ); } } } } +function getBabelShowConfigForHint(file: File) { + let { filename } = file.opts; + if (!filename || filename === "unknown") { + filename = "[name of the input file]"; + } + return `\ +If you already set the same 'loose' mode for these plugins in your config, it's possible that they \ +are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded \ +configuration: +\tnpx cross-env BABEL_SHOW_CONFIG_FOR=${filename} ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info.`; +} + function hasFeature(file: File, feature: number) { return !!(file.get(featuresKey) & feature); } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/input.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/input.js new file mode 100644 index 000000000000..22b552f070de --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/input.js @@ -0,0 +1,5 @@ +class A { + x = 2; + + #foo() {} +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/options.json new file mode 100644 index 000000000000..5d3a4b885c43 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/options.json @@ -0,0 +1,15 @@ +{ + "BABEL_8_BREAKING": false, + "os": ["win32"], + "validateLogs": true, + "presets": [ + [ + "env", + { + "targets": { "node": 10 }, + "shippedProposals": true + } + ] + ], + "plugins": [["proposal-private-methods", { "loose": true }]] +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/output.js new file mode 100644 index 000000000000..ec1282b425a0 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/output.js @@ -0,0 +1,17 @@ +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +var _foo = _classPrivateFieldLooseKey("foo"); + +class A { + constructor() { + Object.defineProperty(this, _foo, { + value: _foo2 + }); + this.x = 2; + } + +} + +var _foo2 = function _foo2() {}; diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/stderr.txt new file mode 100644 index 000000000000..2cfc0dc0e19f --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/stderr.txt @@ -0,0 +1,5 @@ +Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-class-properties since the "loose" mode option was set to "true" for @babel/plugin-proposal-private-methods. +The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding + ["@babel/plugin-proposal-class-properties", { "loose": true }] +to the "plugins" section of your Babel config. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR=\packages\babel-preset-env\test\fixtures\loose-class-features-precedence\methods-loose-preset-not-loose\input.js environment variable to show the loaded configuration. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/options.json index bc5be796a79c..de898bec3296 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/options.json +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/options.json @@ -1,12 +1,14 @@ { "BABEL_8_BREAKING": false, + "os": ["darwin", "linux"], "validateLogs": true, "presets": [ - ["env", { - "targets": { "node": 10 } - }] + [ + "env", + { + "targets": { "node": 10 } + } + ] ], - "plugins": [ - ["transform-private-methods", { "loose": true }] - ] + "plugins": [["transform-private-methods", { "loose": true }]] } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/stderr.txt index a95410dc69b0..68f6eca319e2 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/stderr.txt +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/stderr.txt @@ -2,7 +2,17 @@ Though the "loose" option was set to "false" in your @babel/preset-env config, i The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-property-in-object", { "loose": true }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-class-properties since the "loose" mode option was set to "true" for @babel/plugin-transform-private-property-in-object. The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-class-properties", { "loose": true }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-loose-preset-not-loose/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-loose-preset-not-loose/stderr.txt index dc1e60cd598a..5f54faada2cc 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-loose-preset-not-loose/stderr.txt +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-loose-preset-not-loose/stderr.txt @@ -2,3 +2,8 @@ Though the "loose" option was set to "false" in your @babel/preset-env config, i The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-property-in-object", { "loose": true }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-loose-preset-not-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/stderr.txt index 48b743c0072f..3f9cebe1b553 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/stderr.txt +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/stderr.txt @@ -2,3 +2,8 @@ Though the "loose" option was set to "true" in your @babel/preset-env config, it The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-property-in-object", { "loose": false }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/input.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/input.js new file mode 100644 index 000000000000..22b552f070de --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/input.js @@ -0,0 +1,5 @@ +class A { + x = 2; + + #foo() {} +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/options.json new file mode 100644 index 000000000000..6b7c0e3124e1 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/options.json @@ -0,0 +1,15 @@ +{ + "BABEL_8_BREAKING": false, + "os": ["win32"], + "validateLogs": true, + "presets": [ + [ + "env", + { + "targets": { "node": 10 }, + "shippedProposals": true + } + ] + ], + "plugins": [["proposal-class-properties", { "loose": true }]] +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/output.js new file mode 100644 index 000000000000..ec1282b425a0 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/output.js @@ -0,0 +1,17 @@ +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +var _foo = _classPrivateFieldLooseKey("foo"); + +class A { + constructor() { + Object.defineProperty(this, _foo, { + value: _foo2 + }); + this.x = 2; + } + +} + +var _foo2 = function _foo2() {}; diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/stderr.txt new file mode 100644 index 000000000000..e3eff15e6988 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/stderr.txt @@ -0,0 +1,5 @@ +Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-private-methods since the "loose" mode option was set to "true" for @babel/plugin-proposal-class-properties. +The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding + ["@babel/plugin-proposal-private-methods", { "loose": true }] +to the "plugins" section of your Babel config. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR=\packages\babel-preset-env\test\fixtures\loose-class-features-precedence\properties-loose-preset-not-loose\input.js environment variable to show the loaded configuration. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/options.json index 3fc0457f51e1..f4d79dac0b41 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/options.json +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/options.json @@ -1,12 +1,14 @@ { "BABEL_8_BREAKING": false, + "os": ["darwin", "linux"], "validateLogs": true, "presets": [ - ["env", { - "targets": { "node": 10 } - }] + [ + "env", + { + "targets": { "node": 10 } + } + ] ], - "plugins": [ - ["transform-class-properties", { "loose": true }] - ] + "plugins": [["transform-class-properties", { "loose": true }]] } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/stderr.txt index 1e4e880d80a4..7c7048d8b790 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/stderr.txt +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/stderr.txt @@ -2,7 +2,17 @@ Though the "loose" option was set to "false" in your @babel/preset-env config, i The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-property-in-object", { "loose": true }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-private-methods since the "loose" mode option was set to "true" for @babel/plugin-transform-private-property-in-object. The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-methods", { "loose": true }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/input.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/input.js new file mode 100644 index 000000000000..22b552f070de --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/input.js @@ -0,0 +1,5 @@ +class A { + x = 2; + + #foo() {} +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/options.json new file mode 100644 index 000000000000..5e9e4715c79d --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/options.json @@ -0,0 +1,16 @@ +{ + "BABEL_8_BREAKING": false, + "os": ["win32"], + "validateLogs": true, + "presets": [ + [ + "env", + { + "targets": { "node": 10 }, + "shippedProposals": true, + "loose": true + } + ] + ], + "plugins": [["proposal-class-properties", { "loose": false }]] +} diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/output.js new file mode 100644 index 000000000000..97d788f68d4c --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/output.js @@ -0,0 +1,14 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +var _foo = new WeakSet(); + +class A { + constructor() { + _foo.add(this); + + _defineProperty(this, "x", 2); + } + +} + +var _foo2 = function _foo2() {}; diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/stderr.txt new file mode 100644 index 000000000000..337ef6702db0 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/stderr.txt @@ -0,0 +1,5 @@ +Though the "loose" option was set to "true" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-private-methods since the "loose" mode option was set to "false" for @babel/plugin-proposal-class-properties. +The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding + ["@babel/plugin-proposal-private-methods", { "loose": false }] +to the "plugins" section of your Babel config. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR=\packages\babel-preset-env\test\fixtures\loose-class-features-precedence\properties-not-loose-preset-loose\input.js environment variable to show the loaded configuration. diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/options.json b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/options.json index 7318a7f957b6..6622ab174a92 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/options.json +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/options.json @@ -1,13 +1,15 @@ { "BABEL_8_BREAKING": false, + "os": ["darwin", "linux"], "validateLogs": true, "presets": [ - ["env", { - "targets": { "node": 10 }, - "loose": true - }] + [ + "env", + { + "targets": { "node": 10 }, + "loose": true + } + ] ], - "plugins": [ - ["transform-class-properties", { "loose": false }] - ] + "plugins": [["transform-class-properties", { "loose": false }]] } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/stderr.txt b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/stderr.txt index f0dcd2c216dc..4f176ebe7dd0 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/stderr.txt +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/stderr.txt @@ -2,7 +2,17 @@ Though the "loose" option was set to "true" in your @babel/preset-env config, it The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-property-in-object", { "loose": false }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info. Though the "loose" option was set to "true" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-private-methods since the "loose" mode option was set to "false" for @babel/plugin-transform-private-property-in-object. The "loose" option must be the same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods and @babel/plugin-transform-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-transform-private-methods", { "loose": false }] to the "plugins" section of your Babel config. + +If you already set the same 'loose' mode for these plugins in your config, it's possible that they are enabled multiple times with different options. +You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration: + npx cross-env BABEL_SHOW_CONFIG_FOR=/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/input.js ...your build command... +See https://babeljs.io/docs/configuration#print-effective-configs for more info.