diff --git a/packages/babel-parser/src/plugins/flow/index.js b/packages/babel-parser/src/plugins/flow/index.js index 437acdb847d5..44c45b0bfbb4 100644 --- a/packages/babel-parser/src/plugins/flow/index.js +++ b/packages/babel-parser/src/plugins/flow/index.js @@ -1818,11 +1818,7 @@ export default (superClass: Class): Class => // 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(); @@ -2651,8 +2647,7 @@ export default (superClass: Class): Class => 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; @@ -2667,8 +2662,7 @@ export default (superClass: Class): Class => } else { if ( specifierTypeKind !== null && - (tokenIsIdentifier(this.state.type) || - tokenIsKeyword(this.state.type)) + tokenIsKeywordOrIdentifier(this.state.type) ) { // `import {type foo` specifier.imported = this.parseIdentifier(true); diff --git a/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/input.js b/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/input.js new file mode 100644 index 000000000000..b2451f12687c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/input.js @@ -0,0 +1 @@ +interf\u{61}ce A {} diff --git a/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/output.json b/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/output.json new file mode 100644 index 000000000000..58f646e999a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/interface-types/escape-in-interface/output.json @@ -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": [] + } +} \ No newline at end of file