From 741939c5177f21de522eb63de5fce14c6bee5e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 27 Feb 2024 17:24:29 +0100 Subject: [PATCH] Suggest using `BABEL_SHOW_CONFIG_FOR` for config problems (#12428) Co-authored-by: Babel Bot <30521560+liuxingbaoyu@users.noreply.github.com> --- packages/babel-core/src/parser/index.ts | 7 ++++- .../src/parser/util/missing-plugin-helper.ts | 13 ++++++++ packages/babel-core/test/api.js | 30 +++++++++++-------- .../src/features.ts | 22 ++++++++++++-- .../input.js | 5 ++++ .../options.json | 15 ++++++++++ .../output.js | 10 +++++++ .../stderr.txt | 18 +++++++++++ .../options.json | 14 +++++---- .../methods-loose-preset-not-loose/stderr.txt | 10 +++++++ .../stderr.txt | 5 ++++ .../stderr.txt | 5 ++++ .../input.js | 5 ++++ .../options.json | 15 ++++++++++ .../output.js | 10 +++++++ .../stderr.txt | 18 +++++++++++ .../options.json | 14 +++++---- .../stderr.txt | 10 +++++++ .../input.js | 5 ++++ .../options.json | 16 ++++++++++ .../output.js | 8 +++++ .../stderr.txt | 18 +++++++++++ .../options.json | 16 +++++----- .../stderr.txt | 10 +++++++ 24 files changed, 265 insertions(+), 34 deletions(-) create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/input.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/options.json create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/output.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/stderr.txt create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/input.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/options.json create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/output.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/stderr.txt create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/input.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/options.json create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/output.js create mode 100644 packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/stderr.txt 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..0b10c557b96c 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} +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..6aceceea0b62 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( + /npx cross-env BABEL_SHOW_CONFIG_FOR=(.*?)[\\/]parsing-errors[\\/]syntax-and-transform[\\/]file.js/, + ); }); }); 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..9c264a9f4ae4 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} +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..feac11e4b801 --- /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": [["transform-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..7aff5e3da03b --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/output.js @@ -0,0 +1,10 @@ +var _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"); +class A { + constructor() { + Object.defineProperty(this, _foo, { + value: _foo2 + }); + this.x = 2; + } +} +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..29c81dd338db --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/methods-loose-preset-not-loose-win/stderr.txt @@ -0,0 +1,18 @@ +Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-private-property-in-object since the "loose" mode option was set to "true" for @babel/plugin-transform-private-methods. +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-win/input.js +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-win/input.js +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/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..9ab2e71b6385 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 +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 +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..94b1bdec4389 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 +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..3bd7421fd1f3 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 +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..e114102aea94 --- /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": [["transform-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..7aff5e3da03b --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/output.js @@ -0,0 +1,10 @@ +var _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"); +class A { + constructor() { + Object.defineProperty(this, _foo, { + value: _foo2 + }); + this.x = 2; + } +} +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..3419152e67c3 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-loose-preset-not-loose-win/stderr.txt @@ -0,0 +1,18 @@ +Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-private-property-in-object since the "loose" mode option was set to "true" for @babel/plugin-transform-class-properties. +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-win/input.js +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-win/input.js +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/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..096eeb741bd5 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 +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 +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..55d9fb93bc37 --- /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": [["transform-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..a0b753219f3c --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/output.js @@ -0,0 +1,8 @@ +var _foo = /*#__PURE__*/new WeakSet(); +class A { + constructor() { + babelHelpers.classPrivateMethodInitSpec(this, _foo); + babelHelpers.defineProperty(this, "x", 2); + } +} +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..8d30f98e1fd2 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose-win/stderr.txt @@ -0,0 +1,18 @@ +Though the "loose" option was set to "true" in your @babel/preset-env config, it will not be used for @babel/plugin-transform-private-property-in-object since the "loose" mode option was set to "false" for @babel/plugin-transform-class-properties. +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-win/input.js +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-win/input.js +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/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..2f8a4a49608c 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 +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 +See https://babeljs.io/docs/configuration#print-effective-configs for more info.