From 5717b81dffc5701280b92503d2a2c6afe00826fc Mon Sep 17 00:00:00 2001 From: Ori Livni Date: Wed, 28 Nov 2018 14:23:31 +0200 Subject: [PATCH] TS parser - ignore re-exported symbols, to make it possible to support --isolatedModules - https://github.com/Microsoft/TypeScript/issues/28481 --- src/parse-ts.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/parse-ts.js b/src/parse-ts.js index aa0e801..1b0a0aa 100644 --- a/src/parse-ts.js +++ b/src/parse-ts.js @@ -12,9 +12,24 @@ function parseTs({ code, uri }) { * @type {Map.} */ const exportsData = new Map(); + /** + * Because `--isolatedModules` flag we need to manually re-export bindings. So we ignore them + * @type {Set.} + */ + const ignoredExportsOfImports = new Set(); + const file = ts.createSourceFile(uri, code, ts.ScriptTarget.ESNext, /*setParentNodes */ false); + /** + * + * @param {string} val + * @param {import("typescript").Statement} node + */ const push = (val, node) => { + if (ignoredExportsOfImports.has(val)) { + return; + } + const loc = file.getLineAndCharacterOfPosition(node.pos); exportsData.set(val, { @@ -27,6 +42,24 @@ function parseTs({ code, uri }) { * Process */ + file.statements.forEach(statement => { + if (statement.kind === ts.SyntaxKind.ImportDeclaration) { + if ( + statement.importClause != null && + statement.importClause.namedBindings != null && + Array.isArray(statement.importClause.namedBindings.elements) + ) { + statement.importClause.namedBindings.elements.forEach(element => { + if (element.propertyName != null) { + ignoredExportsOfImports.add(element.propertyName.escapedText); + } else { + ignoredExportsOfImports.add(element.name.escapedText); + } + }); + } + } + }); + file.statements .filter(s => { if (s.kind === ts.SyntaxKind.ExportDeclaration) {