Skip to content

Commit

Permalink
refactor: remove inClassProperty parser state (#10906)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Dec 24, 2019
1 parent c09664f commit a18166d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 11 deletions.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -1389,7 +1389,7 @@ export default class ExpressionParser extends LValParser {
if (this.eat(tt.dot)) {
const metaProp = this.parseMetaProperty(node, meta, "target");

if (!this.scope.inNonArrowFunction && !this.state.inClassProperty) {
if (!this.scope.inNonArrowFunction && !this.scope.inClass) {
let error = "new.target can only be used in functions";

if (this.hasPlugin("classProperties")) {
Expand Down
9 changes: 0 additions & 9 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -1048,11 +1048,9 @@ export default class StatementParser extends ExpressionParser {
}

const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
const oldInClassProperty = this.state.inClassProperty;
const oldYieldPos = this.state.yieldPos;
const oldAwaitPos = this.state.awaitPos;
this.state.maybeInArrowParameters = false;
this.state.inClassProperty = false;
this.state.yieldPos = -1;
this.state.awaitPos = -1;
this.scope.enter(functionFlags(node.async, node.generator));
Expand Down Expand Up @@ -1084,7 +1082,6 @@ export default class StatementParser extends ExpressionParser {
}

this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
this.state.inClassProperty = oldInClassProperty;
this.state.yieldPos = oldYieldPos;
this.state.awaitPos = oldAwaitPos;

Expand Down Expand Up @@ -1575,13 +1572,10 @@ export default class StatementParser extends ExpressionParser {
parseClassPrivateProperty(
node: N.ClassPrivateProperty,
): N.ClassPrivateProperty {
this.state.inClassProperty = true;

this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);

node.value = this.eat(tt.eq) ? this.parseMaybeAssign() : null;
this.semicolon();
this.state.inClassProperty = false;

this.scope.exit();

Expand All @@ -1593,8 +1587,6 @@ export default class StatementParser extends ExpressionParser {
this.expectPlugin("classProperties");
}

this.state.inClassProperty = true;

this.scope.enter(SCOPE_CLASS | SCOPE_SUPER);

if (this.match(tt.eq)) {
Expand All @@ -1605,7 +1597,6 @@ export default class StatementParser extends ExpressionParser {
node.value = null;
}
this.semicolon();
this.state.inClassProperty = false;

this.scope.exit();

Expand Down
1 change: 0 additions & 1 deletion packages/babel-parser/src/tokenizer/state.js
Expand Up @@ -64,7 +64,6 @@ export default class State {
inType: boolean = false;
noAnonFunctionType: boolean = false;
inPropertyName: boolean = false;
inClassProperty: boolean = false;
hasFlowComment: boolean = false;
isIterator: boolean = false;

Expand Down

0 comments on commit a18166d

Please sign in to comment.