From a24206eb9670a6b7f66495d6359b3f1d288a00da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 13 Jan 2019 00:35:22 +0100 Subject: [PATCH] Fix error for decorators not enabled (#9321) * Fix error for decorators not enabled * Update error message --- .../src/features.js | 12 ++++++++++-- .../decorators-legacy-interop/wrong-order/input.js | 2 ++ .../wrong-order/options.json | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/input.js create mode 100644 packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/options.json diff --git a/packages/babel-helper-create-class-features-plugin/src/features.js b/packages/babel-helper-create-class-features-plugin/src/features.js index afd8a29f20..9772a5dd4e 100644 --- a/packages/babel-helper-create-class-features-plugin/src/features.js +++ b/packages/babel-helper-create-class-features-plugin/src/features.js @@ -39,9 +39,17 @@ export function isLoose(file, feature) { } export function verifyUsedFeatures(path, file) { - if (hasOwnDecorators(path)) { + if (hasOwnDecorators(path.node)) { if (!hasFeature(file, FEATURES.decorators)) { - throw path.buildCodeFrameError("Decorators are not enabled."); + throw path.buildCodeFrameError( + "Decorators are not enabled." + + "\nIf you are using " + + '["@babel/plugin-proposal-decorators", { "legacy": true }], ' + + 'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' + + "and enable loose mode, like so:\n" + + '\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' + + '\t["@babel/plugin-proposal-class-properties", { "loose": true }]', + ); } if (path.isPrivate()) { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/input.js new file mode 100644 index 0000000000..248eee836d --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/input.js @@ -0,0 +1,2 @@ +@deco +class Foo {} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/options.json new file mode 100644 index 0000000000..64fd0cbcea --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/decorators-legacy-interop/wrong-order/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["proposal-class-properties", { "loose": true }], + ["proposal-decorators", { "legacy": true }] + ], + "throws": "Decorators are not enabled." +}