Skip to content

Commit

Permalink
Add check for fields === private method loose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-mc committed Nov 26, 2018
1 parent 465810c commit a84882e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/babel-plugin-class-features/src/features.js
Expand Up @@ -39,6 +39,10 @@ export function isLoose(file, feature) {
}

export function verifyUsedFeatures(path, file) {
if (hasDecorators(path) && !hasFeature(file, FEATURES.decorators)) {
throw path.buildCodeFrameError("Decorators are not enabled.");
}

if (hasFeature(file, FEATURES.decorators)) {
throw new Error(
"@babel/plugin-class-features doesn't support decorators yet.",
Expand All @@ -63,8 +67,15 @@ export function verifyUsedFeatures(path, file) {
}
}

if (hasDecorators(path) && !hasFeature(file, FEATURES.decorators)) {
throw path.buildCodeFrameError("Decorators are not enabled.");
if (
hasFeature(file, FEATURES.privateMethods) &&
hasFeature(file, FEATURES.fields) &&
isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.fields)
) {
throw new Error(
"'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " +
"and @babel/plugin-proposal-private-methods",
);
}

if (path.isProperty()) {
Expand Down
Expand Up @@ -6,7 +6,7 @@
"helperVersion": "7.1.6"
}
],
"proposal-private-methods",
["proposal-private-methods", { "loose": true }],
["proposal-class-properties", { "loose": true }],
"transform-classes",
"transform-block-scoping",
Expand Down

0 comments on commit a84882e

Please sign in to comment.