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
package/src/compiler/ast.ts
CHANGED
|
@@ -450,13 +450,10 @@ export class Token extends Node {
|
|
|
450
450
|
|
|
451
451
|
export class Identifier extends Node {
|
|
452
452
|
text: string;
|
|
453
|
-
// Set by the binder.
|
|
454
|
-
flowNode: FlowNode | undefined;
|
|
455
453
|
|
|
456
454
|
constructor(text: string) {
|
|
457
455
|
super(SyntaxKind.Identifier);
|
|
458
456
|
this.text = text;
|
|
459
|
-
this.flowNode = undefined;
|
|
460
457
|
}
|
|
461
458
|
|
|
462
459
|
forEachChild(_v: NodeVisitor): boolean {
|
|
@@ -478,6 +475,29 @@ export class Identifier extends Node {
|
|
|
478
475
|
}
|
|
479
476
|
}
|
|
480
477
|
|
|
478
|
+
/**
|
|
479
|
+
* An identifier that can be read as a reference, such as an expression or a shorthand property
|
|
480
|
+
* name, and so holds the binder's flow node. The parser creates a plain `Identifier` for names
|
|
481
|
+
* whose flow node nothing reads: declaration names, property names and property access names.
|
|
482
|
+
*/
|
|
483
|
+
export class ReferenceIdentifier extends Identifier {
|
|
484
|
+
// Set by the binder.
|
|
485
|
+
flowNode: FlowNode | undefined;
|
|
486
|
+
|
|
487
|
+
constructor(text: string) {
|
|
488
|
+
super(text);
|
|
489
|
+
this.flowNode = undefined;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
copy(): Identifier {
|
|
493
|
+
const node = new ReferenceIdentifier(this.text);
|
|
494
|
+
node.flags = this.flags;
|
|
495
|
+
node.pos = this.pos;
|
|
496
|
+
node.end = this.end;
|
|
497
|
+
return node;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
481
501
|
export class PrivateIdentifier extends Node {
|
|
482
502
|
text: string;
|
|
483
503
|
|
|
@@ -8152,12 +8172,6 @@ export class SourceFile extends Node {
|
|
|
8152
8172
|
patternAmbientModules: PatternAmbientModule[];
|
|
8153
8173
|
/** UMD exports from `export as namespace N`. */
|
|
8154
8174
|
globalExports: SymbolTable | undefined;
|
|
8155
|
-
/**
|
|
8156
|
-
* By name, the first property of the unions of the file's object literals that leave the name
|
|
8157
|
-
* missing (checker-symbol-types.ts `scanSiblingProperties`), where a parse thread scanned the file
|
|
8158
|
-
* and could resolve the enums the scan needed.
|
|
8159
|
-
*/
|
|
8160
|
-
siblingProperties: Map<string, Node> | undefined;
|
|
8161
8175
|
|
|
8162
8176
|
constructor(
|
|
8163
8177
|
fileName: string,
|
|
@@ -8210,7 +8224,6 @@ export class SourceFile extends Node {
|
|
|
8210
8224
|
this.symbolCount = 0;
|
|
8211
8225
|
this.patternAmbientModules = [];
|
|
8212
8226
|
this.globalExports = undefined;
|
|
8213
|
-
this.siblingProperties = undefined;
|
|
8214
8227
|
}
|
|
8215
8228
|
|
|
8216
8229
|
forEachChild(v: NodeVisitor): boolean {
|
|
@@ -8239,11 +8252,6 @@ export class SourceFile extends Node {
|
|
|
8239
8252
|
this.diagnosticFile().computeCaches();
|
|
8240
8253
|
}
|
|
8241
8254
|
|
|
8242
|
-
/** Like `computeCaches`, from the UTF-16 code units of the text (at least `text.length` of them). */
|
|
8243
|
-
computeCachesFromUnits(units: Uint16Array): void {
|
|
8244
|
-
this.diagnosticFile().computeCachesFromUnits(units);
|
|
8245
|
-
}
|
|
8246
|
-
|
|
8247
8255
|
/** The file as diagnostics see it. */
|
|
8248
8256
|
diagnosticFile(): DiagnosticFile {
|
|
8249
8257
|
let file = this.diagnosticFileCache;
|
|
@@ -12153,8 +12161,8 @@ export function setNextContainer(node: Node, value: Node | undefined): void {
|
|
|
12153
12161
|
export function getFlowNode(node: Node): FlowNode | undefined {
|
|
12154
12162
|
switch (node.kind) {
|
|
12155
12163
|
case SyntaxKind.Identifier:
|
|
12156
|
-
if (node instanceof
|
|
12157
|
-
const holder:
|
|
12164
|
+
if (node instanceof ReferenceIdentifier) {
|
|
12165
|
+
const holder: ReferenceIdentifier = node;
|
|
12158
12166
|
return holder.flowNode;
|
|
12159
12167
|
}
|
|
12160
12168
|
break;
|
|
@@ -12425,8 +12433,8 @@ export function getFlowNode(node: Node): FlowNode | undefined {
|
|
|
12425
12433
|
export function setFlowNode(node: Node, value: FlowNode | undefined): void {
|
|
12426
12434
|
switch (node.kind) {
|
|
12427
12435
|
case SyntaxKind.Identifier:
|
|
12428
|
-
if (node instanceof
|
|
12429
|
-
const target:
|
|
12436
|
+
if (node instanceof ReferenceIdentifier) {
|
|
12437
|
+
const target: ReferenceIdentifier = node;
|
|
12430
12438
|
target.flowNode = value;
|
|
12431
12439
|
}
|
|
12432
12440
|
break;
|
|
@@ -52,7 +52,7 @@ import { getJSDoc } from './parser.js';
|
|
|
52
52
|
import { isAssignmentOperator, isLeftHandSideExpression, isStringLiteralLike, nodeIsMissing } from './ast-utilities.js';
|
|
53
53
|
import { Scanner, computeLineOfPosition, skipTrivia } from './scanner.js';
|
|
54
54
|
import { SyntaxKind } from './syntax-kind.js';
|
|
55
|
-
import { InternalSymbolName, type Symbol } from './symbol.js';
|
|
55
|
+
import { getDeclarations, InternalSymbolName, type Symbol } from './symbol.js';
|
|
56
56
|
|
|
57
57
|
// Modifiers and flags
|
|
58
58
|
|
|
@@ -1003,7 +1003,7 @@ export function moduleExportNameIsDefault(node: Node): boolean {
|
|
|
1003
1003
|
}
|
|
1004
1004
|
|
|
1005
1005
|
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Node | undefined {
|
|
1006
|
-
for (const declaration of symbol
|
|
1006
|
+
for (const declaration of getDeclarations(symbol)) if (declaration.kind === kind) return declaration;
|
|
1007
1007
|
return undefined;
|
|
1008
1008
|
}
|
|
1009
1009
|
|
package/src/compiler/binder.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
PrefixUnaryExpression,
|
|
42
42
|
PropertyAccessExpression,
|
|
43
43
|
QualifiedName,
|
|
44
|
+
ReferenceIdentifier,
|
|
44
45
|
type SourceFile,
|
|
45
46
|
SwitchStatement,
|
|
46
47
|
TryStatement,
|
|
@@ -150,18 +151,21 @@ import { Diagnostic, type DiagnosticMessage, Diagnostics } from './diagnostics.j
|
|
|
150
151
|
import { FlowFlags, FlowNode, FlowReduceLabel, FlowSwitchClause } from './flow.js';
|
|
151
152
|
import { removeFileExtension } from './path.js';
|
|
152
153
|
import { getIdentifierToken, tokenToString } from './scanner.js';
|
|
154
|
+
import { SyntaxKind } from './syntax-kind.js';
|
|
153
155
|
import {
|
|
154
|
-
InternalSymbolName,
|
|
155
|
-
Symbol,
|
|
156
|
-
SymbolFlags,
|
|
157
|
-
type SymbolTable,
|
|
158
156
|
addDeclaration,
|
|
157
|
+
copyDeclarations,
|
|
158
|
+
declarationCount,
|
|
159
|
+
getDeclarations,
|
|
159
160
|
getExports,
|
|
160
161
|
getMembers,
|
|
161
162
|
getSymbolId,
|
|
163
|
+
InternalSymbolName,
|
|
162
164
|
internalSymbolNamePrefix,
|
|
165
|
+
Symbol,
|
|
166
|
+
SymbolFlags,
|
|
167
|
+
type SymbolTable,
|
|
163
168
|
} from './symbol.js';
|
|
164
|
-
import { SyntaxKind } from './syntax-kind.js';
|
|
165
169
|
|
|
166
170
|
/** How a node scopes declarations and control flow. */
|
|
167
171
|
export const enum ContainerFlags {
|
|
@@ -518,7 +522,7 @@ class Binder extends NodeVisitor {
|
|
|
518
522
|
messageNeedsName = false;
|
|
519
523
|
}
|
|
520
524
|
let multipleDefaultExports = false;
|
|
521
|
-
if (symbol
|
|
525
|
+
if (declarationCount(symbol) !== 0) {
|
|
522
526
|
// A default export (by modifier, or `export default` assignment) after another one.
|
|
523
527
|
if (isDefaultExport || (node instanceof ExportAssignment && !(node as ExportAssignment).isExportEquals)) {
|
|
524
528
|
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
|
|
@@ -545,7 +549,7 @@ class Binder extends NodeVisitor {
|
|
|
545
549
|
]),
|
|
546
550
|
);
|
|
547
551
|
}
|
|
548
|
-
const declarations = symbol
|
|
552
|
+
const declarations = getDeclarations(symbol);
|
|
549
553
|
for (let index = 0; index < declarations.length; index++) {
|
|
550
554
|
const declaration = declarations[index]!;
|
|
551
555
|
const decl = getNameOfDeclaration(declaration) ?? declaration;
|
|
@@ -742,7 +746,7 @@ class Binder extends NodeVisitor {
|
|
|
742
746
|
addDeclarationToSymbol(symbol: Symbol, node: Node, symbolFlags: SymbolFlags): void {
|
|
743
747
|
symbol.flags |= symbolFlags;
|
|
744
748
|
setSymbol(node, symbol);
|
|
745
|
-
if (symbol.
|
|
749
|
+
if (getDeclarations(symbol).indexOf(node) < 0) addDeclaration(symbol, node);
|
|
746
750
|
// A const-enum-only namespace merged with a class, function or regular enum isn't one anymore.
|
|
747
751
|
if (
|
|
748
752
|
(symbol.flags & SymbolFlags.ConstEnumOnlyModule) !== 0 &&
|
|
@@ -805,7 +809,7 @@ class Binder extends NodeVisitor {
|
|
|
805
809
|
// the container's locals; anonymous declarations like type literals go in no table.
|
|
806
810
|
switch (node.kind) {
|
|
807
811
|
case SyntaxKind.Identifier:
|
|
808
|
-
(node
|
|
812
|
+
if (node instanceof ReferenceIdentifier) node.flowNode = this.currentFlowValue();
|
|
809
813
|
this.checkContextualIdentifier(node as Identifier);
|
|
810
814
|
break;
|
|
811
815
|
case SyntaxKind.ThisKeyword:
|
|
@@ -1153,7 +1157,7 @@ class Binder extends NodeVisitor {
|
|
|
1153
1157
|
symbol.valueDeclaration = this.file;
|
|
1154
1158
|
if (name === 'module') {
|
|
1155
1159
|
const exportsProperty = this.newSymbol(SymbolFlags.ModuleExports | SymbolFlags.Property, 'exports');
|
|
1156
|
-
exportsProperty
|
|
1160
|
+
copyDeclarations(exportsProperty, symbol);
|
|
1157
1161
|
exportsProperty.valueDeclaration = this.file;
|
|
1158
1162
|
exportsProperty.parent = symbol;
|
|
1159
1163
|
getMembers(symbol).set('exports', exportsProperty);
|
|
@@ -2096,7 +2100,7 @@ class Binder extends NodeVisitor {
|
|
|
2096
2100
|
const exports = getExports(symbol);
|
|
2097
2101
|
const existing = exports.get('prototype');
|
|
2098
2102
|
if (existing !== undefined)
|
|
2099
|
-
this.errorOnNode(existing.
|
|
2103
|
+
this.errorOnNode(existing.declaration!, Diagnostics.Duplicate_identifier_0, ['prototype']);
|
|
2100
2104
|
exports.set('prototype', prototypeSymbol);
|
|
2101
2105
|
prototypeSymbol.parent = symbol;
|
|
2102
2106
|
}
|
|
@@ -46,7 +46,6 @@ import { Diagnostic, type DiagnosticMessage, Diagnostics, chainDiagnostic } from
|
|
|
46
46
|
import { resolveInstanceofExpression } from './checker-operators.js';
|
|
47
47
|
import { skipTrivia } from './scanner.js';
|
|
48
48
|
import { SyntaxKind } from './syntax-kind.js';
|
|
49
|
-
import { InternalSymbolName, type Symbol, SymbolFlags } from './symbol.js';
|
|
50
49
|
import { TokenFlags } from './types.js';
|
|
51
50
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
52
51
|
import { checkSuperExpression } from './checker-super.js';
|
|
@@ -206,6 +205,7 @@ import {
|
|
|
206
205
|
resolveJsxOpeningLikeElement,
|
|
207
206
|
} from './checker-jsx.js';
|
|
208
207
|
import { isCommonJSRequire, resolveExternalModuleTypeByLiteral } from './checker-javascript.js';
|
|
208
|
+
import { declarationCount, getDeclarations, InternalSymbolName, type Symbol, SymbolFlags } from './symbol.js';
|
|
209
209
|
|
|
210
210
|
/** The type of an optional chain's expression with the chain's `undefined` removed. */
|
|
211
211
|
export function getOptionalExpressionType(c: Checker, exprType: Type, expression: Node): Type {
|
|
@@ -1674,9 +1674,9 @@ function addImplementationSuccessElaboration(
|
|
|
1674
1674
|
diagnostic: Diagnostic,
|
|
1675
1675
|
): void {
|
|
1676
1676
|
const symbol = failed.declaration !== undefined ? getSymbol(failed.declaration) : undefined;
|
|
1677
|
-
if (symbol === undefined || symbol
|
|
1677
|
+
if (symbol === undefined || declarationCount(symbol) <= 1) return;
|
|
1678
1678
|
let implementation: Node | undefined;
|
|
1679
|
-
for (const d of symbol
|
|
1679
|
+
for (const d of getDeclarations(symbol)) {
|
|
1680
1680
|
if (isFunctionLikeDeclarationKind(d.kind) && nodeIsPresent(getBody(d))) {
|
|
1681
1681
|
implementation = d;
|
|
1682
1682
|
break;
|
|
@@ -29,7 +29,6 @@ import { isFunctionLike } from './ast-utilities.js';
|
|
|
29
29
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
30
30
|
import { type Diagnostic, Diagnostics } from './diagnostics.js';
|
|
31
31
|
import { ScriptTarget } from './options.js';
|
|
32
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
33
32
|
import { getSymbolOfDeclaration } from './checker-symbols.js';
|
|
34
33
|
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
35
34
|
import { isPropertyInitializedInStaticBlocks } from './checker-classes.js';
|
|
@@ -38,6 +37,7 @@ import { getExportSymbolOfValueSymbolIfExported } from './checker-symbols.js';
|
|
|
38
37
|
import { getBaseTypes, getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
39
38
|
import { getPropertyOfType } from './checker-members.js';
|
|
40
39
|
import { FunctionFlags, getFunctionFlags } from './checker-utilities.js';
|
|
40
|
+
import { getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
41
41
|
|
|
42
42
|
/** Reports a block-scoped variable, class or enum resolved at `errorLocation` before its declaration. */
|
|
43
43
|
export function checkResolvedBlockScopedVariable(c: Checker, resolved: Symbol, errorLocation: Node): void {
|
|
@@ -50,7 +50,7 @@ export function checkResolvedBlockScopedVariable(c: Checker, resolved: Symbol, e
|
|
|
50
50
|
)
|
|
51
51
|
return;
|
|
52
52
|
let declaration: Node | undefined;
|
|
53
|
-
for (const d of result
|
|
53
|
+
for (const d of getDeclarations(result)) {
|
|
54
54
|
if (isBlockOrCatchScoped(d) || isClassLike(d) || d.kind === SyntaxKind.EnumDeclaration) {
|
|
55
55
|
declaration = d;
|
|
56
56
|
break;
|
|
@@ -62,7 +62,6 @@ import {
|
|
|
62
62
|
isClassLike,
|
|
63
63
|
} from './binder-utilities.js';
|
|
64
64
|
import { Diagnostic, type DiagnosticMessage, Diagnostics } from './diagnostics.js';
|
|
65
|
-
import { InternalSymbolName, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
66
65
|
import { SyntaxKind } from './syntax-kind.js';
|
|
67
66
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
68
67
|
import { IntrinsicTypeKind, getLiteralTypeFromPropertyName, intrinsicTypeKind } from './checker-type-operators.js';
|
|
@@ -142,6 +141,14 @@ import { checkFunctionOrMethodSymbols } from './checker-overloads.js';
|
|
|
142
141
|
import { checkJSDocFullSignature } from './checker-jsdoc.js';
|
|
143
142
|
import { checkAliasSymbol } from './checker-modules.js';
|
|
144
143
|
import { checkDecorators } from './checker-decorators.js';
|
|
144
|
+
import {
|
|
145
|
+
declarationCount,
|
|
146
|
+
getDeclarations,
|
|
147
|
+
getSymbolId,
|
|
148
|
+
InternalSymbolName,
|
|
149
|
+
type Symbol,
|
|
150
|
+
SymbolFlags,
|
|
151
|
+
} from './symbol.js';
|
|
145
152
|
|
|
146
153
|
// ---- Variables and parameters
|
|
147
154
|
|
|
@@ -250,8 +257,8 @@ export function checkVariableLikeDeclaration(c: Checker, node: Node): void {
|
|
|
250
257
|
checkTypeAssignableToAndOptionallyElaborate(c, initType, t, node, initializer);
|
|
251
258
|
checkUsingDeclarationInitializer(c, node, initializer, initType);
|
|
252
259
|
}
|
|
253
|
-
if (name !== undefined && symbol
|
|
254
|
-
for (const d of symbol
|
|
260
|
+
if (name !== undefined && declarationCount(symbol) > 1) {
|
|
261
|
+
for (const d of getDeclarations(symbol)) {
|
|
255
262
|
if (d !== node && isVariableLike(d) && !areDeclarationFlagsIdentical(d, node)) {
|
|
256
263
|
reportNonIdenticalModifiers(c, name);
|
|
257
264
|
break;
|
|
@@ -786,15 +793,15 @@ export function checkEnumDeclaration(c: Checker, node: Node): void {
|
|
|
786
793
|
const links = c.symbolLinks(symbol);
|
|
787
794
|
if (links.enumChecked) return;
|
|
788
795
|
links.enumChecked = true;
|
|
789
|
-
if (symbol
|
|
796
|
+
if (declarationCount(symbol) > 1) {
|
|
790
797
|
const enumIsConst = isEnumConst(node);
|
|
791
|
-
for (const d of symbol
|
|
798
|
+
for (const d of getDeclarations(symbol))
|
|
792
799
|
if (d.kind === SyntaxKind.EnumDeclaration && isEnumConst(d) !== enumIsConst)
|
|
793
800
|
c.error(getNameOfDeclaration(d), Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
|
|
794
801
|
}
|
|
795
802
|
// Only one declaration of a merged enum may continue automatic numbering from zero.
|
|
796
803
|
let seenEnumMissingInitialInitializer = false;
|
|
797
|
-
for (const d of symbol
|
|
804
|
+
for (const d of getDeclarations(symbol)) {
|
|
798
805
|
if (d.kind !== SyntaxKind.EnumDeclaration) continue;
|
|
799
806
|
const members = (d as EnumDeclaration).members.nodes;
|
|
800
807
|
if (members.length === 0 || getInitializer(members[0]!) !== undefined) continue;
|
|
@@ -851,7 +858,7 @@ export function checkModuleDeclaration(c: Checker, node: Node): void {
|
|
|
851
858
|
Diagnostics.Namespaces_are_not_allowed_in_global_script_files_when_0_is_enabled_If_this_file_is_not_intended_to_be_a_global_script_set_moduleDetection_to_force_or_add_an_empty_export_statement,
|
|
852
859
|
c.compilerOptions.verbatimModuleSyntax === true ? 'verbatimModuleSyntax' : 'isolatedModules',
|
|
853
860
|
);
|
|
854
|
-
if (symbol
|
|
861
|
+
if (declarationCount(symbol) > 1) {
|
|
855
862
|
const classOrFunction = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
|
|
856
863
|
if (classOrFunction !== undefined) {
|
|
857
864
|
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunction))
|
|
@@ -907,7 +914,7 @@ export function isInstantiatedModule(node: Node, preserveConstEnums: boolean): b
|
|
|
907
914
|
}
|
|
908
915
|
|
|
909
916
|
function getFirstNonAmbientClassOrFunctionDeclaration(symbol: Symbol): Node | undefined {
|
|
910
|
-
for (const d of symbol
|
|
917
|
+
for (const d of getDeclarations(symbol))
|
|
911
918
|
if (
|
|
912
919
|
(d.kind === SyntaxKind.ClassDeclaration ||
|
|
913
920
|
(d.kind === SyntaxKind.FunctionDeclaration && nodeIsPresent(getBody(d)))) &&
|
|
@@ -995,16 +1002,16 @@ export function checkExternalModuleExports(c: Checker, node: Node): void {
|
|
|
995
1002
|
if (id === InternalSymbolName.ExportStar || (symbol.flags & (SymbolFlags.Namespace | SymbolFlags.Enum)) !== 0)
|
|
996
1003
|
continue;
|
|
997
1004
|
let count = 0;
|
|
998
|
-
for (const d of symbol
|
|
1005
|
+
for (const d of getDeclarations(symbol))
|
|
999
1006
|
if (isNotOverload(d) && !isAccessorDeclaration(d) && d.kind !== SyntaxKind.InterfaceDeclaration) count++;
|
|
1000
1007
|
// A type alias may merge with one value.
|
|
1001
1008
|
if ((symbol.flags & SymbolFlags.TypeAlias) !== 0 && count <= 2) continue;
|
|
1002
1009
|
if (count <= 1) continue;
|
|
1003
1010
|
let allExportsProperties = true;
|
|
1004
|
-
for (const d of symbol
|
|
1011
|
+
for (const d of getDeclarations(symbol))
|
|
1005
1012
|
if (getAssignmentDeclarationKind(d) !== JSDeclarationKind.ExportsProperty) allExportsProperties = false;
|
|
1006
1013
|
if (allExportsProperties) continue;
|
|
1007
|
-
for (const d of symbol
|
|
1014
|
+
for (const d of getDeclarations(symbol))
|
|
1008
1015
|
if (isNotOverload(d)) c.error(d, Diagnostics.Cannot_redeclare_exported_variable_0, id);
|
|
1009
1016
|
}
|
|
1010
1017
|
}
|
|
@@ -1063,7 +1070,7 @@ export function checkExportsOnMergedDeclarations(c: Checker, node: Node): void {
|
|
|
1063
1070
|
let exported = DeclarationSpaces.None;
|
|
1064
1071
|
let nonExported = DeclarationSpaces.None;
|
|
1065
1072
|
let defaultExported = DeclarationSpaces.None;
|
|
1066
|
-
for (const d of symbol
|
|
1073
|
+
for (const d of getDeclarations(symbol)) {
|
|
1067
1074
|
const spaces = getDeclarationSpaces(c, d);
|
|
1068
1075
|
const flags = getEffectiveDeclarationFlags(d, ModifierFlags.Export | ModifierFlags.Default);
|
|
1069
1076
|
if ((flags & ModifierFlags.Export) !== 0) {
|
|
@@ -1075,7 +1082,7 @@ export function checkExportsOnMergedDeclarations(c: Checker, node: Node): void {
|
|
|
1075
1082
|
const commonForExportsAndLocals = exported & nonExported;
|
|
1076
1083
|
const commonForDefaultAndNonDefault = defaultExported & nonDefaultExported;
|
|
1077
1084
|
if (commonForExportsAndLocals === 0 && commonForDefaultAndNonDefault === 0) return;
|
|
1078
|
-
for (const d of symbol
|
|
1085
|
+
for (const d of getDeclarations(symbol)) {
|
|
1079
1086
|
const spaces = getDeclarationSpaces(c, d);
|
|
1080
1087
|
const name = getNameOfDeclaration(d);
|
|
1081
1088
|
const text = declarationNameToString(getSourceFileOfNode(d), name);
|
|
@@ -1136,7 +1143,7 @@ function getAliasDeclarationSpaces(c: Checker, node: Node): DeclarationSpaces {
|
|
|
1136
1143
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
1137
1144
|
if (symbol === undefined) return DeclarationSpaces.None;
|
|
1138
1145
|
let result = DeclarationSpaces.None;
|
|
1139
|
-
for (const d of resolveAlias(c, symbol)
|
|
1146
|
+
for (const d of getDeclarations(resolveAlias(c, symbol))) result |= getDeclarationSpaces(c, d);
|
|
1140
1147
|
return result;
|
|
1141
1148
|
}
|
|
1142
1149
|
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
} from './ast.js';
|
|
22
22
|
import { getSourceFileOfNode, isEnumConst, isObjectLiteralMethod } from './binder-utilities.js';
|
|
23
23
|
import { Diagnostics } from './diagnostics.js';
|
|
24
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
25
24
|
import { SyntaxKind } from './syntax-kind.js';
|
|
26
25
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
27
26
|
import { elaborateNeverIntersection } from './checker-property-access.js';
|
|
@@ -88,6 +87,7 @@ import { getIndexedAccessType, isGenericMappedType } from './checker-type-operat
|
|
|
88
87
|
import { getSignatureInstantiation } from './checker-signatures.js';
|
|
89
88
|
import { evaluateEnumMember, EvaluatedFlags, EvaluatedKind } from './checker-evaluator.js';
|
|
90
89
|
import { checkTypeAssignableTo, isTypeIdenticalTo } from './relations.js';
|
|
90
|
+
import { getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
91
91
|
|
|
92
92
|
export { getParentOfSymbol };
|
|
93
93
|
|
|
@@ -153,7 +153,7 @@ export function getDeclaredTypeOfClassOrInterface(c: Checker, symbol: Symbol): I
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
function isThislessInterface(c: Checker, symbol: Symbol): boolean {
|
|
156
|
-
for (const declaration of symbol
|
|
156
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
157
157
|
if (declaration.kind !== SyntaxKind.InterfaceDeclaration) continue;
|
|
158
158
|
if ((declaration.flags & NodeFlags.ContainsThis) !== 0) return false;
|
|
159
159
|
for (const node of getExtendsHeritageClauseElements(declaration)) {
|
|
@@ -201,7 +201,7 @@ export function getExtendsHeritageClauseElement(node: Node): Node | undefined {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
export function getClassLikeDeclarationOfSymbol(symbol: Symbol): Node | undefined {
|
|
204
|
-
for (const d of symbol
|
|
204
|
+
for (const d of getDeclarations(symbol))
|
|
205
205
|
if (d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.ClassExpression) return d;
|
|
206
206
|
return undefined;
|
|
207
207
|
}
|
|
@@ -210,7 +210,7 @@ function getOuterTypeParametersOfClassOrInterface(c: Checker, symbol: Symbol): T
|
|
|
210
210
|
let declaration = symbol.valueDeclaration;
|
|
211
211
|
if ((symbol.flags & (SymbolFlags.Class | SymbolFlags.Function)) === 0) {
|
|
212
212
|
declaration = undefined;
|
|
213
|
-
for (const d of symbol
|
|
213
|
+
for (const d of getDeclarations(symbol)) {
|
|
214
214
|
if (d.kind === SyntaxKind.InterfaceDeclaration) {
|
|
215
215
|
declaration = d;
|
|
216
216
|
break;
|
|
@@ -310,7 +310,7 @@ export function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(c: Checker,
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
function appendLocalTypeParameters(c: Checker, types: Type[], symbol: Symbol): Type[] {
|
|
313
|
-
for (const node of symbol
|
|
313
|
+
for (const node of getDeclarations(symbol)) {
|
|
314
314
|
if (
|
|
315
315
|
node.kind === SyntaxKind.InterfaceDeclaration ||
|
|
316
316
|
node.kind === SyntaxKind.ClassDeclaration ||
|
|
@@ -343,7 +343,7 @@ export function getDeclaredTypeOfTypeAlias(c: Checker, symbol: Symbol): Type {
|
|
|
343
343
|
if (links.declaredType !== undefined) return links.declaredType;
|
|
344
344
|
if (!pushTypeResolution(c, symbol, TypeSystemPropertyName.DeclaredType)) return c.errorType;
|
|
345
345
|
let declaration: Node | undefined;
|
|
346
|
-
for (const d of symbol
|
|
346
|
+
for (const d of getDeclarations(symbol))
|
|
347
347
|
if (d.kind === SyntaxKind.TypeAliasDeclaration || d.kind === SyntaxKind.JSTypeAliasDeclaration) {
|
|
348
348
|
declaration = d;
|
|
349
349
|
break;
|
|
@@ -374,7 +374,7 @@ export function getDeclaredTypeOfEnum(c: Checker, symbol: Symbol): Type {
|
|
|
374
374
|
const links = c.symbolLinks(symbol);
|
|
375
375
|
if (links.declaredType !== undefined) return links.declaredType;
|
|
376
376
|
const memberTypes: Type[] = [];
|
|
377
|
-
for (const declaration of symbol
|
|
377
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
378
378
|
if (declaration.kind !== SyntaxKind.EnumDeclaration) continue;
|
|
379
379
|
for (const member of (declaration as EnumDeclaration).members.nodes) {
|
|
380
380
|
if (!hasBindableName(member)) continue;
|
|
@@ -561,7 +561,7 @@ export function getBaseTypes(c: Checker, t: Type): Type[] {
|
|
|
561
561
|
if ((t.symbol!.flags & SymbolFlags.Interface) !== 0) resolveBaseTypesOfInterface(c, t as InterfaceType);
|
|
562
562
|
}
|
|
563
563
|
if (!popTypeResolution(c))
|
|
564
|
-
for (const declaration of t.symbol
|
|
564
|
+
for (const declaration of getDeclarations(t.symbol!))
|
|
565
565
|
if (declaration.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.InterfaceDeclaration)
|
|
566
566
|
reportCircularBaseType(c, declaration, t);
|
|
567
567
|
// Circular defaults may leave members partially resolved; reset them.
|
|
@@ -659,7 +659,7 @@ function isInJS(node: Node): boolean {
|
|
|
659
659
|
}
|
|
660
660
|
|
|
661
661
|
function resolveBaseTypesOfInterface(c: Checker, t: InterfaceType): void {
|
|
662
|
-
for (const declaration of t.symbol
|
|
662
|
+
for (const declaration of getDeclarations(t.symbol!)) {
|
|
663
663
|
if (declaration.kind !== SyntaxKind.InterfaceDeclaration) continue;
|
|
664
664
|
for (const node of getExtendsHeritageClauseElements(declaration)) {
|
|
665
665
|
const baseType = getReducedType(c, getTypeFromTypeNode(c, node));
|
|
@@ -798,7 +798,7 @@ export function hasNonCircularBaseConstraint(c: Checker, t: Type): boolean {
|
|
|
798
798
|
|
|
799
799
|
export function getConstraintDeclaration(t: Type): Node | undefined {
|
|
800
800
|
if (t.symbol !== undefined)
|
|
801
|
-
for (const d of t.symbol
|
|
801
|
+
for (const d of getDeclarations(t.symbol))
|
|
802
802
|
if (d.kind === SyntaxKind.TypeParameter) {
|
|
803
803
|
const constraint = (d as TypeParameterDeclaration).constraint;
|
|
804
804
|
if (constraint !== undefined) return constraint;
|
|
@@ -850,7 +850,7 @@ export function getResolvedTypeParameterDefault(c: Checker, t: TypeParameter): T
|
|
|
850
850
|
side.resolvedDefaultType = c.resolvingDefaultType;
|
|
851
851
|
let defaultType: Type = c.noConstraintType;
|
|
852
852
|
if (t.symbol !== undefined)
|
|
853
|
-
for (const d of t.symbol
|
|
853
|
+
for (const d of getDeclarations(t.symbol))
|
|
854
854
|
if (d.kind === SyntaxKind.TypeParameter) {
|
|
855
855
|
const node = (d as TypeParameterDeclaration).defaultType;
|
|
856
856
|
if (node !== undefined) {
|
|
@@ -878,7 +878,7 @@ export function getMinTypeArgumentCount(c: Checker, typeParameters: readonly Typ
|
|
|
878
878
|
/** Whether a type parameter is declared with a default, without resolving it. */
|
|
879
879
|
function hasTypeParameterDefault(t: Type): boolean {
|
|
880
880
|
if (t.symbol === undefined) return false;
|
|
881
|
-
for (const d of t.symbol
|
|
881
|
+
for (const d of getDeclarations(t.symbol))
|
|
882
882
|
if (d.kind === SyntaxKind.TypeParameter && (d as TypeParameterDeclaration).defaultType !== undefined) return true;
|
|
883
883
|
return false;
|
|
884
884
|
}
|
|
@@ -37,7 +37,6 @@ import {
|
|
|
37
37
|
isAutoAccessorPropertyDeclaration,
|
|
38
38
|
} from './binder-utilities.js';
|
|
39
39
|
import { type DiagnosticMessage, Diagnostics } from './diagnostics.js';
|
|
40
|
-
import { type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
|
|
41
40
|
import { SyntaxKind } from './syntax-kind.js';
|
|
42
41
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
43
42
|
import { ModuleKind, getEmitModuleKind, ScriptTarget, getUseDefineForClassFields } from './options.js';
|
|
@@ -89,6 +88,7 @@ import {
|
|
|
89
88
|
getGlobalClassSetterDecoratorContextType,
|
|
90
89
|
getGlobalTypedPropertyDescriptorType,
|
|
91
90
|
} from './checker-globals.js';
|
|
91
|
+
import { getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
92
92
|
|
|
93
93
|
// ---- Checks
|
|
94
94
|
|
|
@@ -230,12 +230,12 @@ function checkMetadataTypeImport(c: Checker, typeNode: Node | undefined): void {
|
|
|
230
230
|
(typeName.kind === SyntaxKind.Identifier ? SymbolFlags.Type : SymbolFlags.Namespace) | SymbolFlags.Alias;
|
|
231
231
|
const rootSymbol = resolveName(c, rootName, getText(rootName), meaning, undefined, true, false);
|
|
232
232
|
if (rootSymbol === undefined || (rootSymbol.flags & SymbolFlags.Alias) === 0 || symbolIsValue(c, rootSymbol)) return;
|
|
233
|
-
if (rootSymbol.
|
|
233
|
+
if (getDeclarations(rootSymbol).some(isTypeOnlyImportOrExportDeclaration)) return;
|
|
234
234
|
const diagnostic = c.error(
|
|
235
235
|
typeName,
|
|
236
236
|
Diagnostics.A_type_referenced_in_a_decorated_signature_must_be_imported_with_import_type_or_a_namespace_import_when_isolatedModules_and_emitDecoratorMetadata_are_enabled,
|
|
237
237
|
);
|
|
238
|
-
const aliasDeclaration = rootSymbol.
|
|
238
|
+
const aliasDeclaration = getDeclarations(rootSymbol).find(isAliasSymbolDeclaration);
|
|
239
239
|
if (aliasDeclaration !== undefined)
|
|
240
240
|
diagnostic.addRelatedInfo(
|
|
241
241
|
createDiagnosticForNode(aliasDeclaration, Diagnostics.X_0_was_imported_here, [getText(rootName)]),
|
|
@@ -24,7 +24,6 @@ import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
|
24
24
|
import { type Signature, SignatureFlags, type Type } from './checker-types.js';
|
|
25
25
|
import { type Diagnostic, Diagnostics } from './diagnostics.js';
|
|
26
26
|
import { getJSDoc } from './parser.js';
|
|
27
|
-
import { type Symbol, SymbolFlags } from './symbol.js';
|
|
28
27
|
import { SyntaxKind } from './syntax-kind.js';
|
|
29
28
|
import { getDeclarationOfAliasSymbol, getParentOfSymbol, resolveAlias } from './checker-symbols.js';
|
|
30
29
|
import { getTargetOfAliasDeclaration } from './checker-modules.js';
|
|
@@ -33,6 +32,7 @@ import { entityNameToString } from './checker-expressions.js';
|
|
|
33
32
|
import { isErrorType } from './checker-type-factory.js';
|
|
34
33
|
import { getPropertyOfType } from './checker-members.js';
|
|
35
34
|
import { signatureToString } from './type-printer.js';
|
|
35
|
+
import { declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
|
|
36
36
|
|
|
37
37
|
/** Whether `declaration`, or the statement it belongs to, has a `@deprecated` JSDoc tag. */
|
|
38
38
|
export function isDeprecatedDeclaration(declaration: Node): boolean {
|
|
@@ -56,7 +56,7 @@ function getJSDocDeprecatedTag(node: Node): Node | undefined {
|
|
|
56
56
|
* members when all are.
|
|
57
57
|
*/
|
|
58
58
|
export function isDeprecatedSymbol(c: Checker, symbol: Symbol): boolean {
|
|
59
|
-
const declarations = symbol
|
|
59
|
+
const declarations = getDeclarations(symbol);
|
|
60
60
|
const parentSymbol = getParentOfSymbol(c, symbol);
|
|
61
61
|
if (parentSymbol !== undefined && declarations.length > 1)
|
|
62
62
|
return (parentSymbol.flags & SymbolFlags.Interface) !== 0
|
|
@@ -208,7 +208,7 @@ function isUncalledFunctionReference(c: Checker, node: Node, symbol: Symbol): bo
|
|
|
208
208
|
node.kind === SyntaxKind.Identifier &&
|
|
209
209
|
hasMatchingArgument(c, parent, node)
|
|
210
210
|
);
|
|
211
|
-
for (const d of symbol
|
|
211
|
+
for (const d of getDeclarations(symbol)) if (isFunctionLikeKind(d.kind) && !isDeprecatedDeclaration(d)) return false;
|
|
212
212
|
return true;
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -263,9 +263,9 @@ export function resolveAliasWithDeprecationCheck(c: Checker, symbol: Symbol, loc
|
|
|
263
263
|
while ((current.flags & SymbolFlags.Alias) !== 0) {
|
|
264
264
|
const target = getImmediateAliasedSymbol(c, current);
|
|
265
265
|
if (target === undefined || target === targetSymbol) break;
|
|
266
|
-
if (target
|
|
266
|
+
if (declarationCount(target) !== 0) {
|
|
267
267
|
if (isDeprecatedSymbol(c, target)) {
|
|
268
|
-
addDeprecatedSuggestion(c, location, target
|
|
268
|
+
addDeprecatedSuggestion(c, location, getDeclarations(target), target.name);
|
|
269
269
|
break;
|
|
270
270
|
}
|
|
271
271
|
if (current === targetSymbol) break;
|
|
@@ -288,11 +288,11 @@ function getImmediateAliasedSymbol(c: Checker, symbol: Symbol): Symbol | undefin
|
|
|
288
288
|
export function checkDeprecatedIdentifier(c: Checker, node: Node, localOrExportSymbol: Symbol): void {
|
|
289
289
|
const targetSymbol = resolveAliasWithDeprecationCheck(c, localOrExportSymbol, node);
|
|
290
290
|
if (
|
|
291
|
-
targetSymbol
|
|
291
|
+
declarationCount(targetSymbol) !== 0 &&
|
|
292
292
|
isDeprecatedSymbol(c, targetSymbol) &&
|
|
293
293
|
isUncalledFunctionReference(c, node, targetSymbol)
|
|
294
294
|
)
|
|
295
|
-
addDeprecatedSuggestion(c, node, targetSymbol
|
|
295
|
+
addDeprecatedSuggestion(c, node, getDeclarations(targetSymbol), getText(node));
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
/** Reports a property access to a deprecated property. */
|
|
@@ -301,9 +301,9 @@ export function checkDeprecatedProperty(c: Checker, node: Node, right: Node, pro
|
|
|
301
301
|
if (
|
|
302
302
|
isDeprecatedSymbol(c, targetPropSymbol) &&
|
|
303
303
|
isUncalledFunctionReference(c, node, targetPropSymbol) &&
|
|
304
|
-
targetPropSymbol
|
|
304
|
+
declarationCount(targetPropSymbol) !== 0
|
|
305
305
|
)
|
|
306
|
-
addDeprecatedSuggestion(c, right, targetPropSymbol
|
|
306
|
+
addDeprecatedSuggestion(c, right, getDeclarations(targetPropSymbol), getText(right));
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
/** Reports a property access resolved through a deprecated index signature. */
|
|
@@ -314,11 +314,7 @@ export function checkDeprecatedIndexSignature(c: Checker, right: Node, declarati
|
|
|
314
314
|
|
|
315
315
|
/** Reports an element access or indexed access type selecting a deprecated property. */
|
|
316
316
|
export function checkDeprecatedIndexedAccess(c: Checker, accessNode: Node, prop: Symbol, propName: string): void {
|
|
317
|
-
if (
|
|
318
|
-
prop.declarations.length === 0 ||
|
|
319
|
-
!isDeprecatedSymbol(c, prop) ||
|
|
320
|
-
!isUncalledFunctionReference(c, accessNode, prop)
|
|
321
|
-
)
|
|
317
|
+
if (declarationCount(prop) === 0 || !isDeprecatedSymbol(c, prop) || !isUncalledFunctionReference(c, accessNode, prop))
|
|
322
318
|
return;
|
|
323
319
|
const deprecatedNode =
|
|
324
320
|
accessNode.kind === SyntaxKind.ElementAccessExpression
|
|
@@ -326,7 +322,7 @@ export function checkDeprecatedIndexedAccess(c: Checker, accessNode: Node, prop:
|
|
|
326
322
|
: accessNode.kind === SyntaxKind.IndexedAccessType
|
|
327
323
|
? (accessNode as IndexedAccessTypeNode).indexType
|
|
328
324
|
: accessNode;
|
|
329
|
-
addDeprecatedSuggestion(c, deprecatedNode, prop
|
|
325
|
+
addDeprecatedSuggestion(c, deprecatedNode, getDeclarations(prop), propName);
|
|
330
326
|
}
|
|
331
327
|
|
|
332
328
|
/** Reports a type reference or import type naming a deprecated type. */
|
|
@@ -334,9 +330,9 @@ export function checkDeprecatedTypeReference(c: Checker, node: Node, type: Type)
|
|
|
334
330
|
if (isErrorType(c, type)) return;
|
|
335
331
|
const symbol = c.resolvedSymbols.get(node.id);
|
|
336
332
|
if (symbol === undefined) return;
|
|
337
|
-
for (const d of symbol
|
|
333
|
+
for (const d of getDeclarations(symbol)) {
|
|
338
334
|
if (isTypeDeclaration(d) && isDeprecatedDeclaration(d)) {
|
|
339
|
-
addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), symbol
|
|
335
|
+
addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), getDeclarations(symbol), symbol.name);
|
|
340
336
|
return;
|
|
341
337
|
}
|
|
342
338
|
}
|
|
@@ -345,8 +341,8 @@ export function checkDeprecatedTypeReference(c: Checker, node: Node, type: Type)
|
|
|
345
341
|
/** Reports an import specifier importing a deprecated declaration. */
|
|
346
342
|
export function checkDeprecatedImportSpecifier(c: Checker, node: Node, symbol: Symbol): void {
|
|
347
343
|
const targetSymbol = resolveAliasWithDeprecationCheck(c, symbol, node);
|
|
348
|
-
if (isDeprecatedSymbol(c, targetSymbol) && targetSymbol
|
|
349
|
-
addDeprecatedSuggestion(c, node, targetSymbol
|
|
344
|
+
if (isDeprecatedSymbol(c, targetSymbol) && declarationCount(targetSymbol) !== 0)
|
|
345
|
+
addDeprecatedSuggestion(c, node, getDeclarations(targetSymbol), targetSymbol.name);
|
|
350
346
|
}
|
|
351
347
|
|
|
352
348
|
/** Reports a JSX attribute setting a deprecated property of the element's contextual props type. */
|
|
@@ -354,6 +350,6 @@ export function checkDeprecatedJsxAttribute(c: Checker, contextualType: Type, at
|
|
|
354
350
|
const name = attribute.name;
|
|
355
351
|
if (name.kind !== SyntaxKind.Identifier) return;
|
|
356
352
|
const prop = getPropertyOfType(c, contextualType, getText(name));
|
|
357
|
-
if (prop !== undefined && prop
|
|
358
|
-
addDeprecatedSuggestion(c, name, prop
|
|
353
|
+
if (prop !== undefined && declarationCount(prop) !== 0 && isDeprecatedSymbol(c, prop))
|
|
354
|
+
addDeprecatedSuggestion(c, name, getDeclarations(prop), getText(name));
|
|
359
355
|
}
|