diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index f4306aff76ab..0cd8a0a15759 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -3715,7 +3715,9 @@ export default (superClass: Class): Class => } else if (tokenIsKeywordOrIdentifier(this.state.type)) { // { type something ...? } hasTypeSpecifier = true; - leftOfAs = this.parseIdentifier(); + leftOfAs = isImport + ? this.parseIdentifier() + : this.parseModuleExportName(); } if (hasTypeSpecifier && isInTypeOnlyImportExport) { this.raise( diff --git a/packages/babel-parser/test/fixtures/typescript/type-only-import-export-specifiers/export-type-only-keyword/output.json b/packages/babel-parser/test/fixtures/typescript/type-only-import-export-specifiers/export-type-only-keyword/output.json index 2f9439c2bf9e..73d3206463af 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-only-import-export-specifiers/export-type-only-keyword/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-only-import-export-specifiers/export-type-only-keyword/output.json @@ -3,7 +3,6 @@ "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":19,"index":34}}, "errors": [ "SyntaxError: Unexpected keyword 'if'. (1:6)", - "SyntaxError: Unexpected keyword 'if'. (2:14)", "SyntaxError: Unexpected keyword 'if'. (2:14)" ], "program": {