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
|
@@ -2,10 +2,10 @@ import { type Identifier, type Node, type PatternAmbientModule, type SourceFile,
|
|
|
2
2
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
3
3
|
import { type Diagnostic, type DiagnosticMessage } from './diagnostics.js';
|
|
4
4
|
import { NameResolver } from './name-resolver.js';
|
|
5
|
-
import { Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
6
5
|
import { type Checker } from './checker.js';
|
|
7
6
|
import { type Type, type Signature } from './checker-types.js';
|
|
8
7
|
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
8
|
+
import { Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
9
9
|
/** The binder's name resolver with the checker's merging, alias handling and errors. */
|
|
10
10
|
export declare class CheckerNameResolver extends NameResolver {
|
|
11
11
|
readonly checker: Checker;
|
|
@@ -108,7 +108,7 @@ export declare function isAmbientModuleSymbolName(name: string): boolean;
|
|
|
108
108
|
export declare function mergeSymbolTable(c: Checker, target: SymbolTable, source: SymbolTable, unidirectional: boolean, mergedParent: Symbol | undefined): void;
|
|
109
109
|
/** Merges `source` into `target`, cloning a non-transient target first. */
|
|
110
110
|
export declare function mergeSymbol(c: Checker, target: Symbol, source: Symbol, unidirectional: boolean): Symbol;
|
|
111
|
-
export declare function addDuplicateDeclarationError(c: Checker, node: Node, message: DiagnosticMessage, name: string, relatedNodes: Node[]): void;
|
|
111
|
+
export declare function addDuplicateDeclarationError(c: Checker, node: Node, message: DiagnosticMessage, name: string, relatedNodes: readonly Node[]): void;
|
|
112
112
|
export declare function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags;
|
|
113
113
|
export declare function cloneSymbol(c: Checker, symbol: Symbol): Symbol;
|
|
114
114
|
export declare function getMergedSymbol(c: Checker, symbol: Symbol): Symbol;
|
|
@@ -10,7 +10,6 @@ import { checkResolvedBlockScopedVariable, getEmitStandardClassFields } from './
|
|
|
10
10
|
import { declarationNameToString, getNameOfDeclaration, getRootDeclaration, getSourceFileOfNode, getSourceTextOfNode, getDeclarationOfKind, getThisContainer, hasStaticModifier, isClassLike, isEntityNameExpression, isExternalOrCommonJSModule, isPartOfTypeQuery, isStatic, } from './binder-utilities.js';
|
|
11
11
|
import { compareDiagnostics } from './diagnostics.js';
|
|
12
12
|
import { NameResolver } from './name-resolver.js';
|
|
13
|
-
import { Symbol, addDeclaration, getSymbolId, } from './symbol.js';
|
|
14
13
|
import { createDiagnosticForNode } from './checker.js';
|
|
15
14
|
import { compareSymbols } from './checker-type-factory.js';
|
|
16
15
|
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
@@ -22,6 +21,7 @@ import { getLateBindableNameOfDeclaration, getPropertyNameFromType, isTypeUsable
|
|
|
22
21
|
import { checkTypeOnlyAliasUse, markAliasDeclarationOfNameIfTypeOnly, getExportsOfModuleWorker, getTargetOfAliasDeclaration, getTypeOnlyAliasDeclaration, isTypeOnlyImportOrExportDeclaration, resolveExternalModuleNameWorker, resolveExternalModuleSymbol, resolveIndirectionAlias, } from './checker-modules.js';
|
|
23
22
|
import { isJSAliasDeclaration } from './checker-javascript.js';
|
|
24
23
|
import { getFeatureMap } from './checker-features.js';
|
|
24
|
+
import { addDeclaration, declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, Symbol, } from './symbol.js';
|
|
25
25
|
// ---- Name resolution
|
|
26
26
|
/** The binder's name resolver with the checker's merging, alias handling and errors. */
|
|
27
27
|
export class CheckerNameResolver extends NameResolver {
|
|
@@ -92,8 +92,8 @@ export class CheckerNameResolver extends NameResolver {
|
|
|
92
92
|
(meaning & 111551 /* SymbolFlags.Value */) === 111551 /* SymbolFlags.Value */ &&
|
|
93
93
|
(location.flags & 4194304 /* NodeFlags.JSDoc */) === 0) {
|
|
94
94
|
const merged = getMergedSymbol(c, result);
|
|
95
|
-
if (merged
|
|
96
|
-
merged.
|
|
95
|
+
if (declarationCount(merged) !== 0 &&
|
|
96
|
+
getDeclarations(merged).every((d) => d.kind === 271 /* SyntaxKind.NamespaceExportDeclaration */ ||
|
|
97
97
|
(d.kind === 307 /* SyntaxKind.SourceFile */ && d.globalExports !== undefined)))
|
|
98
98
|
c.addErrorOrSuggestion(c.compilerOptions.allowUmdGlobalAccess !== true, createDiagnosticForNode(location, 819 /* Diagnostics.X_0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead */, [result.name]));
|
|
99
99
|
}
|
|
@@ -125,7 +125,7 @@ export class CheckerNameResolver extends NameResolver {
|
|
|
125
125
|
const locals = isGlobal ? getLocals(lastLocation) : undefined;
|
|
126
126
|
const nonValueSymbol = locals !== undefined ? getSymbolOfMeaning(c, locals, name, ~111551 /* SymbolFlags.Value */) : undefined;
|
|
127
127
|
if (nonValueSymbol !== undefined) {
|
|
128
|
-
const importDeclaration = nonValueSymbol.
|
|
128
|
+
const importDeclaration = getDeclarations(nonValueSymbol).find((d) => d.kind === 277 /* SyntaxKind.ImportSpecifier */ ||
|
|
129
129
|
d.kind === 274 /* SyntaxKind.ImportClause */ ||
|
|
130
130
|
d.kind === 275 /* SyntaxKind.NamespaceImport */ ||
|
|
131
131
|
d.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */);
|
|
@@ -469,7 +469,7 @@ function mergeFileGlobals(c, file) {
|
|
|
469
469
|
if (locals !== undefined) {
|
|
470
470
|
const fileGlobalThis = locals.get('globalThis');
|
|
471
471
|
if (fileGlobalThis !== undefined)
|
|
472
|
-
for (const d of fileGlobalThis
|
|
472
|
+
for (const d of getDeclarations(fileGlobalThis))
|
|
473
473
|
c.addDiagnostic(createDiagnosticForNode(d, 568 /* Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0 */, [
|
|
474
474
|
'globalThis',
|
|
475
475
|
]));
|
|
@@ -743,7 +743,7 @@ export function initializeGlobals(c) {
|
|
|
743
743
|
// addUndefinedToGlobalsOrErrorOnRedeclaration
|
|
744
744
|
const target = globals.get('undefined');
|
|
745
745
|
if (target !== undefined) {
|
|
746
|
-
for (const declaration of target
|
|
746
|
+
for (const declaration of getDeclarations(target))
|
|
747
747
|
if (!isTypeDeclaration(declaration))
|
|
748
748
|
c.addDiagnostic(createDiagnosticForNode(declaration, 568 /* Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0 */, ['undefined']));
|
|
749
749
|
}
|
|
@@ -791,7 +791,7 @@ function mergeModuleAugmentation(c, moduleName) {
|
|
|
791
791
|
const moduleNode = moduleName.parent;
|
|
792
792
|
const augmentationSymbol = moduleNode.symbol;
|
|
793
793
|
// Several augmentations in one file share a symbol; merge it once.
|
|
794
|
-
if (augmentationSymbol.
|
|
794
|
+
if (augmentationSymbol.declaration !== moduleNode)
|
|
795
795
|
return;
|
|
796
796
|
if (isGlobalScopeAugmentation(moduleNode)) {
|
|
797
797
|
if (augmentationSymbol.exports !== undefined)
|
|
@@ -877,7 +877,7 @@ export function mergeSymbol(c, target, source, unidirectional) {
|
|
|
877
877
|
target.flags |= sourceFlags;
|
|
878
878
|
if (source.valueDeclaration !== undefined)
|
|
879
879
|
setValueDeclaration(target, source.valueDeclaration);
|
|
880
|
-
for (const d of source
|
|
880
|
+
for (const d of getDeclarations(source))
|
|
881
881
|
addDeclaration(target, d);
|
|
882
882
|
if (source.members !== undefined) {
|
|
883
883
|
if (target.members === undefined)
|
|
@@ -895,7 +895,7 @@ export function mergeSymbol(c, target, source, unidirectional) {
|
|
|
895
895
|
else if ((target.flags & 1024 /* SymbolFlags.NamespaceModule */) !== 0) {
|
|
896
896
|
// `var globalThis` already reports a conflict with the built-in.
|
|
897
897
|
if (target !== c.globalThisSymbol)
|
|
898
|
-
c.error(getNameOfDeclaration(source.
|
|
898
|
+
c.error(getNameOfDeclaration(source.declaration), 783 /* Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity */, symbolToString(c, target));
|
|
899
899
|
}
|
|
900
900
|
else
|
|
901
901
|
reportMergeSymbolError(c, target, source);
|
|
@@ -916,14 +916,14 @@ function reportMergeSymbolError(c, target, source) {
|
|
|
916
916
|
addDuplicateDeclarationErrors(c, target, message, name, source);
|
|
917
917
|
}
|
|
918
918
|
function isPlainJSFile(symbol) {
|
|
919
|
-
if (symbol
|
|
919
|
+
if (declarationCount(symbol) === 0)
|
|
920
920
|
return false;
|
|
921
|
-
const file = getSourceFileOfNode(symbol.
|
|
921
|
+
const file = getSourceFileOfNode(symbol.declaration);
|
|
922
922
|
return file.isJS() && file.checkJsDirective === undefined;
|
|
923
923
|
}
|
|
924
924
|
function addDuplicateDeclarationErrors(c, target, message, name, source) {
|
|
925
|
-
for (const node of target
|
|
926
|
-
addDuplicateDeclarationError(c, node, message, name, source
|
|
925
|
+
for (const node of getDeclarations(target))
|
|
926
|
+
addDuplicateDeclarationError(c, node, message, name, getDeclarations(source));
|
|
927
927
|
}
|
|
928
928
|
export function addDuplicateDeclarationError(c, node, message, name, relatedNodes) {
|
|
929
929
|
const errorNode = getNameOfDeclaration(node) ?? node;
|
|
@@ -994,7 +994,7 @@ export function getExcludedSymbolFlags(flags) {
|
|
|
994
994
|
}
|
|
995
995
|
export function cloneSymbol(c, symbol) {
|
|
996
996
|
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
997
|
-
result
|
|
997
|
+
setDeclarations(result, getDeclarations(symbol).slice());
|
|
998
998
|
result.parent = symbol.parent;
|
|
999
999
|
result.valueDeclaration = symbol.valueDeclaration;
|
|
1000
1000
|
if (symbol.members !== undefined)
|
|
@@ -1010,7 +1010,7 @@ export function cloneSymbol(c, symbol) {
|
|
|
1010
1010
|
*/
|
|
1011
1011
|
function copySharedSymbol(c, shared) {
|
|
1012
1012
|
const result = c.newSymbol(shared.flags, shared.name);
|
|
1013
|
-
result
|
|
1013
|
+
setDeclarations(result, getDeclarations(shared).slice());
|
|
1014
1014
|
result.parent = shared.parent;
|
|
1015
1015
|
result.valueDeclaration = shared.valueDeclaration;
|
|
1016
1016
|
if (shared.members !== undefined)
|
|
@@ -1053,7 +1053,7 @@ export function getSymbolOfDeclaration(c, node) {
|
|
|
1053
1053
|
return symbol !== undefined ? getMergedSymbol(c, getLateBoundSymbol(c, symbol)) : undefined;
|
|
1054
1054
|
}
|
|
1055
1055
|
function hasStaticDeclaration(symbol) {
|
|
1056
|
-
for (const d of symbol
|
|
1056
|
+
for (const d of getDeclarations(symbol))
|
|
1057
1057
|
if (hasStaticModifier(d))
|
|
1058
1058
|
return true;
|
|
1059
1059
|
return false;
|
|
@@ -1074,7 +1074,7 @@ export function getLateBoundSymbol(c, symbol) {
|
|
|
1074
1074
|
else {
|
|
1075
1075
|
// An `F[name] = …` assignment in a script has no parent. Checking its target late-binds it
|
|
1076
1076
|
// with the members of the function it's assigned to.
|
|
1077
|
-
for (const declaration of symbol
|
|
1077
|
+
for (const declaration of getDeclarations(symbol))
|
|
1078
1078
|
if (declaration instanceof BinaryExpression)
|
|
1079
1079
|
checkExpressionCached(c, declaration.left);
|
|
1080
1080
|
}
|
|
@@ -1084,7 +1084,7 @@ export function getLateBoundSymbol(c, symbol) {
|
|
|
1084
1084
|
return links.lateSymbol;
|
|
1085
1085
|
}
|
|
1086
1086
|
function hasLateBindableDeclaration(c, symbol) {
|
|
1087
|
-
for (const declaration of symbol
|
|
1087
|
+
for (const declaration of getDeclarations(symbol))
|
|
1088
1088
|
if (hasLateBindableName(c, declaration))
|
|
1089
1089
|
return true;
|
|
1090
1090
|
return false;
|
|
@@ -1095,7 +1095,7 @@ export function getGlobalSymbol(c, name, meaning, diagnostic) {
|
|
|
1095
1095
|
return resolveName(c, undefined, name, meaning, diagnostic, false, false);
|
|
1096
1096
|
}
|
|
1097
1097
|
function getGlobalTypeDeclaration(symbol) {
|
|
1098
|
-
for (const d of symbol
|
|
1098
|
+
for (const d of getDeclarations(symbol)) {
|
|
1099
1099
|
switch (d.kind) {
|
|
1100
1100
|
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1101
1101
|
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
@@ -1187,8 +1187,8 @@ export function resolveSymbolEx(c, symbol, dontResolveAlias) {
|
|
|
1187
1187
|
return symbol;
|
|
1188
1188
|
}
|
|
1189
1189
|
export function getDeclarationOfAliasSymbol(symbol) {
|
|
1190
|
-
for (let i = symbol
|
|
1191
|
-
const d = symbol
|
|
1190
|
+
for (let i = declarationCount(symbol) - 1; i >= 0; i--) {
|
|
1191
|
+
const d = declarationAt(symbol, i);
|
|
1192
1192
|
if (isAliasSymbolDeclaration(d))
|
|
1193
1193
|
return d;
|
|
1194
1194
|
}
|
|
@@ -1323,7 +1323,7 @@ function getResolvedMembersOrExports(c, symbol, isStatic) {
|
|
|
1323
1323
|
else
|
|
1324
1324
|
links.resolvedMembers = early;
|
|
1325
1325
|
let late;
|
|
1326
|
-
for (const decl of symbol
|
|
1326
|
+
for (const decl of getDeclarations(symbol)) {
|
|
1327
1327
|
const members = getMembersOfDeclaration(decl);
|
|
1328
1328
|
if (members === undefined)
|
|
1329
1329
|
continue;
|
|
@@ -1345,7 +1345,7 @@ function getResolvedMembersOrExports(c, symbol, isStatic) {
|
|
|
1345
1345
|
// JavaScript `F[name] = …` assignments with late-bindable names.
|
|
1346
1346
|
const assignments = isStatic ? symbol.exports?.get("\uFFFEassignment" /* InternalSymbolName.AssignmentDeclaration */) : undefined;
|
|
1347
1347
|
if (assignments !== undefined)
|
|
1348
|
-
for (const member of assignments
|
|
1348
|
+
for (const member of getDeclarations(assignments))
|
|
1349
1349
|
if (hasLateBindableName(c, member)) {
|
|
1350
1350
|
if (late === undefined)
|
|
1351
1351
|
late = new Map();
|
|
@@ -1401,7 +1401,9 @@ function lateBindMember(c, parent, early, late, decl) {
|
|
|
1401
1401
|
}
|
|
1402
1402
|
const earlySymbol = early.get(memberName);
|
|
1403
1403
|
if ((lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) !== 0) {
|
|
1404
|
-
const declarations = earlySymbol !== undefined
|
|
1404
|
+
const declarations = earlySymbol !== undefined
|
|
1405
|
+
? getDeclarations(earlySymbol).concat(getDeclarations(lateSymbol))
|
|
1406
|
+
: getDeclarations(lateSymbol);
|
|
1405
1407
|
const name = (type.flags & 16384) !== 0 ? declarationNameToString(getSourceFileOfNode(declName), declName) : memberName;
|
|
1406
1408
|
for (const d of declarations)
|
|
1407
1409
|
c.error(getNameOfDeclaration(d) ?? d, 478 /* Diagnostics.Duplicate_identifier_0 */, name);
|
|
@@ -1430,13 +1432,13 @@ function lateBindIndexSignature(c, early, late, decl) {
|
|
|
1430
1432
|
late.set("\uFFFEindex" /* InternalSymbolName.Index */, indexSymbol);
|
|
1431
1433
|
}
|
|
1432
1434
|
// Unlike late-bound members, `decl` gets no late symbol: the index symbol isn't one property.
|
|
1433
|
-
if (indexSymbol
|
|
1435
|
+
if (declarationCount(indexSymbol) === 0 || (getSymbol(decl).flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) === 0)
|
|
1434
1436
|
addDeclaration(indexSymbol, decl);
|
|
1435
1437
|
}
|
|
1436
1438
|
function addDeclarationToLateBoundSymbol(c, symbol, member, symbolFlags) {
|
|
1437
1439
|
const memberSymbol = getSymbol(member);
|
|
1438
1440
|
c.symbolLinks(memberSymbol).lateSymbol = symbol;
|
|
1439
|
-
if (symbol
|
|
1441
|
+
if (declarationCount(symbol) === 0 || (memberSymbol.flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) === 0) {
|
|
1440
1442
|
symbol.flags |= symbolFlags;
|
|
1441
1443
|
addDeclaration(symbol, member);
|
|
1442
1444
|
}
|
|
@@ -1457,7 +1459,7 @@ export function symbolIsValue(c, symbol) {
|
|
|
1457
1459
|
function isDeclarationContainedBy(symbol, container) {
|
|
1458
1460
|
const declaration = symbol.valueDeclaration;
|
|
1459
1461
|
if (declaration !== undefined)
|
|
1460
|
-
for (const d of container
|
|
1462
|
+
for (const d of getDeclarations(container))
|
|
1461
1463
|
if (declaration.pos >= d.pos && declaration.end <= d.end)
|
|
1462
1464
|
return true;
|
|
1463
1465
|
return false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
|
-
import { type Symbol, type SymbolTable } from './symbol.js';
|
|
3
2
|
import type { Checker } from './checker.js';
|
|
4
3
|
import { ElementFlags, IndexInfo, IndexType, IndexedAccessType, IntersectionType, LiteralType, ObjectFlags, ObjectType, Signature, StructuredType, SubstitutionType, TupleElementInfo, TupleType, type Type, TypeAlias, TypeFlags, TypeMapper, TypeReference, UnionType } from './checker-types.js';
|
|
4
|
+
import { type Symbol, type SymbolTable } from './symbol.js';
|
|
5
5
|
export declare const enum UnionReduction {
|
|
6
6
|
None = 0,
|
|
7
7
|
Literal = 1,
|
|
@@ -22,7 +22,7 @@ export declare function typeListHash(types: readonly Type[], alias: TypeAlias |
|
|
|
22
22
|
export declare function newObjectType(c: Checker, objectFlags: ObjectFlags, symbol: Symbol | undefined): ObjectType;
|
|
23
23
|
export declare function newAnonymousType(c: Checker, symbol: Symbol | undefined): ObjectType;
|
|
24
24
|
export declare function createAnonymousType(c: Checker, symbol: Symbol | undefined, members: SymbolTable | undefined, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): ObjectType;
|
|
25
|
-
export declare function setStructuredTypeMembers(c: Checker, t:
|
|
25
|
+
export declare function setStructuredTypeMembers(c: Checker, t: Type, members: SymbolTable | undefined, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): void;
|
|
26
26
|
export declare function newUnionType(c: Checker, objectFlags: ObjectFlags, types: Type[]): UnionType;
|
|
27
27
|
export declare function newIntersectionType(c: Checker, objectFlags: ObjectFlags, types: Type[]): IntersectionType;
|
|
28
28
|
export declare function newIndexType(c: Checker, target: Type, indexFlags: number): IndexType;
|
|
@@ -8,7 +8,6 @@ import { getAliasForTypeNode, getTypeArgumentsOfDeferredReference } from './chec
|
|
|
8
8
|
import { popTypeResolution, pushTypeResolution } from './checker-symbols.js';
|
|
9
9
|
import { isGenericIndexType } from './checker-type-operators.js';
|
|
10
10
|
import { compareCodePoints } from './diagnostics.js';
|
|
11
|
-
import { getSymbolId } from './symbol.js';
|
|
12
11
|
import { cachedTypeKey, EvolvingArrayType, IndexInfo, IndexType, IndexedAccessType, InstantiationExpressionType, InterfaceType, IntersectionType, MappedType, ObjectType, ReverseMappedType, SubstitutionType, TemplateLiteralType, TupleElementInfo, TupleType, TypeAlias, TypeReference, UnionType, ArrayTypeMapper, ArrayToSingleTypeMapper, MergedTypeMapper, SimpleTypeMapper, emptyIndexInfos, emptySignatures, emptySymbols, emptyTypes, ReferenceCache, } from './checker-types.js';
|
|
13
12
|
import { getNamedMembers, getMembersOfSymbol } from './checker-symbols.js';
|
|
14
13
|
import { getBaseConstraintOfType, getBaseConstraintOrType, getIndexTypeOfType, getPropertiesOfType, getTypeOfPropertyOfType, isArrayLikeType, resolveStructuredTypeMembers, hasResolvedProperties, memberResolutionFlags, membersHolder, } from './checker-members.js';
|
|
@@ -19,6 +18,7 @@ import { getIndexedAccessType, isGenericMappedType, isTypeMatchedByTemplateLiter
|
|
|
19
18
|
import { addOptionality } from './checker-symbol-types.js';
|
|
20
19
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
21
20
|
import { isPartOfTypeNode } from './transformers/alias-references.js';
|
|
21
|
+
import { declarationCount, getSymbolId } from './symbol.js';
|
|
22
22
|
// ---- Keys
|
|
23
23
|
export function typeListKey(types) {
|
|
24
24
|
let key = '';
|
|
@@ -418,14 +418,14 @@ export function compareSymbols(c, s1, s2) {
|
|
|
418
418
|
return 1;
|
|
419
419
|
if (s2 === undefined)
|
|
420
420
|
return -1;
|
|
421
|
-
if (s1
|
|
422
|
-
const r = compareNodes(c, s1.
|
|
421
|
+
if (declarationCount(s1) !== 0 && declarationCount(s2) !== 0) {
|
|
422
|
+
const r = compareNodes(c, s1.declaration, s2.declaration);
|
|
423
423
|
if (r !== 0)
|
|
424
424
|
return r;
|
|
425
425
|
}
|
|
426
|
-
else if (s1
|
|
426
|
+
else if (declarationCount(s1) !== 0)
|
|
427
427
|
return -1;
|
|
428
|
-
else if (s2
|
|
428
|
+
else if (declarationCount(s2) !== 0)
|
|
429
429
|
return 1;
|
|
430
430
|
const r = compareCodePoints(s1.name, s2.name);
|
|
431
431
|
if (r !== 0)
|
|
@@ -490,6 +490,19 @@ function compareTypeLists(c, s1, s2) {
|
|
|
490
490
|
}
|
|
491
491
|
return 0;
|
|
492
492
|
}
|
|
493
|
+
/** compareTypeLists of the targets of two array mappers. */
|
|
494
|
+
function compareMapperTargets(c, a, b) {
|
|
495
|
+
const n1 = a.targetCount();
|
|
496
|
+
const n2 = b.targetCount();
|
|
497
|
+
if (n1 !== n2)
|
|
498
|
+
return n1 - n2;
|
|
499
|
+
for (let i = 0; i < n1; i++) {
|
|
500
|
+
const r = compareTypes(c, a.targetAt(i), b.targetAt(i));
|
|
501
|
+
if (r !== 0)
|
|
502
|
+
return r;
|
|
503
|
+
}
|
|
504
|
+
return 0;
|
|
505
|
+
}
|
|
493
506
|
function compareElementLabels(n1, n2) {
|
|
494
507
|
if (n1 === n2)
|
|
495
508
|
return 0;
|
|
@@ -544,7 +557,7 @@ export function compareTypeMappers(c, m1, m2) {
|
|
|
544
557
|
const a = m1;
|
|
545
558
|
const b = m2;
|
|
546
559
|
const r = compareTypeLists(c, a.sources, b.sources);
|
|
547
|
-
return r !== 0 ? r :
|
|
560
|
+
return r !== 0 ? r : compareMapperTargets(c, a, b);
|
|
548
561
|
}
|
|
549
562
|
case 3 /* TypeMapperKind.Merged */: {
|
|
550
563
|
const a = m1;
|
|
@@ -591,9 +604,9 @@ function declarationPlaces(c, t) {
|
|
|
591
604
|
const queue = [t];
|
|
592
605
|
const seen = new Set();
|
|
593
606
|
const visit = (symbol) => {
|
|
594
|
-
if (symbol === undefined || symbol
|
|
607
|
+
if (symbol === undefined || declarationCount(symbol) === 0)
|
|
595
608
|
return;
|
|
596
|
-
const node = symbol.
|
|
609
|
+
const node = symbol.declaration;
|
|
597
610
|
const file = sourceFileOf(node);
|
|
598
611
|
(file.isDeclarationFile ? libraryPlaces : places).push((c.fileIndex.get(file) ?? 0) * 0x4000000 + node.pos);
|
|
599
612
|
};
|
|
@@ -603,8 +616,8 @@ function declarationPlaces(c, t) {
|
|
|
603
616
|
if (m instanceof SimpleTypeMapper)
|
|
604
617
|
queue.push(m.target);
|
|
605
618
|
else if (m instanceof ArrayTypeMapper)
|
|
606
|
-
for (
|
|
607
|
-
queue.push(
|
|
619
|
+
for (let i = 0; i < m.targetCount(); i++)
|
|
620
|
+
queue.push(m.targetAt(i));
|
|
608
621
|
else if (m instanceof ArrayToSingleTypeMapper)
|
|
609
622
|
queue.push(m.target);
|
|
610
623
|
else if (m instanceof MergedTypeMapper || m instanceof CompositeTypeMapper) {
|
|
@@ -912,14 +925,42 @@ export function unionContainsType(c, union, t) {
|
|
|
912
925
|
if (types.length < linearTypeSearchLimit)
|
|
913
926
|
return indexOfType(types, t, 0) >= 0;
|
|
914
927
|
const side = sideOf(c, union);
|
|
915
|
-
let
|
|
916
|
-
if (
|
|
928
|
+
let table = side.constituentIds;
|
|
929
|
+
if (table === undefined) {
|
|
917
930
|
if (side.membershipTests++ === 0)
|
|
918
931
|
return binarySearchTypes(c, types, t) >= 0;
|
|
919
|
-
|
|
920
|
-
side.
|
|
932
|
+
table = constituentTable(types);
|
|
933
|
+
side.constituentIds = table;
|
|
934
|
+
}
|
|
935
|
+
// Type ids are unique within a checker, so a matching id is `t` itself.
|
|
936
|
+
const key = t.id + 1;
|
|
937
|
+
const mask = table.length - 1;
|
|
938
|
+
for (let slot = Math.imul(key, 0x9e3779b1) & mask;; slot = (slot + 1) & mask) {
|
|
939
|
+
const value = table[slot];
|
|
940
|
+
if (value === key)
|
|
941
|
+
return true;
|
|
942
|
+
if (value === 0)
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* An open-addressing table of the ids of `types` (each plus one; zero marks an empty slot), with at
|
|
948
|
+
* least twice as many slots as types so that probes stay short.
|
|
949
|
+
*/
|
|
950
|
+
function constituentTable(types) {
|
|
951
|
+
let size = 4;
|
|
952
|
+
while (size < types.length * 2)
|
|
953
|
+
size *= 2;
|
|
954
|
+
const table = new Int32Array(size);
|
|
955
|
+
const mask = size - 1;
|
|
956
|
+
for (const t of types) {
|
|
957
|
+
const key = t.id + 1;
|
|
958
|
+
let slot = Math.imul(key, 0x9e3779b1) & mask;
|
|
959
|
+
while (table[slot] !== 0)
|
|
960
|
+
slot = (slot + 1) & mask;
|
|
961
|
+
table[slot] = key;
|
|
921
962
|
}
|
|
922
|
-
return
|
|
963
|
+
return table;
|
|
923
964
|
}
|
|
924
965
|
/**
|
|
925
966
|
* Whether `union` contains every type of the sorted `types` (the constituents of another union).
|
|
@@ -2046,7 +2087,7 @@ export function createTypeReferenceEx(c, target, typeArguments, objectFlags) {
|
|
|
2046
2087
|
return existing;
|
|
2047
2088
|
const type = newObjectType(c, 4 /* ObjectFlags.Reference */ | objectFlags | getPropagatingFlagsOfTypes(typeArguments, 0 /* TypeFlags.None */), target.symbol);
|
|
2048
2089
|
type.target = target;
|
|
2049
|
-
type.resolvedTypeArguments = typeArguments;
|
|
2090
|
+
type.resolvedTypeArguments = c.typeLists.intern(hash, typeArguments);
|
|
2050
2091
|
references.add(hash, type);
|
|
2051
2092
|
return type;
|
|
2052
2093
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type IndexedAccessTypeNode, type Node } from './ast.js';
|
|
2
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
3
2
|
import type { Checker } from './checker.js';
|
|
4
3
|
import { ElementFlags, type InterfaceType, type Type, TypeAlias } from './checker-types.js';
|
|
4
|
+
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
5
5
|
export declare function getTypeFromTypeNode(c: Checker, node: Node): Type;
|
|
6
6
|
export declare function getTypeFromThisTypeNode(c: Checker, node: Node): Type;
|
|
7
7
|
export declare function getTypeFromIndexedAccessTypeNode(c: Checker, node: IndexedAccessTypeNode): Type;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Types from type nodes: `getTypeFromTypeNode` and the resolution of type references.
|
|
2
2
|
import { getExpression, getName, getText, getType, getSymbol, getBody, getTypeArguments, } from './ast.js';
|
|
3
3
|
import { declarationNameToString, getSourceFileOfNode, getThisContainer, isClassLike, isStatic, isDeclarationStatementKind, } from './binder-utilities.js';
|
|
4
|
-
import { getSymbolId } from './symbol.js';
|
|
5
4
|
import { TupleElementInfo, TypeAlias, UniqueESSymbolType, emptyTypes, newTypeMapper, } from './checker-types.js';
|
|
6
5
|
import { createArrayType, aliasKey, createDeferredTypeReference, createNormalizedTupleType, createTypeReferenceEx, getIntersectionTypeEx, getRegularTypeOfLiteralType, getTemplateLiteralType, getTupleTargetType, getUnionTypeEx, getIntersectionType, everyType, isArrayOrTupleType, isPatternLiteralType, newObjectType, typeListKey, } from './checker-type-factory.js';
|
|
7
6
|
import { getMembersOfSymbol, getMergedSymbol, getSymbolOfDeclaration, resolveAlias, resolveEntityName, } from './checker-symbols.js';
|
|
@@ -15,6 +14,7 @@ import { checkExpression, checkExpressionCached, getResolvedSymbol } from './che
|
|
|
15
14
|
import { checkExpressionWithTypeArguments } from './checker-calls.js';
|
|
16
15
|
import { getIntendedTypeFromJSDocTypeReference } from './checker-jsdoc.js';
|
|
17
16
|
import { getCombinedNodeFlags, hasSyntacticModifier } from './binder-utilities.js';
|
|
17
|
+
import { getDeclarations, getSymbolId } from './symbol.js';
|
|
18
18
|
export function getTypeFromTypeNode(c, node) {
|
|
19
19
|
return getConditionalFlowTypeOfType(c, getTypeFromTypeNodeWorker(c, node), node);
|
|
20
20
|
}
|
|
@@ -568,7 +568,7 @@ export function getAliasSymbolForTypeNode(c, node) {
|
|
|
568
568
|
}
|
|
569
569
|
function isLocalTypeAlias(symbol) {
|
|
570
570
|
let declaration;
|
|
571
|
-
for (const d of symbol
|
|
571
|
+
for (const d of getDeclarations(symbol)) {
|
|
572
572
|
if (isTypeAlias(d)) {
|
|
573
573
|
declaration = d;
|
|
574
574
|
break;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
|
-
import { type Symbol } from './symbol.js';
|
|
3
2
|
import type { Checker } from './checker.js';
|
|
4
3
|
import { AccessFlags, ConditionalRoot, ConditionalType, IndexFlags, IndexedAccessType, type MappedType, type TemplateLiteralType, type Type, type TypeAlias, TypeFlags, type TypeMapper, type TypeParameter, type TupleType, type UnionType } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
export declare function isGenericType(c: Checker, t: Type): boolean;
|
|
6
6
|
export declare function isGenericObjectType(c: Checker, t: Type): boolean;
|
|
7
7
|
export declare function isGenericIndexType(c: Checker, t: Type): boolean;
|
|
@@ -5,7 +5,6 @@ import { getTypeOfPropertyOfContextualType } from './checker-contextual.js';
|
|
|
5
5
|
import { checkDeprecatedIndexedAccess } from './checker-deprecation.js';
|
|
6
6
|
import { isSelfTypeAccess, markPropertyAsReferenced } from './checker-unused.js';
|
|
7
7
|
import { getName, getQuestionToken, getType, getSymbol, getDotDotDotToken, getElements, getExpression, getText, } from './ast.js';
|
|
8
|
-
import { getSymbolId } from './symbol.js';
|
|
9
8
|
import { cachedTypeKey, ConditionalRoot, ConditionalType, IndexInfo, StringMappingType, appendTypeMapping, prependTypeMapping, newTypeMapper, ReferenceArgs, } from './checker-types.js';
|
|
10
9
|
import { aliasKey, createArrayTypeEx, createTupleTypeEx, everyType, filterType, getElementTypes, getIntersectionType, getIntersectionTypeEx, getRegularTypeOfLiteralType, getStringLiteralType, getTemplateLiteralType, getTotalFixedElementCount, getTypeArguments, getUnionType, getUnionTypeEx, isArrayType, isEmptyAnonymousObjectType, isErrorType, isGenericStringLikeType, isGenericTupleType, isPatternLiteralType, isReadonlyArrayType, isTupleType, mapType, mapTypeEx, intersectTypes, mapTypeWithAlias, newIndexType, newIndexedAccessType, newObjectType, newSubstitutionType, setStructuredTypeMembers, someType, tupleTargetOf, typeListKey, typesOf, typeListHash, } from './checker-type-factory.js';
|
|
11
10
|
import { appendIndexInfo, getApparentType, getApplicableIndexInfo, getDeclarationModifierFlagsFromSymbol, getIndexInfoOfType, getPropertyOfObjectType, getIndexInfosOfType, getPropertiesOfType, getPropertyOfType, getReducedApparentType, getReducedType, getBaseConstraintOfType, getIndexTypeOfType, hasPropertiesOfType, keepPropertiesOnly, memberResolutionFlags, } from './checker-members.js';
|
|
@@ -24,6 +23,7 @@ import { getSuggestionForNonexistentProperty, isAssignmentToReadonlyEntity, isDe
|
|
|
24
23
|
import { checkComputedPropertyName, checkExpression } from './checker-expressions.js';
|
|
25
24
|
import { getPropertyNameFromType, isNumericLiteralName, isTypeUsableAsPropertyName, isValidIndexKeyType, maybeTypeOfKind, isLateBoundName, } from './checker-utilities.js';
|
|
26
25
|
import { inferTypesForConditional, inferTypesFromTemplateLiteralType, isValidBigIntString, isValidNumberString, instantiateReverseMappedType as instantiateReverseMappedTypeOfInference, resolveReverseMappedTypeMembers as resolveReverseMappedTypeMembersOfInference, } from './checker-inference.js';
|
|
26
|
+
import { copyDeclarations, declarationCount, getSymbolId, } from './symbol.js';
|
|
27
27
|
// ---- Genericity
|
|
28
28
|
export function isGenericType(c, t) {
|
|
29
29
|
return getGenericObjectFlags(c, t) !== 0;
|
|
@@ -1155,7 +1155,7 @@ export function resolveMappedTypeMembers(c, t) {
|
|
|
1155
1155
|
if (modifiersProp !== undefined) {
|
|
1156
1156
|
c.symbolSyntheticOrigins.set(symbolId, modifiersProp);
|
|
1157
1157
|
if (shouldLinkPropDeclarations)
|
|
1158
|
-
prop
|
|
1158
|
+
copyDeclarations(prop, modifiersProp);
|
|
1159
1159
|
}
|
|
1160
1160
|
members.set(propName, prop);
|
|
1161
1161
|
}
|
|
@@ -1632,7 +1632,7 @@ function computeReferenceArgs(c, root) {
|
|
|
1632
1632
|
let kind = 0 /* ReferenceArgKind.Fixed */;
|
|
1633
1633
|
let inferTypeParameter;
|
|
1634
1634
|
for (const tp of root.inferTypeParameters) {
|
|
1635
|
-
const declaration = tp.symbol?.
|
|
1635
|
+
const declaration = tp.symbol?.declaration;
|
|
1636
1636
|
if (declaration === undefined ||
|
|
1637
1637
|
isNodeDescendantOf(declaration, argNode) ||
|
|
1638
1638
|
containsTypeParameterReference(c, tp, argNode)) {
|
|
@@ -1643,8 +1643,8 @@ function computeReferenceArgs(c, root) {
|
|
|
1643
1643
|
if (kind === 3 /* ReferenceArgKind.Other */) {
|
|
1644
1644
|
const inner = skipTypeParentheses(argNode);
|
|
1645
1645
|
if (inner.kind === 196 /* SyntaxKind.InferType */) {
|
|
1646
|
-
const tp = root.inferTypeParameters.find((t) => t.symbol.
|
|
1647
|
-
if (tp !== undefined && tp.symbol
|
|
1646
|
+
const tp = root.inferTypeParameters.find((t) => t.symbol.declaration === inner.typeParameter);
|
|
1647
|
+
if (tp !== undefined && declarationCount(tp.symbol) === 1 && !isReferencedInOtherArg(c, tp, argNodes, i)) {
|
|
1648
1648
|
kind = 1 /* ReferenceArgKind.Infer */;
|
|
1649
1649
|
inferTypeParameter = tp;
|
|
1650
1650
|
}
|
|
@@ -300,12 +300,42 @@ export declare class TypeAlias {
|
|
|
300
300
|
* aliasKey(alias)` plus a suffix spelled, without building them. A lookup takes a number hashing the
|
|
301
301
|
* parts (`typeListHash`); entries keep their parts, so a match is exact and keys sharing a hash chain.
|
|
302
302
|
* Like tsgo's hashed type list keys. A list must not change after it keys an entry.
|
|
303
|
+
*
|
|
304
|
+
* Entries are numbered in the order they are added: `heads` maps a hash to its first entry, and the
|
|
305
|
+
* lists and values of the entries are kept in arrays by number. Aliases, tags and the chains of
|
|
306
|
+
* entries that share a hash get arrays once an entry needs them.
|
|
303
307
|
*/
|
|
304
308
|
export declare class TypeListCache<V> {
|
|
305
|
-
private
|
|
309
|
+
private heads;
|
|
310
|
+
private lists;
|
|
311
|
+
private values;
|
|
312
|
+
private aliases;
|
|
313
|
+
private tags;
|
|
314
|
+
/** The next entry with the same hash, or -1. */
|
|
315
|
+
private nexts;
|
|
316
|
+
constructor();
|
|
306
317
|
get(hash: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number): V | undefined;
|
|
307
318
|
set(hash: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number, value: V): void;
|
|
308
319
|
clear(): void;
|
|
320
|
+
/** The number of the entry with these parts, or -1. */
|
|
321
|
+
private find;
|
|
322
|
+
private findFrom;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* One list for each sequence of types that a checker keeps (`Checker.typeLists`): references and
|
|
326
|
+
* instantiation caches hold the same type arguments in many places, mostly lists of one or two types,
|
|
327
|
+
* and share one list for them. A list must not change once it is in the table.
|
|
328
|
+
*/
|
|
329
|
+
export declare class TypeListTable {
|
|
330
|
+
private readonly heads;
|
|
331
|
+
private readonly lists;
|
|
332
|
+
/** The next list with the same hash, or -1, once two lists share one. */
|
|
333
|
+
private nexts;
|
|
334
|
+
/**
|
|
335
|
+
* The list in the table with the types of `types`, in order, or `types` itself, which joins the
|
|
336
|
+
* table. `hash` is `typeListHash(types, undefined, 0)`.
|
|
337
|
+
*/
|
|
338
|
+
intern(hash: number, types: Type[]): Type[];
|
|
309
339
|
}
|
|
310
340
|
/**
|
|
311
341
|
* The references to a generic class, interface or tuple type, by the hash of their type arguments
|
|
@@ -336,7 +366,7 @@ export declare class TypeExtra implements ProgramLifetime {
|
|
|
336
366
|
origin: Type | undefined;
|
|
337
367
|
keyPropertyName: string;
|
|
338
368
|
constituentMap: Map<Type, Type> | undefined;
|
|
339
|
-
|
|
369
|
+
constituentIds: Int32Array | undefined;
|
|
340
370
|
membershipTests: number;
|
|
341
371
|
uniqueLiteralFilledInstantiation: Type | undefined;
|
|
342
372
|
constructor();
|
|
@@ -587,13 +617,27 @@ export declare class EvolvingArrayType extends ObjectType {
|
|
|
587
617
|
finalArrayType: Type | undefined;
|
|
588
618
|
constructor(objectFlags: ObjectFlags, id: number);
|
|
589
619
|
}
|
|
590
|
-
|
|
620
|
+
/**
|
|
621
|
+
* A union or intersection. Few have their members resolved or their properties cached, so those
|
|
622
|
+
* live in `membersOf` (`UnionOrIntersectionMembers`), which is created when they are first written.
|
|
623
|
+
*/
|
|
624
|
+
export declare class UnionOrIntersectionType extends Type {
|
|
591
625
|
readonly types: Type[];
|
|
626
|
+
membersOf: UnionOrIntersectionMembers | undefined;
|
|
627
|
+
constructor(flags: TypeFlags, objectFlags: ObjectFlags, id: number, types: Type[]);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* The resolved members of a union or intersection (`membersHolder`) and the caches of its
|
|
631
|
+
* properties, created on first use.
|
|
632
|
+
*/
|
|
633
|
+
export declare class UnionOrIntersectionMembers extends StructuredType {
|
|
592
634
|
propertyCache: SymbolTable | undefined;
|
|
593
635
|
propertyCacheWithoutFunctionPropertyAugment: SymbolTable | undefined;
|
|
594
636
|
resolvedProperties: Symbol[] | undefined;
|
|
595
|
-
constructor(flags: TypeFlags,
|
|
637
|
+
constructor(flags: TypeFlags, id: number);
|
|
596
638
|
}
|
|
639
|
+
/** The members holder of a union or intersection, created if it has none yet. */
|
|
640
|
+
export declare function unionOrIntersectionMembers(t: UnionOrIntersectionType): UnionOrIntersectionMembers;
|
|
597
641
|
/** A union; all of its own fields are rarely set and live in `extra`. */
|
|
598
642
|
export declare class UnionType extends UnionOrIntersectionType {
|
|
599
643
|
constructor(objectFlags: ObjectFlags, id: number, types: Type[]);
|
|
@@ -609,9 +653,13 @@ export declare class UnionType extends UnionOrIntersectionType {
|
|
|
609
653
|
set keyPropertyName(name: string);
|
|
610
654
|
get constituentMap(): Map<Type, Type> | undefined;
|
|
611
655
|
set constituentMap(map: Map<Type, Type> | undefined);
|
|
612
|
-
/**
|
|
613
|
-
|
|
614
|
-
|
|
656
|
+
/**
|
|
657
|
+
* A hash table of the ids of a large union's constituents, for membership tests; created on the
|
|
658
|
+
* second test (`constituentTable`). About eight bytes a constituent, where a set of them took
|
|
659
|
+
* about five times that.
|
|
660
|
+
*/
|
|
661
|
+
get constituentIds(): Int32Array | undefined;
|
|
662
|
+
set constituentIds(ids: Int32Array | undefined);
|
|
615
663
|
get membershipTests(): number;
|
|
616
664
|
set membershipTests(tests: number);
|
|
617
665
|
}
|
|
@@ -824,6 +872,22 @@ export declare class ArrayTypeMapper extends TypeMapper {
|
|
|
824
872
|
map(type: Type): Type;
|
|
825
873
|
kind(): TypeMapperKind;
|
|
826
874
|
mapsThisOnly(): boolean;
|
|
875
|
+
/** The number of targets, one per source. */
|
|
876
|
+
targetCount(): number;
|
|
877
|
+
/** The target of the source at `index`. */
|
|
878
|
+
targetAt(index: number): Type;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* The mapper of a type reference's members: its type arguments, then the reference itself for the
|
|
882
|
+
* last source, the class or interface's `this` type. `targets` holds the type arguments only, so the
|
|
883
|
+
* reference's own list serves without a copy that adds the reference.
|
|
884
|
+
*/
|
|
885
|
+
export declare class ThisArgumentTypeMapper extends ArrayTypeMapper {
|
|
886
|
+
readonly thisTarget: Type;
|
|
887
|
+
constructor(sources: Type[], typeArguments: Type[], thisTarget: Type);
|
|
888
|
+
map(type: Type): Type;
|
|
889
|
+
targetCount(): number;
|
|
890
|
+
targetAt(index: number): Type;
|
|
827
891
|
}
|
|
828
892
|
/** An ArrayTypeMapper that looks its sources up in an index, built on its first lookup. */
|
|
829
893
|
export declare class IndexedArrayTypeMapper extends ArrayTypeMapper {
|
|
@@ -850,6 +914,8 @@ export declare class MergedTypeMapper extends TypeMapper {
|
|
|
850
914
|
kind(): TypeMapperKind;
|
|
851
915
|
}
|
|
852
916
|
export declare function newTypeMapper(sources: Type[], targets: Type[]): TypeMapper;
|
|
917
|
+
/** `newTypeMapper(sources, [...typeArguments, thisTarget])`, without building that list where it can. */
|
|
918
|
+
export declare function newThisArgumentTypeMapper(sources: Type[], typeArguments: Type[], thisTarget: Type): TypeMapper;
|
|
853
919
|
export declare function mergeTypeMappers(m1: TypeMapper | undefined, m2: TypeMapper): TypeMapper;
|
|
854
920
|
export declare function prependTypeMapping(source: Type, target: Type, mapper: TypeMapper | undefined): TypeMapper;
|
|
855
921
|
export declare function appendTypeMapping(mapper: TypeMapper | undefined, source: Type, target: Type): TypeMapper;
|