Skip to content

Commit

Permalink
TS parser - ignore re-exported symbols, to make it possible to suppor…
Browse files Browse the repository at this point in the history
…t --isolatedModules

- microsoft/TypeScript#28481
  • Loading branch information
oriSomething committed Nov 28, 2018
1 parent 12dbd9a commit 5717b81
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/parse-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@ function parseTs({ code, uri }) {
* @type {Map.<string,{ line: number }>}
*/
const exportsData = new Map();
/**
* Because `--isolatedModules` flag we need to manually re-export bindings. So we ignore them
* @type {Set.<string>}
*/
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, {
Expand All @@ -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) {
Expand Down

0 comments on commit 5717b81

Please sign in to comment.