Skip to content

Commit

Permalink
Replaced an array of symbols with a set of symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
timocov committed Nov 26, 2023
1 parent 2c18acb commit 5595933
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 2 additions & 5 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const path = require('path');

// override tsconfig for tests
process.env.TS_NODE_PROJECT = path.resolve(__dirname, './tsconfig.options.json');

// just transpile in tests
process.env.TS_NODE_TRANSPILE_ONLY = 'true';

const config = {
Expand All @@ -16,9 +18,4 @@ const config = {
slow: 5000,
};

if (process.env.TESTS_REPORT_FILE) {
config.reporter = 'xunit';
config['reporter-options'] = `output=${process.env.TESTS_REPORT_FILE}`;
}

module.exports = config;
8 changes: 7 additions & 1 deletion src/bundle-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,13 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
const leftSymbols = splitTransientSymbol(getNodeSymbol(left, typeChecker) as ts.Symbol, typeChecker);
const rightSymbols = splitTransientSymbol(getNodeSymbol(right, typeChecker) as ts.Symbol, typeChecker);

return leftSymbols.some((leftSymbol: ts.Symbol) => rightSymbols.includes(leftSymbol));
for (const leftSymbol of leftSymbols) {

Check failure on line 619 in src/bundle-generator.ts

View workflow job for this annotation

GitHub Actions / The next TS

Type 'Set<Symbol>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.

Check failure on line 619 in src/bundle-generator.ts

View workflow job for this annotation

GitHub Actions / Current TS

Type 'Set<Symbol>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
if (rightSymbols.has(leftSymbol)) {
return true;
}
}

return false;
}

function getDeclarationsForExportedValues(exp: ts.ExportAssignment | ts.ExportDeclaration): ts.Declaration[] {
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ export function getDeclarationNameSymbol(name: NodeName, typeChecker: ts.TypeChe
return getActualSymbol(symbol, typeChecker);
}

export function splitTransientSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol[] {
export function splitTransientSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChecker): Set<ts.Symbol> {
// actually I think we even don't need to operate/use "Transient" symbols anywhere
// it's kind of aliased symbol, but just merged
// but it's hard to refractor everything to use array of symbols instead of just symbol
// so let's fix it for some places
if ((symbol.flags & ts.SymbolFlags.Transient) === 0) {
return [symbol];
return new Set([symbol]);
}

// "Transient" symbol is kinda "merged" symbol
// I don't really know is this way to "split" is correct
// but it seems that it works for now ¯\_(ツ)_/¯
const declarations = getDeclarationsForSymbol(symbol);
const result: ts.Symbol[] = [];
const result = new Set<ts.Symbol>();
for (const declaration of declarations) {
if (!isNodeNamedDeclaration(declaration) || declaration.name === undefined) {
continue;
Expand All @@ -86,7 +86,7 @@ export function splitTransientSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChec
continue;
}

result.push(getActualSymbol(sym, typeChecker));
result.add(getActualSymbol(sym, typeChecker));
}

return result;
Expand Down

0 comments on commit 5595933

Please sign in to comment.