Fix error for decorators not enabled (#9321)

* Fix error for decorators not enabled

* Update error message
This commit is contained in:
Nicolò Ribaudo 2019-01-13 00:35:22 +01:00 committed by GitHub
parent d6b4ab75ee
commit a24206eb96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -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()) {

View File

@ -0,0 +1,7 @@
{
"plugins": [
["proposal-class-properties", { "loose": true }],
["proposal-decorators", { "legacy": true }]
],
"throws": "Decorators are not enabled."
}