Parse class heritage as strict mode code (#9315)
This commit is contained in:
@@ -994,8 +994,16 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.next();
|
||||
this.takeDecorators(node);
|
||||
this.parseClassId(node, isStatement, optionalId);
|
||||
|
||||
// class bodies and heritages are implicitly strict
|
||||
const oldStrict = this.state.strict;
|
||||
this.state.strict = true;
|
||||
|
||||
this.parseClassSuper(node);
|
||||
this.parseClassBody(node);
|
||||
|
||||
this.state.strict = oldStrict;
|
||||
|
||||
return this.finishNode(
|
||||
node,
|
||||
isStatement ? "ClassDeclaration" : "ClassExpression",
|
||||
@@ -1020,9 +1028,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
|
||||
parseClassBody(node: N.Class): void {
|
||||
// class bodies are implicitly strict
|
||||
const oldStrict = this.state.strict;
|
||||
this.state.strict = true;
|
||||
this.state.classLevel++;
|
||||
|
||||
const state = { hadConstructor: false };
|
||||
@@ -1087,7 +1092,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
node.body = this.finishNode(classBody, "ClassBody");
|
||||
|
||||
this.state.classLevel--;
|
||||
this.state.strict = oldStrict;
|
||||
}
|
||||
|
||||
parseClassMember(
|
||||
|
||||
4
packages/babel-parser/test/fixtures/es2015/class/extends-strict/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/es2015/class/extends-strict/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class C extends (function B() {
|
||||
with ({});
|
||||
return B;
|
||||
}()) {}
|
||||
3
packages/babel-parser/test/fixtures/es2015/class/extends-strict/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/class/extends-strict/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'with' in strict mode (2:2)"
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected \"{\" (1:22)"
|
||||
"throws": "yield is a reserved word in strict mode (1:16)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user