Skip to content

Commit

Permalink
fix: disallow escape in interface keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 15, 2021
1 parent 2e0de96 commit 3bd0561
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/babel-parser/src/plugins/flow/index.js
Expand Up @@ -1818,11 +1818,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// interfaces and enums
parseStatement(context: ?string, topLevel?: boolean): N.Statement {
// strict mode handling of `interface` since it's a reserved word
if (
this.state.strict &&
tokenIsIdentifier(this.state.type) &&
this.state.value === "interface"
) {
if (this.state.strict && this.isContextual(tt._interface)) {
const lookahead = this.lookahead();
if (tokenIsKeywordOrIdentifier(lookahead.type)) {
const node = this.startNode();
Expand Down Expand Up @@ -2651,8 +2647,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const as_ident = this.parseIdentifier(true);
if (
specifierTypeKind !== null &&
!tokenIsIdentifier(this.state.type) &&
!tokenIsKeyword(this.state.type)
!tokenIsKeywordOrIdentifier(this.state.type)
) {
// `import {type as ,` or `import {type as }`
specifier.imported = as_ident;
Expand All @@ -2667,8 +2662,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} else {
if (
specifierTypeKind !== null &&
(tokenIsIdentifier(this.state.type) ||
tokenIsKeyword(this.state.type))
tokenIsKeywordOrIdentifier(this.state.type)
) {
// `import {type foo`
specifier.imported = this.parseIdentifier(true);
Expand Down
@@ -0,0 +1 @@
interf\u{61}ce A {}
@@ -0,0 +1,38 @@
{
"type": "File",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface'. (1:0)"
],
"program": {
"type": "Program",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "InterfaceDeclaration",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"id": {
"type": "Identifier",
"start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"A"},
"name": "A"
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":17,"end":19,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":19}},
"callProperties": [],
"properties": [],
"indexers": [],
"internalSlots": [],
"exact": false
}
}
],
"directives": []
}
}

0 comments on commit 3bd0561

Please sign in to comment.