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
|
@@ -18,6 +18,7 @@ import { createPromiseType } from './checker-iteration.js';
|
|
|
18
18
|
import { getFunctionFlags } from './checker-utilities.js';
|
|
19
19
|
import { typeToString } from './type-printer.js';
|
|
20
20
|
import { elaborateJsxComponents } from './checker-jsx.js';
|
|
21
|
+
import { declarationCount } from './symbol.js';
|
|
21
22
|
/** Checks that `source` relates to `target`, elaborating into `expr` when possible. */
|
|
22
23
|
export function checkTypeRelatedToAndOptionallyElaborate(c, source, target, relation, errorNode, expr, headMessage, diagnosticOutput) {
|
|
23
24
|
if (isTypeRelatedTo(c, source, target, relation))
|
|
@@ -221,11 +222,11 @@ export function elaborateElement(c, source, target, relation, prop, next, nameTy
|
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
if (!issuedElaboration &&
|
|
224
|
-
((targetProp !== undefined && targetProp
|
|
225
|
-
(target.symbol !== undefined && target.symbol
|
|
226
|
-
const targetNode = targetProp !== undefined && targetProp
|
|
227
|
-
? targetProp.
|
|
228
|
-
: target.symbol.
|
|
225
|
+
((targetProp !== undefined && declarationCount(targetProp) !== 0) ||
|
|
226
|
+
(target.symbol !== undefined && declarationCount(target.symbol) !== 0))) {
|
|
227
|
+
const targetNode = targetProp !== undefined && declarationCount(targetProp) !== 0
|
|
228
|
+
? targetProp.declaration
|
|
229
|
+
: target.symbol.declaration;
|
|
229
230
|
if (propertyName === '' || (nameType.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0)
|
|
230
231
|
propertyName = typeToString(c, nameType);
|
|
231
232
|
if (!c.host.isSourceFileDefaultLibrary(getSourceFileOfNode(targetNode)))
|
|
@@ -279,8 +280,8 @@ function elaborateArrowFunction(c, node, source, target, relation, diagnosticOut
|
|
|
279
280
|
if (diagnostics.length === 0)
|
|
280
281
|
return false;
|
|
281
282
|
const diagnostic = diagnostics[0];
|
|
282
|
-
if (target.symbol !== undefined && target.symbol
|
|
283
|
-
diagnostic.addRelatedInfo(createDiagnosticForNode(target.symbol.
|
|
283
|
+
if (target.symbol !== undefined && declarationCount(target.symbol) !== 0)
|
|
284
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(target.symbol.declaration, 1517 /* Diagnostics.The_expected_type_comes_from_the_return_type_of_this_signature */, []));
|
|
284
285
|
if ((getFunctionFlags(node) & 2 /* FunctionFlags.Async */) === 0 &&
|
|
285
286
|
getTypeOfPropertyOfType(c, sourceReturn, 'then') === undefined &&
|
|
286
287
|
checkTypeRelatedTo(c, createPromiseType(c, sourceReturn), targetReturn, relation, undefined, undefined, undefined))
|
|
@@ -45,7 +45,8 @@ declare class PendingHelperCheck {
|
|
|
45
45
|
export declare class EmitHelperFileLinks {
|
|
46
46
|
helpersModule: Symbol | undefined;
|
|
47
47
|
requestedHelpers: number;
|
|
48
|
-
|
|
48
|
+
/** Created on the first check; most files have none. */
|
|
49
|
+
pending: PendingHelperCheck[] | undefined;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Under --importHelpers, the emit of the syntax at `location` calls `helpers` from tslib. Reports TS2354 when
|
|
@@ -16,7 +16,8 @@ class PendingHelperCheck {
|
|
|
16
16
|
export class EmitHelperFileLinks {
|
|
17
17
|
helpersModule = undefined;
|
|
18
18
|
requestedHelpers = 0 /* ExternalEmitHelpers.None */;
|
|
19
|
-
|
|
19
|
+
/** Created on the first check; most files have none. */
|
|
20
|
+
pending = undefined;
|
|
20
21
|
}
|
|
21
22
|
function fileLinks(c, file) {
|
|
22
23
|
let links = c.emitHelperFileLinks.get(file);
|
|
@@ -45,7 +46,7 @@ export function checkExternalEmitHelpers(c, location, helpers) {
|
|
|
45
46
|
const fileIndex = c.fileIndex.get(file);
|
|
46
47
|
const checkingIndex = c.fileIndex.get(checking);
|
|
47
48
|
if (fileIndex !== undefined && checkingIndex !== undefined && fileIndex < checkingIndex) {
|
|
48
|
-
fileLinks(c, file).pending.push(new PendingHelperCheck(location, helpers));
|
|
49
|
+
(fileLinks(c, file).pending ??= []).push(new PendingHelperCheck(location, helpers));
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -78,10 +79,10 @@ export function checkExternalEmitHelpers(c, location, helpers) {
|
|
|
78
79
|
/** Runs the helper checks for nodes of `file` that were reached while checking later files. */
|
|
79
80
|
export function checkPendingExternalEmitHelpers(c, file) {
|
|
80
81
|
const links = c.emitHelperFileLinks.get(file);
|
|
81
|
-
if (links === undefined
|
|
82
|
+
if (links?.pending === undefined)
|
|
82
83
|
return;
|
|
83
84
|
const pending = links.pending;
|
|
84
|
-
links.pending =
|
|
85
|
+
links.pending = undefined;
|
|
85
86
|
for (const check of pending)
|
|
86
87
|
checkExternalEmitHelpers(c, check.location, check.helpers);
|
|
87
88
|
}
|
|
@@ -2,12 +2,12 @@ import { type EntityName, type FileReference, type Identifier, type ImportDeclar
|
|
|
2
2
|
import type { Checker } from './checker.js';
|
|
3
3
|
import type { CompilerOptions, ModuleKind } from './options.js';
|
|
4
4
|
import type { EmitContext } from './printer/emit-context.js';
|
|
5
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
6
5
|
import { DeclarationEmitResolver, NodeBuilderFlags, type SymbolAccessibilityResult, type SymbolTracker } from './transformers/declarations-resolver.js';
|
|
7
6
|
import type { SyntacticDeclarationEmitResolver } from './transformers/declarations-syntactic.js';
|
|
8
7
|
import { SyntacticEmitResolver } from './transformers/emit-resolver.js';
|
|
9
8
|
import type { Evaluation, ReferenceResolver } from './transformers/reference-resolver.js';
|
|
10
9
|
import { TypeReferenceSerializationKind } from './transformers/type-serialization.js';
|
|
10
|
+
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
11
11
|
export declare class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
12
12
|
readonly checker: Checker;
|
|
13
13
|
/** Answers the queries that don't need types. */
|
|
@@ -25,6 +25,7 @@ import { isTypeIdenticalTo } from './relations.js';
|
|
|
25
25
|
import { beginDeclarationEmitVisibility, isDeclarationVisible, isSymbolAccessible, markDeclarationVisible, } from './symbol-accessibility.js';
|
|
26
26
|
import { DeclarationEmitResolver, } from './transformers/declarations-resolver.js';
|
|
27
27
|
import { SyntacticEmitResolver } from './transformers/emit-resolver.js';
|
|
28
|
+
import { declarationCount, getDeclarations } from './symbol.js';
|
|
28
29
|
const declarationEmitInternalFlags = 8 /* NodeBuilderInternalFlags.AllowUnresolvedNames */;
|
|
29
30
|
const aliasMeaning = 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */;
|
|
30
31
|
export class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
@@ -105,7 +106,7 @@ export class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
|
105
106
|
while (exportSymbol !== undefined && !visited.has(exportSymbol)) {
|
|
106
107
|
visited.add(exportSymbol);
|
|
107
108
|
let next = undefined;
|
|
108
|
-
for (const declaration of exportSymbol
|
|
109
|
+
for (const declaration of getDeclarations(exportSymbol)) {
|
|
109
110
|
markDeclarationVisible(c, declaration);
|
|
110
111
|
if (declaration instanceof ImportEqualsDeclaration &&
|
|
111
112
|
declaration.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */) {
|
|
@@ -144,7 +145,7 @@ export class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
|
144
145
|
const merged = getMergedSymbol(c, s);
|
|
145
146
|
if (merged === s)
|
|
146
147
|
continue;
|
|
147
|
-
for (const d of merged
|
|
148
|
+
for (const d of getDeclarations(merged))
|
|
148
149
|
if (getSourceFileOfNode(d) === importTarget)
|
|
149
150
|
return true;
|
|
150
151
|
}
|
|
@@ -430,8 +431,8 @@ export function getTypeReferenceSerializationKind(c, typeName, location) {
|
|
|
430
431
|
let isTypeOnly = false;
|
|
431
432
|
if (typeName.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
432
433
|
const root = resolveEntityName(c, getFirstIdentifier(typeName), 111551 /* SymbolFlags.Value */, true, true, location);
|
|
433
|
-
if (root !== undefined && root
|
|
434
|
-
isTypeOnly = root.
|
|
434
|
+
if (root !== undefined && declarationCount(root) > 0)
|
|
435
|
+
isTypeOnly = getDeclarations(root).every(isTypeOnlyImportOrExportDeclaration);
|
|
435
436
|
}
|
|
436
437
|
const valueSymbol = resolveEntityName(c, typeName, 111551 /* SymbolFlags.Value */, true, true, location);
|
|
437
438
|
let resolvedValue = valueSymbol;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// `checkGrammarSourceFile` walks a file once after it is type checked and runs the grammar checks
|
|
4
4
|
// of each node in the order tsgo's checker runs them. Checks that need types read the checker's
|
|
5
5
|
// caches. Errors reported with `grammarError*` are dropped when the file has parse errors.
|
|
6
|
-
import { ElementAccessExpression, Identifier, NodeVisitor, StringLiteral, getAsteriskToken, getBody, getElements, getExpression, getHeritageClauses, getInitializer, getLabel, getIsTypeOnly, getLocals, getMembers, getModifiers, getName, getNodeId, getParameters, getPostfixToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, isDeclarationNode, } from './ast.js';
|
|
6
|
+
import { ElementAccessExpression, Identifier, NodeVisitor, StringLiteral, getAsteriskToken, getBody, getElements, getExpression, getHeritageClauses, getInitializer, getLabel, getIsTypeOnly, getLocals, getMembers, getModifiers, getName, getNodeId, getParameters, getPostfixToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, isDeclarationNode, callQuestionDotToken, callTypeArguments, } from './ast.js';
|
|
7
7
|
import { canHaveDecorators, canHaveIllegalDecorators, getExternalModuleName, getTextOfNodeFromSourceText, isAmbientModule, isFunctionLike, isFunctionLikeDeclarationKind, isModifierKind, isStringLiteralLike, modifierToFlag, nodeIsPresent, isInJSFile, } from './ast-utilities.js';
|
|
8
8
|
import { getCombinedModifierFlags, getCombinedNodeFlags, getContainingClass, getRangeOfTokenAtPosition, getSourceFileOfNode, hasSyntacticModifier, isAutoAccessorPropertyDeclaration, isClassLike, isDynamicName, isEntityNameExpression, isExternalModule, isInTopLevelContext, isModuleAugmentationExternal, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, } from './binder-utilities.js';
|
|
9
9
|
import { findUseStrictPrologue } from './binder.js';
|
|
@@ -20,9 +20,10 @@ import { Diagnostic, messageCategory } from './diagnostics.js';
|
|
|
20
20
|
import { ModuleKind, ScriptTarget, getEmitModuleKind } from './options.js';
|
|
21
21
|
import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
|
|
22
22
|
import { SourceFileMetadata, getEmitModuleFormatOfFile, getImpliedNodeFormatForEmit } from './program-utilities.js';
|
|
23
|
-
import { Scanner, ScannerErrorReporter,
|
|
23
|
+
import { Scanner, ScannerErrorReporter, skipTrivia, tokenToString } from './scanner.js';
|
|
24
24
|
import { typeToString } from './type-printer.js';
|
|
25
25
|
import { findMismatchedAugmentsTag } from './checker-jsdoc.js';
|
|
26
|
+
import { getDeclarations } from './symbol.js';
|
|
26
27
|
/** Runs the grammar checks of every node of `file`. */
|
|
27
28
|
export function checkGrammarSourceFile(c, file) {
|
|
28
29
|
const g = new GrammarChecker(c, file);
|
|
@@ -821,7 +822,7 @@ function getFirstAccessorOfPair(c, node) {
|
|
|
821
822
|
if (symbol === undefined)
|
|
822
823
|
return node;
|
|
823
824
|
const otherKind = node.kind === 178 /* SyntaxKind.GetAccessor */ ? 179 /* SyntaxKind.SetAccessor */ : 178 /* SyntaxKind.GetAccessor */;
|
|
824
|
-
for (const declaration of symbol
|
|
825
|
+
for (const declaration of getDeclarations(symbol))
|
|
825
826
|
if (declaration.kind === otherKind && declaration.pos < node.pos)
|
|
826
827
|
return declaration;
|
|
827
828
|
return node;
|
|
@@ -857,8 +858,8 @@ function checkGrammarDecorator(g, decorator) {
|
|
|
857
858
|
if (!canHaveCallExpression)
|
|
858
859
|
errorNode = node;
|
|
859
860
|
// A `?.` token comes first, so it wins over an earlier error node.
|
|
860
|
-
if (call
|
|
861
|
-
errorNode = call
|
|
861
|
+
if (callQuestionDotToken(call) !== undefined)
|
|
862
|
+
errorNode = callQuestionDotToken(call);
|
|
862
863
|
node = call.expression;
|
|
863
864
|
canHaveCallExpression = false;
|
|
864
865
|
continue;
|
|
@@ -969,10 +970,23 @@ function checkGrammarArrowFunction(g, node) {
|
|
|
969
970
|
const arrowToken = arrow.equalsGreaterThanToken;
|
|
970
971
|
if (arrowToken === undefined)
|
|
971
972
|
return false;
|
|
972
|
-
|
|
973
|
-
return (computeLineOfPosition(lineStarts, arrowToken.pos) !== computeLineOfPosition(lineStarts, arrowToken.end) &&
|
|
973
|
+
return (hasLineBreak(g.file.text, arrowToken.pos, arrowToken.end) &&
|
|
974
974
|
grammarErrorOnNode(g, arrowToken, 156 /* Diagnostics.Line_terminator_not_permitted_before_arrow */));
|
|
975
975
|
}
|
|
976
|
+
/**
|
|
977
|
+
* Whether a line starts in `(pos, end]`, so that `pos` and `end` are on different lines: after an
|
|
978
|
+
* LF, LS or PS, or a CR that no LF follows (`computeLineStarts`), without the file's line starts.
|
|
979
|
+
*/
|
|
980
|
+
function hasLineBreak(text, pos, end) {
|
|
981
|
+
for (let i = pos; i < end; i++) {
|
|
982
|
+
const c = text.charCodeAt(i);
|
|
983
|
+
if (c === 0x0a || c === 0x2028 || c === 0x2029)
|
|
984
|
+
return true;
|
|
985
|
+
if (c === 0x0d && text.charCodeAt(i + 1) !== 0x0a)
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
976
990
|
function checkGrammarForGenerator(g, node) {
|
|
977
991
|
const asteriskToken = getAsteriskToken(node);
|
|
978
992
|
if (asteriskToken === undefined)
|
|
@@ -2366,7 +2380,7 @@ function checkGrammarCallExpression(g, node) {
|
|
|
2366
2380
|
if (isImportCall)
|
|
2367
2381
|
checkGrammarImportCallExpression(g, node);
|
|
2368
2382
|
else
|
|
2369
|
-
checkGrammarTypeArguments(g, node
|
|
2383
|
+
checkGrammarTypeArguments(g, callTypeArguments(node));
|
|
2370
2384
|
}
|
|
2371
2385
|
function checkGrammarImportCallExpression(g, node) {
|
|
2372
2386
|
const moduleKind = g.moduleKind;
|
|
@@ -2380,7 +2394,7 @@ function checkGrammarImportCallExpression(g, node) {
|
|
|
2380
2394
|
}
|
|
2381
2395
|
else if (moduleKind === ModuleKind.ES2015)
|
|
2382
2396
|
return grammarErrorOnNode(g, node, 259 /* Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node16_node18_node20_or_nodenext */);
|
|
2383
|
-
if (node
|
|
2397
|
+
if (callTypeArguments(node) !== undefined)
|
|
2384
2398
|
return grammarErrorOnNode(g, node, 262 /* Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments */);
|
|
2385
2399
|
const args = node.arguments;
|
|
2386
2400
|
const argumentNodes = args.nodes;
|
|
@@ -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 { type Type } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
/** Checks a class's merged declarations, members, base class, implemented types and index signatures. */
|
|
6
6
|
export declare function checkClassHeritage(c: Checker, node: Node): void;
|
|
7
7
|
/**
|
|
@@ -24,6 +24,7 @@ import { checkTypeAssignableTo, checkTypeRelatedTo, compareProperties, isTypeAss
|
|
|
24
24
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
25
25
|
import { checkFunctionOrConstructorSymbol } from './checker-overloads.js';
|
|
26
26
|
import { isPropertyInitializedInConstructor } from './checker-classes.js';
|
|
27
|
+
import { declarationCount, getDeclarations, } from './symbol.js';
|
|
27
28
|
// ---- Classes
|
|
28
29
|
/** Checks a class's merged declarations, members, base class, implemented types and index signatures. */
|
|
29
30
|
export function checkClassHeritage(c, node) {
|
|
@@ -349,7 +350,7 @@ function isImplementedByOtherBaseType(c, t, baseType, base) {
|
|
|
349
350
|
/** With `useDefineForClassFields`, a redeclared property without an initializer resets the base value. */
|
|
350
351
|
function checkPropertyOverwritesBase(c, t, baseType, base, derived, baseDeclarationFlags, derivedDeclarationFlags) {
|
|
351
352
|
let uninitialized;
|
|
352
|
-
for (const d of derived
|
|
353
|
+
for (const d of getDeclarations(derived)) {
|
|
353
354
|
if (d.kind === 173 /* SyntaxKind.PropertyDeclaration */ && getInitializer(d) === undefined) {
|
|
354
355
|
uninitialized = d;
|
|
355
356
|
break;
|
|
@@ -360,7 +361,7 @@ function checkPropertyOverwritesBase(c, t, baseType, base, derived, baseDeclarat
|
|
|
360
361
|
(baseDeclarationFlags & 64 /* ModifierFlags.Abstract */) !== 0 ||
|
|
361
362
|
(derivedDeclarationFlags & 64 /* ModifierFlags.Abstract */) !== 0)
|
|
362
363
|
return;
|
|
363
|
-
for (const d of derived
|
|
364
|
+
for (const d of getDeclarations(derived))
|
|
364
365
|
if ((d.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
|
|
365
366
|
return;
|
|
366
367
|
const constructor = findConstructorDeclaration(getClassLikeDeclarationOfSymbol(t.symbol));
|
|
@@ -404,12 +405,12 @@ function reportMissingAbstractMembers(c, node, missing) {
|
|
|
404
405
|
function arePropertiesAbstractOrInterface(base, baseDeclarationFlags) {
|
|
405
406
|
// Synthetic (intersection) properties need any declaration to qualify; others need all.
|
|
406
407
|
if ((base.checkFlags & 6 /* CheckFlags.Synthetic */) !== 0) {
|
|
407
|
-
for (const d of base
|
|
408
|
+
for (const d of getDeclarations(base))
|
|
408
409
|
if (isPropertyAbstractOrInterface(d, baseDeclarationFlags))
|
|
409
410
|
return true;
|
|
410
411
|
return false;
|
|
411
412
|
}
|
|
412
|
-
for (const d of base
|
|
413
|
+
for (const d of getDeclarations(base))
|
|
413
414
|
if (!isPropertyAbstractOrInterface(d, baseDeclarationFlags))
|
|
414
415
|
return false;
|
|
415
416
|
return true;
|
|
@@ -485,13 +486,13 @@ function checkMemberForOverrideModifier(c, node, staticType, baseStaticType, bas
|
|
|
485
486
|
return;
|
|
486
487
|
}
|
|
487
488
|
if (baseProp === undefined ||
|
|
488
|
-
baseProp
|
|
489
|
+
declarationCount(baseProp) === 0 ||
|
|
489
490
|
memberHasOverrideModifier ||
|
|
490
491
|
c.compilerOptions.noImplicitOverride !== true ||
|
|
491
492
|
(node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
|
|
492
493
|
return;
|
|
493
494
|
let baseHasAbstract = false;
|
|
494
|
-
for (const d of baseProp
|
|
495
|
+
for (const d of getDeclarations(baseProp)) {
|
|
495
496
|
if (hasSyntacticModifier(d, 64 /* ModifierFlags.Abstract */)) {
|
|
496
497
|
baseHasAbstract = true;
|
|
497
498
|
break;
|
|
@@ -590,14 +591,14 @@ function checkInheritedPropertiesAreIdentical(c, t, typeNode) {
|
|
|
590
591
|
// ---- Type parameters of merged declarations
|
|
591
592
|
/** Reports class and interface declarations of one symbol whose type parameters differ. */
|
|
592
593
|
export function checkTypeParameterListsIdentical(c, symbol) {
|
|
593
|
-
if (symbol
|
|
594
|
+
if (declarationCount(symbol) === 1)
|
|
594
595
|
return;
|
|
595
596
|
const links = c.symbolLinks(symbol);
|
|
596
597
|
if (links.typeParametersChecked)
|
|
597
598
|
return;
|
|
598
599
|
links.typeParametersChecked = true;
|
|
599
600
|
const declarations = [];
|
|
600
|
-
for (const d of symbol
|
|
601
|
+
for (const d of getDeclarations(symbol))
|
|
601
602
|
if (d.kind === 264 /* SyntaxKind.ClassDeclaration */ || d.kind === 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
602
603
|
declarations.push(d);
|
|
603
604
|
if (declarations.length <= 1)
|
|
@@ -618,7 +619,7 @@ export function checkTypeParameterListsIdentical(c, symbol) {
|
|
|
618
619
|
}
|
|
619
620
|
/** Reports the declarations of an `infer` type parameter declared more than once with different constraints. */
|
|
620
621
|
export function checkInferTypeParameterDeclarations(c, symbol) {
|
|
621
|
-
if (symbol
|
|
622
|
+
if (declarationCount(symbol) <= 1)
|
|
622
623
|
return;
|
|
623
624
|
const links = c.symbolLinks(symbol);
|
|
624
625
|
if (links.typeParametersChecked)
|
|
@@ -626,7 +627,7 @@ export function checkInferTypeParameterDeclarations(c, symbol) {
|
|
|
626
627
|
links.typeParametersChecked = true;
|
|
627
628
|
const declarations = [];
|
|
628
629
|
const typeParameterLists = [];
|
|
629
|
-
for (const d of symbol
|
|
630
|
+
for (const d of getDeclarations(symbol)) {
|
|
630
631
|
if (d.kind === 169 /* SyntaxKind.TypeParameter */) {
|
|
631
632
|
declarations.push(d);
|
|
632
633
|
typeParameterLists.push([d]);
|
|
@@ -711,7 +712,7 @@ export function checkObjectTypeForDuplicateDeclarations(c, node, checkPrivateNam
|
|
|
711
712
|
}
|
|
712
713
|
}
|
|
713
714
|
function checkPropertyOrAccessor(c, node, names, symbol, kind, isStaticMember) {
|
|
714
|
-
if (symbol
|
|
715
|
+
if (declarationCount(symbol) <= 1)
|
|
715
716
|
return;
|
|
716
717
|
const state = names.get(symbol.name) ?? 0 /* MemberKind.None */;
|
|
717
718
|
if (state === 0 /* MemberKind.None */)
|
|
@@ -865,12 +866,12 @@ function checkTypeForDuplicateIndexSignatures(c, node) {
|
|
|
865
866
|
if (symbol === undefined)
|
|
866
867
|
return;
|
|
867
868
|
const indexSymbol = getIndexSymbol(c, symbol);
|
|
868
|
-
if (indexSymbol === undefined || indexSymbol
|
|
869
|
+
if (indexSymbol === undefined || declarationCount(indexSymbol) <= 1)
|
|
869
870
|
return;
|
|
870
871
|
// Late-bound index signatures may duplicate each other and explicit ones.
|
|
871
872
|
const keyTypes = [];
|
|
872
873
|
const declarationsByKey = [];
|
|
873
|
-
for (const declaration of indexSymbol
|
|
874
|
+
for (const declaration of getDeclarations(indexSymbol)) {
|
|
874
875
|
if (declaration.kind !== 182 /* SyntaxKind.IndexSignature */)
|
|
875
876
|
continue;
|
|
876
877
|
const parameters = getParameters(declaration).nodes;
|
|
@@ -1,8 +1,8 @@
|
|
|
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 { type ConditionalRoot, type IndexType, type MappedType, type ReverseMappedType, type Signature, type TemplateLiteralType, type Type, TypeMapper } from './checker-types.js';
|
|
5
4
|
import { type TypeComparer } from './relations.js';
|
|
5
|
+
import { type Symbol } from './symbol.js';
|
|
6
6
|
export declare const enum InferenceFlags {
|
|
7
7
|
None = 0,
|
|
8
8
|
/** Infer `silentNeverType` for no inferences (otherwise `unknown`). */
|
|
@@ -56,28 +56,38 @@ export declare class IntraExpressionInferenceSite {
|
|
|
56
56
|
readonly type: Type;
|
|
57
57
|
constructor(node: Node, type: Type);
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The inferences for a set of type parameters. The context is its own fixing mapper (`mapper`), and
|
|
61
|
+
* each read of `nonFixingMapper` returns a new mapper that reads the context: no mapper the context
|
|
62
|
+
* holds refers back to it, so a context whose inference is done is freed by reference counting
|
|
63
|
+
* rather than by the cycle collector.
|
|
64
|
+
*/
|
|
65
|
+
export declare class InferenceContext extends TypeMapper {
|
|
66
|
+
readonly c: Checker;
|
|
60
67
|
inferences: InferenceInfo[];
|
|
61
68
|
/** The generic signature inferences are made for, if any. */
|
|
62
69
|
readonly signature: Signature | undefined;
|
|
63
70
|
flags: InferenceFlags;
|
|
64
71
|
readonly compareTypes: TypeComparer;
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
nonFixingMapper: TypeMapper;
|
|
72
|
+
/** Combined after the non-fixing mapper (conditional types' `infer` constraints), if any. */
|
|
73
|
+
nonFixingOuter: TypeMapper | undefined;
|
|
68
74
|
/** Maps to inferences from the return type, if any. */
|
|
69
75
|
returnMapper: TypeMapper | undefined;
|
|
70
76
|
outerReturnMapper: TypeMapper | undefined;
|
|
71
77
|
inferredTypeParameters: Type[] | undefined;
|
|
72
|
-
|
|
78
|
+
/** Created on the first site; most contexts get none. */
|
|
79
|
+
intraExpressionInferenceSites: IntraExpressionInferenceSite[] | undefined;
|
|
73
80
|
constructor(c: Checker, inferences: InferenceInfo[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer);
|
|
81
|
+
/** Fixes inferences. */
|
|
82
|
+
get mapper(): TypeMapper;
|
|
83
|
+
/** Maps to the current inferences without fixing them. */
|
|
84
|
+
get nonFixingMapper(): TypeMapper;
|
|
85
|
+
map(type: Type): Type;
|
|
74
86
|
}
|
|
75
|
-
/** Maps a context's type parameters to their inferred types
|
|
76
|
-
export declare class
|
|
77
|
-
readonly c: Checker;
|
|
87
|
+
/** Maps a context's type parameters to their inferred types without fixing them. */
|
|
88
|
+
export declare class NonFixingInferenceMapper extends TypeMapper {
|
|
78
89
|
readonly context: InferenceContext;
|
|
79
|
-
|
|
80
|
-
constructor(c: Checker, context: InferenceContext, fixing: boolean);
|
|
90
|
+
constructor(context: InferenceContext);
|
|
81
91
|
map(type: Type): Type;
|
|
82
92
|
}
|
|
83
93
|
export declare function createInferenceContext(c: Checker, typeParameters: readonly Type[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer | undefined): InferenceContext;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// types of type parameters.
|
|
3
3
|
import { sideOf, signatureSideOf } from './side-state.js';
|
|
4
4
|
import { hasSyntacticModifier } from './binder-utilities.js';
|
|
5
|
-
import { getSymbolId } from './symbol.js';
|
|
6
5
|
import { ArrayToSingleTypeMapper, MergedTypeMapper, TupleElementInfo, TypeMapper, newTypeMapper, SimpleTypeMapper, emptyTypes, } from './checker-types.js';
|
|
7
6
|
import { createAnonymousType, createArrayType, createArrayTypeEx, createTupleType, createTupleTypeEx, filterType, getBaseTypeOfLiteralType, getBigIntLiteralType, getElementTypes, getEndElementCount, getIntersectionType, getNumberLiteralType, getRegularTypeOfLiteralType, getStringLiteralType, getTemplateLiteralType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, getWidenedLiteralType, isArrayOrTupleType, isErrorType, isArrayType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, mapType, newIndexInfo, newObjectType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
8
7
|
import { getDeclaredTypeOfClassOrInterface, getDeclaredTypeOfSymbol, fillMissingTypeArguments, getConstraintOfTypeParameter, getDefaultFromTypeParameter, getMinTypeArgumentCount, getDeclaredTypeOfTypeParameter, } from './checker-declared-types.js';
|
|
@@ -17,6 +16,7 @@ import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
|
17
16
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
18
17
|
import { parsePseudoBigInt } from './pseudo-bigint.js';
|
|
19
18
|
import { getContextualTypeForInference } from './checker-contextual.js';
|
|
19
|
+
import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
|
|
20
20
|
// Shared empty candidate lists: an InferenceInfo gets its own on its first candidate, as tsgo's nil
|
|
21
21
|
// slices do. Never changed.
|
|
22
22
|
const noCandidates = [];
|
|
@@ -61,57 +61,78 @@ export class IntraExpressionInferenceSite {
|
|
|
61
61
|
this.type = type;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The inferences for a set of type parameters. The context is its own fixing mapper (`mapper`), and
|
|
66
|
+
* each read of `nonFixingMapper` returns a new mapper that reads the context: no mapper the context
|
|
67
|
+
* holds refers back to it, so a context whose inference is done is freed by reference counting
|
|
68
|
+
* rather than by the cycle collector.
|
|
69
|
+
*/
|
|
70
|
+
export class InferenceContext extends TypeMapper {
|
|
71
|
+
c;
|
|
65
72
|
inferences;
|
|
66
73
|
/** The generic signature inferences are made for, if any. */
|
|
67
74
|
signature;
|
|
68
75
|
flags;
|
|
69
76
|
compareTypes;
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
nonFixingMapper;
|
|
77
|
+
/** Combined after the non-fixing mapper (conditional types' `infer` constraints), if any. */
|
|
78
|
+
nonFixingOuter = undefined;
|
|
73
79
|
/** Maps to inferences from the return type, if any. */
|
|
74
80
|
returnMapper = undefined;
|
|
75
81
|
outerReturnMapper = undefined;
|
|
76
82
|
inferredTypeParameters = undefined;
|
|
77
|
-
|
|
83
|
+
/** Created on the first site; most contexts get none. */
|
|
84
|
+
intraExpressionInferenceSites = undefined;
|
|
78
85
|
constructor(c, inferences, signature, flags, compareTypes) {
|
|
86
|
+
super();
|
|
87
|
+
this.c = c;
|
|
79
88
|
this.inferences = inferences;
|
|
80
89
|
this.signature = signature;
|
|
81
90
|
this.flags = flags;
|
|
82
91
|
this.compareTypes = compareTypes;
|
|
83
|
-
this.mapper = new InferenceTypeMapper(c, this, true);
|
|
84
|
-
this.nonFixingMapper = new InferenceTypeMapper(c, this, false);
|
|
85
92
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.c
|
|
95
|
-
this.context = context;
|
|
96
|
-
this.fixing = fixing;
|
|
93
|
+
/** Fixes inferences. */
|
|
94
|
+
get mapper() {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** Maps to the current inferences without fixing them. */
|
|
98
|
+
get nonFixingMapper() {
|
|
99
|
+
const mapper = new NonFixingInferenceMapper(this);
|
|
100
|
+
const outer = this.nonFixingOuter;
|
|
101
|
+
return outer !== undefined ? combineTypeMappers(this.c, mapper, outer) : mapper;
|
|
97
102
|
}
|
|
98
103
|
map(type) {
|
|
99
|
-
const inferences = this.
|
|
104
|
+
const inferences = this.inferences;
|
|
100
105
|
for (let i = 0; i < inferences.length; i++) {
|
|
101
106
|
const inference = inferences[i];
|
|
102
107
|
if (type !== inference.typeParameter)
|
|
103
108
|
continue;
|
|
104
|
-
if (
|
|
109
|
+
if (!inference.isFixed) {
|
|
105
110
|
// Infer from intra-expression sites before committing to an inference.
|
|
106
|
-
inferFromIntraExpressionSites(this.c, this
|
|
111
|
+
inferFromIntraExpressionSites(this.c, this);
|
|
107
112
|
clearCachedInferences(inferences);
|
|
108
113
|
inference.isFixed = true;
|
|
109
114
|
}
|
|
110
|
-
return getInferredType(this.c, this
|
|
115
|
+
return getInferredType(this.c, this, i);
|
|
111
116
|
}
|
|
112
117
|
return type;
|
|
113
118
|
}
|
|
114
119
|
}
|
|
120
|
+
/** Maps a context's type parameters to their inferred types without fixing them. */
|
|
121
|
+
export class NonFixingInferenceMapper extends TypeMapper {
|
|
122
|
+
context;
|
|
123
|
+
constructor(context) {
|
|
124
|
+
super();
|
|
125
|
+
this.context = context;
|
|
126
|
+
}
|
|
127
|
+
map(type) {
|
|
128
|
+
const context = this.context;
|
|
129
|
+
const inferences = context.inferences;
|
|
130
|
+
for (let i = 0; i < inferences.length; i++)
|
|
131
|
+
if (type === inferences[i].typeParameter)
|
|
132
|
+
return getInferredType(context.c, context, i);
|
|
133
|
+
return type;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
115
136
|
export function createInferenceContext(c, typeParameters, signature, flags, compareTypes) {
|
|
116
137
|
const inferences = [];
|
|
117
138
|
for (const tp of typeParameters)
|
|
@@ -144,7 +165,7 @@ export function createOuterReturnMapper(c, context) {
|
|
|
144
165
|
return context.outerReturnMapper;
|
|
145
166
|
}
|
|
146
167
|
export function addIntraExpressionInferenceSite(context, node, type) {
|
|
147
|
-
context.intraExpressionInferenceSites.push(new IntraExpressionInferenceSite(node, type));
|
|
168
|
+
(context.intraExpressionInferenceSites ??= []).push(new IntraExpressionInferenceSite(node, type));
|
|
148
169
|
}
|
|
149
170
|
export function clearCachedInferences(inferences) {
|
|
150
171
|
for (const inference of inferences)
|
|
@@ -179,7 +200,7 @@ function hasTypeParameterDefault(tp) {
|
|
|
179
200
|
const symbol = tp.symbol;
|
|
180
201
|
if (symbol === undefined)
|
|
181
202
|
return false;
|
|
182
|
-
for (const d of symbol
|
|
203
|
+
for (const d of getDeclarations(symbol))
|
|
183
204
|
if (d.kind === 169 /* SyntaxKind.TypeParameter */ && d.defaultType !== undefined)
|
|
184
205
|
return true;
|
|
185
206
|
return false;
|
|
@@ -991,9 +1012,9 @@ function isTopLevelClassStaticSide(t) {
|
|
|
991
1012
|
(symbol.flags &
|
|
992
1013
|
(16 /* SymbolFlags.Function */ | 8192 /* SymbolFlags.Method */ | 2048 /* SymbolFlags.TypeLiteral */ | 4096 /* SymbolFlags.ObjectLiteral */)) !==
|
|
993
1014
|
0 ||
|
|
994
|
-
symbol
|
|
1015
|
+
declarationCount(symbol) === 0)
|
|
995
1016
|
return false;
|
|
996
|
-
for (const d of symbol
|
|
1017
|
+
for (const d of getDeclarations(symbol)) {
|
|
997
1018
|
if (d.kind !== 264 /* SyntaxKind.ClassDeclaration */ &&
|
|
998
1019
|
d.kind !== 265 /* SyntaxKind.InterfaceDeclaration */ &&
|
|
999
1020
|
d.kind !== 268 /* SyntaxKind.ModuleDeclaration */)
|
|
@@ -1031,7 +1052,7 @@ function createEmptyObjectTypeFromStringLiteral(c, t) {
|
|
|
1031
1052
|
const literalProp = c.newSymbol(4 /* SymbolFlags.Property */, name);
|
|
1032
1053
|
c.symbolTypes.set(getSymbolId(literalProp), c.anyType);
|
|
1033
1054
|
if (u.symbol !== undefined) {
|
|
1034
|
-
literalProp
|
|
1055
|
+
copyDeclarations(literalProp, u.symbol);
|
|
1035
1056
|
literalProp.valueDeclaration = u.symbol.valueDeclaration;
|
|
1036
1057
|
}
|
|
1037
1058
|
members.set(name, literalProp);
|
|
@@ -1101,7 +1122,7 @@ function typesDefinitelyUnrelated(c, source, target) {
|
|
|
1101
1122
|
function hasUnmatchedProperty(c, source, target, matchDiscriminantProperties) {
|
|
1102
1123
|
const t = getReducedApparentType(c, target);
|
|
1103
1124
|
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0 ||
|
|
1104
|
-
sideOf(c, t).resolvedProperties !== undefined)
|
|
1125
|
+
sideOf(c, t).membersOf?.resolvedProperties !== undefined)
|
|
1105
1126
|
return getUnmatchedProperty(c, source, target, false, matchDiscriminantProperties) !== undefined;
|
|
1106
1127
|
const containingType = t;
|
|
1107
1128
|
const isUnion = (t.flags & 134217728 /* TypeFlags.Union */) !== 0;
|
|
@@ -1146,7 +1167,7 @@ export function isConstTypeVariable(c, t, depth) {
|
|
|
1146
1167
|
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
|
|
1147
1168
|
if (t.symbol === undefined)
|
|
1148
1169
|
return false;
|
|
1149
|
-
for (const d of t.symbol
|
|
1170
|
+
for (const d of getDeclarations(t.symbol))
|
|
1150
1171
|
if (hasSyntacticModifier(d, 4096 /* ModifierFlags.Const */))
|
|
1151
1172
|
return true;
|
|
1152
1173
|
return false;
|
|
@@ -1616,7 +1637,7 @@ export function resolveReverseMappedTypeMembers(c, t) {
|
|
|
1616
1637
|
}
|
|
1617
1638
|
const checkFlags = 8192 /* CheckFlags.ReverseMapped */ | (readonlyMask && isReadonlySymbol(c, prop) ? 8 /* CheckFlags.Readonly */ : 0);
|
|
1618
1639
|
const inferredProp = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */ | (prop.flags & optionalMask), prop.name, checkFlags);
|
|
1619
|
-
inferredProp
|
|
1640
|
+
copyDeclarations(inferredProp, prop);
|
|
1620
1641
|
const links = c.symbolLinks(inferredProp);
|
|
1621
1642
|
const id = inferredProp.id;
|
|
1622
1643
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
@@ -1678,7 +1699,9 @@ export function instantiateReverseMappedType(c, t, mapper) {
|
|
|
1678
1699
|
/** Infers early from intra-expression sites (context-sensitive elements of object and array literals). */
|
|
1679
1700
|
export function inferFromIntraExpressionSites(c, context) {
|
|
1680
1701
|
const sites = context.intraExpressionInferenceSites;
|
|
1681
|
-
|
|
1702
|
+
if (sites === undefined)
|
|
1703
|
+
return;
|
|
1704
|
+
context.intraExpressionInferenceSites = undefined;
|
|
1682
1705
|
for (const site of sites) {
|
|
1683
1706
|
const contextualType = getContextualTypeForInference(c, site.node);
|
|
1684
1707
|
if (contextualType !== undefined)
|
|
@@ -1940,7 +1963,7 @@ export function inferTypesForConditional(c, root, checkType, extendsType, mapper
|
|
|
1940
1963
|
// so the non-fixing mapper combines with `mapper`.
|
|
1941
1964
|
const context = createInferenceContext(c, root.inferTypeParameters, undefined, 0 /* InferenceFlags.None */, undefined);
|
|
1942
1965
|
if (mapper !== undefined)
|
|
1943
|
-
context.
|
|
1966
|
+
context.nonFixingOuter = mapper;
|
|
1944
1967
|
// Inferences from constraints could eagerly resolve what should defer; contravariance is always strict.
|
|
1945
1968
|
if (!checkTypeDeferred)
|
|
1946
1969
|
inferTypes(c, context.inferences, checkType, extendsType, 512 /* InferencePriority.NoConstraints */ | 1024 /* InferencePriority.AlwaysStrict */, false);
|
|
@@ -2014,7 +2037,7 @@ export function getInferredTypeParameterConstraint(c, t, omitTypeReferences = fa
|
|
|
2014
2037
|
const inferences = [];
|
|
2015
2038
|
const symbol = t.symbol;
|
|
2016
2039
|
if (symbol !== undefined)
|
|
2017
|
-
for (const declaration of symbol
|
|
2040
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
2018
2041
|
if (declaration.parent === undefined || declaration.parent.kind !== 196 /* SyntaxKind.InferType */)
|
|
2019
2042
|
continue;
|
|
2020
2043
|
let child = declaration.parent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryExpression, type Node } from './ast.js';
|
|
2
|
-
import { type Symbol } from './symbol.js';
|
|
3
2
|
import type { Checker } from './checker.js';
|
|
4
3
|
import { type Type } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
/** The type of the CommonJS `module` symbol or its `exports` property. */
|
|
6
6
|
export declare function getTypeOfModuleExportsSymbol(c: Checker, symbol: Symbol): Type;
|
|
7
7
|
/** The type of a symbol declared by JavaScript assignments or `Object.defineProperty` calls. */
|