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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { BinaryExpression, BindingElement, BindingPattern, ClassExpression, ExportDeclaration, ImportEqualsDeclaration, VariableDeclaration, getExpression, getInitializer, getLocals, getName, getNodeId, getText, getType, } from './ast.js';
|
|
5
5
|
import { isAmbientModule, isInJSFile } from './ast-utilities.js';
|
|
6
6
|
import { getCombinedModifierFlags, getRootDeclaration, getSourceFileOfNode, hasSyntacticModifier, isAccessExpression, isEntityNameExpression, isExportsIdentifier, isExternalModule, isExternalOrCommonJSModule, isGlobalSourceFile, isModuleExportsAccessExpression, } from './binder-utilities.js';
|
|
7
|
-
import { SymbolAccessibilityCaches } from './checker.js';
|
|
7
|
+
import { ExternalModuleContainerIndex, SymbolAccessibilityCaches, fileIndexScale } from './checker.js';
|
|
8
8
|
import { getEffectiveDeclarationFlags } from './checker-declarations.js';
|
|
9
9
|
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
10
10
|
import { checkExpressionCached } from './checker-expressions.js';
|
|
@@ -12,11 +12,11 @@ import { resolveExternalModuleName, resolveExternalModuleSymbol } from './checke
|
|
|
12
12
|
import { getExportsOfSymbol, getMergedSymbol, getParentOfSymbol, getSymbolFlags, getSymbolOfDeclaration, resolveAlias, resolveSymbol, } from './checker-symbols.js';
|
|
13
13
|
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
14
14
|
import { compareSymbols } from './checker-type-factory.js';
|
|
15
|
-
import { getSymbolId } from './symbol.js';
|
|
16
15
|
import { SymbolAccessibilityResult, accessible } from './transformers/declarations-resolver.js';
|
|
17
16
|
import { getAnyImportSyntax, getDeclarationContainer, isExternalModuleAugmentation, isLateVisibilityPaintedStatement, } from './transformers/declarations-syntactic.js';
|
|
18
17
|
import { isImplicitlyExportedJSDocDeclaration } from './binder-utilities.js';
|
|
19
18
|
import { symbolToString } from './type-printer.js';
|
|
19
|
+
import { declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
|
|
20
20
|
const tableKindScale = 2 ** 44;
|
|
21
21
|
function tableId(kind, id) {
|
|
22
22
|
return kind * tableKindScale + id;
|
|
@@ -61,7 +61,7 @@ function isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, meaning, shou
|
|
|
61
61
|
return result;
|
|
62
62
|
// A symbol not exported from its module, or from another module without an alias, can't be named.
|
|
63
63
|
let symbolExternalModule = undefined;
|
|
64
|
-
for (const d of symbol
|
|
64
|
+
for (const d of getDeclarations(symbol)) {
|
|
65
65
|
symbolExternalModule = getExternalModuleContainer(c, d);
|
|
66
66
|
if (symbolExternalModule !== undefined)
|
|
67
67
|
break;
|
|
@@ -109,7 +109,7 @@ function isAnySymbolAccessible(c, symbols, enclosingDeclaration, initialSymbol,
|
|
|
109
109
|
return undefined;
|
|
110
110
|
}
|
|
111
111
|
export function hasNonGlobalAugmentationExternalModuleDeclaration(symbol) {
|
|
112
|
-
for (const d of symbol
|
|
112
|
+
for (const d of getDeclarations(symbol))
|
|
113
113
|
if (hasNonGlobalAugmentationExternalModuleSymbol(d))
|
|
114
114
|
return true;
|
|
115
115
|
return false;
|
|
@@ -128,18 +128,22 @@ function isModuleWithStringLiteralName(node) {
|
|
|
128
128
|
export function getQualifiedLeftMeaning(rightMeaning) {
|
|
129
129
|
return rightMeaning === 111551 /* SymbolFlags.Value */ ? 111551 /* SymbolFlags.Value */ : 1920 /* SymbolFlags.Namespace */;
|
|
130
130
|
}
|
|
131
|
+
/** The merged symbol `symbol` resolves to through aliases. */
|
|
132
|
+
function getResolvedTarget(c, symbol) {
|
|
133
|
+
const resolved = resolveSymbol(c, getMergedSymbol(c, symbol));
|
|
134
|
+
return resolved !== undefined ? getMergedSymbol(c, resolved) : undefined;
|
|
135
|
+
}
|
|
131
136
|
/** `s1` if both symbols resolve to the same symbol, else undefined. */
|
|
132
137
|
export function getSymbolIfSameReference(c, s1, s2) {
|
|
133
|
-
const r1 =
|
|
134
|
-
|
|
135
|
-
if (r1 !== undefined && r2 !== undefined && getMergedSymbol(c, r1) === getMergedSymbol(c, r2))
|
|
138
|
+
const r1 = getResolvedTarget(c, s1);
|
|
139
|
+
if (r1 !== undefined && r1 === getResolvedTarget(c, s2))
|
|
136
140
|
return s1;
|
|
137
141
|
return undefined;
|
|
138
142
|
}
|
|
139
143
|
// ---- Containers
|
|
140
144
|
function getWithAlternativeContainers(c, container, symbol, enclosingDeclaration, meaning) {
|
|
141
145
|
const additionalContainers = [];
|
|
142
|
-
for (const d of container
|
|
146
|
+
for (const d of getDeclarations(container)) {
|
|
143
147
|
const fileSymbol = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, container);
|
|
144
148
|
if (fileSymbol !== undefined)
|
|
145
149
|
additionalContainers.push(fileSymbol);
|
|
@@ -225,24 +229,117 @@ function getAlternativeContainingModules(c, symbol, enclosingDeclaration) {
|
|
|
225
229
|
const cached = cache.containers.get(symbolId);
|
|
226
230
|
if (cached !== undefined)
|
|
227
231
|
return cached;
|
|
228
|
-
// Search every module;
|
|
232
|
+
// Search every module; independent of the location.
|
|
233
|
+
const containers = getExternalModuleContainers(c, symbol);
|
|
234
|
+
cache.containers.set(symbolId, containers);
|
|
235
|
+
return containers;
|
|
236
|
+
}
|
|
237
|
+
/** The modules that export `symbol`, and its parent module, in program order. */
|
|
238
|
+
function getExternalModuleContainers(c, symbol) {
|
|
239
|
+
const cache = caches(c);
|
|
240
|
+
if (cache.externalModuleContainers === undefined)
|
|
241
|
+
buildExternalModuleContainerIndex(c);
|
|
242
|
+
const index = cache.externalModuleContainers;
|
|
243
|
+
// Re-entered from an alias resolved while building the index, or too many files to index.
|
|
244
|
+
if (!index.complete)
|
|
245
|
+
return scanExternalModuleContainers(c, symbol);
|
|
246
|
+
// The parent module contains the symbol even when the symbol is absent from its exports.
|
|
247
|
+
const parent = getParentOfSymbol(c, symbol);
|
|
248
|
+
let parentIndex = externalModuleFileIndex(c, parent);
|
|
249
|
+
const result = [];
|
|
250
|
+
const target = getResolvedTarget(c, symbol);
|
|
251
|
+
if (target !== undefined) {
|
|
252
|
+
const keys = index.keys;
|
|
253
|
+
const first = getSymbolId(target) * fileIndexScale;
|
|
254
|
+
let low = 0;
|
|
255
|
+
let high = keys.length;
|
|
256
|
+
while (low < high) {
|
|
257
|
+
const mid = (low + high) >>> 1;
|
|
258
|
+
if (keys[mid] < first)
|
|
259
|
+
low = mid + 1;
|
|
260
|
+
else
|
|
261
|
+
high = mid;
|
|
262
|
+
}
|
|
263
|
+
for (let i = low; i < keys.length && keys[i] < first + fileIndexScale; i++) {
|
|
264
|
+
const fileIndex = keys[i] - first;
|
|
265
|
+
if (parentIndex >= 0 && parentIndex <= fileIndex) {
|
|
266
|
+
if (parentIndex < fileIndex)
|
|
267
|
+
result.push(parent);
|
|
268
|
+
parentIndex = -1;
|
|
269
|
+
}
|
|
270
|
+
// `as`: scriptc passes an element of a subclass array only as that class.
|
|
271
|
+
result.push(getSymbolOfDeclaration(c, c.files[fileIndex]));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (parentIndex >= 0)
|
|
275
|
+
result.push(parent);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
/** The position in `Checker.files` of the external module `symbol`, or -1 for any other symbol. */
|
|
279
|
+
function externalModuleFileIndex(c, symbol) {
|
|
280
|
+
if (symbol === undefined || (symbol.flags & 512 /* SymbolFlags.ValueModule */) === 0)
|
|
281
|
+
return -1;
|
|
282
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
283
|
+
if (declaration.kind !== 307 /* SyntaxKind.SourceFile */)
|
|
284
|
+
continue;
|
|
285
|
+
const file = declaration;
|
|
286
|
+
if (isExternalModule(file) && getSymbolOfDeclaration(c, declaration) === symbol)
|
|
287
|
+
return c.fileIndex.get(file) ?? -1;
|
|
288
|
+
}
|
|
289
|
+
return -1;
|
|
290
|
+
}
|
|
291
|
+
function buildExternalModuleContainerIndex(c) {
|
|
292
|
+
const index = new ExternalModuleContainerIndex();
|
|
293
|
+
caches(c).externalModuleContainers = index;
|
|
294
|
+
if (c.files.length > fileIndexScale)
|
|
295
|
+
return;
|
|
296
|
+
const keys = [];
|
|
297
|
+
for (let fileIndex = 0; fileIndex < c.files.length; fileIndex++) {
|
|
298
|
+
const file = c.files[fileIndex];
|
|
299
|
+
if (!isExternalModule(file))
|
|
300
|
+
continue;
|
|
301
|
+
// `as`: scriptc passes an element of a subclass array only as that class.
|
|
302
|
+
const container = getSymbolOfDeclaration(c, file);
|
|
303
|
+
if (container === undefined)
|
|
304
|
+
continue;
|
|
305
|
+
for (const exported of getExportsOfSymbol(c, container).values()) {
|
|
306
|
+
const target = getResolvedTarget(c, exported);
|
|
307
|
+
if (target !== undefined)
|
|
308
|
+
keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
|
|
309
|
+
}
|
|
310
|
+
const exportEquals = container.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
311
|
+
const target = exportEquals !== undefined ? getResolvedTarget(c, exportEquals) : undefined;
|
|
312
|
+
if (target !== undefined)
|
|
313
|
+
keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
|
|
314
|
+
}
|
|
315
|
+
keys.sort((a, b) => a - b);
|
|
316
|
+
// A module that exports a symbol under several names gives it one key.
|
|
317
|
+
let kept = 0;
|
|
318
|
+
for (let i = 0; i < keys.length; i++)
|
|
319
|
+
if (kept === 0 || keys[i] !== keys[kept - 1])
|
|
320
|
+
keys[kept++] = keys[i];
|
|
321
|
+
// An exact-size copy: each checker keeps its own index for the rest of the compilation.
|
|
322
|
+
index.keys = keys.slice(0, kept);
|
|
323
|
+
index.complete = true;
|
|
324
|
+
}
|
|
325
|
+
/** The modules that export `symbol`, found by checking every module. */
|
|
326
|
+
function scanExternalModuleContainers(c, symbol) {
|
|
327
|
+
const containers = [];
|
|
229
328
|
for (const file of c.host.getSourceFiles()) {
|
|
230
329
|
if (!isExternalModule(file))
|
|
231
330
|
continue;
|
|
232
331
|
// `as`: scriptc passes a for-of element of a subclass array only as that class.
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
results.push(fileSymbol);
|
|
332
|
+
const container = getSymbolOfDeclaration(c, file);
|
|
333
|
+
if (container !== undefined && getAliasForSymbolInContainer(c, container, symbol) !== undefined)
|
|
334
|
+
containers.push(container);
|
|
237
335
|
}
|
|
238
|
-
|
|
239
|
-
return results;
|
|
336
|
+
return containers;
|
|
240
337
|
}
|
|
241
338
|
/** The variable `var a = { x: 1 }` declares, for the anonymous `__object` symbol of its literal. */
|
|
242
339
|
function getVariableDeclarationOfObjectLiteral(c, symbol, meaning) {
|
|
243
|
-
if ((meaning & 111551 /* SymbolFlags.Value */) === 0 || symbol
|
|
340
|
+
if ((meaning & 111551 /* SymbolFlags.Value */) === 0 || declarationCount(symbol) === 0)
|
|
244
341
|
return undefined;
|
|
245
|
-
const firstDecl = symbol.
|
|
342
|
+
const firstDecl = symbol.declaration;
|
|
246
343
|
const parent = firstDecl.parent;
|
|
247
344
|
if (parent === undefined || !(parent instanceof VariableDeclaration))
|
|
248
345
|
return undefined;
|
|
@@ -282,7 +379,7 @@ export function getContainersOfSymbol(c, symbol, enclosingDeclaration, meaning)
|
|
|
282
379
|
if (s !== undefined && candidates.indexOf(s) < 0)
|
|
283
380
|
candidates.push(s);
|
|
284
381
|
};
|
|
285
|
-
for (const d of symbol
|
|
382
|
+
for (const d of getDeclarations(symbol)) {
|
|
286
383
|
const parent = d.parent;
|
|
287
384
|
if (!isAmbientModule(d) && parent !== undefined) {
|
|
288
385
|
// A direct child of a module.
|
|
@@ -448,7 +545,7 @@ class ChainSearch {
|
|
|
448
545
|
(this.useOnlyExternalAliasing && !hasExternalModuleImportEqualsDeclaration(fromTable)) ||
|
|
449
546
|
(isLocalNameLookup && hasNamespaceReexportDeclaration(fromTable)) ||
|
|
450
547
|
// Exports are in scope, but export specifiers aren't.
|
|
451
|
-
(!ignoreQualification && fromTable.
|
|
548
|
+
(!ignoreQualification && getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */)))
|
|
452
549
|
continue;
|
|
453
550
|
const resolved = resolveAlias(c, fromTable);
|
|
454
551
|
const candidate = this.candidateListForSymbol(fromTable, resolved, ignoreQualification);
|
|
@@ -542,10 +639,10 @@ function compareSymbolChains(c, a, b) {
|
|
|
542
639
|
return 0;
|
|
543
640
|
}
|
|
544
641
|
function isUMDExportSymbol(symbol) {
|
|
545
|
-
return symbol
|
|
642
|
+
return declarationCount(symbol) > 0 && symbol.declaration.kind === 271 /* SyntaxKind.NamespaceExportDeclaration */;
|
|
546
643
|
}
|
|
547
644
|
function hasNamespaceReexportDeclaration(symbol) {
|
|
548
|
-
for (const d of symbol
|
|
645
|
+
for (const d of getDeclarations(symbol))
|
|
549
646
|
if (isNamespaceReexportDeclaration(d))
|
|
550
647
|
return true;
|
|
551
648
|
return false;
|
|
@@ -556,7 +653,7 @@ function isNamespaceReexportDeclaration(node) {
|
|
|
556
653
|
node.parent.moduleSpecifier !== undefined);
|
|
557
654
|
}
|
|
558
655
|
function hasExternalModuleImportEqualsDeclaration(symbol) {
|
|
559
|
-
for (const d of symbol
|
|
656
|
+
for (const d of getDeclarations(symbol))
|
|
560
657
|
if (isExternalModuleImportEqualsDeclaration(d))
|
|
561
658
|
return true;
|
|
562
659
|
return false;
|
|
@@ -576,7 +673,7 @@ export function needsQualification(c, symbol, enclosingDeclaration, meaning) {
|
|
|
576
673
|
return true;
|
|
577
674
|
// Qualify if the symbol of this name has the meaning sought.
|
|
578
675
|
const shouldResolveAlias = (fromTable.flags & 2097152 /* SymbolFlags.Alias */) !== 0 &&
|
|
579
|
-
!fromTable.
|
|
676
|
+
!getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */);
|
|
580
677
|
if (shouldResolveAlias)
|
|
581
678
|
fromTable = resolveAlias(c, fromTable);
|
|
582
679
|
const flags = shouldResolveAlias ? getSymbolFlags(c, fromTable) : fromTable.flags;
|
|
@@ -589,9 +686,9 @@ export function needsQualification(c, symbol, enclosingDeclaration, meaning) {
|
|
|
589
686
|
return qualify;
|
|
590
687
|
}
|
|
591
688
|
function isPropertyOrMethodDeclarationSymbol(symbol) {
|
|
592
|
-
if (symbol
|
|
689
|
+
if (declarationCount(symbol) === 0)
|
|
593
690
|
return false;
|
|
594
|
-
for (const declaration of symbol
|
|
691
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
595
692
|
switch (declaration.kind) {
|
|
596
693
|
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
597
694
|
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
@@ -834,7 +931,7 @@ export function hasVisibleDeclarations(c, symbol, shouldComputeAliasesToMakeVisi
|
|
|
834
931
|
if (aliases.indexOf(statement) < 0)
|
|
835
932
|
aliases.push(statement);
|
|
836
933
|
};
|
|
837
|
-
for (const declaration of symbol
|
|
934
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
838
935
|
if (declaration.kind === 79 /* SyntaxKind.Identifier */ || isDeclarationVisible(c, declaration))
|
|
839
936
|
continue;
|
|
840
937
|
// Unexported imports can name types if their parent is visible.
|
|
@@ -132,19 +132,46 @@ export declare class SymbolRareFields implements ProgramLifetime {
|
|
|
132
132
|
members: SymbolTable | undefined;
|
|
133
133
|
exports: SymbolTable | undefined;
|
|
134
134
|
exportSymbol: Symbol | undefined;
|
|
135
|
+
/** All declarations of a symbol that has more than one (`getDeclarations`). */
|
|
136
|
+
declarations: Node[] | undefined;
|
|
137
|
+
/** The value declaration where it is not the first declaration (`Symbol.valueDeclaration`). */
|
|
138
|
+
valueDeclaration: Node | undefined;
|
|
135
139
|
}
|
|
136
140
|
export declare class Symbol implements ProgramLifetime {
|
|
137
141
|
flags: SymbolFlags;
|
|
138
|
-
|
|
142
|
+
/** The check flags, and `valueDeclarationIsFirst`. */
|
|
143
|
+
private bits;
|
|
139
144
|
readonly name: string;
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
/**
|
|
146
|
+
* The first declaration. A symbol with more keeps all of them in its rare fields; read them with
|
|
147
|
+
* `declarationCount`, `declarationAt` and `getDeclarations`. Written only through `setFirst`,
|
|
148
|
+
* which keeps the value declaration.
|
|
149
|
+
*/
|
|
150
|
+
declaration: Node | undefined;
|
|
142
151
|
parent: Symbol | undefined;
|
|
143
152
|
private rareFields;
|
|
144
153
|
/** Assigned on first use by `getSymbolId`, or at creation while threads share the program; 0 until then. */
|
|
145
154
|
id: number;
|
|
146
155
|
constructor(flags: SymbolFlags, name: string);
|
|
156
|
+
get checkFlags(): CheckFlags;
|
|
157
|
+
set checkFlags(flags: CheckFlags);
|
|
158
|
+
/** Makes `node` the first declaration, keeping the value declaration. */
|
|
159
|
+
setFirst(node: Node | undefined): void;
|
|
160
|
+
/**
|
|
161
|
+
* The declaration of the symbol's value. Almost always the first declaration, which a bit of `bits`
|
|
162
|
+
* says; any other is kept in the rare fields.
|
|
163
|
+
*/
|
|
164
|
+
get valueDeclaration(): Node | undefined;
|
|
165
|
+
set valueDeclaration(node: Node | undefined);
|
|
147
166
|
private rareFieldsOrNew;
|
|
167
|
+
/**
|
|
168
|
+
* The declarations, for tsc-ts/api's `Symbol.declarations`. The compiler reads `declaration`,
|
|
169
|
+
* `declarationCount` and `declarationAt`: for a single declaration this builds a list on each read.
|
|
170
|
+
*/
|
|
171
|
+
get declarations(): readonly Node[];
|
|
172
|
+
/** All declarations where there are more than one, else undefined. */
|
|
173
|
+
get moreDeclarations(): Node[] | undefined;
|
|
174
|
+
set moreDeclarations(value: Node[] | undefined);
|
|
148
175
|
get members(): SymbolTable | undefined;
|
|
149
176
|
set members(value: SymbolTable | undefined);
|
|
150
177
|
get exports(): SymbolTable | undefined;
|
|
@@ -182,6 +209,21 @@ export declare function lastSymbolIdValue(): number;
|
|
|
182
209
|
export declare function reserveSymbolIds(last: number): void;
|
|
183
210
|
/** Appends `node` to the declarations of `symbol`. */
|
|
184
211
|
export declare function addDeclaration(symbol: Symbol, node: Node): void;
|
|
212
|
+
/** The number of declarations of `symbol`. */
|
|
213
|
+
export declare function declarationCount(symbol: Symbol): number;
|
|
214
|
+
/** The declaration of `symbol` at `index`, which is below `declarationCount(symbol)`. */
|
|
215
|
+
export declare function declarationAt(symbol: Symbol, index: number): Node;
|
|
216
|
+
/**
|
|
217
|
+
* The declarations of `symbol`, in order. A symbol with one declaration gets a new list each call;
|
|
218
|
+
* hot paths read `declaration`, `declarationCount` and `declarationAt` instead.
|
|
219
|
+
*/
|
|
220
|
+
export declare function getDeclarations(symbol: Symbol): readonly Node[];
|
|
221
|
+
/** Whether `node` is a declaration of `symbol`. */
|
|
222
|
+
export declare function hasDeclaration(symbol: Symbol, node: Node): boolean;
|
|
223
|
+
/** Gives `target` the declarations of `source`; a list of several is shared, as the list was before. */
|
|
224
|
+
export declare function copyDeclarations(target: Symbol, source: Symbol): void;
|
|
225
|
+
/** Replaces the declarations of `symbol` with `declarations`, which it keeps when they are more than one. */
|
|
226
|
+
export declare function setDeclarations(symbol: Symbol, declarations: readonly Node[]): void;
|
|
185
227
|
/** A program-wide id, assigned to each symbol when first requested. */
|
|
186
228
|
export declare function getSymbolId(symbol: Symbol): number;
|
|
187
229
|
/** The exports table of `symbol`, created if missing. */
|
|
@@ -3,27 +3,74 @@ export class SymbolRareFields {
|
|
|
3
3
|
members = undefined;
|
|
4
4
|
exports = undefined;
|
|
5
5
|
exportSymbol = undefined;
|
|
6
|
+
/** All declarations of a symbol that has more than one (`getDeclarations`). */
|
|
7
|
+
declarations = undefined;
|
|
8
|
+
/** The value declaration where it is not the first declaration (`Symbol.valueDeclaration`). */
|
|
9
|
+
valueDeclaration = undefined;
|
|
6
10
|
}
|
|
11
|
+
/** In `Symbol.bits`, above the check flags: the value declaration is the first declaration. */
|
|
12
|
+
const valueDeclarationIsFirst = 1 << 30;
|
|
7
13
|
export class Symbol {
|
|
8
14
|
flags;
|
|
9
|
-
|
|
15
|
+
/** The check flags, and `valueDeclarationIsFirst`. */
|
|
16
|
+
bits;
|
|
10
17
|
name;
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The first declaration. A symbol with more keeps all of them in its rare fields; read them with
|
|
20
|
+
* `declarationCount`, `declarationAt` and `getDeclarations`. Written only through `setFirst`,
|
|
21
|
+
* which keeps the value declaration.
|
|
22
|
+
*/
|
|
23
|
+
declaration;
|
|
13
24
|
parent;
|
|
14
25
|
rareFields;
|
|
15
26
|
/** Assigned on first use by `getSymbolId`, or at creation while threads share the program; 0 until then. */
|
|
16
27
|
id;
|
|
17
28
|
constructor(flags, name) {
|
|
18
29
|
this.flags = flags;
|
|
19
|
-
this.
|
|
30
|
+
this.bits = 0;
|
|
20
31
|
this.name = name;
|
|
21
|
-
this.
|
|
22
|
-
this.valueDeclaration = undefined;
|
|
32
|
+
this.declaration = undefined;
|
|
23
33
|
this.parent = undefined;
|
|
24
34
|
this.rareFields = undefined;
|
|
25
35
|
this.id = idsAtCreation ? takeSymbolId() : 0;
|
|
26
36
|
}
|
|
37
|
+
get checkFlags() {
|
|
38
|
+
return (this.bits & ~valueDeclarationIsFirst);
|
|
39
|
+
}
|
|
40
|
+
set checkFlags(flags) {
|
|
41
|
+
this.bits = (this.bits & valueDeclarationIsFirst) | flags;
|
|
42
|
+
}
|
|
43
|
+
/** Makes `node` the first declaration, keeping the value declaration. */
|
|
44
|
+
setFirst(node) {
|
|
45
|
+
if ((this.bits & valueDeclarationIsFirst) !== 0 && node !== this.declaration) {
|
|
46
|
+
// The value declaration stays what it was.
|
|
47
|
+
this.rareFieldsOrNew().valueDeclaration = this.declaration;
|
|
48
|
+
this.bits &= ~valueDeclarationIsFirst;
|
|
49
|
+
}
|
|
50
|
+
this.declaration = node;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The declaration of the symbol's value. Almost always the first declaration, which a bit of `bits`
|
|
54
|
+
* says; any other is kept in the rare fields.
|
|
55
|
+
*/
|
|
56
|
+
get valueDeclaration() {
|
|
57
|
+
if ((this.bits & valueDeclarationIsFirst) !== 0)
|
|
58
|
+
return this.declaration;
|
|
59
|
+
const group = this.rareFields;
|
|
60
|
+
return group === undefined ? undefined : group.valueDeclaration;
|
|
61
|
+
}
|
|
62
|
+
set valueDeclaration(node) {
|
|
63
|
+
const group = this.rareFields;
|
|
64
|
+
if (node !== undefined && node === this.declaration) {
|
|
65
|
+
this.bits |= valueDeclarationIsFirst;
|
|
66
|
+
if (group !== undefined)
|
|
67
|
+
group.valueDeclaration = undefined;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.bits &= ~valueDeclarationIsFirst;
|
|
71
|
+
if (node !== undefined || group !== undefined)
|
|
72
|
+
this.rareFieldsOrNew().valueDeclaration = node;
|
|
73
|
+
}
|
|
27
74
|
rareFieldsOrNew() {
|
|
28
75
|
let group = this.rareFields;
|
|
29
76
|
if (group === undefined) {
|
|
@@ -32,6 +79,23 @@ export class Symbol {
|
|
|
32
79
|
}
|
|
33
80
|
return group;
|
|
34
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The declarations, for tsc-ts/api's `Symbol.declarations`. The compiler reads `declaration`,
|
|
84
|
+
* `declarationCount` and `declarationAt`: for a single declaration this builds a list on each read.
|
|
85
|
+
*/
|
|
86
|
+
get declarations() {
|
|
87
|
+
return getDeclarations(this);
|
|
88
|
+
}
|
|
89
|
+
/** All declarations where there are more than one, else undefined. */
|
|
90
|
+
get moreDeclarations() {
|
|
91
|
+
const group = this.rareFields;
|
|
92
|
+
return group === undefined ? undefined : group.declarations;
|
|
93
|
+
}
|
|
94
|
+
set moreDeclarations(value) {
|
|
95
|
+
if (value === undefined && this.rareFields === undefined)
|
|
96
|
+
return;
|
|
97
|
+
this.rareFieldsOrNew().declarations = value;
|
|
98
|
+
}
|
|
35
99
|
get members() {
|
|
36
100
|
const group = this.rareFields;
|
|
37
101
|
return group === undefined ? undefined : group.members;
|
|
@@ -156,11 +220,58 @@ export function reserveSymbolIds(last) {
|
|
|
156
220
|
const noDeclarations = [];
|
|
157
221
|
/** Appends `node` to the declarations of `symbol`. */
|
|
158
222
|
export function addDeclaration(symbol, node) {
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
symbol.
|
|
223
|
+
const first = symbol.declaration;
|
|
224
|
+
if (first === undefined) {
|
|
225
|
+
symbol.setFirst(node);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const more = symbol.moreDeclarations;
|
|
229
|
+
if (more !== undefined)
|
|
230
|
+
more.push(node);
|
|
162
231
|
else
|
|
163
|
-
|
|
232
|
+
symbol.moreDeclarations = [first, node];
|
|
233
|
+
}
|
|
234
|
+
/** The number of declarations of `symbol`. */
|
|
235
|
+
export function declarationCount(symbol) {
|
|
236
|
+
if (symbol.declaration === undefined)
|
|
237
|
+
return 0;
|
|
238
|
+
const more = symbol.moreDeclarations;
|
|
239
|
+
return more !== undefined ? more.length : 1;
|
|
240
|
+
}
|
|
241
|
+
/** The declaration of `symbol` at `index`, which is below `declarationCount(symbol)`. */
|
|
242
|
+
export function declarationAt(symbol, index) {
|
|
243
|
+
return index === 0 ? symbol.declaration : symbol.moreDeclarations[index];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The declarations of `symbol`, in order. A symbol with one declaration gets a new list each call;
|
|
247
|
+
* hot paths read `declaration`, `declarationCount` and `declarationAt` instead.
|
|
248
|
+
*/
|
|
249
|
+
export function getDeclarations(symbol) {
|
|
250
|
+
const first = symbol.declaration;
|
|
251
|
+
if (first === undefined)
|
|
252
|
+
return noDeclarations;
|
|
253
|
+
const more = symbol.moreDeclarations;
|
|
254
|
+
return more !== undefined ? more : [first];
|
|
255
|
+
}
|
|
256
|
+
/** Whether `node` is a declaration of `symbol`. */
|
|
257
|
+
export function hasDeclaration(symbol, node) {
|
|
258
|
+
const first = symbol.declaration;
|
|
259
|
+
if (first === undefined)
|
|
260
|
+
return false;
|
|
261
|
+
if (first === node)
|
|
262
|
+
return true;
|
|
263
|
+
const more = symbol.moreDeclarations;
|
|
264
|
+
return more !== undefined && more.indexOf(node) >= 0;
|
|
265
|
+
}
|
|
266
|
+
/** Gives `target` the declarations of `source`; a list of several is shared, as the list was before. */
|
|
267
|
+
export function copyDeclarations(target, source) {
|
|
268
|
+
target.setFirst(source.declaration);
|
|
269
|
+
target.moreDeclarations = source.moreDeclarations;
|
|
270
|
+
}
|
|
271
|
+
/** Replaces the declarations of `symbol` with `declarations`, which it keeps when they are more than one. */
|
|
272
|
+
export function setDeclarations(symbol, declarations) {
|
|
273
|
+
symbol.setFirst(declarations.length !== 0 ? declarations[0] : undefined);
|
|
274
|
+
symbol.moreDeclarations = declarations.length > 1 ? declarations : undefined;
|
|
164
275
|
}
|
|
165
276
|
/**
|
|
166
277
|
* The symbols of `table` by escaped name, with their ids assigned, as tsc-ts's public API types them: the map's
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Node, NodeVisitor, type SourceFile } from '../ast.js';
|
|
2
2
|
import { type CompilerOptions } from '../options.js';
|
|
3
|
-
import { type Symbol } from '../symbol.js';
|
|
4
3
|
import { type ReferenceResolver } from './reference-resolver.js';
|
|
4
|
+
import { type Symbol } from '../symbol.js';
|
|
5
5
|
export declare class AliasReferences extends NodeVisitor {
|
|
6
6
|
readonly options: CompilerOptions;
|
|
7
7
|
readonly resolver: ReferenceResolver;
|
|
@@ -9,6 +9,7 @@ import { JsxEmit, getIsolatedModules, getStrictOptionValue, shouldPreserveConstE
|
|
|
9
9
|
import { getDeclarationOfAliasSymbol } from './reference-resolver.js';
|
|
10
10
|
import { getFirstConstructorWithBody, getRestParameterElementType, getSetAccessorValueParameter, nodeCanBeDecorated, } from './decorator-utilities.js';
|
|
11
11
|
import { hasDecorators, hasSyntacticModifier } from './utilities.js';
|
|
12
|
+
import { getDeclarations } from '../symbol.js';
|
|
12
13
|
export class AliasReferences extends NodeVisitor {
|
|
13
14
|
options;
|
|
14
15
|
resolver;
|
|
@@ -149,7 +150,7 @@ export class AliasReferences extends NodeVisitor {
|
|
|
149
150
|
if (symbol === undefined)
|
|
150
151
|
return undefined;
|
|
151
152
|
const kind = node.kind === 179 /* SyntaxKind.SetAccessor */ ? 178 /* SyntaxKind.GetAccessor */ : 179 /* SyntaxKind.SetAccessor */;
|
|
152
|
-
for (const declaration of symbol
|
|
153
|
+
for (const declaration of getDeclarations(symbol))
|
|
153
154
|
if (declaration.kind === kind)
|
|
154
155
|
return declaration;
|
|
155
156
|
return undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Lowers class fields, private names, static blocks and `accessor` fields: initializers move to
|
|
2
2
|
// the constructor (useDefineForClassFields: false, or targets before ES2022), private members
|
|
3
3
|
// become WeakMaps, WeakSets and hoisted functions, and static `this` and `super` refer to the class.
|
|
4
|
-
import { ArrayLiteralExpression, BinaryExpression, Block, CallExpression, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConstructorDeclaration, ElementAccessExpression, ExportAssignment, ExpressionWithTypeArguments, GetAccessorDeclaration, HeritageClause, Identifier, NodeList, ObjectLiteralExpression, ParameterDeclaration, ParenthesizedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, SetAccessorDeclaration, ShorthandPropertyAssignment, SpreadAssignment, SpreadElement, StringLiteral, TryStatement, NewExpression, ArrowFunction, CatchClause, FunctionExpression, MethodDeclaration, NodeVisitor, VoidExpression, getBody, getParameters, getInitializer, getMembers, getModifiers, getName, } from '../ast.js';
|
|
4
|
+
import { ArrayLiteralExpression, BinaryExpression, Block, CallExpression, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConstructorDeclaration, ElementAccessExpression, ExportAssignment, ExpressionWithTypeArguments, GetAccessorDeclaration, HeritageClause, Identifier, NodeList, ObjectLiteralExpression, ParameterDeclaration, ParenthesizedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, SetAccessorDeclaration, ShorthandPropertyAssignment, SpreadAssignment, SpreadElement, StringLiteral, TryStatement, NewExpression, ArrowFunction, CatchClause, FunctionExpression, MethodDeclaration, NodeVisitor, VoidExpression, getBody, getParameters, getInitializer, getMembers, getModifiers, getName, callQuestionDotToken, callTypeArguments, newCallExpression, } from '../ast.js';
|
|
5
5
|
import { isLeftHandSideExpression } from '../ast-utilities.js';
|
|
6
6
|
import { getNameOfDeclaration, hasStaticModifier, isAssignmentExpression, isAutoAccessorPropertyDeclaration, isClassLike, isDestructuringAssignment, isMethodOrAccessor, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, } from '../binder-utilities.js';
|
|
7
7
|
import { isIdentifierText } from '../scanner.js';
|
|
@@ -963,7 +963,7 @@ export class ClassFieldsTransformer extends Transformer {
|
|
|
963
963
|
if (node instanceof ParenthesizedExpression)
|
|
964
964
|
return factory.cloneNode(node, new ParenthesizedExpression(node.expression));
|
|
965
965
|
if (node instanceof CallExpression)
|
|
966
|
-
return factory.cloneNode(node,
|
|
966
|
+
return factory.cloneNode(node, newCallExpression(node.expression, callQuestionDotToken(node), callTypeArguments(node), node.arguments, node.flags, false));
|
|
967
967
|
return factory.cloneNode(node, node.deepClone());
|
|
968
968
|
}
|
|
969
969
|
visitCallExpression(node) {
|
|
@@ -980,7 +980,7 @@ export class ClassFieldsTransformer extends Transformer {
|
|
|
980
980
|
for (let i = 0; i < visitedArgs.length; i++)
|
|
981
981
|
args.push(visitedArgs[i]);
|
|
982
982
|
const optional = (node.flags & 32 /* NodeFlags.OptionalChain */) !== 0;
|
|
983
|
-
const call = factory.created(new PropertyAccessExpression(target, optional ? node
|
|
983
|
+
const call = factory.created(new PropertyAccessExpression(target, optional ? callQuestionDotToken(node) : undefined, factory.createIdentifier('call'), optional ? 32 /* NodeFlags.OptionalChain */ : 0 /* NodeFlags.None */));
|
|
984
984
|
return factory.updateCallExpression(node, call, undefined, undefined, factory.createNodeList(args), node.flags);
|
|
985
985
|
}
|
|
986
986
|
const data = this.staticSuperData(callee);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// CommonJS module output: imports become `require` calls, exports assignments to `exports`.
|
|
2
|
-
import { ArrowFunction, BinaryExpression, BindingPattern, Block, CallExpression, CaseBlock, CaseOrDefaultClause, CatchClause, ClassDeclaration, ClassExpression, DoStatement, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExternalModuleReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, LabeledStatement, NamedExports, NamespaceExport, NodeList, NodeVisitor, ObjectLiteralExpression, ArrayLiteralExpression, ParenthesizedExpression, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PropertyAssignment, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateSpan, TemplateTail, TryStatement, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, EmptyStatement, getElements, getName, } from '../ast.js';
|
|
2
|
+
import { ArrowFunction, BinaryExpression, BindingPattern, Block, CallExpression, CaseBlock, CaseOrDefaultClause, CatchClause, ClassDeclaration, ClassExpression, DoStatement, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExternalModuleReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, LabeledStatement, NamedExports, NamespaceExport, NodeList, NodeVisitor, ObjectLiteralExpression, ArrayLiteralExpression, ParenthesizedExpression, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PropertyAssignment, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateSpan, TemplateTail, TryStatement, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, EmptyStatement, getElements, getName, callQuestionDotToken, } from '../ast.js';
|
|
3
3
|
import { getExternalModuleName, isImportCall, isInJSFile, isRequireCall } from '../ast-utilities.js';
|
|
4
4
|
import { isAssignmentExpression, isDestructuringAssignment } from '../binder-utilities.js';
|
|
5
5
|
import { JsxEmit, ModuleKind, ScriptTarget, getEmitModuleKind, getEmitScriptTarget, } from '../options.js';
|
|
@@ -869,7 +869,7 @@ export class CommonJSModuleTransformer extends Transformer {
|
|
|
869
869
|
const callee = node.expression;
|
|
870
870
|
if (callee instanceof Identifier) {
|
|
871
871
|
const expression = this.visitExpressionIdentifier(callee);
|
|
872
|
-
const updated = this.factory.updateCallExpression(node, expression, node
|
|
872
|
+
const updated = this.factory.updateCallExpression(node, expression, callQuestionDotToken(node), undefined, this.visitNodes(node.arguments), node.flags);
|
|
873
873
|
if (!(expression instanceof Identifier) && (this.context.getEmitFlags(callee) & 1024 /* EmitFlags.HelperName */) === 0)
|
|
874
874
|
this.context.addEmitFlags(updated, 1048576 /* EmitFlags.IndirectCall */);
|
|
875
875
|
return updated;
|
|
@@ -938,7 +938,7 @@ export class CommonJSModuleTransformer extends Transformer {
|
|
|
938
938
|
if (rewritten !== first || visitedRest !== rest)
|
|
939
939
|
args = new NodeList(args.pos, args.end, [rewritten].concat(visitedRest));
|
|
940
940
|
}
|
|
941
|
-
return factory.updateCallExpression(node, expression, node
|
|
941
|
+
return factory.updateCallExpression(node, expression, callQuestionDotToken(node), undefined, args, node.flags);
|
|
942
942
|
}
|
|
943
943
|
visitTaggedTemplateExpression(node) {
|
|
944
944
|
const tag = node.tag;
|
|
@@ -6,6 +6,7 @@ import { isFunctionLikeDeclarationKind } from '../ast-utilities.js';
|
|
|
6
6
|
import { Diagnostic } from '../diagnostics.js';
|
|
7
7
|
import { isStatement } from '../printer/utilities.js';
|
|
8
8
|
import { isParameterPropertyDeclaration } from './utilities.js';
|
|
9
|
+
import { getDeclarations } from '../symbol.js';
|
|
9
10
|
export function createDiagnosticForNode(node, message, args) {
|
|
10
11
|
const file = getSourceFileOfNode(node);
|
|
11
12
|
const range = getErrorRangeForNode(file, node);
|
|
@@ -527,7 +528,7 @@ export function getAllAccessorDeclarations(accessor) {
|
|
|
527
528
|
let other = undefined;
|
|
528
529
|
const symbol = getSymbol(accessor);
|
|
529
530
|
if (symbol !== undefined)
|
|
530
|
-
for (const declaration of symbol
|
|
531
|
+
for (const declaration of getDeclarations(symbol))
|
|
531
532
|
if (declaration.kind === otherKind) {
|
|
532
533
|
other = declaration;
|
|
533
534
|
break;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// pseudochecker and the isolatedDeclarations rules. Annotations, literals, `as const` values
|
|
3
3
|
// and function expressions with annotated returns have pseudo-types; everything else is
|
|
4
4
|
// "inferred" and needs the checker.
|
|
5
|
-
import { ArrayLiteralExpression, ArrowFunction, FunctionExpression, MethodDeclaration, GetAccessorDeclaration, NodeVisitor, ObjectLiteralExpression, ParameterDeclaration, PrefixUnaryExpression, PropertyAssignment, PropertyDeclaration, ReturnStatement, SetAccessorDeclaration, TypeReferenceNode, VariableDeclaration, UnionTypeNode, IntersectionTypeNode, getAsteriskToken, getBody, getExpression, getName, getParameters, getPostfixToken, getSymbol, getType, getTypeParameters, } from '../ast.js';
|
|
5
|
+
import { ArrayLiteralExpression, ArrowFunction, FunctionExpression, MethodDeclaration, GetAccessorDeclaration, NodeVisitor, ObjectLiteralExpression, ParameterDeclaration, PrefixUnaryExpression, PropertyAssignment, PropertyDeclaration, ReturnStatement, SetAccessorDeclaration, TypeReferenceNode, VariableDeclaration, UnionTypeNode, IntersectionTypeNode, getAsteriskToken, getBody, getExpression, getName, getParameters, getPostfixToken, getSymbol, getType, getTypeParameters, propertyAssignmentPostfixToken, } from '../ast.js';
|
|
6
6
|
import { isFunctionLike, nodeIsMissing } from '../ast-utilities.js';
|
|
7
7
|
import { getCombinedNodeFlags, hasSyntacticModifier, isIdentifierNamed } from '../binder-utilities.js';
|
|
8
8
|
import { getAllAccessorDeclarations } from './declarations-diagnostics.js';
|
|
9
|
+
import { declarationCount, getDeclarations } from '../symbol.js';
|
|
9
10
|
export class PseudoType {
|
|
10
11
|
kind;
|
|
11
12
|
constructor(kind) {
|
|
@@ -249,7 +250,7 @@ export class PseudoChecker {
|
|
|
249
250
|
// A property declared more than once has the type of its first declaration; only the checker
|
|
250
251
|
// knows which, so the type is still written from this one but counted as uncertain.
|
|
251
252
|
const symbol = getSymbol(node);
|
|
252
|
-
if (symbol !== undefined && symbol
|
|
253
|
+
if (symbol !== undefined && declarationCount(symbol) > 1)
|
|
253
254
|
this.uncertain++;
|
|
254
255
|
if (node instanceof PropertyDeclaration) {
|
|
255
256
|
const initializer = node.initializer;
|
|
@@ -277,7 +278,8 @@ export class PseudoChecker {
|
|
|
277
278
|
const initializer = declaration.initializer;
|
|
278
279
|
// As tsgo, the file's own declarations; merged ones are left to the checker's type comparison.
|
|
279
280
|
const symbol = declaration.symbol;
|
|
280
|
-
if (initializer !== undefined &&
|
|
281
|
+
if (initializer !== undefined &&
|
|
282
|
+
(symbol === undefined || countVariableDeclarations(getDeclarations(symbol)) === 1)) {
|
|
281
283
|
if (!isContextuallyTyped(declaration)) {
|
|
282
284
|
// Const template literals may become literal types, so they aren't inferred.
|
|
283
285
|
if ((getCombinedNodeFlags(declaration) & 2 /* NodeFlags.Const */) !== 0 &&
|
|
@@ -414,7 +416,7 @@ export class PseudoChecker {
|
|
|
414
416
|
}
|
|
415
417
|
case 303 /* SyntaxKind.PropertyAssignment */: {
|
|
416
418
|
const assignment = property;
|
|
417
|
-
const postfix = assignment
|
|
419
|
+
const postfix = propertyAssignmentPostfixToken(assignment);
|
|
418
420
|
members.push(new PseudoMember(1 /* PseudoMemberKind.Property */, assignment.name, postfix !== undefined && postfix.kind === 57 /* SyntaxKind.QuestionToken */, false, undefined, [], [], this.typeFromExpression(assignment.initializer)));
|
|
419
421
|
break;
|
|
420
422
|
}
|