From 559593390ceff067a56cae46817f95159f15389b Mon Sep 17 00:00:00 2001 From: Evgeniy Timokhov Date: Thu, 26 Oct 2023 01:03:51 +0100 Subject: [PATCH] Replaced an array of symbols with a set of symbols --- .mocharc.js | 7 ++----- src/bundle-generator.ts | 8 +++++++- src/helpers/typescript.ts | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.mocharc.js b/.mocharc.js index 604bc30..c4f0be5 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -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 = { @@ -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; diff --git a/src/bundle-generator.ts b/src/bundle-generator.ts index c45d406..6524546 100644 --- a/src/bundle-generator.ts +++ b/src/bundle-generator.ts @@ -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) { + if (rightSymbols.has(leftSymbol)) { + return true; + } + } + + return false; } function getDeclarationsForExportedValues(exp: ts.ExportAssignment | ts.ExportDeclaration): ts.Declaration[] { diff --git a/src/helpers/typescript.ts b/src/helpers/typescript.ts index 7ad919d..1bd9f62 100644 --- a/src/helpers/typescript.ts +++ b/src/helpers/typescript.ts @@ -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 { // 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(); for (const declaration of declarations) { if (!isNodeNamedDeclaration(declaration) || declaration.name === undefined) { continue; @@ -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;