tsc-ts 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api/compiler/ast.d.ts +10 -9
- package/dist/api/compiler/ast.js +22 -16
- package/dist/api/compiler/binder-utilities.js +2 -1
- package/dist/api/compiler/binder.js +9 -8
- package/dist/api/compiler/checker-calls.js +3 -2
- package/dist/api/compiler/checker-declaration-order.js +2 -1
- package/dist/api/compiler/checker-declarations.js +14 -14
- package/dist/api/compiler/checker-declared-types.d.ts +1 -1
- package/dist/api/compiler/checker-declared-types.js +12 -11
- package/dist/api/compiler/checker-decorators.js +3 -3
- package/dist/api/compiler/checker-deprecation.js +17 -18
- package/dist/api/compiler/checker-destructuring.d.ts +1 -1
- package/dist/api/compiler/checker-destructuring.js +3 -3
- package/dist/api/compiler/checker-elaboration.js +8 -7
- package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
- package/dist/api/compiler/checker-emit-resolver.js +5 -4
- package/dist/api/compiler/checker-grammar.js +18 -4
- package/dist/api/compiler/checker-heritage.d.ts +1 -1
- package/dist/api/compiler/checker-heritage.js +14 -13
- package/dist/api/compiler/checker-inference.d.ts +1 -1
- package/dist/api/compiler/checker-inference.js +9 -9
- package/dist/api/compiler/checker-javascript.d.ts +1 -1
- package/dist/api/compiler/checker-javascript.js +5 -4
- package/dist/api/compiler/checker-jsx.d.ts +1 -1
- package/dist/api/compiler/checker-jsx.js +4 -4
- package/dist/api/compiler/checker-literals.js +2 -2
- package/dist/api/compiler/checker-members.d.ts +5 -3
- package/dist/api/compiler/checker-members.js +75 -53
- package/dist/api/compiler/checker-modules.d.ts +1 -1
- package/dist/api/compiler/checker-modules.js +13 -13
- package/dist/api/compiler/checker-object-literals.d.ts +1 -1
- package/dist/api/compiler/checker-object-literals.js +11 -7
- package/dist/api/compiler/checker-overloads.d.ts +1 -1
- package/dist/api/compiler/checker-overloads.js +4 -3
- package/dist/api/compiler/checker-property-access.d.ts +1 -1
- package/dist/api/compiler/checker-property-access.js +2 -2
- package/dist/api/compiler/checker-services.js +2 -2
- package/dist/api/compiler/checker-signatures.d.ts +1 -1
- package/dist/api/compiler/checker-signatures.js +9 -8
- package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
- package/dist/api/compiler/checker-symbol-types.js +22 -952
- package/dist/api/compiler/checker-symbols.d.ts +2 -2
- package/dist/api/compiler/checker-symbols.js +29 -27
- package/dist/api/compiler/checker-type-factory.d.ts +2 -2
- package/dist/api/compiler/checker-type-factory.js +57 -16
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
- package/dist/api/compiler/checker-type-nodes.js +2 -2
- package/dist/api/compiler/checker-type-operators.d.ts +1 -1
- package/dist/api/compiler/checker-type-operators.js +5 -5
- package/dist/api/compiler/checker-types.d.ts +73 -7
- package/dist/api/compiler/checker-types.js +220 -43
- package/dist/api/compiler/checker-unused.d.ts +1 -1
- package/dist/api/compiler/checker-unused.js +3 -3
- package/dist/api/compiler/checker.d.ts +29 -8
- package/dist/api/compiler/checker.js +29 -9
- package/dist/api/compiler/diagnostics.d.ts +2 -8
- package/dist/api/compiler/diagnostics.js +4 -40
- package/dist/api/compiler/file-include.d.ts +35 -8
- package/dist/api/compiler/file-include.js +81 -18
- package/dist/api/compiler/file-loader.d.ts +33 -4
- package/dist/api/compiler/file-loader.js +90 -24
- package/dist/api/compiler/instantiation.d.ts +1 -1
- package/dist/api/compiler/instantiation.js +86 -50
- package/dist/api/compiler/link-tables.d.ts +69 -0
- package/dist/api/compiler/link-tables.js +236 -0
- package/dist/api/compiler/name-resolver.js +3 -3
- package/dist/api/compiler/node-builder-names.d.ts +1 -1
- package/dist/api/compiler/node-builder-names.js +12 -12
- package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
- package/dist/api/compiler/node-builder-pseudo.js +2 -1
- package/dist/api/compiler/node-builder.d.ts +1 -1
- package/dist/api/compiler/node-builder.js +16 -16
- package/dist/api/compiler/parallel-parse.d.ts +2 -0
- package/dist/api/compiler/parallel-parse.js +4 -0
- package/dist/api/compiler/parser.d.ts +33 -16
- package/dist/api/compiler/parser.js +95 -76
- package/dist/api/compiler/printer/emit-context.d.ts +5 -2
- package/dist/api/compiler/printer/emit-context.js +19 -13
- package/dist/api/compiler/program-checker.js +3 -0
- package/dist/api/compiler/program.js +9 -1
- package/dist/api/compiler/relations.d.ts +1 -1
- package/dist/api/compiler/relations.js +10 -10
- package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
- package/dist/api/compiler/symbol-accessibility.js +123 -26
- package/dist/api/compiler/symbol.d.ts +45 -3
- package/dist/api/compiler/symbol.js +121 -10
- package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
- package/dist/api/compiler/transformers/alias-references.js +2 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
- package/dist/api/compiler/transformers/declarations-pseudo.js +4 -2
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
- package/dist/api/compiler/transformers/declarations.js +6 -5
- package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
- package/dist/api/compiler/transformers/reference-resolver.js +26 -24
- package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/subtree-facts.js +7 -5
- package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/syntax-facts.js +9 -5
- package/dist/api/compiler/transformers/type-serialization.js +12 -12
- package/package.json +9 -9
- package/src/compiler/ast.ts +27 -19
- package/src/compiler/binder-utilities.ts +2 -2
- package/src/compiler/binder.ts +15 -11
- package/src/compiler/checker-calls.ts +3 -3
- package/src/compiler/checker-declaration-order.ts +2 -2
- package/src/compiler/checker-declarations.ts +21 -14
- package/src/compiler/checker-declared-types.ts +12 -12
- package/src/compiler/checker-decorators.ts +3 -3
- package/src/compiler/checker-deprecation.ts +17 -21
- package/src/compiler/checker-destructuring.ts +3 -3
- package/src/compiler/checker-elaboration.ts +8 -8
- package/src/compiler/checker-emit-resolver.ts +5 -5
- package/src/compiler/checker-grammar.ts +17 -5
- package/src/compiler/checker-heritage.ts +21 -14
- package/src/compiler/checker-inference.ts +17 -9
- package/src/compiler/checker-javascript.ts +5 -5
- package/src/compiler/checker-jsx.ts +12 -8
- package/src/compiler/checker-literals.ts +2 -2
- package/src/compiler/checker-members.ts +91 -47
- package/src/compiler/checker-modules.ts +23 -13
- package/src/compiler/checker-object-literals.ts +22 -6
- package/src/compiler/checker-overloads.ts +6 -6
- package/src/compiler/checker-property-access.ts +2 -2
- package/src/compiler/checker-services.ts +2 -2
- package/src/compiler/checker-signatures.ts +9 -9
- package/src/compiler/checker-symbol-types.ts +20 -940
- package/src/compiler/checker-symbols.ts +42 -35
- package/src/compiler/checker-type-factory.ts +53 -16
- package/src/compiler/checker-type-nodes.ts +2 -2
- package/src/compiler/checker-type-operators.ts +13 -5
- package/src/compiler/checker-types.ts +223 -43
- package/src/compiler/checker-unused.ts +3 -3
- package/src/compiler/checker.ts +31 -9
- package/src/compiler/diagnostics.ts +5 -44
- package/src/compiler/file-include.ts +85 -17
- package/src/compiler/file-loader.ts +104 -35
- package/src/compiler/incremental.ts +39 -5
- package/src/compiler/instantiation.ts +99 -55
- package/src/compiler/link-tables.ts +245 -0
- package/src/compiler/name-resolver.ts +3 -3
- package/src/compiler/node-builder-names.ts +21 -19
- package/src/compiler/node-builder-pseudo.ts +2 -2
- package/src/compiler/node-builder.ts +24 -16
- package/src/compiler/parallel-check.ts +11 -8
- package/src/compiler/parallel-parse.ts +5 -0
- package/src/compiler/parse-thread.ts +0 -4
- package/src/compiler/parser.ts +120 -70
- package/src/compiler/printer/emit-context.ts +20 -15
- package/src/compiler/program-checker.ts +2 -0
- package/src/compiler/program.ts +8 -1
- package/src/compiler/relations.ts +10 -10
- package/src/compiler/symbol-accessibility.ts +120 -25
- package/src/compiler/symbol.ts +127 -9
- package/src/compiler/transformers/alias-references.ts +2 -2
- package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
- package/src/compiler/transformers/declarations-pseudo.ts +7 -4
- package/src/compiler/transformers/declarations-syntactic.ts +17 -9
- package/src/compiler/transformers/declarations-tracker.ts +3 -3
- package/src/compiler/transformers/declarations.ts +6 -6
- package/src/compiler/transformers/reference-resolver.ts +37 -25
- package/src/compiler/transformers/subtree-facts.ts +13 -5
- package/src/compiler/transformers/syntax-facts.ts +10 -5
- package/src/compiler/transformers/type-serialization.ts +12 -12
- package/src/compiler/tsc-build.ts +17 -13
- package/src/compiler/tsc-cli.ts +9 -6
- package/src/compiler/tsc-compile.ts +16 -7
- package/src/compiler/tsc-watch.ts +94 -26
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
isPrivateIdentifierClassElementDeclaration,
|
|
34
34
|
} from './binder-utilities.js';
|
|
35
35
|
import { Diagnostics } from './diagnostics.js';
|
|
36
|
-
import { CheckFlags, SymbolFlags, type Symbol, getSymbolId } from './symbol.js';
|
|
37
36
|
import { SyntaxKind } from './syntax-kind.js';
|
|
38
37
|
import type { Checker } from './checker.js';
|
|
39
38
|
import {
|
|
@@ -116,6 +115,7 @@ import { TypeFacts, getNonNullableType, getTypeWithFacts, hasTypeFacts } from '.
|
|
|
116
115
|
import { sliceTupleType } from './checker-signatures.js';
|
|
117
116
|
import { getPropertyNameFromType, isTypeUsableAsPropertyName, maybeTypeOfKind } from './checker-utilities.js';
|
|
118
117
|
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
118
|
+
import { CheckFlags, copyDeclarations, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
119
119
|
|
|
120
120
|
function isBindingPatternNode(node: Node | undefined): boolean {
|
|
121
121
|
return (
|
|
@@ -766,7 +766,7 @@ export function isSpreadableProperty(prop: Symbol): boolean {
|
|
|
766
766
|
(prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor)) === 0;
|
|
767
767
|
let hasPrivateName = false;
|
|
768
768
|
let inClass = false;
|
|
769
|
-
for (const d of prop
|
|
769
|
+
for (const d of getDeclarations(prop)) {
|
|
770
770
|
if (isPrivateIdentifierClassElementDeclaration(d)) hasPrivateName = true;
|
|
771
771
|
if (d.parent !== undefined && isClassLike(d.parent)) inClass = true;
|
|
772
772
|
}
|
|
@@ -785,7 +785,7 @@ export function getSpreadSymbol(c: Checker, prop: Symbol, readonly: boolean): Sy
|
|
|
785
785
|
);
|
|
786
786
|
const id = getSymbolId(result);
|
|
787
787
|
c.symbolTypes.set(id, isSetonlyAccessor ? c.undefinedType : getTypeOfSymbol(c, prop));
|
|
788
|
-
result
|
|
788
|
+
copyDeclarations(result, prop);
|
|
789
789
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
790
790
|
c.symbolSyntheticOrigins.set(id, prop);
|
|
791
791
|
return result;
|
|
@@ -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
|
),
|
|
@@ -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;
|
|
@@ -130,12 +130,12 @@ import { ModuleKind, ScriptTarget, getEmitModuleKind } from './options.js';
|
|
|
130
130
|
import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
|
|
131
131
|
import { SourceFileMetadata, getEmitModuleFormatOfFile, getImpliedNodeFormatForEmit } from './program-utilities.js';
|
|
132
132
|
import { CharacterCodes } from './character-codes.js';
|
|
133
|
-
import { Scanner, ScannerErrorReporter,
|
|
134
|
-
import { SymbolFlags } from './symbol.js';
|
|
133
|
+
import { Scanner, ScannerErrorReporter, skipTrivia, tokenToString } from './scanner.js';
|
|
135
134
|
import { typeToString } from './type-printer.js';
|
|
136
135
|
import type { ScriptTarget as LanguageTarget } from './types.js';
|
|
137
136
|
import { SyntaxKind } from './syntax-kind.js';
|
|
138
137
|
import { findMismatchedAugmentsTag } from './checker-jsdoc.js';
|
|
138
|
+
import { getDeclarations, SymbolFlags } from './symbol.js';
|
|
139
139
|
|
|
140
140
|
/** Runs the grammar checks of every node of `file`. */
|
|
141
141
|
export function checkGrammarSourceFile(c: Checker, file: SourceFile): void {
|
|
@@ -1266,7 +1266,7 @@ function getFirstAccessorOfPair(c: Checker, node: Node): Node {
|
|
|
1266
1266
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
1267
1267
|
if (symbol === undefined) return node;
|
|
1268
1268
|
const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
|
|
1269
|
-
for (const declaration of symbol
|
|
1269
|
+
for (const declaration of getDeclarations(symbol))
|
|
1270
1270
|
if (declaration.kind === otherKind && declaration.pos < node.pos) return declaration;
|
|
1271
1271
|
return node;
|
|
1272
1272
|
}
|
|
@@ -1437,13 +1437,25 @@ function checkGrammarArrowFunction(g: GrammarChecker, node: Node): boolean {
|
|
|
1437
1437
|
}
|
|
1438
1438
|
const arrowToken = arrow.equalsGreaterThanToken;
|
|
1439
1439
|
if (arrowToken === undefined) return false;
|
|
1440
|
-
const lineStarts = g.file.lineStarts();
|
|
1441
1440
|
return (
|
|
1442
|
-
|
|
1441
|
+
hasLineBreak(g.file.text, arrowToken.pos, arrowToken.end) &&
|
|
1443
1442
|
grammarErrorOnNode(g, arrowToken, Diagnostics.Line_terminator_not_permitted_before_arrow)
|
|
1444
1443
|
);
|
|
1445
1444
|
}
|
|
1446
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* Whether a line starts in `(pos, end]`, so that `pos` and `end` are on different lines: after an
|
|
1448
|
+
* LF, LS or PS, or a CR that no LF follows (`computeLineStarts`), without the file's line starts.
|
|
1449
|
+
*/
|
|
1450
|
+
function hasLineBreak(text: string, pos: number, end: number): boolean {
|
|
1451
|
+
for (let i = pos; i < end; i++) {
|
|
1452
|
+
const c = text.charCodeAt(i);
|
|
1453
|
+
if (c === 0x0a || c === 0x2028 || c === 0x2029) return true;
|
|
1454
|
+
if (c === 0x0d && text.charCodeAt(i + 1) !== 0x0a) return true;
|
|
1455
|
+
}
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1447
1459
|
function checkGrammarForGenerator(g: GrammarChecker, node: Node): boolean {
|
|
1448
1460
|
const asteriskToken = getAsteriskToken(node);
|
|
1449
1461
|
if (asteriskToken === undefined) return false;
|
|
@@ -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,
|
|
@@ -427,7 +435,7 @@ export function someInferenceHasCandidatesOrDefault(inferences: InferenceInfo[])
|
|
|
427
435
|
function hasTypeParameterDefault(tp: Type): boolean {
|
|
428
436
|
const symbol = tp.symbol;
|
|
429
437
|
if (symbol === undefined) return false;
|
|
430
|
-
for (const d of symbol
|
|
438
|
+
for (const d of getDeclarations(symbol))
|
|
431
439
|
if (d.kind === SyntaxKind.TypeParameter && (d as TypeParameterDeclaration).defaultType !== undefined) return true;
|
|
432
440
|
return false;
|
|
433
441
|
}
|
|
@@ -1324,10 +1332,10 @@ function isTopLevelClassStaticSide(t: Type): boolean {
|
|
|
1324
1332
|
(symbol.flags &
|
|
1325
1333
|
(SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral)) !==
|
|
1326
1334
|
0 ||
|
|
1327
|
-
symbol
|
|
1335
|
+
declarationCount(symbol) === 0
|
|
1328
1336
|
)
|
|
1329
1337
|
return false;
|
|
1330
|
-
for (const d of symbol
|
|
1338
|
+
for (const d of getDeclarations(symbol)) {
|
|
1331
1339
|
if (
|
|
1332
1340
|
d.kind !== SyntaxKind.ClassDeclaration &&
|
|
1333
1341
|
d.kind !== SyntaxKind.InterfaceDeclaration &&
|
|
@@ -1370,7 +1378,7 @@ function createEmptyObjectTypeFromStringLiteral(c: Checker, t: Type): Type {
|
|
|
1370
1378
|
const literalProp = c.newSymbol(SymbolFlags.Property, name);
|
|
1371
1379
|
c.symbolTypes.set(getSymbolId(literalProp), c.anyType);
|
|
1372
1380
|
if (u.symbol !== undefined) {
|
|
1373
|
-
literalProp
|
|
1381
|
+
copyDeclarations(literalProp, u.symbol);
|
|
1374
1382
|
literalProp.valueDeclaration = u.symbol.valueDeclaration;
|
|
1375
1383
|
}
|
|
1376
1384
|
members.set(name, literalProp);
|
|
@@ -1452,7 +1460,7 @@ function hasUnmatchedProperty(c: Checker, source: Type, target: Type, matchDiscr
|
|
|
1452
1460
|
const t = getReducedApparentType(c, target);
|
|
1453
1461
|
if (
|
|
1454
1462
|
(t.flags & TypeFlags.UnionOrIntersection) === 0 ||
|
|
1455
|
-
sideOf(c, t as UnionOrIntersectionType).resolvedProperties !== undefined
|
|
1463
|
+
sideOf(c, t as UnionOrIntersectionType).membersOf?.resolvedProperties !== undefined
|
|
1456
1464
|
)
|
|
1457
1465
|
return getUnmatchedProperty(c, source, target, false, matchDiscriminantProperties) !== undefined;
|
|
1458
1466
|
const containingType = t as UnionOrIntersectionType;
|
|
@@ -1495,7 +1503,7 @@ export function isConstTypeVariable(c: Checker, t: Type | undefined, depth: numb
|
|
|
1495
1503
|
if (depth >= 5 || t === undefined) return false;
|
|
1496
1504
|
if ((t.flags & TypeFlags.TypeParameter) !== 0) {
|
|
1497
1505
|
if (t.symbol === undefined) return false;
|
|
1498
|
-
for (const d of t.symbol
|
|
1506
|
+
for (const d of getDeclarations(t.symbol)) if (hasSyntacticModifier(d, ModifierFlags.Const)) return true;
|
|
1499
1507
|
return false;
|
|
1500
1508
|
}
|
|
1501
1509
|
if ((t.flags & TypeFlags.UnionOrIntersection) !== 0) {
|
|
@@ -2031,7 +2039,7 @@ export function resolveReverseMappedTypeMembers(c: Checker, t: ReverseMappedType
|
|
|
2031
2039
|
prop.name,
|
|
2032
2040
|
checkFlags,
|
|
2033
2041
|
);
|
|
2034
|
-
inferredProp
|
|
2042
|
+
copyDeclarations(inferredProp, prop);
|
|
2035
2043
|
const links = c.symbolLinks(inferredProp);
|
|
2036
2044
|
const id = inferredProp.id;
|
|
2037
2045
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
@@ -2484,7 +2492,7 @@ export function getInferredTypeParameterConstraint(c: Checker, t: Type, omitType
|
|
|
2484
2492
|
const inferences: Type[] = [];
|
|
2485
2493
|
const symbol = t.symbol;
|
|
2486
2494
|
if (symbol !== undefined)
|
|
2487
|
-
for (const declaration of symbol
|
|
2495
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
2488
2496
|
if (declaration.parent === undefined || declaration.parent.kind !== SyntaxKind.InferType) continue;
|
|
2489
2497
|
let child: Node = declaration.parent;
|
|
2490
2498
|
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);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Object literal types: freshness and regular forms.
|
|
2
2
|
import type { Checker } from './checker.js';
|
|
3
|
-
import { CheckFlags, type Symbol
|
|
3
|
+
import { CheckFlags, copyDeclarations, getSymbolId, type Symbol } from './symbol.js';
|
|
4
4
|
import { CachedTypeKind, cachedTypeKey, ObjectFlags, type Type, TypeFlags } from './checker-types.js';
|
|
5
5
|
import { createAnonymousType } from './checker-type-factory.js';
|
|
6
6
|
import { getPropertiesOfObjectType, resolveStructuredTypeMembers } from './checker-members.js';
|
|
@@ -41,7 +41,7 @@ export function getRegularTypeOfObjectLiteral(c: Checker, t: Type): Type {
|
|
|
41
41
|
|
|
42
42
|
function createSymbolWithTypeLocal(c: Checker, source: Symbol, t: Type): Symbol {
|
|
43
43
|
const symbol = c.newSymbolWithCheckFlags(source.flags, source.name, source.checkFlags & CheckFlags.Readonly);
|
|
44
|
-
symbol
|
|
44
|
+
copyDeclarations(symbol, source);
|
|
45
45
|
symbol.parent = source.parent;
|
|
46
46
|
symbol.valueDeclaration = source.valueDeclaration;
|
|
47
47
|
const id = getSymbolId(symbol);
|