tsc-ts 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api/compiler/ast.d.ts +67 -27
- package/dist/api/compiler/ast.js +156 -55
- package/dist/api/compiler/binder-utilities.js +4 -3
- package/dist/api/compiler/binder.js +14 -13
- package/dist/api/compiler/checker-calls.js +7 -6
- package/dist/api/compiler/checker-contextual.js +1 -1
- package/dist/api/compiler/checker-declaration-order.js +2 -1
- package/dist/api/compiler/checker-declarations.js +14 -14
- package/dist/api/compiler/checker-declared-types.d.ts +1 -1
- package/dist/api/compiler/checker-declared-types.js +12 -11
- package/dist/api/compiler/checker-decorators.js +3 -3
- package/dist/api/compiler/checker-deprecation.js +17 -18
- package/dist/api/compiler/checker-destructuring.d.ts +1 -1
- package/dist/api/compiler/checker-destructuring.js +3 -3
- package/dist/api/compiler/checker-elaboration.js +8 -7
- package/dist/api/compiler/checker-emit-helpers.d.ts +2 -1
- package/dist/api/compiler/checker-emit-helpers.js +5 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
- package/dist/api/compiler/checker-emit-resolver.js +5 -4
- package/dist/api/compiler/checker-grammar.js +23 -9
- package/dist/api/compiler/checker-heritage.d.ts +1 -1
- package/dist/api/compiler/checker-heritage.js +14 -13
- package/dist/api/compiler/checker-inference.d.ts +21 -11
- package/dist/api/compiler/checker-inference.js +57 -34
- package/dist/api/compiler/checker-javascript.d.ts +1 -1
- package/dist/api/compiler/checker-javascript.js +5 -4
- package/dist/api/compiler/checker-jsx.d.ts +1 -1
- package/dist/api/compiler/checker-jsx.js +4 -4
- package/dist/api/compiler/checker-literals.js +2 -2
- package/dist/api/compiler/checker-members.d.ts +32 -3
- package/dist/api/compiler/checker-members.js +240 -53
- package/dist/api/compiler/checker-modules.d.ts +15 -1
- package/dist/api/compiler/checker-modules.js +86 -14
- package/dist/api/compiler/checker-object-literals.d.ts +1 -1
- package/dist/api/compiler/checker-object-literals.js +11 -7
- package/dist/api/compiler/checker-overloads.d.ts +1 -1
- package/dist/api/compiler/checker-overloads.js +4 -3
- package/dist/api/compiler/checker-property-access.d.ts +1 -1
- package/dist/api/compiler/checker-property-access.js +2 -2
- package/dist/api/compiler/checker-services.js +2 -2
- package/dist/api/compiler/checker-signatures.d.ts +1 -1
- package/dist/api/compiler/checker-signatures.js +9 -8
- package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
- package/dist/api/compiler/checker-symbol-types.js +22 -952
- package/dist/api/compiler/checker-symbols.d.ts +2 -2
- package/dist/api/compiler/checker-symbols.js +29 -27
- package/dist/api/compiler/checker-type-factory.d.ts +2 -2
- package/dist/api/compiler/checker-type-factory.js +57 -16
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
- package/dist/api/compiler/checker-type-nodes.js +2 -2
- package/dist/api/compiler/checker-type-operators.d.ts +1 -1
- package/dist/api/compiler/checker-type-operators.js +5 -5
- package/dist/api/compiler/checker-types.d.ts +73 -7
- package/dist/api/compiler/checker-types.js +220 -43
- package/dist/api/compiler/checker-unused.d.ts +1 -1
- package/dist/api/compiler/checker-unused.js +3 -3
- package/dist/api/compiler/checker.d.ts +45 -8
- package/dist/api/compiler/checker.js +46 -9
- package/dist/api/compiler/diagnostics.d.ts +2 -8
- package/dist/api/compiler/diagnostics.js +13 -45
- package/dist/api/compiler/file-include.d.ts +35 -8
- package/dist/api/compiler/file-include.js +81 -18
- package/dist/api/compiler/file-loader.d.ts +33 -4
- package/dist/api/compiler/file-loader.js +90 -24
- package/dist/api/compiler/instantiation.d.ts +1 -1
- package/dist/api/compiler/instantiation.js +86 -50
- package/dist/api/compiler/link-tables.d.ts +69 -0
- package/dist/api/compiler/link-tables.js +236 -0
- package/dist/api/compiler/name-resolver.js +3 -3
- package/dist/api/compiler/node-builder-names.d.ts +1 -1
- package/dist/api/compiler/node-builder-names.js +12 -12
- package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
- package/dist/api/compiler/node-builder-pseudo.js +2 -1
- package/dist/api/compiler/node-builder.d.ts +1 -1
- package/dist/api/compiler/node-builder.js +16 -16
- package/dist/api/compiler/parallel-parse.d.ts +2 -0
- package/dist/api/compiler/parallel-parse.js +7 -1
- package/dist/api/compiler/parser.d.ts +33 -16
- package/dist/api/compiler/parser.js +127 -98
- package/dist/api/compiler/printer/emit-context.d.ts +5 -2
- package/dist/api/compiler/printer/emit-context.js +19 -13
- package/dist/api/compiler/printer/factory-base.js +8 -8
- package/dist/api/compiler/printer/factory.js +4 -4
- package/dist/api/compiler/printer/printer.js +6 -6
- package/dist/api/compiler/program-checker.d.ts +5 -0
- package/dist/api/compiler/program-checker.js +14 -1
- package/dist/api/compiler/program.js +9 -1
- package/dist/api/compiler/relations.d.ts +1 -1
- package/dist/api/compiler/relations.js +18 -13
- package/dist/api/compiler/reparser.js +13 -5
- package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
- package/dist/api/compiler/symbol-accessibility.js +123 -26
- package/dist/api/compiler/symbol.d.ts +45 -3
- package/dist/api/compiler/symbol.js +121 -10
- package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
- package/dist/api/compiler/transformers/alias-references.js +2 -1
- package/dist/api/compiler/transformers/class-fields.js +3 -3
- package/dist/api/compiler/transformers/commonjs-module.js +3 -3
- package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
- package/dist/api/compiler/transformers/declarations-pseudo.js +6 -4
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
- package/dist/api/compiler/transformers/declarations.js +6 -5
- package/dist/api/compiler/transformers/module.js +2 -2
- package/dist/api/compiler/transformers/optional-chain.js +3 -3
- package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
- package/dist/api/compiler/transformers/reference-resolver.js +26 -24
- package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/subtree-facts.js +9 -7
- package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/syntax-facts.js +9 -5
- package/dist/api/compiler/transformers/tagged-template.js +2 -2
- package/dist/api/compiler/transformers/type-eraser.js +2 -2
- package/dist/api/compiler/transformers/type-serialization.js +12 -12
- package/dist/api/compiler/transformers/visitor-base.js +3 -3
- package/dist/api/compiler/tsconfig.js +2 -2
- package/package.json +9 -9
- package/src/compiler/ast.ts +211 -78
- package/src/compiler/binder-utilities.ts +4 -3
- package/src/compiler/binder.ts +26 -16
- package/src/compiler/checker-calls.ts +8 -6
- package/src/compiler/checker-contextual.ts +1 -1
- package/src/compiler/checker-declaration-order.ts +2 -2
- package/src/compiler/checker-declarations.ts +21 -14
- package/src/compiler/checker-declared-types.ts +12 -12
- package/src/compiler/checker-decorators.ts +3 -3
- package/src/compiler/checker-deprecation.ts +17 -21
- package/src/compiler/checker-destructuring.ts +3 -3
- package/src/compiler/checker-elaboration.ts +8 -8
- package/src/compiler/checker-emit-helpers.ts +5 -4
- package/src/compiler/checker-emit-resolver.ts +5 -5
- package/src/compiler/checker-grammar.ts +22 -8
- package/src/compiler/checker-heritage.ts +21 -14
- package/src/compiler/checker-inference.ts +66 -34
- package/src/compiler/checker-javascript.ts +5 -5
- package/src/compiler/checker-jsx.ts +12 -8
- package/src/compiler/checker-literals.ts +2 -2
- package/src/compiler/checker-members.ts +255 -47
- package/src/compiler/checker-modules.ts +115 -14
- package/src/compiler/checker-object-literals.ts +22 -6
- package/src/compiler/checker-overloads.ts +6 -6
- package/src/compiler/checker-property-access.ts +2 -2
- package/src/compiler/checker-services.ts +2 -2
- package/src/compiler/checker-signatures.ts +9 -9
- package/src/compiler/checker-symbol-types.ts +20 -940
- package/src/compiler/checker-symbols.ts +42 -35
- package/src/compiler/checker-type-factory.ts +53 -16
- package/src/compiler/checker-type-nodes.ts +2 -2
- package/src/compiler/checker-type-operators.ts +13 -5
- package/src/compiler/checker-types.ts +223 -43
- package/src/compiler/checker-unused.ts +3 -3
- package/src/compiler/checker.ts +50 -9
- package/src/compiler/decoder.ts +5 -4
- package/src/compiler/diagnostics.ts +14 -48
- package/src/compiler/encoder.ts +10 -5
- package/src/compiler/file-include.ts +85 -17
- package/src/compiler/file-loader.ts +104 -35
- package/src/compiler/incremental.ts +39 -5
- package/src/compiler/instantiation.ts +99 -55
- package/src/compiler/link-tables.ts +245 -0
- package/src/compiler/name-resolver.ts +3 -3
- package/src/compiler/node-builder-names.ts +21 -19
- package/src/compiler/node-builder-pseudo.ts +2 -2
- package/src/compiler/node-builder.ts +24 -16
- package/src/compiler/parallel-check.ts +11 -8
- package/src/compiler/parallel-parse.ts +8 -1
- package/src/compiler/parse-thread.ts +0 -4
- package/src/compiler/parser.ts +173 -93
- package/src/compiler/printer/emit-context.ts +20 -15
- package/src/compiler/printer/factory-base.ts +14 -7
- package/src/compiler/printer/factory.ts +5 -3
- package/src/compiler/printer/printer.ts +8 -6
- package/src/compiler/program-checker.ts +12 -1
- package/src/compiler/program.ts +8 -1
- package/src/compiler/relations.ts +20 -12
- package/src/compiler/reparser.ts +14 -4
- package/src/compiler/symbol-accessibility.ts +120 -25
- package/src/compiler/symbol.ts +127 -9
- package/src/compiler/transformers/alias-references.ts +2 -2
- package/src/compiler/transformers/class-fields.ts +12 -2
- package/src/compiler/transformers/commonjs-module.ts +3 -2
- package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
- package/src/compiler/transformers/declarations-pseudo.ts +9 -5
- package/src/compiler/transformers/declarations-syntactic.ts +17 -9
- package/src/compiler/transformers/declarations-tracker.ts +3 -3
- package/src/compiler/transformers/declarations.ts +7 -7
- package/src/compiler/transformers/module.ts +2 -1
- package/src/compiler/transformers/optional-chain.ts +5 -2
- package/src/compiler/transformers/reference-resolver.ts +37 -25
- package/src/compiler/transformers/subtree-facts.ts +15 -6
- package/src/compiler/transformers/syntax-facts.ts +10 -5
- package/src/compiler/transformers/tagged-template.ts +2 -2
- package/src/compiler/transformers/type-eraser.ts +2 -1
- package/src/compiler/transformers/type-serialization.ts +12 -12
- package/src/compiler/transformers/visitor-base.ts +10 -5
- package/src/compiler/tsc-build.ts +17 -13
- package/src/compiler/tsc-cli.ts +9 -6
- package/src/compiler/tsc-compile.ts +16 -7
- package/src/compiler/tsc-watch.ts +94 -26
- package/src/compiler/tsconfig.ts +2 -1
|
@@ -112,7 +112,6 @@ import {
|
|
|
112
112
|
tryExtractTSExtension,
|
|
113
113
|
tryGetExtensionFromPath,
|
|
114
114
|
} from './path.js';
|
|
115
|
-
import { InternalSymbolName, type Symbol, SymbolFlags, type SymbolTable, getSymbolId } from './symbol.js';
|
|
116
115
|
import { SyntaxKind } from './syntax-kind.js';
|
|
117
116
|
import { isExpressionNode } from './transformers/alias-references.js';
|
|
118
117
|
import { type Checker, type CheckerHost, createDiagnosticForNode } from './checker.js';
|
|
@@ -162,6 +161,17 @@ import { createPromiseType } from './checker-iteration.js';
|
|
|
162
161
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
163
162
|
import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
|
|
164
163
|
import { grammarErrorOnNode } from './checker-operators.js';
|
|
164
|
+
import {
|
|
165
|
+
declarationAt,
|
|
166
|
+
declarationCount,
|
|
167
|
+
getDeclarations,
|
|
168
|
+
getSymbolId,
|
|
169
|
+
InternalSymbolName,
|
|
170
|
+
setDeclarations,
|
|
171
|
+
type Symbol,
|
|
172
|
+
SymbolFlags,
|
|
173
|
+
type SymbolTable,
|
|
174
|
+
} from './symbol.js';
|
|
165
175
|
|
|
166
176
|
// ---- Resolution
|
|
167
177
|
|
|
@@ -216,6 +226,22 @@ export function resolveExternalModuleNameWorker(
|
|
|
216
226
|
);
|
|
217
227
|
}
|
|
218
228
|
|
|
229
|
+
/** A `resolveExternalModule` result that reported nothing, and the arguments it was computed for. */
|
|
230
|
+
export class ModuleResolution {
|
|
231
|
+
constructor(
|
|
232
|
+
readonly moduleReference: string,
|
|
233
|
+
readonly moduleNotFoundError: DiagnosticMessage | undefined,
|
|
234
|
+
readonly isForAugmentation: boolean,
|
|
235
|
+
readonly symbol: Symbol | undefined,
|
|
236
|
+
) {}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The module symbol `moduleReference` resolves to from `location`, reporting resolution errors at
|
|
241
|
+
* `errorNode`. Each name an import or export declaration lists resolves its module specifier again,
|
|
242
|
+
* with the same result and the same diagnostics: a result that reported nothing is kept for the
|
|
243
|
+
* specifier and returned to later calls from the same declaration (`sharesSpecifierContext`).
|
|
244
|
+
*/
|
|
219
245
|
export function resolveExternalModule(
|
|
220
246
|
c: Checker,
|
|
221
247
|
location: Node,
|
|
@@ -223,6 +249,80 @@ export function resolveExternalModule(
|
|
|
223
249
|
moduleNotFoundError: DiagnosticMessage | undefined,
|
|
224
250
|
errorNode: Node | undefined,
|
|
225
251
|
isForAugmentation: boolean,
|
|
252
|
+
): Symbol | undefined {
|
|
253
|
+
// An augmentation merged later can give the resolved module a new merged symbol, so results are
|
|
254
|
+
// kept only once every augmentation is merged.
|
|
255
|
+
const shared = c.modulesMerged && errorNode !== undefined && sharesSpecifierContext(location, errorNode);
|
|
256
|
+
if (shared) {
|
|
257
|
+
const known = c.moduleResolutions.get(errorNode);
|
|
258
|
+
if (
|
|
259
|
+
known !== undefined &&
|
|
260
|
+
known.moduleReference === moduleReference &&
|
|
261
|
+
known.moduleNotFoundError === moduleNotFoundError &&
|
|
262
|
+
known.isForAugmentation === isForAugmentation
|
|
263
|
+
)
|
|
264
|
+
return known.symbol;
|
|
265
|
+
}
|
|
266
|
+
const reports = c.reports;
|
|
267
|
+
const symbol = resolveExternalModuleWorker(
|
|
268
|
+
c,
|
|
269
|
+
location,
|
|
270
|
+
moduleReference,
|
|
271
|
+
moduleNotFoundError,
|
|
272
|
+
errorNode,
|
|
273
|
+
isForAugmentation,
|
|
274
|
+
);
|
|
275
|
+
if (shared && c.reports === reports)
|
|
276
|
+
c.moduleResolutions.set(
|
|
277
|
+
errorNode,
|
|
278
|
+
new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, symbol),
|
|
279
|
+
);
|
|
280
|
+
return symbol;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Whether a resolution from `location` with errors at `errorNode` depends on `location` only through
|
|
285
|
+
* the declaration that `errorNode` is the module specifier of: `location` is that declaration, a
|
|
286
|
+
* clause or specifier inside it, or the specifier itself. The resolution mode, the emittability of
|
|
287
|
+
* the import and its resolution-mode attributes then all come from that declaration.
|
|
288
|
+
*/
|
|
289
|
+
function sharesSpecifierContext(location: Node, errorNode: Node): boolean {
|
|
290
|
+
const declaration = errorNode.parent;
|
|
291
|
+
if (
|
|
292
|
+
declaration === undefined ||
|
|
293
|
+
(declaration.kind !== SyntaxKind.ImportDeclaration &&
|
|
294
|
+
declaration.kind !== SyntaxKind.JSImportDeclaration &&
|
|
295
|
+
declaration.kind !== SyntaxKind.ExportDeclaration) ||
|
|
296
|
+
getModuleSpecifier(declaration) !== errorNode
|
|
297
|
+
)
|
|
298
|
+
return false;
|
|
299
|
+
for (let current: Node | undefined = location; current !== undefined; current = current.parent)
|
|
300
|
+
switch (current.kind) {
|
|
301
|
+
case SyntaxKind.ImportDeclaration:
|
|
302
|
+
case SyntaxKind.JSImportDeclaration:
|
|
303
|
+
case SyntaxKind.ExportDeclaration:
|
|
304
|
+
return current === declaration;
|
|
305
|
+
case SyntaxKind.ImportClause:
|
|
306
|
+
case SyntaxKind.NamedImports:
|
|
307
|
+
case SyntaxKind.NamespaceImport:
|
|
308
|
+
case SyntaxKind.ImportSpecifier:
|
|
309
|
+
case SyntaxKind.NamedExports:
|
|
310
|
+
case SyntaxKind.NamespaceExport:
|
|
311
|
+
case SyntaxKind.ExportSpecifier:
|
|
312
|
+
break;
|
|
313
|
+
default:
|
|
314
|
+
if (current !== errorNode) return false;
|
|
315
|
+
}
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function resolveExternalModuleWorker(
|
|
320
|
+
c: Checker,
|
|
321
|
+
location: Node,
|
|
322
|
+
moduleReference: string,
|
|
323
|
+
moduleNotFoundError: DiagnosticMessage | undefined,
|
|
324
|
+
errorNode: Node | undefined,
|
|
325
|
+
isForAugmentation: boolean,
|
|
226
326
|
): Symbol | undefined {
|
|
227
327
|
if (errorNode !== undefined && moduleReference.startsWith('@types/'))
|
|
228
328
|
c.error(
|
|
@@ -779,7 +879,8 @@ function isOnlyImportableAsDefault(c: Checker, usage: Node, resolvedModule: Symb
|
|
|
779
879
|
const targetFile = moduleSymbol !== undefined ? getSourceFileOfModuleSymbol(moduleSymbol) : undefined;
|
|
780
880
|
return (
|
|
781
881
|
targetFile !== undefined &&
|
|
782
|
-
(isJsonSourceFile(targetFile) ||
|
|
882
|
+
(isJsonSourceFile(targetFile) ||
|
|
883
|
+
(targetFile.fileName.endsWith('.d.json.ts') && getDeclarationFileExtension(targetFile.fileName) === '.d.json.ts'))
|
|
783
884
|
);
|
|
784
885
|
}
|
|
785
886
|
|
|
@@ -787,7 +888,7 @@ function isOnlyImportableAsDefault(c: Checker, usage: Node, resolvedModule: Symb
|
|
|
787
888
|
function getSourceFileOfModuleSymbol(symbol: Symbol): SourceFile | undefined {
|
|
788
889
|
let declaration = symbol.valueDeclaration;
|
|
789
890
|
if (declaration === undefined)
|
|
790
|
-
for (const d of symbol
|
|
891
|
+
for (const d of getDeclarations(symbol))
|
|
791
892
|
if (!(isAmbientModule(d) && isModuleAugmentationExternal(d)) && !isGlobalScopeAugmentation(d)) {
|
|
792
893
|
declaration = d;
|
|
793
894
|
break;
|
|
@@ -857,7 +958,7 @@ function createDefaultPropertyWrapperForModule(
|
|
|
857
958
|
|
|
858
959
|
function cloneTypeAsModuleType(c: Checker, symbol: Symbol, moduleType: Type): Symbol {
|
|
859
960
|
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
860
|
-
result
|
|
961
|
+
setDeclarations(result, getDeclarations(symbol).slice());
|
|
861
962
|
result.valueDeclaration = symbol.valueDeclaration;
|
|
862
963
|
if (symbol.members !== undefined) result.members = new Map(symbol.members);
|
|
863
964
|
if (symbol.exports !== undefined) result.exports = new Map(symbol.exports);
|
|
@@ -869,7 +970,7 @@ function cloneTypeAsModuleType(c: Checker, symbol: Symbol, moduleType: Type): Sy
|
|
|
869
970
|
|
|
870
971
|
function getSourceFileDeclaration(symbol: Symbol | undefined): SourceFile | undefined {
|
|
871
972
|
if (symbol === undefined) return undefined;
|
|
872
|
-
for (const d of symbol
|
|
973
|
+
for (const d of getDeclarations(symbol)) if (d.kind === SyntaxKind.SourceFile) return d as SourceFile;
|
|
873
974
|
return undefined;
|
|
874
975
|
}
|
|
875
976
|
|
|
@@ -919,7 +1020,7 @@ function canHaveSyntheticDefault(
|
|
|
919
1020
|
}
|
|
920
1021
|
|
|
921
1022
|
function hasSyntacticDefault(symbol: Symbol): boolean {
|
|
922
|
-
for (const d of symbol
|
|
1023
|
+
for (const d of getDeclarations(symbol)) if (isSyntacticDefault(d)) return true;
|
|
923
1024
|
return false;
|
|
924
1025
|
}
|
|
925
1026
|
|
|
@@ -1154,7 +1255,7 @@ function reportNonDefaultExport(c: Checker, moduleSymbol: Symbol, node: Node): v
|
|
|
1154
1255
|
);
|
|
1155
1256
|
const exportStar = moduleSymbol.exports?.get(InternalSymbolName.ExportStar);
|
|
1156
1257
|
if (exportStar === undefined) return;
|
|
1157
|
-
for (const d of exportStar
|
|
1258
|
+
for (const d of getDeclarations(exportStar)) {
|
|
1158
1259
|
const specifier = getModuleSpecifier(d);
|
|
1159
1260
|
if (d.kind !== SyntaxKind.ExportDeclaration || specifier === undefined) continue;
|
|
1160
1261
|
const resolved = resolveExternalModuleName(c, d, specifier, false);
|
|
@@ -1304,9 +1405,9 @@ function combineValueAndTypeSymbols(c: Checker, valueSymbol: Symbol, typeSymbol:
|
|
|
1304
1405
|
if ((typeSymbol.flags & SymbolFlags.Value) !== 0) return typeSymbol;
|
|
1305
1406
|
if ((valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) !== 0) return valueSymbol;
|
|
1306
1407
|
const result = c.newSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
|
|
1307
|
-
const declarations = valueSymbol.
|
|
1308
|
-
for (const d of typeSymbol
|
|
1309
|
-
result
|
|
1408
|
+
const declarations = getDeclarations(valueSymbol).slice();
|
|
1409
|
+
for (const d of getDeclarations(typeSymbol)) if (!declarations.includes(d)) declarations.push(d);
|
|
1410
|
+
setDeclarations(result, declarations);
|
|
1310
1411
|
result.parent = valueSymbol.parent ?? typeSymbol.parent;
|
|
1311
1412
|
result.valueDeclaration = valueSymbol.valueDeclaration;
|
|
1312
1413
|
if (typeSymbol.members !== undefined) result.members = new Map(typeSymbol.members);
|
|
@@ -1412,10 +1513,10 @@ function reportNonExportedMember(
|
|
|
1412
1513
|
symbolToString(c, exportedSymbol),
|
|
1413
1514
|
)
|
|
1414
1515
|
: c.error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
|
|
1415
|
-
for (let i = 0; i < localSymbol
|
|
1516
|
+
for (let i = 0; i < declarationCount(localSymbol); i++)
|
|
1416
1517
|
diagnostic.addRelatedInfo(
|
|
1417
1518
|
createDiagnosticForNode(
|
|
1418
|
-
localSymbol
|
|
1519
|
+
declarationAt(localSymbol, i),
|
|
1419
1520
|
i === 0 ? Diagnostics.X_0_is_declared_here : Diagnostics.X_and_here,
|
|
1420
1521
|
[declarationName],
|
|
1421
1522
|
),
|
|
@@ -1985,7 +2086,7 @@ class ExportCollector {
|
|
|
1985
2086
|
if (exportStars !== undefined) {
|
|
1986
2087
|
const nested: SymbolTable = new Map<string, Symbol>();
|
|
1987
2088
|
const lookupTable = new Map<string, ExportCollision>();
|
|
1988
|
-
for (const node of exportStars
|
|
2089
|
+
for (const node of getDeclarations(exportStars)) {
|
|
1989
2090
|
const specifier = (node as ExportDeclaration).moduleSpecifier;
|
|
1990
2091
|
const resolved = resolveExternalModuleName(this.c, node, specifier, false);
|
|
1991
2092
|
const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
|
|
@@ -2551,7 +2652,7 @@ function checkExportSpecifier(c: Checker, node: Node): void {
|
|
|
2551
2652
|
symbol !== undefined &&
|
|
2552
2653
|
(symbol === c.undefinedSymbol ||
|
|
2553
2654
|
symbol === c.globalThisSymbol ||
|
|
2554
|
-
(symbol
|
|
2655
|
+
(declarationCount(symbol) > 0 && isGlobalSourceFile(getDeclarationContainer(symbol.declaration!))))
|
|
2555
2656
|
)
|
|
2556
2657
|
c.error(
|
|
2557
2658
|
exportedName,
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import { isAssignmentTarget } from './binder-utilities.js';
|
|
17
17
|
import { createDiagnosticForNode, type Checker } from './checker.js';
|
|
18
18
|
import { Diagnostics } from './diagnostics.js';
|
|
19
|
-
import { CheckFlags, type Symbol, SymbolFlags, internalSymbolNamePrefix, getSymbolId } from './symbol.js';
|
|
20
19
|
import { SyntaxKind } from './syntax-kind.js';
|
|
21
20
|
import {
|
|
22
21
|
CheckMode,
|
|
@@ -46,6 +45,8 @@ import {
|
|
|
46
45
|
getPropertiesOfType,
|
|
47
46
|
getPropertyOfType,
|
|
48
47
|
getReducedType,
|
|
48
|
+
keepPropertiesOnly,
|
|
49
|
+
scannedLiteralPropertiesLimit,
|
|
49
50
|
} from './checker-members.js';
|
|
50
51
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
51
52
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
@@ -76,6 +77,17 @@ import {
|
|
|
76
77
|
import { addIntraExpressionInferenceSite } from './checker-inference.js';
|
|
77
78
|
import { isEmptyObjectType } from './checker-type-factory.js';
|
|
78
79
|
import { getTypeOfExpandoObjectLiteral, isJSObjectLiteral } from './checker-javascript.js';
|
|
80
|
+
import {
|
|
81
|
+
CheckFlags,
|
|
82
|
+
copyDeclarations,
|
|
83
|
+
declarationCount,
|
|
84
|
+
getDeclarations,
|
|
85
|
+
getSymbolId,
|
|
86
|
+
internalSymbolNamePrefix,
|
|
87
|
+
setDeclarations,
|
|
88
|
+
type Symbol,
|
|
89
|
+
SymbolFlags,
|
|
90
|
+
} from './symbol.js';
|
|
79
91
|
|
|
80
92
|
/** Builds the type of the members collected since the last spread. */
|
|
81
93
|
class ObjectLiteralBuilder {
|
|
@@ -123,6 +135,8 @@ class ObjectLiteralBuilder {
|
|
|
123
135
|
if (this.patternWithComputedProperties)
|
|
124
136
|
result.objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties;
|
|
125
137
|
if (this.inDestructuringPattern) c.patternForType.set(result, this.node);
|
|
138
|
+
// A literal of a few properties keeps them as a list; a lookup by name compares their names.
|
|
139
|
+
keepPropertiesOnly(c, result, this.members, scannedLiteralPropertiesLimit);
|
|
126
140
|
return result;
|
|
127
141
|
}
|
|
128
142
|
|
|
@@ -229,7 +243,7 @@ export function checkObjectLiteral(c: Checker, node: Node, checkMode: CheckMode)
|
|
|
229
243
|
typeToString(c, contextualType!),
|
|
230
244
|
);
|
|
231
245
|
}
|
|
232
|
-
prop
|
|
246
|
+
copyDeclarations(prop, member);
|
|
233
247
|
prop.parent = member.parent;
|
|
234
248
|
prop.valueDeclaration = member.valueDeclaration;
|
|
235
249
|
c.symbolTypes.set(id, t);
|
|
@@ -317,7 +331,7 @@ function getObjectLiteralIndexInfo(c: Checker, isReadonly: boolean, properties:
|
|
|
317
331
|
(keyType === c.esSymbolType && isSymbolWithSymbolName(c, prop))
|
|
318
332
|
) {
|
|
319
333
|
propTypes.push(getTypeOfSymbol(c, prop));
|
|
320
|
-
if (isSymbolWithComputedName(prop)) components.push(prop.
|
|
334
|
+
if (isSymbolWithComputedName(prop)) components.push(prop.declaration!);
|
|
321
335
|
}
|
|
322
336
|
}
|
|
323
337
|
const unionType =
|
|
@@ -328,7 +342,7 @@ function getObjectLiteralIndexInfo(c: Checker, isReadonly: boolean, properties:
|
|
|
328
342
|
}
|
|
329
343
|
|
|
330
344
|
function getFirstDeclarationName(symbol: Symbol): Node | undefined {
|
|
331
|
-
return symbol
|
|
345
|
+
return declarationCount(symbol) !== 0 ? getName(symbol.declaration!) : undefined;
|
|
332
346
|
}
|
|
333
347
|
|
|
334
348
|
function isSymbolWithSymbolName(c: Checker, symbol: Symbol): boolean {
|
|
@@ -470,7 +484,7 @@ export function getSpreadType(
|
|
|
470
484
|
);
|
|
471
485
|
c.symbolLeftSpreads.set(id, leftProp);
|
|
472
486
|
c.symbolRightSpreads.set(id, rightProp);
|
|
473
|
-
result
|
|
487
|
+
setDeclarations(result, getDeclarations(leftProp).concat(getDeclarations(rightProp)));
|
|
474
488
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(leftProp)));
|
|
475
489
|
members.set(leftProp.name, result);
|
|
476
490
|
}
|
|
@@ -479,6 +493,7 @@ export function getSpreadType(
|
|
|
479
493
|
const spread = createAnonymousType(c, symbol, members, [], [], spreadIndexInfos);
|
|
480
494
|
spread.objectFlags |=
|
|
481
495
|
ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral | ObjectFlags.ContainsSpread | objectFlags;
|
|
496
|
+
keepPropertiesOnly(c, spread, members, scannedLiteralPropertiesLimit);
|
|
482
497
|
return spread;
|
|
483
498
|
}
|
|
484
499
|
|
|
@@ -564,12 +579,13 @@ function tryMergeUnionOfObjectTypeAndEmptyObject(c: Checker, t: Type, readonly:
|
|
|
564
579
|
id,
|
|
565
580
|
isSetonlyAccessor ? c.undefinedType : addOptionality(c, getTypeOfSymbol(c, prop), true, true),
|
|
566
581
|
);
|
|
567
|
-
result
|
|
582
|
+
copyDeclarations(result, prop);
|
|
568
583
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
569
584
|
c.symbolSyntheticOrigins.set(id, prop);
|
|
570
585
|
members.set(prop.name, result);
|
|
571
586
|
}
|
|
572
587
|
const spread = createAnonymousType(c, firstType.symbol, members, [], [], getIndexInfosOfType(c, firstType));
|
|
573
588
|
spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral;
|
|
589
|
+
keepPropertiesOnly(c, spread, members, scannedLiteralPropertiesLimit);
|
|
574
590
|
return spread;
|
|
575
591
|
}
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
} from './binder-utilities.js';
|
|
24
24
|
import { nodeIsMissing, nodeIsPresent } from './ast-utilities.js';
|
|
25
25
|
import { type DiagnosticMessage, Diagnostics } from './diagnostics.js';
|
|
26
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
27
26
|
import { SyntaxKind } from './syntax-kind.js';
|
|
28
27
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
29
28
|
import type { Signature } from './checker-types.js';
|
|
@@ -39,6 +38,7 @@ import { checkComputedPropertyName } from './checker-expressions.js';
|
|
|
39
38
|
import { hasDynamicName, hasLateBindableName } from './checker-utilities.js';
|
|
40
39
|
import { isSignatureAssignableTo, isTypeIdenticalTo, isTypeRelatedTo } from './relations.js';
|
|
41
40
|
import { getEffectiveDeclarationFlags } from './checker-declarations.js';
|
|
41
|
+
import { getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
42
42
|
|
|
43
43
|
/** Checks the overloads of a function or method declaration's local and export symbols. */
|
|
44
44
|
export function checkFunctionOrMethodSymbols(c: Checker, node: Node): void {
|
|
@@ -84,7 +84,7 @@ class OverloadChecker {
|
|
|
84
84
|
|
|
85
85
|
check(): void {
|
|
86
86
|
const c = this.c;
|
|
87
|
-
const declarations = this.symbol
|
|
87
|
+
const declarations = getDeclarations(this.symbol);
|
|
88
88
|
let someNodeFlags = ModifierFlags.None;
|
|
89
89
|
let allNodeFlags = flagsToCheck();
|
|
90
90
|
let someHaveQuestionToken = false;
|
|
@@ -184,8 +184,8 @@ class OverloadChecker {
|
|
|
184
184
|
reportClassMergedWithFunction(): void {
|
|
185
185
|
const c = this.c;
|
|
186
186
|
const classes: Node[] = [];
|
|
187
|
-
for (const d of this.symbol
|
|
188
|
-
for (const d of this.symbol
|
|
187
|
+
for (const d of getDeclarations(this.symbol)) if (d.kind === SyntaxKind.ClassDeclaration) classes.push(d);
|
|
188
|
+
for (const d of getDeclarations(this.symbol)) {
|
|
189
189
|
let message: DiagnosticMessage;
|
|
190
190
|
if (d.kind === SyntaxKind.ClassDeclaration)
|
|
191
191
|
message = Diagnostics.Class_declaration_cannot_implement_overload_list_for_0;
|
|
@@ -201,7 +201,7 @@ class OverloadChecker {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
checkFlagAgreement(
|
|
204
|
-
overloads: Node[],
|
|
204
|
+
overloads: readonly Node[],
|
|
205
205
|
implementation: Node | undefined,
|
|
206
206
|
someOverloadFlags: ModifierFlags,
|
|
207
207
|
allOverloadFlags: ModifierFlags,
|
|
@@ -290,7 +290,7 @@ class OverloadChecker {
|
|
|
290
290
|
* The declaration whose flags overloads must agree with: the implementation when it shares the first
|
|
291
291
|
* overload's container (so overloads from other files aren't reported), else the first overload.
|
|
292
292
|
*/
|
|
293
|
-
function getCanonicalOverload(overloads: Node[], implementation: Node | undefined): Node {
|
|
293
|
+
function getCanonicalOverload(overloads: readonly Node[], implementation: Node | undefined): Node {
|
|
294
294
|
return implementation !== undefined && implementation.parent === overloads[0]!.parent
|
|
295
295
|
? implementation
|
|
296
296
|
: overloads[0]!;
|
|
@@ -37,7 +37,6 @@ import {
|
|
|
37
37
|
import { isFunctionLike, isInJSFile } from './ast-utilities.js';
|
|
38
38
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
39
39
|
import { type Diagnostic, Diagnostics } from './diagnostics.js';
|
|
40
|
-
import { CheckFlags, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
41
40
|
import { SyntaxKind } from './syntax-kind.js';
|
|
42
41
|
import {
|
|
43
42
|
CheckMode,
|
|
@@ -102,6 +101,7 @@ import {
|
|
|
102
101
|
getResolvedSymbol,
|
|
103
102
|
} from './checker-expressions.js';
|
|
104
103
|
import { isJSLiteralType, isThisPropertyAccessInConstructor } from './checker-javascript.js';
|
|
104
|
+
import { CheckFlags, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
105
105
|
|
|
106
106
|
export function checkPropertyAccessExpressionOrQualifiedName(
|
|
107
107
|
c: Checker,
|
|
@@ -607,7 +607,7 @@ function checkPropertyAccessibilityAtLocation(
|
|
|
607
607
|
}
|
|
608
608
|
|
|
609
609
|
function hasClassInstancePropertyDeclaration(symbol: Symbol): boolean {
|
|
610
|
-
for (const d of symbol
|
|
610
|
+
for (const d of getDeclarations(symbol)) if (isClassInstanceProperty(d)) return true;
|
|
611
611
|
return false;
|
|
612
612
|
}
|
|
613
613
|
|
|
@@ -126,7 +126,7 @@ import {
|
|
|
126
126
|
} from './checker-type-nodes.js';
|
|
127
127
|
import { CheckMode, type Signature, type Type } from './checker-types.js';
|
|
128
128
|
import { getNodeAtPosition } from './parser.js';
|
|
129
|
-
import { CheckFlags, InternalSymbolName, type Symbol, SymbolFlags
|
|
129
|
+
import { CheckFlags, getSymbolId, InternalSymbolName, setDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
130
130
|
import { SyntaxKind } from './syntax-kind.js';
|
|
131
131
|
|
|
132
132
|
// ---- Symbols at locations
|
|
@@ -397,7 +397,7 @@ function getApplicableIndexSymbol(c: Checker, t: Type, keyType: Type): Symbol |
|
|
|
397
397
|
declarations.push(other.declaration);
|
|
398
398
|
if (declarations.length !== 0) {
|
|
399
399
|
const symbol = c.newSymbolWithCheckFlags(SymbolFlags.Property, InternalSymbolName.Index, CheckFlags.IndexSymbol);
|
|
400
|
-
symbol
|
|
400
|
+
setDeclarations(symbol, declarations);
|
|
401
401
|
symbol.valueDeclaration = declarations[0]!;
|
|
402
402
|
symbol.parent = t.symbol;
|
|
403
403
|
c.symbolTypes.set(getSymbolId(symbol), info.valueType);
|
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
getDeclarationOfKind,
|
|
31
31
|
} from './binder-utilities.js';
|
|
32
32
|
import { Diagnostics } from './diagnostics.js';
|
|
33
|
-
import { InternalSymbolName, type Symbol, SymbolFlags } from './symbol.js';
|
|
34
33
|
import { SyntaxKind } from './syntax-kind.js';
|
|
35
34
|
import type { Checker } from './checker.js';
|
|
36
35
|
import {
|
|
@@ -111,6 +110,7 @@ import { isTypeAssignableTo, type TypeComparer } from './relations.js';
|
|
|
111
110
|
import { getReturnTypeFromBody, getTypePredicateFromBody } from './checker-functions.js';
|
|
112
111
|
import { checkComputedPropertyName } from './checker-expressions.js';
|
|
113
112
|
import { hasLateBindableIndexSignature } from './checker-utilities.js';
|
|
113
|
+
import { declarationCount, getDeclarations, InternalSymbolName, type Symbol, SymbolFlags } from './symbol.js';
|
|
114
114
|
|
|
115
115
|
// ---- From declarations
|
|
116
116
|
|
|
@@ -118,7 +118,7 @@ import { hasLateBindableIndexSignature } from './checker-utilities.js';
|
|
|
118
118
|
export function getSignaturesOfSymbol(c: Checker, symbol: Symbol | undefined): Signature[] {
|
|
119
119
|
if (symbol === undefined) return [];
|
|
120
120
|
const result: Signature[] = [];
|
|
121
|
-
const declarations = symbol
|
|
121
|
+
const declarations = getDeclarations(symbol);
|
|
122
122
|
for (let i = 0; i < declarations.length; i++) {
|
|
123
123
|
const decl = declarations[i]!;
|
|
124
124
|
if (!isFunctionLikeNode(decl)) continue;
|
|
@@ -362,7 +362,7 @@ export function getReturnTypeFromAnnotation(c: Checker, declaration: Node): Type
|
|
|
362
362
|
if (declaration.kind === SyntaxKind.GetAccessor) {
|
|
363
363
|
const symbol = getSymbolOfDeclaration(c, declaration);
|
|
364
364
|
if (symbol !== undefined) {
|
|
365
|
-
const setter = symbol.
|
|
365
|
+
const setter = getDeclarations(symbol).find((d) => d.kind === SyntaxKind.SetAccessor);
|
|
366
366
|
if (setter !== undefined) {
|
|
367
367
|
const parameters = getParameters(setter);
|
|
368
368
|
if (parameters !== undefined) {
|
|
@@ -898,7 +898,7 @@ export function getIndexInfosOfIndexSymbol(c: Checker, indexSymbol: Symbol, sibl
|
|
|
898
898
|
let readonlyNumber = true;
|
|
899
899
|
let readonlySymbol = true;
|
|
900
900
|
const propertySymbols: Symbol[] = [];
|
|
901
|
-
for (const declaration of indexSymbol
|
|
901
|
+
for (const declaration of getDeclarations(indexSymbol)) {
|
|
902
902
|
if (declaration.kind === SyntaxKind.IndexSignature) {
|
|
903
903
|
const parameters = getParameters(declaration)?.nodes ?? [];
|
|
904
904
|
const returnTypeNode = getType(declaration);
|
|
@@ -952,7 +952,7 @@ import { ContextFlags, getContextualTypeEx } from './checker-contextual.js';
|
|
|
952
952
|
/** Whether `symbol` is a known symbol or has a computed name of a symbol type. */
|
|
953
953
|
function isSymbolWithSymbolName(c: Checker, symbol: Symbol): boolean {
|
|
954
954
|
if (symbol.name.startsWith('\ufffe@')) return true;
|
|
955
|
-
const name = symbol
|
|
955
|
+
const name = declarationCount(symbol) !== 0 ? getName(symbol.declaration!) : undefined;
|
|
956
956
|
return (
|
|
957
957
|
name !== undefined &&
|
|
958
958
|
name.kind === SyntaxKind.ComputedPropertyName &&
|
|
@@ -963,7 +963,7 @@ function isSymbolWithSymbolName(c: Checker, symbol: Symbol): boolean {
|
|
|
963
963
|
/** Whether `symbol` has a numeric name, or a computed name of a number type. */
|
|
964
964
|
function isSymbolWithNumericName(c: Checker, symbol: Symbol): boolean {
|
|
965
965
|
if (isNumericLiteralName(symbol.name)) return true;
|
|
966
|
-
const name = symbol
|
|
966
|
+
const name = declarationCount(symbol) !== 0 ? getName(symbol.declaration!) : undefined;
|
|
967
967
|
if (name === undefined) return false;
|
|
968
968
|
if (name.kind === SyntaxKind.ComputedPropertyName)
|
|
969
969
|
return isTypeAssignableToKind(c, checkComputedPropertyName(c, name), TypeFlags.NumberLike);
|
|
@@ -985,7 +985,7 @@ function getObjectLiteralIndexInfo(c: Checker, isReadonly: boolean, properties:
|
|
|
985
985
|
(keyType === c.esSymbolType && isSymbolWithSymbolName(c, prop))
|
|
986
986
|
) {
|
|
987
987
|
propTypes.push(getTypeOfSymbol(c, prop));
|
|
988
|
-
if (isSymbolWithComputedName(prop)) components.push(prop.
|
|
988
|
+
if (isSymbolWithComputedName(prop)) components.push(prop.declaration!);
|
|
989
989
|
}
|
|
990
990
|
}
|
|
991
991
|
const unionType =
|
|
@@ -996,8 +996,8 @@ function getObjectLiteralIndexInfo(c: Checker, isReadonly: boolean, properties:
|
|
|
996
996
|
}
|
|
997
997
|
|
|
998
998
|
function isSymbolWithComputedName(symbol: Symbol): boolean {
|
|
999
|
-
if (symbol
|
|
1000
|
-
const name = getName(symbol.
|
|
999
|
+
if (declarationCount(symbol) === 0) return false;
|
|
1000
|
+
const name = getName(symbol.declaration!);
|
|
1001
1001
|
return name !== undefined && name.kind === SyntaxKind.ComputedPropertyName;
|
|
1002
1002
|
}
|
|
1003
1003
|
|