Skip to content

Commit

Permalink
feat: throw when ClassStatic is seen on class features plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Oct 6, 2020
1 parent ba24899 commit bed0bd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
19 changes: 18 additions & 1 deletion packages/babel-helper-create-class-features-plugin/src/index.js
Expand Up @@ -120,6 +120,18 @@ export function createClassFeaturePlugin({
}

if (!isDecorated) isDecorated = hasOwnDecorators(path.node);

if (path.isStaticBlock()) {
throw path.buildCodeFrameError(`Incorrect plugin orders, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins
{
"plugins": [
"@babel/plugin-proposal-class-static-block",
"@babel/plugin-proposal-private-property-in-object",
"@babel/plugin-proposal-private-methods",
"@babel/plugin-proposal-class-properties",
]
}`);
}
}

if (!props.length && !isDecorated) return;
Expand Down Expand Up @@ -188,7 +200,12 @@ export function createClassFeaturePlugin({
},

PrivateName(path) {
if (this.file.get(versionKey) !== version) return;
if (
this.file.get(versionKey) !== version ||
path.parentPath.isPrivate({ key: path.node })
) {
return;
}

throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`);
},
Expand Down
Expand Up @@ -21,22 +21,21 @@ describe("plugin ordering", () => {
proposalClassStaticBlock,
],
});
}).toThrowErrorMatchingInlineSnapshot(`
"/Users/jh/code/babel/example.js: Incorrect plugin orders, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins
})
.toThrow(`Incorrect plugin orders, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins
{
\\"plugins\\": [
\\"@babel/plugin-proposal-class-static-block\\",
\\"@babel/plugin-proposal-private-property-in-object\\",
\\"@babel/plugin-proposal-private-methods\\",
\\"@babel/plugin-proposal-class-properties\\",
"plugins": [
"@babel/plugin-proposal-class-static-block",
"@babel/plugin-proposal-private-property-in-object",
"@babel/plugin-proposal-private-methods",
"@babel/plugin-proposal-class-properties",
]
}
1 | class Foo {
> 2 | static {
| ^
3 | this.foo = Foo.bar;
4 | }
5 | static bar = 42;"
`);
5 | static bar = 42;`);
});
});

0 comments on commit bed0bd4

Please sign in to comment.