tsc-ts 0.0.5 → 0.0.6
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 +10 -9
- package/dist/api/compiler/ast.js +22 -16
- package/dist/api/compiler/binder-utilities.js +2 -1
- package/dist/api/compiler/binder.js +9 -8
- package/dist/api/compiler/checker-calls.js +3 -2
- 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-resolver.d.ts +1 -1
- package/dist/api/compiler/checker-emit-resolver.js +5 -4
- package/dist/api/compiler/checker-grammar.js +18 -4
- 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 +1 -1
- package/dist/api/compiler/checker-inference.js +9 -9
- 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 +5 -3
- package/dist/api/compiler/checker-members.js +75 -53
- package/dist/api/compiler/checker-modules.d.ts +1 -1
- package/dist/api/compiler/checker-modules.js +13 -13
- 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 +29 -8
- package/dist/api/compiler/checker.js +29 -9
- package/dist/api/compiler/diagnostics.d.ts +2 -8
- package/dist/api/compiler/diagnostics.js +4 -40
- 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 +4 -0
- package/dist/api/compiler/parser.d.ts +33 -16
- package/dist/api/compiler/parser.js +95 -76
- 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/program-checker.js +3 -0
- package/dist/api/compiler/program.js +9 -1
- package/dist/api/compiler/relations.d.ts +1 -1
- package/dist/api/compiler/relations.js +10 -10
- 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/declarations-diagnostics.js +2 -1
- package/dist/api/compiler/transformers/declarations-pseudo.js +4 -2
- 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/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 +7 -5
- 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/type-serialization.js +12 -12
- package/package.json +9 -9
- package/src/compiler/ast.ts +27 -19
- package/src/compiler/binder-utilities.ts +2 -2
- package/src/compiler/binder.ts +15 -11
- package/src/compiler/checker-calls.ts +3 -3
- 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-resolver.ts +5 -5
- package/src/compiler/checker-grammar.ts +17 -5
- package/src/compiler/checker-heritage.ts +21 -14
- package/src/compiler/checker-inference.ts +17 -9
- 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 +91 -47
- package/src/compiler/checker-modules.ts +23 -13
- 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 +31 -9
- package/src/compiler/diagnostics.ts +5 -44
- 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 +5 -0
- package/src/compiler/parse-thread.ts +0 -4
- package/src/compiler/parser.ts +120 -70
- package/src/compiler/printer/emit-context.ts +20 -15
- package/src/compiler/program-checker.ts +2 -0
- package/src/compiler/program.ts +8 -1
- package/src/compiler/relations.ts +10 -10
- 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/declarations-diagnostics.ts +2 -1
- package/src/compiler/transformers/declarations-pseudo.ts +7 -4
- package/src/compiler/transformers/declarations-syntactic.ts +17 -9
- package/src/compiler/transformers/declarations-tracker.ts +3 -3
- package/src/compiler/transformers/declarations.ts +6 -6
- package/src/compiler/transformers/reference-resolver.ts +37 -25
- package/src/compiler/transformers/subtree-facts.ts +13 -5
- package/src/compiler/transformers/syntax-facts.ts +10 -5
- package/src/compiler/transformers/type-serialization.ts +12 -12
- 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
|
@@ -46,15 +46,6 @@ import {
|
|
|
46
46
|
} from './binder-utilities.js';
|
|
47
47
|
import { type Diagnostic, type DiagnosticMessage, Diagnostics, compareDiagnostics } from './diagnostics.js';
|
|
48
48
|
import { NameResolver } from './name-resolver.js';
|
|
49
|
-
import {
|
|
50
|
-
CheckFlags,
|
|
51
|
-
InternalSymbolName,
|
|
52
|
-
Symbol,
|
|
53
|
-
SymbolFlags,
|
|
54
|
-
type SymbolTable,
|
|
55
|
-
addDeclaration,
|
|
56
|
-
getSymbolId,
|
|
57
|
-
} from './symbol.js';
|
|
58
49
|
import { SyntaxKind } from './syntax-kind.js';
|
|
59
50
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
60
51
|
import {
|
|
@@ -92,6 +83,19 @@ import {
|
|
|
92
83
|
import { isJSAliasDeclaration } from './checker-javascript.js';
|
|
93
84
|
import { getFeatureMap } from './checker-features.js';
|
|
94
85
|
import { NodeBuilderInternalFlags } from './transformers/declarations-resolver.js';
|
|
86
|
+
import {
|
|
87
|
+
addDeclaration,
|
|
88
|
+
CheckFlags,
|
|
89
|
+
declarationAt,
|
|
90
|
+
declarationCount,
|
|
91
|
+
getDeclarations,
|
|
92
|
+
getSymbolId,
|
|
93
|
+
InternalSymbolName,
|
|
94
|
+
setDeclarations,
|
|
95
|
+
Symbol,
|
|
96
|
+
SymbolFlags,
|
|
97
|
+
type SymbolTable,
|
|
98
|
+
} from './symbol.js';
|
|
95
99
|
|
|
96
100
|
// ---- Name resolution
|
|
97
101
|
|
|
@@ -200,8 +204,8 @@ export class CheckerNameResolver extends NameResolver {
|
|
|
200
204
|
) {
|
|
201
205
|
const merged = getMergedSymbol(c, result);
|
|
202
206
|
if (
|
|
203
|
-
merged
|
|
204
|
-
merged.
|
|
207
|
+
declarationCount(merged) !== 0 &&
|
|
208
|
+
getDeclarations(merged).every(
|
|
205
209
|
(d) =>
|
|
206
210
|
d.kind === SyntaxKind.NamespaceExportDeclaration ||
|
|
207
211
|
(d.kind === SyntaxKind.SourceFile && (d as SourceFile).globalExports !== undefined),
|
|
@@ -259,7 +263,7 @@ export class CheckerNameResolver extends NameResolver {
|
|
|
259
263
|
const locals = isGlobal ? getLocals(lastLocation!) : undefined;
|
|
260
264
|
const nonValueSymbol = locals !== undefined ? getSymbolOfMeaning(c, locals, name, ~SymbolFlags.Value) : undefined;
|
|
261
265
|
if (nonValueSymbol !== undefined) {
|
|
262
|
-
const importDeclaration = nonValueSymbol.
|
|
266
|
+
const importDeclaration = getDeclarations(nonValueSymbol).find(
|
|
263
267
|
(d) =>
|
|
264
268
|
d.kind === SyntaxKind.ImportSpecifier ||
|
|
265
269
|
d.kind === SyntaxKind.ImportClause ||
|
|
@@ -728,7 +732,7 @@ function mergeFileGlobals(c: Checker, file: SourceFile): void {
|
|
|
728
732
|
if (locals !== undefined) {
|
|
729
733
|
const fileGlobalThis = locals.get('globalThis');
|
|
730
734
|
if (fileGlobalThis !== undefined)
|
|
731
|
-
for (const d of fileGlobalThis
|
|
735
|
+
for (const d of getDeclarations(fileGlobalThis))
|
|
732
736
|
c.addDiagnostic(
|
|
733
737
|
createDiagnosticForNode(d, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, [
|
|
734
738
|
'globalThis',
|
|
@@ -992,7 +996,7 @@ export function initializeGlobals(c: Checker): void {
|
|
|
992
996
|
// addUndefinedToGlobalsOrErrorOnRedeclaration
|
|
993
997
|
const target = globals.get('undefined');
|
|
994
998
|
if (target !== undefined) {
|
|
995
|
-
for (const declaration of target
|
|
999
|
+
for (const declaration of getDeclarations(target))
|
|
996
1000
|
if (!isTypeDeclaration(declaration))
|
|
997
1001
|
c.addDiagnostic(
|
|
998
1002
|
createDiagnosticForNode(
|
|
@@ -1052,7 +1056,7 @@ function mergeModuleAugmentation(c: Checker, moduleName: Node): void {
|
|
|
1052
1056
|
const moduleNode = moduleName.parent as ModuleDeclaration;
|
|
1053
1057
|
const augmentationSymbol = moduleNode.symbol!;
|
|
1054
1058
|
// Several augmentations in one file share a symbol; merge it once.
|
|
1055
|
-
if (augmentationSymbol.
|
|
1059
|
+
if (augmentationSymbol.declaration! !== moduleNode) return;
|
|
1056
1060
|
if (isGlobalScopeAugmentation(moduleNode)) {
|
|
1057
1061
|
if (augmentationSymbol.exports !== undefined)
|
|
1058
1062
|
mergeSymbolTable(c, c.globals, augmentationSymbol.exports, false, undefined);
|
|
@@ -1148,7 +1152,7 @@ export function mergeSymbol(c: Checker, target: Symbol, source: Symbol, unidirec
|
|
|
1148
1152
|
if ((target.flags & SymbolFlags.ConstEnumOnlyModule) === 0) sourceFlags &= ~SymbolFlags.ConstEnumOnlyModule;
|
|
1149
1153
|
target.flags |= sourceFlags;
|
|
1150
1154
|
if (source.valueDeclaration !== undefined) setValueDeclaration(target, source.valueDeclaration);
|
|
1151
|
-
for (const d of source
|
|
1155
|
+
for (const d of getDeclarations(source)) addDeclaration(target, d);
|
|
1152
1156
|
if (source.members !== undefined) {
|
|
1153
1157
|
if (target.members === undefined) target.members = new Map<string, Symbol>();
|
|
1154
1158
|
mergeSymbolTable(c, target.members, source.members, unidirectional, undefined);
|
|
@@ -1162,7 +1166,7 @@ export function mergeSymbol(c: Checker, target: Symbol, source: Symbol, unidirec
|
|
|
1162
1166
|
// `var globalThis` already reports a conflict with the built-in.
|
|
1163
1167
|
if (target !== c.globalThisSymbol)
|
|
1164
1168
|
c.error(
|
|
1165
|
-
getNameOfDeclaration(source.
|
|
1169
|
+
getNameOfDeclaration(source.declaration!),
|
|
1166
1170
|
Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity,
|
|
1167
1171
|
symbolToString(c, target),
|
|
1168
1172
|
);
|
|
@@ -1184,8 +1188,8 @@ function reportMergeSymbolError(c: Checker, target: Symbol, source: Symbol): voi
|
|
|
1184
1188
|
}
|
|
1185
1189
|
|
|
1186
1190
|
function isPlainJSFile(symbol: Symbol): boolean {
|
|
1187
|
-
if (symbol
|
|
1188
|
-
const file = getSourceFileOfNode(symbol.
|
|
1191
|
+
if (declarationCount(symbol) === 0) return false;
|
|
1192
|
+
const file = getSourceFileOfNode(symbol.declaration!);
|
|
1189
1193
|
return file.isJS() && file.checkJsDirective === undefined;
|
|
1190
1194
|
}
|
|
1191
1195
|
|
|
@@ -1196,7 +1200,8 @@ function addDuplicateDeclarationErrors(
|
|
|
1196
1200
|
name: string,
|
|
1197
1201
|
source: Symbol,
|
|
1198
1202
|
): void {
|
|
1199
|
-
for (const node of target
|
|
1203
|
+
for (const node of getDeclarations(target))
|
|
1204
|
+
addDuplicateDeclarationError(c, node, message, name, getDeclarations(source));
|
|
1200
1205
|
}
|
|
1201
1206
|
|
|
1202
1207
|
export function addDuplicateDeclarationError(
|
|
@@ -1204,7 +1209,7 @@ export function addDuplicateDeclarationError(
|
|
|
1204
1209
|
node: Node,
|
|
1205
1210
|
message: DiagnosticMessage,
|
|
1206
1211
|
name: string,
|
|
1207
|
-
relatedNodes: Node[],
|
|
1212
|
+
relatedNodes: readonly Node[],
|
|
1208
1213
|
): void {
|
|
1209
1214
|
const errorNode = getNameOfDeclaration(node) ?? node;
|
|
1210
1215
|
const error = lookupOrIssueError(c, errorNode, message, [name]);
|
|
@@ -1256,7 +1261,7 @@ export function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags {
|
|
|
1256
1261
|
|
|
1257
1262
|
export function cloneSymbol(c: Checker, symbol: Symbol): Symbol {
|
|
1258
1263
|
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
1259
|
-
result
|
|
1264
|
+
setDeclarations(result, getDeclarations(symbol).slice());
|
|
1260
1265
|
result.parent = symbol.parent;
|
|
1261
1266
|
result.valueDeclaration = symbol.valueDeclaration;
|
|
1262
1267
|
if (symbol.members !== undefined) result.members = new Map(symbol.members);
|
|
@@ -1271,7 +1276,7 @@ export function cloneSymbol(c: Checker, symbol: Symbol): Symbol {
|
|
|
1271
1276
|
*/
|
|
1272
1277
|
function copySharedSymbol(c: Checker, shared: Symbol): Symbol {
|
|
1273
1278
|
const result = c.newSymbol(shared.flags, shared.name);
|
|
1274
|
-
result
|
|
1279
|
+
setDeclarations(result, getDeclarations(shared).slice());
|
|
1275
1280
|
result.parent = shared.parent;
|
|
1276
1281
|
result.valueDeclaration = shared.valueDeclaration;
|
|
1277
1282
|
if (shared.members !== undefined) result.members = new Map(shared.members);
|
|
@@ -1315,7 +1320,7 @@ export function getSymbolOfDeclaration(c: Checker, node: Node): Symbol | undefin
|
|
|
1315
1320
|
}
|
|
1316
1321
|
|
|
1317
1322
|
function hasStaticDeclaration(symbol: Symbol): boolean {
|
|
1318
|
-
for (const d of symbol
|
|
1323
|
+
for (const d of getDeclarations(symbol)) if (hasStaticModifier(d)) return true;
|
|
1319
1324
|
return false;
|
|
1320
1325
|
}
|
|
1321
1326
|
|
|
@@ -1331,7 +1336,7 @@ export function getLateBoundSymbol(c: Checker, symbol: Symbol): Symbol {
|
|
|
1331
1336
|
} else {
|
|
1332
1337
|
// An `F[name] = …` assignment in a script has no parent. Checking its target late-binds it
|
|
1333
1338
|
// with the members of the function it's assigned to.
|
|
1334
|
-
for (const declaration of symbol
|
|
1339
|
+
for (const declaration of getDeclarations(symbol))
|
|
1335
1340
|
if (declaration instanceof BinaryExpression) checkExpressionCached(c, declaration.left);
|
|
1336
1341
|
}
|
|
1337
1342
|
}
|
|
@@ -1340,7 +1345,7 @@ export function getLateBoundSymbol(c: Checker, symbol: Symbol): Symbol {
|
|
|
1340
1345
|
}
|
|
1341
1346
|
|
|
1342
1347
|
function hasLateBindableDeclaration(c: Checker, symbol: Symbol): boolean {
|
|
1343
|
-
for (const declaration of symbol
|
|
1348
|
+
for (const declaration of getDeclarations(symbol)) if (hasLateBindableName(c, declaration)) return true;
|
|
1344
1349
|
return false;
|
|
1345
1350
|
}
|
|
1346
1351
|
|
|
@@ -1357,7 +1362,7 @@ export function getGlobalSymbol(
|
|
|
1357
1362
|
}
|
|
1358
1363
|
|
|
1359
1364
|
function getGlobalTypeDeclaration(symbol: Symbol): Node | undefined {
|
|
1360
|
-
for (const d of symbol
|
|
1365
|
+
for (const d of getDeclarations(symbol)) {
|
|
1361
1366
|
switch (d.kind) {
|
|
1362
1367
|
case SyntaxKind.ClassDeclaration:
|
|
1363
1368
|
case SyntaxKind.InterfaceDeclaration:
|
|
@@ -1490,8 +1495,8 @@ export function resolveSymbolEx(c: Checker, symbol: Symbol, dontResolveAlias: bo
|
|
|
1490
1495
|
}
|
|
1491
1496
|
|
|
1492
1497
|
export function getDeclarationOfAliasSymbol(symbol: Symbol): Node | undefined {
|
|
1493
|
-
for (let i = symbol
|
|
1494
|
-
const d = symbol
|
|
1498
|
+
for (let i = declarationCount(symbol) - 1; i >= 0; i--) {
|
|
1499
|
+
const d = declarationAt(symbol, i);
|
|
1495
1500
|
if (isAliasSymbolDeclaration(d)) return d;
|
|
1496
1501
|
}
|
|
1497
1502
|
return undefined;
|
|
@@ -1622,7 +1627,7 @@ function getResolvedMembersOrExports(c: Checker, symbol: Symbol, isStatic: boole
|
|
|
1622
1627
|
if (isStatic) links.resolvedExports = early;
|
|
1623
1628
|
else links.resolvedMembers = early;
|
|
1624
1629
|
let late: SymbolTable | undefined;
|
|
1625
|
-
for (const decl of symbol
|
|
1630
|
+
for (const decl of getDeclarations(symbol)) {
|
|
1626
1631
|
const members = getMembersOfDeclaration(decl);
|
|
1627
1632
|
if (members === undefined) continue;
|
|
1628
1633
|
for (const member of members) {
|
|
@@ -1639,7 +1644,7 @@ function getResolvedMembersOrExports(c: Checker, symbol: Symbol, isStatic: boole
|
|
|
1639
1644
|
// JavaScript `F[name] = …` assignments with late-bindable names.
|
|
1640
1645
|
const assignments = isStatic ? symbol.exports?.get(InternalSymbolName.AssignmentDeclaration) : undefined;
|
|
1641
1646
|
if (assignments !== undefined)
|
|
1642
|
-
for (const member of assignments
|
|
1647
|
+
for (const member of getDeclarations(assignments))
|
|
1643
1648
|
if (hasLateBindableName(c, member)) {
|
|
1644
1649
|
if (late === undefined) late = new Map<string, Symbol>();
|
|
1645
1650
|
lateBindMember(c, symbol, early, late, member);
|
|
@@ -1694,7 +1699,9 @@ function lateBindMember(c: Checker, parent: Symbol, early: SymbolTable, late: Sy
|
|
|
1694
1699
|
const earlySymbol = early.get(memberName);
|
|
1695
1700
|
if ((lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) !== 0) {
|
|
1696
1701
|
const declarations =
|
|
1697
|
-
earlySymbol !== undefined
|
|
1702
|
+
earlySymbol !== undefined
|
|
1703
|
+
? getDeclarations(earlySymbol).concat(getDeclarations(lateSymbol))
|
|
1704
|
+
: getDeclarations(lateSymbol);
|
|
1698
1705
|
const name =
|
|
1699
1706
|
(type.flags & 16384) !== 0 ? declarationNameToString(getSourceFileOfNode(declName), declName) : memberName;
|
|
1700
1707
|
for (const d of declarations) c.error(getNameOfDeclaration(d) ?? d, Diagnostics.Duplicate_identifier_0, name);
|
|
@@ -1723,14 +1730,14 @@ function lateBindIndexSignature(c: Checker, early: SymbolTable, late: SymbolTabl
|
|
|
1723
1730
|
late.set(InternalSymbolName.Index, indexSymbol);
|
|
1724
1731
|
}
|
|
1725
1732
|
// Unlike late-bound members, `decl` gets no late symbol: the index symbol isn't one property.
|
|
1726
|
-
if (indexSymbol
|
|
1733
|
+
if (declarationCount(indexSymbol) === 0 || (getSymbol(decl)!.flags & SymbolFlags.ReplaceableByMethod) === 0)
|
|
1727
1734
|
addDeclaration(indexSymbol, decl);
|
|
1728
1735
|
}
|
|
1729
1736
|
|
|
1730
1737
|
function addDeclarationToLateBoundSymbol(c: Checker, symbol: Symbol, member: Node, symbolFlags: SymbolFlags): void {
|
|
1731
1738
|
const memberSymbol = getSymbol(member)!;
|
|
1732
1739
|
c.symbolLinks(memberSymbol).lateSymbol = symbol;
|
|
1733
|
-
if (symbol
|
|
1740
|
+
if (declarationCount(symbol) === 0 || (memberSymbol.flags & SymbolFlags.ReplaceableByMethod) === 0) {
|
|
1734
1741
|
symbol.flags |= symbolFlags;
|
|
1735
1742
|
addDeclaration(symbol, member);
|
|
1736
1743
|
}
|
|
@@ -1754,7 +1761,7 @@ export function symbolIsValue(c: Checker, symbol: Symbol): boolean {
|
|
|
1754
1761
|
function isDeclarationContainedBy(symbol: Symbol, container: Symbol): boolean {
|
|
1755
1762
|
const declaration = symbol.valueDeclaration;
|
|
1756
1763
|
if (declaration !== undefined)
|
|
1757
|
-
for (const d of container
|
|
1764
|
+
for (const d of getDeclarations(container)) if (declaration.pos >= d.pos && declaration.end <= d.end) return true;
|
|
1758
1765
|
return false;
|
|
1759
1766
|
}
|
|
1760
1767
|
|
|
@@ -9,7 +9,6 @@ import { TypeSystemPropertyName, popTypeResolution, pushTypeResolution } from '.
|
|
|
9
9
|
import { isGenericIndexType } from './checker-type-operators.js';
|
|
10
10
|
import { compareCodePoints } from './diagnostics.js';
|
|
11
11
|
import { Diagnostics } from './diagnostic-messages.js';
|
|
12
|
-
import { CheckFlags, type Symbol, SymbolFlags, type SymbolTable, getSymbolId } from './symbol.js';
|
|
13
12
|
import type { Checker } from './checker.js';
|
|
14
13
|
import {
|
|
15
14
|
CachedTypeKind,
|
|
@@ -79,6 +78,7 @@ import {
|
|
|
79
78
|
import { addOptionality } from './checker-symbol-types.js';
|
|
80
79
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
81
80
|
import { isPartOfTypeNode } from './transformers/alias-references.js';
|
|
81
|
+
import { CheckFlags, declarationCount, getSymbolId, type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
82
82
|
|
|
83
83
|
export const enum UnionReduction {
|
|
84
84
|
None = 0,
|
|
@@ -265,7 +265,7 @@ export function createAnonymousType(
|
|
|
265
265
|
|
|
266
266
|
export function setStructuredTypeMembers(
|
|
267
267
|
c: Checker,
|
|
268
|
-
t:
|
|
268
|
+
t: Type,
|
|
269
269
|
members: SymbolTable | undefined,
|
|
270
270
|
callSignatures: Signature[],
|
|
271
271
|
constructSignatures: Signature[],
|
|
@@ -514,11 +514,11 @@ export function compareSymbols(c: Checker, s1: Symbol | undefined, s2: Symbol |
|
|
|
514
514
|
if (s1 === s2) return 0;
|
|
515
515
|
if (s1 === undefined) return 1;
|
|
516
516
|
if (s2 === undefined) return -1;
|
|
517
|
-
if (s1
|
|
518
|
-
const r = compareNodes(c, s1.
|
|
517
|
+
if (declarationCount(s1) !== 0 && declarationCount(s2) !== 0) {
|
|
518
|
+
const r = compareNodes(c, s1.declaration!, s2.declaration!);
|
|
519
519
|
if (r !== 0) return r;
|
|
520
|
-
} else if (s1
|
|
521
|
-
else if (s2
|
|
520
|
+
} else if (declarationCount(s1) !== 0) return -1;
|
|
521
|
+
else if (declarationCount(s2) !== 0) return 1;
|
|
522
522
|
const r = compareCodePoints(s1.name, s2.name);
|
|
523
523
|
if (r !== 0) return r;
|
|
524
524
|
if (structuralTies) return 0;
|
|
@@ -581,6 +581,18 @@ function compareTypeLists(c: Checker, s1: readonly Type[] | undefined, s2: reado
|
|
|
581
581
|
return 0;
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
/** compareTypeLists of the targets of two array mappers. */
|
|
585
|
+
function compareMapperTargets(c: Checker, a: ArrayTypeMapper, b: ArrayTypeMapper): number {
|
|
586
|
+
const n1 = a.targetCount();
|
|
587
|
+
const n2 = b.targetCount();
|
|
588
|
+
if (n1 !== n2) return n1 - n2;
|
|
589
|
+
for (let i = 0; i < n1; i++) {
|
|
590
|
+
const r = compareTypes(c, a.targetAt(i), b.targetAt(i));
|
|
591
|
+
if (r !== 0) return r;
|
|
592
|
+
}
|
|
593
|
+
return 0;
|
|
594
|
+
}
|
|
595
|
+
|
|
584
596
|
function compareElementLabels(n1: Node | undefined, n2: Node | undefined): number {
|
|
585
597
|
if (n1 === n2) return 0;
|
|
586
598
|
if (n1 === undefined) return -1;
|
|
@@ -626,7 +638,7 @@ export function compareTypeMappers(c: Checker, m1: TypeMapper | undefined, m2: T
|
|
|
626
638
|
const a = m1 as ArrayTypeMapper;
|
|
627
639
|
const b = m2 as ArrayTypeMapper;
|
|
628
640
|
const r = compareTypeLists(c, a.sources, b.sources);
|
|
629
|
-
return r !== 0 ? r :
|
|
641
|
+
return r !== 0 ? r : compareMapperTargets(c, a, b);
|
|
630
642
|
}
|
|
631
643
|
case TypeMapperKind.Merged: {
|
|
632
644
|
const a = m1 as MergedTypeMapper;
|
|
@@ -675,15 +687,15 @@ function declarationPlaces(c: Checker, t: Type): number[] {
|
|
|
675
687
|
const queue: Type[] = [t];
|
|
676
688
|
const seen = new Set<Type>();
|
|
677
689
|
const visit = (symbol: Symbol | undefined): void => {
|
|
678
|
-
if (symbol === undefined || symbol
|
|
679
|
-
const node = symbol.
|
|
690
|
+
if (symbol === undefined || declarationCount(symbol) === 0) return;
|
|
691
|
+
const node = symbol.declaration!;
|
|
680
692
|
const file = sourceFileOf(node);
|
|
681
693
|
(file.isDeclarationFile ? libraryPlaces : places).push((c.fileIndex.get(file) ?? 0) * 0x4000000 + node.pos);
|
|
682
694
|
};
|
|
683
695
|
const mapper = (m: TypeMapper | undefined): void => {
|
|
684
696
|
if (m === undefined) return;
|
|
685
697
|
if (m instanceof SimpleTypeMapper) queue.push(m.target);
|
|
686
|
-
else if (m instanceof ArrayTypeMapper) for (
|
|
698
|
+
else if (m instanceof ArrayTypeMapper) for (let i = 0; i < m.targetCount(); i++) queue.push(m.targetAt(i));
|
|
687
699
|
else if (m instanceof ArrayToSingleTypeMapper) queue.push(m.target);
|
|
688
700
|
else if (m instanceof MergedTypeMapper || m instanceof CompositeTypeMapper) {
|
|
689
701
|
mapper(m.m1);
|
|
@@ -928,13 +940,38 @@ export function unionContainsType(c: Checker, union: UnionType, t: Type): boolea
|
|
|
928
940
|
const types = union.types;
|
|
929
941
|
if (types.length < linearTypeSearchLimit) return indexOfType(types, t, 0) >= 0;
|
|
930
942
|
const side = sideOf(c, union);
|
|
931
|
-
let
|
|
932
|
-
if (
|
|
943
|
+
let table = side.constituentIds;
|
|
944
|
+
if (table === undefined) {
|
|
933
945
|
if (side.membershipTests++ === 0) return binarySearchTypes(c, types, t) >= 0;
|
|
934
|
-
|
|
935
|
-
side.
|
|
946
|
+
table = constituentTable(types);
|
|
947
|
+
side.constituentIds = table;
|
|
948
|
+
}
|
|
949
|
+
// Type ids are unique within a checker, so a matching id is `t` itself.
|
|
950
|
+
const key = t.id + 1;
|
|
951
|
+
const mask = table.length - 1;
|
|
952
|
+
for (let slot = Math.imul(key, 0x9e3779b1) & mask; ; slot = (slot + 1) & mask) {
|
|
953
|
+
const value = table[slot]!;
|
|
954
|
+
if (value === key) return true;
|
|
955
|
+
if (value === 0) return false;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* An open-addressing table of the ids of `types` (each plus one; zero marks an empty slot), with at
|
|
961
|
+
* least twice as many slots as types so that probes stay short.
|
|
962
|
+
*/
|
|
963
|
+
function constituentTable(types: readonly Type[]): Int32Array {
|
|
964
|
+
let size = 4;
|
|
965
|
+
while (size < types.length * 2) size *= 2;
|
|
966
|
+
const table = new Int32Array(size);
|
|
967
|
+
const mask = size - 1;
|
|
968
|
+
for (const t of types) {
|
|
969
|
+
const key = t.id + 1;
|
|
970
|
+
let slot = Math.imul(key, 0x9e3779b1) & mask;
|
|
971
|
+
while (table[slot] !== 0) slot = (slot + 1) & mask;
|
|
972
|
+
table[slot] = key;
|
|
936
973
|
}
|
|
937
|
-
return
|
|
974
|
+
return table;
|
|
938
975
|
}
|
|
939
976
|
|
|
940
977
|
/**
|
|
@@ -2101,7 +2138,7 @@ export function createTypeReferenceEx(c: Checker, target: Type, typeArguments: T
|
|
|
2101
2138
|
target.symbol,
|
|
2102
2139
|
) as TypeReference;
|
|
2103
2140
|
type.target = target;
|
|
2104
|
-
type.resolvedTypeArguments = typeArguments;
|
|
2141
|
+
type.resolvedTypeArguments = c.typeLists.intern(hash, typeArguments);
|
|
2105
2142
|
references.add(hash, type);
|
|
2106
2143
|
return type;
|
|
2107
2144
|
}
|
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
isDeclarationStatementKind,
|
|
40
40
|
} from './binder-utilities.js';
|
|
41
41
|
import { Diagnostics } from './diagnostics.js';
|
|
42
|
-
import { CheckFlags, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
43
42
|
import { SyntaxKind } from './syntax-kind.js';
|
|
44
43
|
import type { Checker } from './checker.js';
|
|
45
44
|
import {
|
|
@@ -115,6 +114,7 @@ import { checkExpression, checkExpressionCached, getResolvedSymbol } from './che
|
|
|
115
114
|
import { checkExpressionWithTypeArguments } from './checker-calls.js';
|
|
116
115
|
import { getIntendedTypeFromJSDocTypeReference } from './checker-jsdoc.js';
|
|
117
116
|
import { getCombinedNodeFlags, hasSyntacticModifier } from './binder-utilities.js';
|
|
117
|
+
import { CheckFlags, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
118
118
|
|
|
119
119
|
export function getTypeFromTypeNode(c: Checker, node: Node): Type {
|
|
120
120
|
return getConditionalFlowTypeOfType(c, getTypeFromTypeNodeWorker(c, node), node);
|
|
@@ -720,7 +720,7 @@ export function getAliasSymbolForTypeNode(c: Checker, node: Node): Symbol | unde
|
|
|
720
720
|
|
|
721
721
|
function isLocalTypeAlias(symbol: Symbol): boolean {
|
|
722
722
|
let declaration: Node | undefined;
|
|
723
|
-
for (const d of symbol
|
|
723
|
+
for (const d of getDeclarations(symbol)) {
|
|
724
724
|
if (isTypeAlias(d)) {
|
|
725
725
|
declaration = d;
|
|
726
726
|
break;
|
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
type TypeReferenceNode,
|
|
26
26
|
} from './ast.js';
|
|
27
27
|
import { Diagnostics, Diagnostic } from './diagnostics.js';
|
|
28
|
-
import { CheckFlags, InternalSymbolName, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
29
28
|
import { SyntaxKind } from './syntax-kind.js';
|
|
30
29
|
import type { Checker } from './checker.js';
|
|
31
30
|
import {
|
|
@@ -189,6 +188,15 @@ import {
|
|
|
189
188
|
instantiateReverseMappedType as instantiateReverseMappedTypeOfInference,
|
|
190
189
|
resolveReverseMappedTypeMembers as resolveReverseMappedTypeMembersOfInference,
|
|
191
190
|
} from './checker-inference.js';
|
|
191
|
+
import {
|
|
192
|
+
CheckFlags,
|
|
193
|
+
copyDeclarations,
|
|
194
|
+
declarationCount,
|
|
195
|
+
getSymbolId,
|
|
196
|
+
InternalSymbolName,
|
|
197
|
+
type Symbol,
|
|
198
|
+
SymbolFlags,
|
|
199
|
+
} from './symbol.js';
|
|
192
200
|
|
|
193
201
|
// ---- Genericity
|
|
194
202
|
|
|
@@ -1658,7 +1666,7 @@ export function resolveMappedTypeMembers(c: Checker, t: MappedType): void {
|
|
|
1658
1666
|
c.symbolKeyTypes.set(symbolId, keyType);
|
|
1659
1667
|
if (modifiersProp !== undefined) {
|
|
1660
1668
|
c.symbolSyntheticOrigins.set(symbolId, modifiersProp);
|
|
1661
|
-
if (shouldLinkPropDeclarations) prop
|
|
1669
|
+
if (shouldLinkPropDeclarations) copyDeclarations(prop, modifiersProp);
|
|
1662
1670
|
}
|
|
1663
1671
|
members.set(propName, prop);
|
|
1664
1672
|
} else if (isValidIndexKeyType(c, propNameType) || (propNameType.flags & (TypeFlags.Any | TypeFlags.Enum)) !== 0) {
|
|
@@ -2251,7 +2259,7 @@ function computeReferenceArgs(c: Checker, root: ConditionalRoot): ReferenceArgs
|
|
|
2251
2259
|
let kind = ReferenceArgKind.Fixed;
|
|
2252
2260
|
let inferTypeParameter: Type | undefined;
|
|
2253
2261
|
for (const tp of root.inferTypeParameters) {
|
|
2254
|
-
const declaration = tp.symbol?.
|
|
2262
|
+
const declaration = tp.symbol?.declaration;
|
|
2255
2263
|
if (
|
|
2256
2264
|
declaration === undefined ||
|
|
2257
2265
|
isNodeDescendantOf(declaration, argNode) ||
|
|
@@ -2265,9 +2273,9 @@ function computeReferenceArgs(c: Checker, root: ConditionalRoot): ReferenceArgs
|
|
|
2265
2273
|
const inner = skipTypeParentheses(argNode);
|
|
2266
2274
|
if (inner.kind === SyntaxKind.InferType) {
|
|
2267
2275
|
const tp = root.inferTypeParameters.find(
|
|
2268
|
-
(t) => t.symbol!.
|
|
2276
|
+
(t) => t.symbol!.declaration === (inner as InferTypeNode).typeParameter,
|
|
2269
2277
|
);
|
|
2270
|
-
if (tp !== undefined && tp.symbol
|
|
2278
|
+
if (tp !== undefined && declarationCount(tp.symbol!) === 1 && !isReferencedInOtherArg(c, tp, argNodes, i)) {
|
|
2271
2279
|
kind = ReferenceArgKind.Infer;
|
|
2272
2280
|
inferTypeParameter = tp;
|
|
2273
2281
|
}
|