Skip to content

Commit

Permalink
fix: use private name in toAssignable
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 15, 2021
1 parent d66ce16 commit 176a1ab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -2245,7 +2245,6 @@ export default class ExpressionParser extends LValParser {
if (refExpressionErrors.privateKey === -1) {
refExpressionErrors.privateKey = privateKeyPos;
}
this.classScope.usePrivateName(value, privateKeyPos);
} else {
this.raise(privateKeyPos, Errors.UnexpectedPrivateField);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/babel-parser/src/parser/lval.js
Expand Up @@ -143,9 +143,14 @@ export default class LValParser extends NodeUtils {
}
break;

case "ObjectProperty":
this.toAssignable(node.value, isLHS);
case "ObjectProperty": {
const { key, value } = node;
if (this.isPrivateName(key)) {
this.classScope.usePrivateName(this.getPrivateNameSV(key), key.start);
}
this.toAssignable(value, isLHS);
break;
}

case "SpreadElement": {
this.checkToRestConversion(node);
Expand Down
Expand Up @@ -2,8 +2,7 @@
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:10)",
"SyntaxError: Private name #x is not defined. (2:10)"
"SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:10)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,8 +2,7 @@
"type": "File",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:10)",
"SyntaxError: Private name #x is not defined. (2:10)"
"SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:10)"
],
"program": {
"type": "Program",
Expand Down

0 comments on commit 176a1ab

Please sign in to comment.