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
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
17
17
|
import { type Diagnostic, type DiagnosticMessage, Diagnostics } from './diagnostics.js';
|
|
18
18
|
import { SyntaxKind } from './syntax-kind.js';
|
|
19
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
20
19
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
21
20
|
import { AccessFlags, SignatureKind, type Type, TypeFlags } from './checker-types.js';
|
|
22
21
|
import { getNumberLiteralType, getUnionType, isTupleType, typesOf } from './checker-type-factory.js';
|
|
@@ -49,6 +48,7 @@ import { FunctionFlags, getFunctionFlags } from './checker-utilities.js';
|
|
|
49
48
|
import { typeToString } from './type-printer.js';
|
|
50
49
|
import { CheckMode } from './checker-types.js';
|
|
51
50
|
import { elaborateJsxComponents } from './checker-jsx.js';
|
|
51
|
+
import { declarationCount, type Symbol, SymbolFlags } from './symbol.js';
|
|
52
52
|
|
|
53
53
|
/** Checks that `source` relates to `target`, elaborating into `expr` when possible. */
|
|
54
54
|
export function checkTypeRelatedToAndOptionallyElaborate(
|
|
@@ -381,13 +381,13 @@ export function elaborateElement(
|
|
|
381
381
|
}
|
|
382
382
|
if (
|
|
383
383
|
!issuedElaboration &&
|
|
384
|
-
((targetProp !== undefined && targetProp
|
|
385
|
-
(target.symbol !== undefined && target.symbol
|
|
384
|
+
((targetProp !== undefined && declarationCount(targetProp) !== 0) ||
|
|
385
|
+
(target.symbol !== undefined && declarationCount(target.symbol) !== 0))
|
|
386
386
|
) {
|
|
387
387
|
const targetNode =
|
|
388
|
-
targetProp !== undefined && targetProp
|
|
389
|
-
? targetProp.
|
|
390
|
-
: target.symbol!.
|
|
388
|
+
targetProp !== undefined && declarationCount(targetProp) !== 0
|
|
389
|
+
? targetProp.declaration!
|
|
390
|
+
: target.symbol!.declaration!;
|
|
391
391
|
if (propertyName === '' || (nameType.flags & TypeFlags.UniqueESSymbol) !== 0)
|
|
392
392
|
propertyName = typeToString(c, nameType);
|
|
393
393
|
if (!c.host.isSourceFileDefaultLibrary(getSourceFileOfNode(targetNode)))
|
|
@@ -456,10 +456,10 @@ function elaborateArrowFunction(
|
|
|
456
456
|
checkTypeRelatedTo(c, sourceReturn, targetReturn, relation, returnExpression, undefined, diagnostics);
|
|
457
457
|
if (diagnostics.length === 0) return false;
|
|
458
458
|
const diagnostic = diagnostics[0]!;
|
|
459
|
-
if (target.symbol !== undefined && target.symbol
|
|
459
|
+
if (target.symbol !== undefined && declarationCount(target.symbol) !== 0)
|
|
460
460
|
diagnostic.addRelatedInfo(
|
|
461
461
|
createDiagnosticForNode(
|
|
462
|
-
target.symbol.
|
|
462
|
+
target.symbol.declaration!,
|
|
463
463
|
Diagnostics.The_expected_type_comes_from_the_return_type_of_this_signature,
|
|
464
464
|
[],
|
|
465
465
|
),
|
|
@@ -57,7 +57,8 @@ class PendingHelperCheck {
|
|
|
57
57
|
export class EmitHelperFileLinks {
|
|
58
58
|
helpersModule: Symbol | undefined = undefined;
|
|
59
59
|
requestedHelpers: number = ExternalEmitHelpers.None;
|
|
60
|
-
|
|
60
|
+
/** Created on the first check; most files have none. */
|
|
61
|
+
pending: PendingHelperCheck[] | undefined = undefined;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
function fileLinks(c: Checker, file: SourceFile): EmitHelperFileLinks {
|
|
@@ -86,7 +87,7 @@ export function checkExternalEmitHelpers(c: Checker, location: Node, helpers: Ex
|
|
|
86
87
|
const fileIndex = c.fileIndex.get(file);
|
|
87
88
|
const checkingIndex = c.fileIndex.get(checking);
|
|
88
89
|
if (fileIndex !== undefined && checkingIndex !== undefined && fileIndex < checkingIndex) {
|
|
89
|
-
fileLinks(c, file).pending.push(new PendingHelperCheck(location, helpers));
|
|
90
|
+
(fileLinks(c, file).pending ??= []).push(new PendingHelperCheck(location, helpers));
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -141,9 +142,9 @@ export function checkExternalEmitHelpers(c: Checker, location: Node, helpers: Ex
|
|
|
141
142
|
/** Runs the helper checks for nodes of `file` that were reached while checking later files. */
|
|
142
143
|
export function checkPendingExternalEmitHelpers(c: Checker, file: SourceFile): void {
|
|
143
144
|
const links = c.emitHelperFileLinks.get(file);
|
|
144
|
-
if (links === undefined
|
|
145
|
+
if (links?.pending === undefined) return;
|
|
145
146
|
const pending = links.pending;
|
|
146
|
-
links.pending =
|
|
147
|
+
links.pending = undefined;
|
|
147
148
|
for (const check of pending) checkExternalEmitHelpers(c, check.location, check.helpers);
|
|
148
149
|
}
|
|
149
150
|
|
|
@@ -95,7 +95,6 @@ import { tryReuseExistingNode } from './node-builder-reuse.js';
|
|
|
95
95
|
import type { CompilerOptions, ModuleKind } from './options.js';
|
|
96
96
|
import type { EmitContext } from './printer/emit-context.js';
|
|
97
97
|
import { isTypeIdenticalTo } from './relations.js';
|
|
98
|
-
import { CheckFlags, type Symbol, SymbolFlags } from './symbol.js';
|
|
99
98
|
import {
|
|
100
99
|
beginDeclarationEmitVisibility,
|
|
101
100
|
isDeclarationVisible,
|
|
@@ -116,6 +115,7 @@ import { SyntacticEmitResolver } from './transformers/emit-resolver.js';
|
|
|
116
115
|
import type { Evaluation, ReferenceResolver } from './transformers/reference-resolver.js';
|
|
117
116
|
import { TypeReferenceSerializationKind } from './transformers/type-serialization.js';
|
|
118
117
|
import { TokenFlags } from './types.js';
|
|
118
|
+
import { CheckFlags, declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
119
119
|
|
|
120
120
|
const declarationEmitInternalFlags = NodeBuilderInternalFlags.AllowUnresolvedNames;
|
|
121
121
|
const aliasMeaning = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias;
|
|
@@ -218,7 +218,7 @@ export class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
|
218
218
|
while (exportSymbol !== undefined && !visited.has(exportSymbol)) {
|
|
219
219
|
visited.add(exportSymbol);
|
|
220
220
|
let next: Symbol | undefined = undefined;
|
|
221
|
-
for (const declaration of exportSymbol
|
|
221
|
+
for (const declaration of getDeclarations(exportSymbol)) {
|
|
222
222
|
markDeclarationVisible(c, declaration);
|
|
223
223
|
if (
|
|
224
224
|
declaration instanceof ImportEqualsDeclaration &&
|
|
@@ -265,7 +265,7 @@ export class CheckerDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
|
265
265
|
for (const s of getExportsOfModule(c, file.symbol).values()) {
|
|
266
266
|
const merged = getMergedSymbol(c, s);
|
|
267
267
|
if (merged === s) continue;
|
|
268
|
-
for (const d of merged
|
|
268
|
+
for (const d of getDeclarations(merged)) if (getSourceFileOfNode(d) === importTarget) return true;
|
|
269
269
|
}
|
|
270
270
|
return false;
|
|
271
271
|
}
|
|
@@ -621,8 +621,8 @@ export function getTypeReferenceSerializationKind(
|
|
|
621
621
|
let isTypeOnly = false;
|
|
622
622
|
if (typeName.kind === SyntaxKind.QualifiedName) {
|
|
623
623
|
const root = resolveEntityName(c, getFirstIdentifier(typeName), SymbolFlags.Value, true, true, location);
|
|
624
|
-
if (root !== undefined && root
|
|
625
|
-
isTypeOnly = root.
|
|
624
|
+
if (root !== undefined && declarationCount(root) > 0)
|
|
625
|
+
isTypeOnly = getDeclarations(root).every(isTypeOnlyImportOrExportDeclaration);
|
|
626
626
|
}
|
|
627
627
|
const valueSymbol = resolveEntityName(c, typeName, SymbolFlags.Value, true, true, location);
|
|
628
628
|
let resolvedValue = valueSymbol;
|
|
@@ -80,6 +80,8 @@ import {
|
|
|
80
80
|
getTypeArguments,
|
|
81
81
|
getTypeParameters,
|
|
82
82
|
isDeclarationNode,
|
|
83
|
+
callQuestionDotToken,
|
|
84
|
+
callTypeArguments,
|
|
83
85
|
} from './ast.js';
|
|
84
86
|
import {
|
|
85
87
|
canHaveDecorators,
|
|
@@ -130,12 +132,12 @@ import { ModuleKind, ScriptTarget, getEmitModuleKind } from './options.js';
|
|
|
130
132
|
import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
|
|
131
133
|
import { SourceFileMetadata, getEmitModuleFormatOfFile, getImpliedNodeFormatForEmit } from './program-utilities.js';
|
|
132
134
|
import { CharacterCodes } from './character-codes.js';
|
|
133
|
-
import { Scanner, ScannerErrorReporter,
|
|
134
|
-
import { SymbolFlags } from './symbol.js';
|
|
135
|
+
import { Scanner, ScannerErrorReporter, skipTrivia, tokenToString } from './scanner.js';
|
|
135
136
|
import { typeToString } from './type-printer.js';
|
|
136
137
|
import type { ScriptTarget as LanguageTarget } from './types.js';
|
|
137
138
|
import { SyntaxKind } from './syntax-kind.js';
|
|
138
139
|
import { findMismatchedAugmentsTag } from './checker-jsdoc.js';
|
|
140
|
+
import { getDeclarations, SymbolFlags } from './symbol.js';
|
|
139
141
|
|
|
140
142
|
/** Runs the grammar checks of every node of `file`. */
|
|
141
143
|
export function checkGrammarSourceFile(c: Checker, file: SourceFile): void {
|
|
@@ -1266,7 +1268,7 @@ function getFirstAccessorOfPair(c: Checker, node: Node): Node {
|
|
|
1266
1268
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
1267
1269
|
if (symbol === undefined) return node;
|
|
1268
1270
|
const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
|
|
1269
|
-
for (const declaration of symbol
|
|
1271
|
+
for (const declaration of getDeclarations(symbol))
|
|
1270
1272
|
if (declaration.kind === otherKind && declaration.pos < node.pos) return declaration;
|
|
1271
1273
|
return node;
|
|
1272
1274
|
}
|
|
@@ -1297,7 +1299,7 @@ function checkGrammarDecorator(g: GrammarChecker, decorator: Decorator): boolean
|
|
|
1297
1299
|
const call = node as CallExpression;
|
|
1298
1300
|
if (!canHaveCallExpression) errorNode = node;
|
|
1299
1301
|
// A `?.` token comes first, so it wins over an earlier error node.
|
|
1300
|
-
if (call
|
|
1302
|
+
if (callQuestionDotToken(call) !== undefined) errorNode = callQuestionDotToken(call);
|
|
1301
1303
|
node = call.expression;
|
|
1302
1304
|
canHaveCallExpression = false;
|
|
1303
1305
|
continue;
|
|
@@ -1437,13 +1439,25 @@ function checkGrammarArrowFunction(g: GrammarChecker, node: Node): boolean {
|
|
|
1437
1439
|
}
|
|
1438
1440
|
const arrowToken = arrow.equalsGreaterThanToken;
|
|
1439
1441
|
if (arrowToken === undefined) return false;
|
|
1440
|
-
const lineStarts = g.file.lineStarts();
|
|
1441
1442
|
return (
|
|
1442
|
-
|
|
1443
|
+
hasLineBreak(g.file.text, arrowToken.pos, arrowToken.end) &&
|
|
1443
1444
|
grammarErrorOnNode(g, arrowToken, Diagnostics.Line_terminator_not_permitted_before_arrow)
|
|
1444
1445
|
);
|
|
1445
1446
|
}
|
|
1446
1447
|
|
|
1448
|
+
/**
|
|
1449
|
+
* Whether a line starts in `(pos, end]`, so that `pos` and `end` are on different lines: after an
|
|
1450
|
+
* LF, LS or PS, or a CR that no LF follows (`computeLineStarts`), without the file's line starts.
|
|
1451
|
+
*/
|
|
1452
|
+
function hasLineBreak(text: string, pos: number, end: number): boolean {
|
|
1453
|
+
for (let i = pos; i < end; i++) {
|
|
1454
|
+
const c = text.charCodeAt(i);
|
|
1455
|
+
if (c === 0x0a || c === 0x2028 || c === 0x2029) return true;
|
|
1456
|
+
if (c === 0x0d && text.charCodeAt(i + 1) !== 0x0a) return true;
|
|
1457
|
+
}
|
|
1458
|
+
return false;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1447
1461
|
function checkGrammarForGenerator(g: GrammarChecker, node: Node): boolean {
|
|
1448
1462
|
const asteriskToken = getAsteriskToken(node);
|
|
1449
1463
|
if (asteriskToken === undefined) return false;
|
|
@@ -3293,7 +3307,7 @@ function checkGrammarCallExpression(g: GrammarChecker, node: CallExpression): vo
|
|
|
3293
3307
|
(callee as MetaProperty).keywordToken === SyntaxKind.ImportKeyword &&
|
|
3294
3308
|
(callee as MetaProperty).name.text === 'defer');
|
|
3295
3309
|
if (isImportCall) checkGrammarImportCallExpression(g, node);
|
|
3296
|
-
else checkGrammarTypeArguments(g, node
|
|
3310
|
+
else checkGrammarTypeArguments(g, callTypeArguments(node));
|
|
3297
3311
|
}
|
|
3298
3312
|
|
|
3299
3313
|
function checkGrammarImportCallExpression(g: GrammarChecker, node: CallExpression): boolean {
|
|
@@ -3319,7 +3333,7 @@ function checkGrammarImportCallExpression(g: GrammarChecker, node: CallExpressio
|
|
|
3319
3333
|
node,
|
|
3320
3334
|
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,
|
|
3321
3335
|
);
|
|
3322
|
-
if (node
|
|
3336
|
+
if (callTypeArguments(node) !== undefined)
|
|
3323
3337
|
return grammarErrorOnNode(
|
|
3324
3338
|
g,
|
|
3325
3339
|
node,
|
|
@@ -31,7 +31,6 @@ import {
|
|
|
31
31
|
} from './binder-utilities.js';
|
|
32
32
|
import { type Diagnostic, type DiagnosticMessage, Diagnostics, chainDiagnostic } from './diagnostics.js';
|
|
33
33
|
import { getUseDefineForClassFields } from './options.js';
|
|
34
|
-
import { CheckFlags, InternalSymbolName, type Symbol, SymbolFlags } from './symbol.js';
|
|
35
34
|
import { SyntaxKind } from './syntax-kind.js';
|
|
36
35
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
37
36
|
import {
|
|
@@ -115,6 +114,14 @@ import { Ternary } from './checker-types.js';
|
|
|
115
114
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
116
115
|
import { checkFunctionOrConstructorSymbol } from './checker-overloads.js';
|
|
117
116
|
import { isPropertyInitializedInConstructor } from './checker-classes.js';
|
|
117
|
+
import {
|
|
118
|
+
CheckFlags,
|
|
119
|
+
declarationCount,
|
|
120
|
+
getDeclarations,
|
|
121
|
+
InternalSymbolName,
|
|
122
|
+
type Symbol,
|
|
123
|
+
SymbolFlags,
|
|
124
|
+
} from './symbol.js';
|
|
118
125
|
|
|
119
126
|
// ---- Classes
|
|
120
127
|
|
|
@@ -519,7 +526,7 @@ function checkPropertyOverwritesBase(
|
|
|
519
526
|
derivedDeclarationFlags: ModifierFlags,
|
|
520
527
|
): void {
|
|
521
528
|
let uninitialized: Node | undefined;
|
|
522
|
-
for (const d of derived
|
|
529
|
+
for (const d of getDeclarations(derived)) {
|
|
523
530
|
if (d.kind === SyntaxKind.PropertyDeclaration && getInitializer(d) === undefined) {
|
|
524
531
|
uninitialized = d;
|
|
525
532
|
break;
|
|
@@ -532,7 +539,7 @@ function checkPropertyOverwritesBase(
|
|
|
532
539
|
(derivedDeclarationFlags & ModifierFlags.Abstract) !== 0
|
|
533
540
|
)
|
|
534
541
|
return;
|
|
535
|
-
for (const d of derived
|
|
542
|
+
for (const d of getDeclarations(derived)) if ((d.flags & NodeFlags.Ambient) !== 0) return;
|
|
536
543
|
const constructor = findConstructorDeclaration(getClassLikeDeclarationOfSymbol(t.symbol!)!);
|
|
537
544
|
const propName = getName(uninitialized)!;
|
|
538
545
|
const postfix = getPostfixToken(uninitialized);
|
|
@@ -618,10 +625,10 @@ function reportMissingAbstractMembers(c: Checker, node: Node | undefined, missin
|
|
|
618
625
|
function arePropertiesAbstractOrInterface(base: Symbol, baseDeclarationFlags: ModifierFlags): boolean {
|
|
619
626
|
// Synthetic (intersection) properties need any declaration to qualify; others need all.
|
|
620
627
|
if ((base.checkFlags & CheckFlags.Synthetic) !== 0) {
|
|
621
|
-
for (const d of base
|
|
628
|
+
for (const d of getDeclarations(base)) if (isPropertyAbstractOrInterface(d, baseDeclarationFlags)) return true;
|
|
622
629
|
return false;
|
|
623
630
|
}
|
|
624
|
-
for (const d of base
|
|
631
|
+
for (const d of getDeclarations(base)) if (!isPropertyAbstractOrInterface(d, baseDeclarationFlags)) return false;
|
|
625
632
|
return true;
|
|
626
633
|
}
|
|
627
634
|
|
|
@@ -733,14 +740,14 @@ function checkMemberForOverrideModifier(
|
|
|
733
740
|
}
|
|
734
741
|
if (
|
|
735
742
|
baseProp === undefined ||
|
|
736
|
-
baseProp
|
|
743
|
+
declarationCount(baseProp) === 0 ||
|
|
737
744
|
memberHasOverrideModifier ||
|
|
738
745
|
c.compilerOptions.noImplicitOverride !== true ||
|
|
739
746
|
(node.flags & NodeFlags.Ambient) !== 0
|
|
740
747
|
)
|
|
741
748
|
return;
|
|
742
749
|
let baseHasAbstract = false;
|
|
743
|
-
for (const d of baseProp
|
|
750
|
+
for (const d of getDeclarations(baseProp)) {
|
|
744
751
|
if (hasSyntacticModifier(d, ModifierFlags.Abstract)) {
|
|
745
752
|
baseHasAbstract = true;
|
|
746
753
|
break;
|
|
@@ -869,12 +876,12 @@ function checkInheritedPropertiesAreIdentical(c: Checker, t: InterfaceType, type
|
|
|
869
876
|
|
|
870
877
|
/** Reports class and interface declarations of one symbol whose type parameters differ. */
|
|
871
878
|
export function checkTypeParameterListsIdentical(c: Checker, symbol: Symbol): void {
|
|
872
|
-
if (symbol
|
|
879
|
+
if (declarationCount(symbol) === 1) return;
|
|
873
880
|
const links = c.symbolLinks(symbol);
|
|
874
881
|
if (links.typeParametersChecked) return;
|
|
875
882
|
links.typeParametersChecked = true;
|
|
876
883
|
const declarations: Node[] = [];
|
|
877
|
-
for (const d of symbol
|
|
884
|
+
for (const d of getDeclarations(symbol))
|
|
878
885
|
if (d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration) declarations.push(d);
|
|
879
886
|
if (declarations.length <= 1) return;
|
|
880
887
|
const t = getDeclaredTypeOfSymbol(c, symbol) as InterfaceType;
|
|
@@ -892,13 +899,13 @@ export function checkTypeParameterListsIdentical(c: Checker, symbol: Symbol): vo
|
|
|
892
899
|
|
|
893
900
|
/** Reports the declarations of an `infer` type parameter declared more than once with different constraints. */
|
|
894
901
|
export function checkInferTypeParameterDeclarations(c: Checker, symbol: Symbol): void {
|
|
895
|
-
if (symbol
|
|
902
|
+
if (declarationCount(symbol) <= 1) return;
|
|
896
903
|
const links = c.symbolLinks(symbol);
|
|
897
904
|
if (links.typeParametersChecked) return;
|
|
898
905
|
links.typeParametersChecked = true;
|
|
899
906
|
const declarations: Node[] = [];
|
|
900
907
|
const typeParameterLists: Node[][] = [];
|
|
901
|
-
for (const d of symbol
|
|
908
|
+
for (const d of getDeclarations(symbol)) {
|
|
902
909
|
if (d.kind === SyntaxKind.TypeParameter) {
|
|
903
910
|
declarations.push(d);
|
|
904
911
|
typeParameterLists.push([d]);
|
|
@@ -1020,7 +1027,7 @@ function checkPropertyOrAccessor(
|
|
|
1020
1027
|
kind: MemberKind,
|
|
1021
1028
|
isStaticMember: boolean,
|
|
1022
1029
|
): void {
|
|
1023
|
-
if (symbol
|
|
1030
|
+
if (declarationCount(symbol) <= 1) return;
|
|
1024
1031
|
const state = names.get(symbol.name) ?? MemberKind.None;
|
|
1025
1032
|
if (state === MemberKind.None) names.set(symbol.name, kind);
|
|
1026
1033
|
// A second property, or a property combined with an accessor.
|
|
@@ -1203,11 +1210,11 @@ function checkTypeForDuplicateIndexSignatures(c: Checker, node: Node): void {
|
|
|
1203
1210
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
1204
1211
|
if (symbol === undefined) return;
|
|
1205
1212
|
const indexSymbol = getIndexSymbol(c, symbol);
|
|
1206
|
-
if (indexSymbol === undefined || indexSymbol
|
|
1213
|
+
if (indexSymbol === undefined || declarationCount(indexSymbol) <= 1) return;
|
|
1207
1214
|
// Late-bound index signatures may duplicate each other and explicit ones.
|
|
1208
1215
|
const keyTypes: Type[] = [];
|
|
1209
1216
|
const declarationsByKey: Node[][] = [];
|
|
1210
|
-
for (const declaration of indexSymbol
|
|
1217
|
+
for (const declaration of getDeclarations(indexSymbol)) {
|
|
1211
1218
|
if (declaration.kind !== SyntaxKind.IndexSignature) continue;
|
|
1212
1219
|
const parameters = getParameters(declaration)!.nodes;
|
|
1213
1220
|
if (parameters.length !== 1) continue;
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
type ConditionalTypeNode,
|
|
14
14
|
} from './ast.js';
|
|
15
15
|
import { hasSyntacticModifier } from './binder-utilities.js';
|
|
16
|
-
import { CheckFlags, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
17
16
|
import { SyntaxKind } from './syntax-kind.js';
|
|
18
17
|
import type { Checker } from './checker.js';
|
|
19
18
|
import {
|
|
@@ -194,6 +193,15 @@ import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
|
194
193
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
195
194
|
import { parsePseudoBigInt } from './pseudo-bigint.js';
|
|
196
195
|
import { getContextualTypeForInference } from './checker-contextual.js';
|
|
196
|
+
import {
|
|
197
|
+
CheckFlags,
|
|
198
|
+
copyDeclarations,
|
|
199
|
+
declarationCount,
|
|
200
|
+
getDeclarations,
|
|
201
|
+
getSymbolId,
|
|
202
|
+
type Symbol,
|
|
203
|
+
SymbolFlags,
|
|
204
|
+
} from './symbol.js';
|
|
197
205
|
|
|
198
206
|
export const enum InferenceFlags {
|
|
199
207
|
None = 0,
|
|
@@ -285,20 +293,27 @@ export class IntraExpressionInferenceSite {
|
|
|
285
293
|
}
|
|
286
294
|
}
|
|
287
295
|
|
|
288
|
-
|
|
296
|
+
/**
|
|
297
|
+
* The inferences for a set of type parameters. The context is its own fixing mapper (`mapper`), and
|
|
298
|
+
* each read of `nonFixingMapper` returns a new mapper that reads the context: no mapper the context
|
|
299
|
+
* holds refers back to it, so a context whose inference is done is freed by reference counting
|
|
300
|
+
* rather than by the cycle collector.
|
|
301
|
+
*/
|
|
302
|
+
export class InferenceContext extends TypeMapper {
|
|
303
|
+
readonly c: Checker;
|
|
289
304
|
inferences: InferenceInfo[];
|
|
290
305
|
/** The generic signature inferences are made for, if any. */
|
|
291
306
|
readonly signature: Signature | undefined;
|
|
292
307
|
flags: InferenceFlags;
|
|
293
308
|
readonly compareTypes: TypeComparer;
|
|
294
|
-
/**
|
|
295
|
-
|
|
296
|
-
nonFixingMapper: TypeMapper;
|
|
309
|
+
/** Combined after the non-fixing mapper (conditional types' `infer` constraints), if any. */
|
|
310
|
+
nonFixingOuter: TypeMapper | undefined = undefined;
|
|
297
311
|
/** Maps to inferences from the return type, if any. */
|
|
298
312
|
returnMapper: TypeMapper | undefined = undefined;
|
|
299
313
|
outerReturnMapper: TypeMapper | undefined = undefined;
|
|
300
314
|
inferredTypeParameters: Type[] | undefined = undefined;
|
|
301
|
-
|
|
315
|
+
/** Created on the first site; most contexts get none. */
|
|
316
|
+
intraExpressionInferenceSites: IntraExpressionInferenceSite[] | undefined = undefined;
|
|
302
317
|
|
|
303
318
|
constructor(
|
|
304
319
|
c: Checker,
|
|
@@ -307,45 +322,61 @@ export class InferenceContext {
|
|
|
307
322
|
flags: InferenceFlags,
|
|
308
323
|
compareTypes: TypeComparer,
|
|
309
324
|
) {
|
|
325
|
+
super();
|
|
326
|
+
this.c = c;
|
|
310
327
|
this.inferences = inferences;
|
|
311
328
|
this.signature = signature;
|
|
312
329
|
this.flags = flags;
|
|
313
330
|
this.compareTypes = compareTypes;
|
|
314
|
-
this.mapper = new InferenceTypeMapper(c, this, true);
|
|
315
|
-
this.nonFixingMapper = new InferenceTypeMapper(c, this, false);
|
|
316
331
|
}
|
|
317
|
-
}
|
|
318
332
|
|
|
319
|
-
/**
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
readonly fixing: boolean;
|
|
333
|
+
/** Fixes inferences. */
|
|
334
|
+
get mapper(): TypeMapper {
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
324
337
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.
|
|
338
|
+
/** Maps to the current inferences without fixing them. */
|
|
339
|
+
get nonFixingMapper(): TypeMapper {
|
|
340
|
+
const mapper = new NonFixingInferenceMapper(this);
|
|
341
|
+
const outer = this.nonFixingOuter;
|
|
342
|
+
return outer !== undefined ? combineTypeMappers(this.c, mapper, outer) : mapper;
|
|
330
343
|
}
|
|
331
344
|
|
|
332
345
|
map(type: Type): Type {
|
|
333
|
-
const inferences = this.
|
|
346
|
+
const inferences = this.inferences;
|
|
334
347
|
for (let i = 0; i < inferences.length; i++) {
|
|
335
348
|
const inference = inferences[i]!;
|
|
336
349
|
if (type !== inference.typeParameter) continue;
|
|
337
|
-
if (
|
|
350
|
+
if (!inference.isFixed) {
|
|
338
351
|
// Infer from intra-expression sites before committing to an inference.
|
|
339
|
-
inferFromIntraExpressionSites(this.c, this
|
|
352
|
+
inferFromIntraExpressionSites(this.c, this);
|
|
340
353
|
clearCachedInferences(inferences);
|
|
341
354
|
inference.isFixed = true;
|
|
342
355
|
}
|
|
343
|
-
return getInferredType(this.c, this
|
|
356
|
+
return getInferredType(this.c, this, i);
|
|
344
357
|
}
|
|
345
358
|
return type;
|
|
346
359
|
}
|
|
347
360
|
}
|
|
348
361
|
|
|
362
|
+
/** Maps a context's type parameters to their inferred types without fixing them. */
|
|
363
|
+
export class NonFixingInferenceMapper extends TypeMapper {
|
|
364
|
+
readonly context: InferenceContext;
|
|
365
|
+
|
|
366
|
+
constructor(context: InferenceContext) {
|
|
367
|
+
super();
|
|
368
|
+
this.context = context;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
map(type: Type): Type {
|
|
372
|
+
const context = this.context;
|
|
373
|
+
const inferences = context.inferences;
|
|
374
|
+
for (let i = 0; i < inferences.length; i++)
|
|
375
|
+
if (type === inferences[i]!.typeParameter) return getInferredType(context.c, context, i);
|
|
376
|
+
return type;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
349
380
|
export function createInferenceContext(
|
|
350
381
|
c: Checker,
|
|
351
382
|
typeParameters: readonly Type[],
|
|
@@ -394,7 +425,7 @@ export function createOuterReturnMapper(c: Checker, context: InferenceContext):
|
|
|
394
425
|
}
|
|
395
426
|
|
|
396
427
|
export function addIntraExpressionInferenceSite(context: InferenceContext, node: Node, type: Type): void {
|
|
397
|
-
context.intraExpressionInferenceSites.push(new IntraExpressionInferenceSite(node, type));
|
|
428
|
+
(context.intraExpressionInferenceSites ??= []).push(new IntraExpressionInferenceSite(node, type));
|
|
398
429
|
}
|
|
399
430
|
|
|
400
431
|
export function clearCachedInferences(inferences: InferenceInfo[]): void {
|
|
@@ -427,7 +458,7 @@ export function someInferenceHasCandidatesOrDefault(inferences: InferenceInfo[])
|
|
|
427
458
|
function hasTypeParameterDefault(tp: Type): boolean {
|
|
428
459
|
const symbol = tp.symbol;
|
|
429
460
|
if (symbol === undefined) return false;
|
|
430
|
-
for (const d of symbol
|
|
461
|
+
for (const d of getDeclarations(symbol))
|
|
431
462
|
if (d.kind === SyntaxKind.TypeParameter && (d as TypeParameterDeclaration).defaultType !== undefined) return true;
|
|
432
463
|
return false;
|
|
433
464
|
}
|
|
@@ -1324,10 +1355,10 @@ function isTopLevelClassStaticSide(t: Type): boolean {
|
|
|
1324
1355
|
(symbol.flags &
|
|
1325
1356
|
(SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral)) !==
|
|
1326
1357
|
0 ||
|
|
1327
|
-
symbol
|
|
1358
|
+
declarationCount(symbol) === 0
|
|
1328
1359
|
)
|
|
1329
1360
|
return false;
|
|
1330
|
-
for (const d of symbol
|
|
1361
|
+
for (const d of getDeclarations(symbol)) {
|
|
1331
1362
|
if (
|
|
1332
1363
|
d.kind !== SyntaxKind.ClassDeclaration &&
|
|
1333
1364
|
d.kind !== SyntaxKind.InterfaceDeclaration &&
|
|
@@ -1370,7 +1401,7 @@ function createEmptyObjectTypeFromStringLiteral(c: Checker, t: Type): Type {
|
|
|
1370
1401
|
const literalProp = c.newSymbol(SymbolFlags.Property, name);
|
|
1371
1402
|
c.symbolTypes.set(getSymbolId(literalProp), c.anyType);
|
|
1372
1403
|
if (u.symbol !== undefined) {
|
|
1373
|
-
literalProp
|
|
1404
|
+
copyDeclarations(literalProp, u.symbol);
|
|
1374
1405
|
literalProp.valueDeclaration = u.symbol.valueDeclaration;
|
|
1375
1406
|
}
|
|
1376
1407
|
members.set(name, literalProp);
|
|
@@ -1452,7 +1483,7 @@ function hasUnmatchedProperty(c: Checker, source: Type, target: Type, matchDiscr
|
|
|
1452
1483
|
const t = getReducedApparentType(c, target);
|
|
1453
1484
|
if (
|
|
1454
1485
|
(t.flags & TypeFlags.UnionOrIntersection) === 0 ||
|
|
1455
|
-
sideOf(c, t as UnionOrIntersectionType).resolvedProperties !== undefined
|
|
1486
|
+
sideOf(c, t as UnionOrIntersectionType).membersOf?.resolvedProperties !== undefined
|
|
1456
1487
|
)
|
|
1457
1488
|
return getUnmatchedProperty(c, source, target, false, matchDiscriminantProperties) !== undefined;
|
|
1458
1489
|
const containingType = t as UnionOrIntersectionType;
|
|
@@ -1495,7 +1526,7 @@ export function isConstTypeVariable(c: Checker, t: Type | undefined, depth: numb
|
|
|
1495
1526
|
if (depth >= 5 || t === undefined) return false;
|
|
1496
1527
|
if ((t.flags & TypeFlags.TypeParameter) !== 0) {
|
|
1497
1528
|
if (t.symbol === undefined) return false;
|
|
1498
|
-
for (const d of t.symbol
|
|
1529
|
+
for (const d of getDeclarations(t.symbol)) if (hasSyntacticModifier(d, ModifierFlags.Const)) return true;
|
|
1499
1530
|
return false;
|
|
1500
1531
|
}
|
|
1501
1532
|
if ((t.flags & TypeFlags.UnionOrIntersection) !== 0) {
|
|
@@ -2031,7 +2062,7 @@ export function resolveReverseMappedTypeMembers(c: Checker, t: ReverseMappedType
|
|
|
2031
2062
|
prop.name,
|
|
2032
2063
|
checkFlags,
|
|
2033
2064
|
);
|
|
2034
|
-
inferredProp
|
|
2065
|
+
copyDeclarations(inferredProp, prop);
|
|
2035
2066
|
const links = c.symbolLinks(inferredProp);
|
|
2036
2067
|
const id = inferredProp.id;
|
|
2037
2068
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
@@ -2118,7 +2149,8 @@ export function instantiateReverseMappedType(c: Checker, t: ReverseMappedType, m
|
|
|
2118
2149
|
/** Infers early from intra-expression sites (context-sensitive elements of object and array literals). */
|
|
2119
2150
|
export function inferFromIntraExpressionSites(c: Checker, context: InferenceContext): void {
|
|
2120
2151
|
const sites = context.intraExpressionInferenceSites;
|
|
2121
|
-
|
|
2152
|
+
if (sites === undefined) return;
|
|
2153
|
+
context.intraExpressionInferenceSites = undefined;
|
|
2122
2154
|
for (const site of sites) {
|
|
2123
2155
|
const contextualType = getContextualTypeForInference(c, site.node);
|
|
2124
2156
|
if (contextualType !== undefined)
|
|
@@ -2394,7 +2426,7 @@ export function inferTypesForConditional(
|
|
|
2394
2426
|
// The constraints of `infer` type parameters may refer to other roots or to what `mapper` maps,
|
|
2395
2427
|
// so the non-fixing mapper combines with `mapper`.
|
|
2396
2428
|
const context = createInferenceContext(c, root.inferTypeParameters, undefined, InferenceFlags.None, undefined);
|
|
2397
|
-
if (mapper !== undefined) context.
|
|
2429
|
+
if (mapper !== undefined) context.nonFixingOuter = mapper;
|
|
2398
2430
|
// Inferences from constraints could eagerly resolve what should defer; contravariance is always strict.
|
|
2399
2431
|
if (!checkTypeDeferred)
|
|
2400
2432
|
inferTypes(
|
|
@@ -2484,7 +2516,7 @@ export function getInferredTypeParameterConstraint(c: Checker, t: Type, omitType
|
|
|
2484
2516
|
const inferences: Type[] = [];
|
|
2485
2517
|
const symbol = t.symbol;
|
|
2486
2518
|
if (symbol !== undefined)
|
|
2487
|
-
for (const declaration of symbol
|
|
2519
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
2488
2520
|
if (declaration.parent === undefined || declaration.parent.kind !== SyntaxKind.InferType) continue;
|
|
2489
2521
|
let child: Node = declaration.parent;
|
|
2490
2522
|
let parent = child.parent;
|
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
isStringOrNumericLiteralLike,
|
|
31
31
|
isVariableDeclarationInitializedToRequire,
|
|
32
32
|
} from './binder-utilities.js';
|
|
33
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
34
33
|
import { SyntaxKind } from './syntax-kind.js';
|
|
35
34
|
import type { Checker } from './checker.js';
|
|
36
35
|
import { ObjectFlags, type Type, TypeFlags } from './checker-types.js';
|
|
@@ -67,6 +66,7 @@ import {
|
|
|
67
66
|
getTypeOfPropertyInBaseClass,
|
|
68
67
|
isAutoTypedProperty,
|
|
69
68
|
} from './checker-classes.js';
|
|
69
|
+
import { declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
70
70
|
|
|
71
71
|
/** How the `this.x` assignments declaring a property are typed. */
|
|
72
72
|
const enum ThisAssignmentKind {
|
|
@@ -99,7 +99,7 @@ export function getWidenedTypeForAssignmentDeclaration(c: Checker, symbol: Symbo
|
|
|
99
99
|
else if (kind === ThisAssignmentKind.Method) t = getTypeOfPropertyInBaseClass(c, symbol);
|
|
100
100
|
if (t === undefined) {
|
|
101
101
|
const types: Type[] = [];
|
|
102
|
-
const declarations = symbol
|
|
102
|
+
const declarations = getDeclarations(symbol);
|
|
103
103
|
for (let i = 0; i < declarations.length; i++) {
|
|
104
104
|
const declaration = declarations[i]!;
|
|
105
105
|
const declaredType = declaration instanceof BinaryExpression ? (declaration as BinaryExpression).type : undefined;
|
|
@@ -234,7 +234,7 @@ function getThisAssignmentKind(c: Checker, symbol: Symbol): ThisAssignmentKind {
|
|
|
234
234
|
if (links.thisAssignmentKind !== 0) return (links.thisAssignmentKind - 1) as ThisAssignmentKind;
|
|
235
235
|
let allThis = true;
|
|
236
236
|
let typeAnnotation: Node | undefined;
|
|
237
|
-
for (const declaration of symbol
|
|
237
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
238
238
|
if (!(declaration instanceof BinaryExpression)) {
|
|
239
239
|
allThis = false;
|
|
240
240
|
break;
|
|
@@ -276,7 +276,7 @@ export function isConstructorDeclaredThisProperty(c: Checker, symbol: Symbol): b
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
function getDeclaringConstructor(symbol: Symbol): Node | undefined {
|
|
279
|
-
for (const declaration of symbol
|
|
279
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
280
280
|
const container = getThisContainer(declaration, false, false);
|
|
281
281
|
if (container.kind === SyntaxKind.Constructor) return container;
|
|
282
282
|
}
|
|
@@ -498,5 +498,5 @@ export function isUndefinedAssignmentToCommonJSExport(c: Checker, left: Node, ri
|
|
|
498
498
|
if (assignment.symbol === undefined) return false;
|
|
499
499
|
if (getAssignmentDeclarationKind(assignment) !== JSDeclarationKind.ExportsProperty) return false;
|
|
500
500
|
const symbol = c.resolvedSymbols.get(left.id);
|
|
501
|
-
return symbol !== undefined && symbol
|
|
501
|
+
return symbol !== undefined && declarationCount(symbol) > 1 && (rightType.flags & TypeFlags.Undefined) !== 0;
|
|
502
502
|
}
|
|
@@ -30,7 +30,6 @@ import { Diagnostic, type DiagnosticMessage, Diagnostics, chainDiagnostic } from
|
|
|
30
30
|
import { JsxEmit } from './options.js';
|
|
31
31
|
import { parseIsolatedEntityName } from './parser.js';
|
|
32
32
|
import { skipTrivia } from './scanner.js';
|
|
33
|
-
import { InternalSymbolName, type Symbol, SymbolFlags, type SymbolTable, getSymbolId } from './symbol.js';
|
|
34
33
|
import { SyntaxKind } from './syntax-kind.js';
|
|
35
34
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
36
35
|
import {
|
|
@@ -162,6 +161,15 @@ import { getIndexedAccessType } from './checker-type-operators.js';
|
|
|
162
161
|
import { filterType, isTupleType } from './checker-type-factory.js';
|
|
163
162
|
import { createTypeFromGenericGlobalType } from './checker-type-factory.js';
|
|
164
163
|
import { isTypeAssignableTo } from './relations.js';
|
|
164
|
+
import {
|
|
165
|
+
copyDeclarations,
|
|
166
|
+
declarationCount,
|
|
167
|
+
getSymbolId,
|
|
168
|
+
InternalSymbolName,
|
|
169
|
+
type Symbol,
|
|
170
|
+
SymbolFlags,
|
|
171
|
+
type SymbolTable,
|
|
172
|
+
} from './symbol.js';
|
|
165
173
|
|
|
166
174
|
const enum JsxFlags {
|
|
167
175
|
None = 0,
|
|
@@ -549,12 +557,8 @@ function getNameFromJsxElementAttributesContainer(c: Checker, containerName: str
|
|
|
549
557
|
const props = getPropertiesOfType(c, getDeclaredTypeOfSymbol(c, sym));
|
|
550
558
|
if (props.length === 0) return '';
|
|
551
559
|
if (props.length === 1) return props[0]!.name;
|
|
552
|
-
if (sym
|
|
553
|
-
c.error(
|
|
554
|
-
sym.declarations[0]!,
|
|
555
|
-
Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property,
|
|
556
|
-
containerName,
|
|
557
|
-
);
|
|
560
|
+
if (declarationCount(sym) !== 0)
|
|
561
|
+
c.error(sym.declaration!, Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, containerName);
|
|
558
562
|
}
|
|
559
563
|
}
|
|
560
564
|
return InternalSymbolName.Missing;
|
|
@@ -953,7 +957,7 @@ export function createJsxAttributesTypeFromAttributesProperty(
|
|
|
953
957
|
const exprType = checkJsxAttribute(c, attributeDecl, checkMode);
|
|
954
958
|
objectFlags |= exprType.objectFlags & ObjectFlags.PropagatingFlags;
|
|
955
959
|
const attributeSymbol = c.newSymbol(SymbolFlags.Property | member.flags, member.name);
|
|
956
|
-
attributeSymbol
|
|
960
|
+
copyDeclarations(attributeSymbol, member);
|
|
957
961
|
attributeSymbol.parent = member.parent;
|
|
958
962
|
if (member.valueDeclaration !== undefined) attributeSymbol.valueDeclaration = member.valueDeclaration;
|
|
959
963
|
const id = getSymbolId(attributeSymbol);
|