From cfd26fdbf27a4c3eae2311ca145e36bc13dd2abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 18 Nov 2019 13:04:34 -0500 Subject: [PATCH] register ImportEqualsSpecifier to scope (#10710) Co-authored-by: --- .../src/plugins/typescript/index.js | 7 + .../export-named-import-require/input.ts | 2 + .../export-named-import-require/output.json | 171 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/output.json diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 4cf196b9a704..1ca9c6a71cce 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -21,6 +21,7 @@ import { BIND_TS_AMBIENT, BIND_TS_NAMESPACE, BIND_CLASS, + BIND_LEXICAL, } from "../../util/scopeflags"; import TypeScriptScopeHandler from "./scope"; import * as charCodes from "charcodes"; @@ -1292,6 +1293,12 @@ export default (superClass: Class): Class => ): N.TsImportEqualsDeclaration { node.isExport = isExport || false; node.id = this.parseIdentifier(); + this.checkLVal( + node.id, + BIND_LEXICAL, + undefined, + "import equals declaration", + ); this.expect(tt.eq); node.moduleReference = this.tsParseModuleReference(); this.semicolon(); diff --git a/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts b/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts new file mode 100644 index 000000000000..6823138bafd9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts @@ -0,0 +1,2 @@ +import a = require("a"); +export { a }; diff --git a/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/output.json b/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/output.json new file mode 100644 index 000000000000..4c31f00de348 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/output.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSImportEqualsDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "isExport": false, + "id": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + "moduleReference": { + "type": "TSExternalModuleReference", + "start": 11, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "StringLiteral", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "extra": { + "rawValue": "a", + "raw": "\"a\"" + }, + "value": "a" + } + } + }, + { + "type": "ExportNamedDeclaration", + "start": 25, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "local": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "exported": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file