Skip to content

Commit

Permalink
fix: add compatibility warning for older @babel/helper versions
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 26, 2021
1 parent 3a30713 commit 4dcd489
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -202,6 +202,7 @@ new-version:
@echo "!!!!!! Update classStaticPrivateFieldDestructureSet !!!!!!"
@echo "!!!!!! helper version in !!!!!!"
@echo "!!!!!! packages/babel-helpers/src/helpers.js !!!!!!"
@echo "!!!!!! packages/babel-helper-create-class-features-plugin/src/fields.js"
@echo "!!!!!! !!!!!!"
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Expand Down
19 changes: 15 additions & 4 deletions packages/babel-helper-create-class-features-plugin/src/fields.js
Expand Up @@ -315,11 +315,22 @@ const privateNameHandlerSpec = {
const { name } = member.node.property.id;
const { id, static: isStatic } = privateNamesMap.get(name);
if (isStatic) {
try {
// classStaticPrivateFieldDestructureSet was introduced in 7.99.0
// eslint-disable-next-line no-var
var helper = file.addHelper("classStaticPrivateFieldDestructureSet");
} catch {
throw new Error(
"Babel can not transpile `[C.#p] = [0]` with @babel/helper < 7.99.0, \n" +
"please update @babel/helper to the latest version",
);
}
return t.memberExpression(
t.callExpression(
file.addHelper("classStaticPrivateFieldDestructureSet"),
[this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)],
),
t.callExpression(helper, [
this.receiver(member),
t.cloneNode(classRef),
t.cloneNode(id),
]),
t.identifier("value"),
);
}
Expand Down

0 comments on commit 4dcd489

Please sign in to comment.