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
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
|
|
5
5
|
// statically, but reads fields of a narrowed value dynamically.
|
|
6
|
-
import { BinaryExpression, CallExpression, ConditionalTypeNode, ElementAccessExpression, ExportAssignment, FunctionExpression, KeywordExpression, ModuleDeclaration, NodeVisitor, PatternAmbientModule, PrefixUnaryExpression, PropertyAccessExpression, TypeAliasDeclaration, VariableDeclaration, getArguments, getBody, getElements, getExpression, getInitializer, getLabel, getLocals, getModifiers, getName, getParameters, getPostfixToken, getProperties, getStatements, getSymbol, getText, isDeclarationNode, isLocalsContainer, setEndFlowNode, setFlowNode, setLocalSymbol, setLocals, setNextContainer, setReturnFlowNode, setSymbol, } from './ast.js';
|
|
6
|
+
import { appendToList, BinaryExpression, CallExpression, ConditionalTypeNode, ElementAccessExpression, ExportAssignment, FunctionExpression, KeywordExpression, ModuleDeclaration, NodeVisitor, PatternAmbientModule, PrefixUnaryExpression, PropertyAccessExpression, ReferenceIdentifier, TypeAliasDeclaration, VariableDeclaration, getArguments, getBody, getElements, getExpression, getInitializer, getLabel, getLocals, getModifiers, getName, getParameters, getPostfixToken, getProperties, getStatements, getSymbol, getText, isDeclarationNode, isLocalsContainer, setEndFlowNode, setFlowNode, setLocalSymbol, setLocals, setNextContainer, setReturnFlowNode, setSymbol, callQuestionDotToken, callTypeArguments, } from './ast.js';
|
|
7
7
|
import { isAmbientModule, isAssignmentOperator, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLeftHandSideExpression, isRequireCall, isStringLiteralLike, nodeIsMissing, nodeIsPresent, } from './ast-utilities.js';
|
|
8
8
|
import { declarationNameToString, expressionIsAlias, getAssignmentDeclarationKind, getCombinedModifierFlags, getContainingClass, getElementOrPropertyAccessName, getErrorRangeForNode, getImmediatelyInvokedFunctionExpression, getModuleInstanceState, StatementsByName, getNameOfDeclaration, getRangeOfTokenAtPosition, getSourceTextOfNode, hasDynamicName, hasSyntacticModifier, isAssignmentTarget, isAsyncFunction, isAutoAccessorPropertyDeclaration, isBlockOrCatchScoped, isBooleanLiteral, isDeclarationStatementKind, isDestructuringAssignment, isDottedName, isEntityNameExpression, isEnumConst, isExpandoInitializer, isExpressionOfOptionalChainRoot, isExternalModule, isExternalOrCommonJSModule, isIdentifierName, isImplicitlyExportedJSDocDeclaration, isInTopLevelContext, isJsonSourceFile, isLogicalExpression, isLogicalOrCoalescingAssignmentExpression, isLogicalOrCoalescingAssignmentOperator, isLogicalOrCoalescingBinaryOperator, isModuleAugmentationExternal, isNullishCoalesce, isObjectLiteralMethod, isObjectLiteralOrClassExpressionMethodOrAccessor, isOptionalChain, isOptionalChainRoot, isOutermostOptionalChain, isParameterPropertyDeclaration, isPartOfParameterDeclaration, isPartOfTypeQuery, isPotentiallyExecutableNode, isPrologueDirective, isPropertyNameLiteral, isPushOrUnshiftIdentifier, isSignedNumericLiteral, isStatic, isStringOrNumericLiteralLike, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, nodeText, skipParentheses, } from './binder-utilities.js';
|
|
9
9
|
import { Diagnostic } from './diagnostics.js';
|
|
10
10
|
import { FlowNode, FlowReduceLabel, FlowSwitchClause } from './flow.js';
|
|
11
11
|
import { removeFileExtension } from './path.js';
|
|
12
12
|
import { getIdentifierToken, tokenToString } from './scanner.js';
|
|
13
|
-
import {
|
|
13
|
+
import { addDeclaration, copyDeclarations, declarationCount, getDeclarations, getExports, getMembers, getSymbolId, internalSymbolNamePrefix, Symbol, } from './symbol.js';
|
|
14
14
|
export function getContainerFlags(node) {
|
|
15
15
|
switch (node.kind) {
|
|
16
16
|
case 232 /* SyntaxKind.ClassExpression */:
|
|
@@ -306,7 +306,7 @@ class Binder extends NodeVisitor {
|
|
|
306
306
|
messageNeedsName = false;
|
|
307
307
|
}
|
|
308
308
|
let multipleDefaultExports = false;
|
|
309
|
-
if (symbol
|
|
309
|
+
if (declarationCount(symbol) !== 0) {
|
|
310
310
|
// A default export (by modifier, or `export default` assignment) after another one.
|
|
311
311
|
if (isDefaultExport || (node instanceof ExportAssignment && !node.isExportEquals)) {
|
|
312
312
|
message = 686 /* Diagnostics.A_module_cannot_have_multiple_default_exports */;
|
|
@@ -325,7 +325,7 @@ class Binder extends NodeVisitor {
|
|
|
325
325
|
'export type { ' + node.name.text + ' }',
|
|
326
326
|
]));
|
|
327
327
|
}
|
|
328
|
-
const declarations = symbol
|
|
328
|
+
const declarations = getDeclarations(symbol);
|
|
329
329
|
for (let index = 0; index < declarations.length; index++) {
|
|
330
330
|
const declaration = declarations[index];
|
|
331
331
|
const decl = getNameOfDeclaration(declaration) ?? declaration;
|
|
@@ -498,7 +498,7 @@ class Binder extends NodeVisitor {
|
|
|
498
498
|
addDeclarationToSymbol(symbol, node, symbolFlags) {
|
|
499
499
|
symbol.flags |= symbolFlags;
|
|
500
500
|
setSymbol(node, symbol);
|
|
501
|
-
if (symbol.
|
|
501
|
+
if (getDeclarations(symbol).indexOf(node) < 0)
|
|
502
502
|
addDeclaration(symbol, node);
|
|
503
503
|
// A const-enum-only namespace merged with a class, function or regular enum isn't one anymore.
|
|
504
504
|
if ((symbol.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) !== 0 &&
|
|
@@ -541,7 +541,7 @@ class Binder extends NodeVisitor {
|
|
|
541
541
|
this.addDiagnostic(new Diagnostic(this.file.diagnosticFile(), range.pos, range.end, message, args));
|
|
542
542
|
}
|
|
543
543
|
addDiagnostic(diagnostic) {
|
|
544
|
-
this.file.bindDiagnostics.
|
|
544
|
+
this.file.bindDiagnostics = appendToList(this.file.bindDiagnostics, diagnostic);
|
|
545
545
|
}
|
|
546
546
|
// Traversal
|
|
547
547
|
bindOptional(node) {
|
|
@@ -553,7 +553,8 @@ class Binder extends NodeVisitor {
|
|
|
553
553
|
// the container's locals; anonymous declarations like type literals go in no table.
|
|
554
554
|
switch (node.kind) {
|
|
555
555
|
case 79 /* SyntaxKind.Identifier */:
|
|
556
|
-
node
|
|
556
|
+
if (node instanceof ReferenceIdentifier)
|
|
557
|
+
node.flowNode = this.currentFlowValue();
|
|
557
558
|
this.checkContextualIdentifier(node);
|
|
558
559
|
break;
|
|
559
560
|
case 109 /* SyntaxKind.ThisKeyword */:
|
|
@@ -906,7 +907,7 @@ class Binder extends NodeVisitor {
|
|
|
906
907
|
symbol.valueDeclaration = this.file;
|
|
907
908
|
if (name === 'module') {
|
|
908
909
|
const exportsProperty = this.newSymbol(134217728 /* SymbolFlags.ModuleExports */ | 4 /* SymbolFlags.Property */, 'exports');
|
|
909
|
-
exportsProperty
|
|
910
|
+
copyDeclarations(exportsProperty, symbol);
|
|
910
911
|
exportsProperty.valueDeclaration = this.file;
|
|
911
912
|
exportsProperty.parent = symbol;
|
|
912
913
|
getMembers(symbol).set('exports', exportsProperty);
|
|
@@ -1618,8 +1619,8 @@ class Binder extends NodeVisitor {
|
|
|
1618
1619
|
this.bind(node.argumentExpression);
|
|
1619
1620
|
}
|
|
1620
1621
|
else if (node instanceof CallExpression) {
|
|
1621
|
-
this.bindOptional(node
|
|
1622
|
-
this.bindNodes(node
|
|
1622
|
+
this.bindOptional(callQuestionDotToken(node));
|
|
1623
|
+
this.bindNodes(callTypeArguments(node));
|
|
1623
1624
|
this.bindNodes(node.arguments);
|
|
1624
1625
|
}
|
|
1625
1626
|
}
|
|
@@ -1630,7 +1631,7 @@ class Binder extends NodeVisitor {
|
|
|
1630
1631
|
// An IIFE's flow node includes the evaluation of its arguments.
|
|
1631
1632
|
const callee = skipParentheses(node.expression);
|
|
1632
1633
|
if (callee.kind === 219 /* SyntaxKind.FunctionExpression */ || callee.kind === 220 /* SyntaxKind.ArrowFunction */) {
|
|
1633
|
-
this.bindNodes(node
|
|
1634
|
+
this.bindNodes(callTypeArguments(node));
|
|
1634
1635
|
this.bindNodes(node.arguments);
|
|
1635
1636
|
this.bind(node.expression);
|
|
1636
1637
|
}
|
|
@@ -1696,7 +1697,7 @@ class Binder extends NodeVisitor {
|
|
|
1696
1697
|
if (starIndex >= 0 && text.indexOf('*', starIndex + 1) >= 0)
|
|
1697
1698
|
this.errorOnFirstToken(name, 1136 /* Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character */, [text]);
|
|
1698
1699
|
else if (starIndex >= 0)
|
|
1699
|
-
this.file.patternAmbientModules.
|
|
1700
|
+
this.file.patternAmbientModules = appendToList(this.file.patternAmbientModules, new PatternAmbientModule(text, starIndex, symbol));
|
|
1700
1701
|
}
|
|
1701
1702
|
return;
|
|
1702
1703
|
}
|
|
@@ -1806,7 +1807,7 @@ class Binder extends NodeVisitor {
|
|
|
1806
1807
|
const exports = getExports(symbol);
|
|
1807
1808
|
const existing = exports.get('prototype');
|
|
1808
1809
|
if (existing !== undefined)
|
|
1809
|
-
this.errorOnNode(existing.
|
|
1810
|
+
this.errorOnNode(existing.declaration, 478 /* Diagnostics.Duplicate_identifier_0 */, ['prototype']);
|
|
1810
1811
|
exports.set('prototype', prototypeSymbol);
|
|
1811
1812
|
prototypeSymbol.parent = symbol;
|
|
1812
1813
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Calls, `new` and tagged templates: signature resolution with type argument inference and overload
|
|
2
2
|
// selection, argument checks and resolution errors.
|
|
3
3
|
import { checkDeprecatedSignature } from './checker-deprecation.js';
|
|
4
|
-
import { Node, getArguments as getArgumentList, getExpression, getName, getParameters, getText, getTypeArguments as getTypeArgumentList, getNodeId, getBody, getSymbol, } from './ast.js';
|
|
4
|
+
import { Node, getArguments as getArgumentList, getExpression, getName, getParameters, getText, getTypeArguments as getTypeArgumentList, getNodeId, getBody, getSymbol, callQuestionDotToken, callTypeArguments, } from './ast.js';
|
|
5
5
|
import { canHaveDecorators, getEffectiveCheckNode, isFunctionLikeDeclarationKind, isImportCall, nodeIsPresent, } from './ast-utilities.js';
|
|
6
6
|
import { getContainingClass, getSourceFileOfNode, isAccessExpression, isExpressionOfOptionalChainRoot, isOptionalChain, isOutermostOptionalChain, isDottedName, } from './binder-utilities.js';
|
|
7
7
|
import { Diagnostic, chainDiagnostic } from './diagnostics.js';
|
|
@@ -38,6 +38,7 @@ import { getGlobalValueSymbol, getSymbolOfDeclaration, resolveName } from './che
|
|
|
38
38
|
import { checkImportCallExpression } from './checker-modules.js';
|
|
39
39
|
import { checkApplicableSignatureForJsxCallLikeElement, getAttributesOf, getEffectiveJsxArguments, inferJsxTypeArguments, isJsxOpeningLikeElement, resolveJsxOpeningLikeElement, } from './checker-jsx.js';
|
|
40
40
|
import { isCommonJSRequire, resolveExternalModuleTypeByLiteral } from './checker-javascript.js';
|
|
41
|
+
import { declarationCount, getDeclarations } from './symbol.js';
|
|
41
42
|
/** The type of an optional chain's expression with the chain's `undefined` removed. */
|
|
42
43
|
export function getOptionalExpressionType(c, exprType, expression) {
|
|
43
44
|
if (isExpressionOfOptionalChainRoot(expression))
|
|
@@ -71,7 +72,7 @@ export function checkCallExpression(c, node, checkMode) {
|
|
|
71
72
|
if ((returnType.flags & 16896 /* TypeFlags.ESSymbolLike */) !== 0 && isSymbolOrSymbolForCall(c, call))
|
|
72
73
|
return getESSymbolLikeTypeForNode(c, walkUpParenthesizedExpressions(node.parent));
|
|
73
74
|
// An assertion call must name its target through explicitly typed declarations.
|
|
74
|
-
if (call
|
|
75
|
+
if (callQuestionDotToken(call) === undefined &&
|
|
75
76
|
node.parent.kind === 245 /* SyntaxKind.ExpressionStatement */ &&
|
|
76
77
|
(returnType.flags & 16 /* TypeFlags.Void */) !== 0 &&
|
|
77
78
|
getTypePredicateOfSignature(c, signature) !== undefined) {
|
|
@@ -195,7 +196,7 @@ function resolveCallExpression(c, node, checkMode) {
|
|
|
195
196
|
const callSignatures = getSignaturesOfType(c, apparentType, 0 /* SignatureKind.Call */);
|
|
196
197
|
const numConstructSignatures = getSignaturesOfType(c, apparentType, 1 /* SignatureKind.Construct */).length;
|
|
197
198
|
if (isUntypedFunctionCall(c, funcType, apparentType, callSignatures.length, numConstructSignatures)) {
|
|
198
|
-
if (!isErrorType(c, funcType) && node
|
|
199
|
+
if (!isErrorType(c, funcType) && callTypeArguments(node) !== undefined)
|
|
199
200
|
c.error(node, 523 /* Diagnostics.Untyped_function_calls_may_not_accept_type_arguments */);
|
|
200
201
|
return resolveUntypedCall(c, node);
|
|
201
202
|
}
|
|
@@ -209,7 +210,7 @@ function resolveCallExpression(c, node, checkMode) {
|
|
|
209
210
|
// An inner generic call returning a function is deferred while an outer call infers, so that
|
|
210
211
|
// inferences can flow through function composition.
|
|
211
212
|
if ((checkMode & 8 /* CheckMode.SkipGenericFunctions */) !== 0 &&
|
|
212
|
-
node
|
|
213
|
+
callTypeArguments(node) === undefined &&
|
|
213
214
|
someGenericFunctionReturningFunction(c, callSignatures)) {
|
|
214
215
|
skippedGenericFunction(c, node, checkMode);
|
|
215
216
|
return c.resolvingSignature;
|
|
@@ -1246,10 +1247,10 @@ function reportCallResolutionErrors(c, s, signatures, headMessage) {
|
|
|
1246
1247
|
/** Notes when the call would have resolved to the implementation signature of the overloads. */
|
|
1247
1248
|
function addImplementationSuccessElaboration(c, s, failed, diagnostic) {
|
|
1248
1249
|
const symbol = failed.declaration !== undefined ? getSymbol(failed.declaration) : undefined;
|
|
1249
|
-
if (symbol === undefined || symbol
|
|
1250
|
+
if (symbol === undefined || declarationCount(symbol) <= 1)
|
|
1250
1251
|
return;
|
|
1251
1252
|
let implementation;
|
|
1252
|
-
for (const d of symbol
|
|
1253
|
+
for (const d of getDeclarations(symbol)) {
|
|
1253
1254
|
if (isFunctionLikeDeclarationKind(d.kind) && nodeIsPresent(getBody(d))) {
|
|
1254
1255
|
implementation = d;
|
|
1255
1256
|
break;
|
|
@@ -110,7 +110,7 @@ export function checkExpressionWithContextualType(c, node, contextualType, infer
|
|
|
110
110
|
let t = checkExpressionEx(c, node, checkMode | 1 /* CheckMode.Contextual */ | (inferenceContext !== undefined ? 2 /* CheckMode.Inferential */ : 0));
|
|
111
111
|
// Intra-expression inference sites only matter during this check.
|
|
112
112
|
if (inferenceContext !== undefined)
|
|
113
|
-
inferenceContext.intraExpressionInferenceSites =
|
|
113
|
+
inferenceContext.intraExpressionInferenceSites = undefined;
|
|
114
114
|
// Contextually typed literals keep their literal types rather than widening during inference.
|
|
115
115
|
if (maybeTypeOfKind(t, 15360 /* TypeFlags.Literal */) &&
|
|
116
116
|
isLiteralOfContextualType(c, t, instantiateContextualType(c, contextualType, node, 0 /* ContextFlags.None */)))
|
|
@@ -12,6 +12,7 @@ import { getExportSymbolOfValueSymbolIfExported } from './checker-symbols.js';
|
|
|
12
12
|
import { getBaseTypes, getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
13
13
|
import { getPropertyOfType } from './checker-members.js';
|
|
14
14
|
import { getFunctionFlags } from './checker-utilities.js';
|
|
15
|
+
import { getDeclarations } from './symbol.js';
|
|
15
16
|
/** Reports a block-scoped variable, class or enum resolved at `errorLocation` before its declaration. */
|
|
16
17
|
export function checkResolvedBlockScopedVariable(c, resolved, errorLocation) {
|
|
17
18
|
const result = getExportSymbolOfValueSymbolIfExported(c, resolved);
|
|
@@ -22,7 +23,7 @@ export function checkResolvedBlockScopedVariable(c, resolved, errorLocation) {
|
|
|
22
23
|
(result.flags & 32 /* SymbolFlags.Class */) !== 0)
|
|
23
24
|
return;
|
|
24
25
|
let declaration;
|
|
25
|
-
for (const d of result
|
|
26
|
+
for (const d of getDeclarations(result)) {
|
|
26
27
|
if (isBlockOrCatchScoped(d) || isClassLike(d) || d.kind === 267 /* SyntaxKind.EnumDeclaration */) {
|
|
27
28
|
declaration = d;
|
|
28
29
|
break;
|
|
@@ -11,7 +11,6 @@ import { getPropertyNameFromType, isBindingPattern, isTypeUsableAsPropertyName }
|
|
|
11
11
|
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
12
12
|
import { declarationNameToString, getNameOfDeclaration, getSourceFileOfNode, getAssignmentDeclarationKind, getCombinedModifierFlags, getCombinedNodeFlags, isPartOfParameterDeclaration, getRootDeclaration, getDeclarationOfKind, getModifierFlags, getModuleInstanceState, getRangeOfTokenAtPosition, hasSyntacticModifier, isEntityNameExpression, isEnumConst, isExternalModule, isModuleAugmentationExternal, isVariableDeclarationInitializedToRequire, isClassLike, } from './binder-utilities.js';
|
|
13
13
|
import { Diagnostic } from './diagnostics.js';
|
|
14
|
-
import { getSymbolId } from './symbol.js';
|
|
15
14
|
import { createDiagnosticForNode } from './checker.js';
|
|
16
15
|
import { getLiteralTypeFromPropertyName, intrinsicTypeKind } from './checker-type-operators.js';
|
|
17
16
|
import { SimpleTypeMapper, } from './checker-types.js';
|
|
@@ -36,6 +35,7 @@ import { checkFunctionOrMethodSymbols } from './checker-overloads.js';
|
|
|
36
35
|
import { checkJSDocFullSignature } from './checker-jsdoc.js';
|
|
37
36
|
import { checkAliasSymbol } from './checker-modules.js';
|
|
38
37
|
import { checkDecorators } from './checker-decorators.js';
|
|
38
|
+
import { declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
|
|
39
39
|
// ---- Variables and parameters
|
|
40
40
|
export function checkVariableStatement(c, node) {
|
|
41
41
|
checkVariableDeclarationList(c, node.declarationList);
|
|
@@ -126,8 +126,8 @@ export function checkVariableLikeDeclaration(c, node) {
|
|
|
126
126
|
checkTypeAssignableToAndOptionallyElaborate(c, initType, t, node, initializer);
|
|
127
127
|
checkUsingDeclarationInitializer(c, node, initializer, initType);
|
|
128
128
|
}
|
|
129
|
-
if (name !== undefined && symbol
|
|
130
|
-
for (const d of symbol
|
|
129
|
+
if (name !== undefined && declarationCount(symbol) > 1) {
|
|
130
|
+
for (const d of getDeclarations(symbol)) {
|
|
131
131
|
if (d !== node && isVariableLike(d) && !areDeclarationFlagsIdentical(d, node)) {
|
|
132
132
|
reportNonIdenticalModifiers(c, name);
|
|
133
133
|
break;
|
|
@@ -552,15 +552,15 @@ export function checkEnumDeclaration(c, node) {
|
|
|
552
552
|
if (links.enumChecked)
|
|
553
553
|
return;
|
|
554
554
|
links.enumChecked = true;
|
|
555
|
-
if (symbol
|
|
555
|
+
if (declarationCount(symbol) > 1) {
|
|
556
556
|
const enumIsConst = isEnumConst(node);
|
|
557
|
-
for (const d of symbol
|
|
557
|
+
for (const d of getDeclarations(symbol))
|
|
558
558
|
if (d.kind === 267 /* SyntaxKind.EnumDeclaration */ && isEnumConst(d) !== enumIsConst)
|
|
559
559
|
c.error(getNameOfDeclaration(d), 637 /* Diagnostics.Enum_declarations_must_all_be_const_or_non_const */);
|
|
560
560
|
}
|
|
561
561
|
// Only one declaration of a merged enum may continue automatic numbering from zero.
|
|
562
562
|
let seenEnumMissingInitialInitializer = false;
|
|
563
|
-
for (const d of symbol
|
|
563
|
+
for (const d of getDeclarations(symbol)) {
|
|
564
564
|
if (d.kind !== 267 /* SyntaxKind.EnumDeclaration */)
|
|
565
565
|
continue;
|
|
566
566
|
const members = d.members.nodes;
|
|
@@ -606,7 +606,7 @@ export function checkModuleDeclaration(c, node) {
|
|
|
606
606
|
// Namespaces of global scripts can merge across files, which a transpiler of one file cannot see.
|
|
607
607
|
if (c.isolatedModules && getSourceFileOfNode(node).externalModuleIndicator === undefined)
|
|
608
608
|
c.error(module.name, 229 /* 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 */, c.compilerOptions.verbatimModuleSyntax === true ? 'verbatimModuleSyntax' : 'isolatedModules');
|
|
609
|
-
if (symbol
|
|
609
|
+
if (declarationCount(symbol) > 1) {
|
|
610
610
|
const classOrFunction = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
|
|
611
611
|
if (classOrFunction !== undefined) {
|
|
612
612
|
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunction))
|
|
@@ -648,7 +648,7 @@ export function isInstantiatedModule(node, preserveConstEnums) {
|
|
|
648
648
|
return (state === 2 /* ModuleInstanceState.Instantiated */ || (preserveConstEnums && state === 3 /* ModuleInstanceState.ConstEnumOnly */));
|
|
649
649
|
}
|
|
650
650
|
function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
|
|
651
|
-
for (const d of symbol
|
|
651
|
+
for (const d of getDeclarations(symbol))
|
|
652
652
|
if ((d.kind === 264 /* SyntaxKind.ClassDeclaration */ ||
|
|
653
653
|
(d.kind === 263 /* SyntaxKind.FunctionDeclaration */ && nodeIsPresent(getBody(d)))) &&
|
|
654
654
|
(d.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
@@ -719,7 +719,7 @@ export function checkExternalModuleExports(c, node) {
|
|
|
719
719
|
if (id === "\uFFFEexport" /* InternalSymbolName.ExportStar */ || (symbol.flags & (1920 /* SymbolFlags.Namespace */ | 384 /* SymbolFlags.Enum */)) !== 0)
|
|
720
720
|
continue;
|
|
721
721
|
let count = 0;
|
|
722
|
-
for (const d of symbol
|
|
722
|
+
for (const d of getDeclarations(symbol))
|
|
723
723
|
if (isNotOverload(d) && !isAccessorDeclaration(d) && d.kind !== 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
724
724
|
count++;
|
|
725
725
|
// A type alias may merge with one value.
|
|
@@ -728,12 +728,12 @@ export function checkExternalModuleExports(c, node) {
|
|
|
728
728
|
if (count <= 1)
|
|
729
729
|
continue;
|
|
730
730
|
let allExportsProperties = true;
|
|
731
|
-
for (const d of symbol
|
|
731
|
+
for (const d of getDeclarations(symbol))
|
|
732
732
|
if (getAssignmentDeclarationKind(d) !== 2 /* JSDeclarationKind.ExportsProperty */)
|
|
733
733
|
allExportsProperties = false;
|
|
734
734
|
if (allExportsProperties)
|
|
735
735
|
continue;
|
|
736
|
-
for (const d of symbol
|
|
736
|
+
for (const d of getDeclarations(symbol))
|
|
737
737
|
if (isNotOverload(d))
|
|
738
738
|
c.error(d, 501 /* Diagnostics.Cannot_redeclare_exported_variable_0 */, id);
|
|
739
739
|
}
|
|
@@ -780,7 +780,7 @@ export function checkExportsOnMergedDeclarations(c, node) {
|
|
|
780
780
|
let exported = 0 /* DeclarationSpaces.None */;
|
|
781
781
|
let nonExported = 0 /* DeclarationSpaces.None */;
|
|
782
782
|
let defaultExported = 0 /* DeclarationSpaces.None */;
|
|
783
|
-
for (const d of symbol
|
|
783
|
+
for (const d of getDeclarations(symbol)) {
|
|
784
784
|
const spaces = getDeclarationSpaces(c, d);
|
|
785
785
|
const flags = getEffectiveDeclarationFlags(d, 32 /* ModifierFlags.Export */ | 2048 /* ModifierFlags.Default */);
|
|
786
786
|
if ((flags & 32 /* ModifierFlags.Export */) !== 0) {
|
|
@@ -797,7 +797,7 @@ export function checkExportsOnMergedDeclarations(c, node) {
|
|
|
797
797
|
const commonForDefaultAndNonDefault = defaultExported & nonDefaultExported;
|
|
798
798
|
if (commonForExportsAndLocals === 0 && commonForDefaultAndNonDefault === 0)
|
|
799
799
|
return;
|
|
800
|
-
for (const d of symbol
|
|
800
|
+
for (const d of getDeclarations(symbol)) {
|
|
801
801
|
const spaces = getDeclarationSpaces(c, d);
|
|
802
802
|
const name = getNameOfDeclaration(d);
|
|
803
803
|
const text = declarationNameToString(getSourceFileOfNode(d), name);
|
|
@@ -847,7 +847,7 @@ function getAliasDeclarationSpaces(c, node) {
|
|
|
847
847
|
if (symbol === undefined)
|
|
848
848
|
return 0 /* DeclarationSpaces.None */;
|
|
849
849
|
let result = 0 /* DeclarationSpaces.None */;
|
|
850
|
-
for (const d of resolveAlias(c, symbol)
|
|
850
|
+
for (const d of getDeclarations(resolveAlias(c, symbol)))
|
|
851
851
|
result |= getDeclarationSpaces(c, d);
|
|
852
852
|
return result;
|
|
853
853
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
2
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
3
|
-
import { type Symbol } from './symbol.js';
|
|
4
3
|
import { SyntaxKind } from './syntax-kind.js';
|
|
5
4
|
import { type Checker } from './checker.js';
|
|
6
5
|
import { InterfaceType, type LiteralType, type Signature, type Type, TypeParameter } from './checker-types.js';
|
|
7
6
|
import { getFirstIdentifier, getMergedSymbol, getParentOfSymbol } from './checker-symbols.js';
|
|
7
|
+
import { type Symbol } from './symbol.js';
|
|
8
8
|
export { getParentOfSymbol };
|
|
9
9
|
export declare function getDeclaredTypeOfSymbol(c: Checker, symbol: Symbol): Type;
|
|
10
10
|
export declare function tryGetDeclaredTypeOfSymbol(c: Checker, symbol: Symbol): Type | undefined;
|
|
@@ -20,6 +20,7 @@ import { getIndexedAccessType, isGenericMappedType } from './checker-type-operat
|
|
|
20
20
|
import { getSignatureInstantiation } from './checker-signatures.js';
|
|
21
21
|
import { evaluateEnumMember } from './checker-evaluator.js';
|
|
22
22
|
import { checkTypeAssignableTo, isTypeIdenticalTo } from './relations.js';
|
|
23
|
+
import { getDeclarations } from './symbol.js';
|
|
23
24
|
export { getParentOfSymbol };
|
|
24
25
|
export function getDeclaredTypeOfSymbol(c, symbol) {
|
|
25
26
|
return tryGetDeclaredTypeOfSymbol(c, symbol) ?? c.errorType;
|
|
@@ -82,7 +83,7 @@ export function getDeclaredTypeOfClassOrInterface(c, symbol) {
|
|
|
82
83
|
return links.declaredType;
|
|
83
84
|
}
|
|
84
85
|
function isThislessInterface(c, symbol) {
|
|
85
|
-
for (const declaration of symbol
|
|
86
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
86
87
|
if (declaration.kind !== 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
87
88
|
continue;
|
|
88
89
|
if ((declaration.flags & 128 /* NodeFlags.ContainsThis */) !== 0)
|
|
@@ -127,7 +128,7 @@ export function getExtendsHeritageClauseElement(node) {
|
|
|
127
128
|
return elements.length !== 0 ? elements[0] : undefined;
|
|
128
129
|
}
|
|
129
130
|
export function getClassLikeDeclarationOfSymbol(symbol) {
|
|
130
|
-
for (const d of symbol
|
|
131
|
+
for (const d of getDeclarations(symbol))
|
|
131
132
|
if (d.kind === 264 /* SyntaxKind.ClassDeclaration */ || d.kind === 232 /* SyntaxKind.ClassExpression */)
|
|
132
133
|
return d;
|
|
133
134
|
return undefined;
|
|
@@ -136,7 +137,7 @@ function getOuterTypeParametersOfClassOrInterface(c, symbol) {
|
|
|
136
137
|
let declaration = symbol.valueDeclaration;
|
|
137
138
|
if ((symbol.flags & (32 /* SymbolFlags.Class */ | 16 /* SymbolFlags.Function */)) === 0) {
|
|
138
139
|
declaration = undefined;
|
|
139
|
-
for (const d of symbol
|
|
140
|
+
for (const d of getDeclarations(symbol)) {
|
|
140
141
|
if (d.kind === 265 /* SyntaxKind.InterfaceDeclaration */) {
|
|
141
142
|
declaration = d;
|
|
142
143
|
break;
|
|
@@ -227,7 +228,7 @@ export function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(c, symbol) {
|
|
|
227
228
|
return appendLocalTypeParameters(c, [], symbol);
|
|
228
229
|
}
|
|
229
230
|
function appendLocalTypeParameters(c, types, symbol) {
|
|
230
|
-
for (const node of symbol
|
|
231
|
+
for (const node of getDeclarations(symbol)) {
|
|
231
232
|
if (node.kind === 265 /* SyntaxKind.InterfaceDeclaration */ ||
|
|
232
233
|
node.kind === 264 /* SyntaxKind.ClassDeclaration */ ||
|
|
233
234
|
node.kind === 232 /* SyntaxKind.ClassExpression */ ||
|
|
@@ -259,7 +260,7 @@ export function getDeclaredTypeOfTypeAlias(c, symbol) {
|
|
|
259
260
|
if (!pushTypeResolution(c, symbol, 2 /* TypeSystemPropertyName.DeclaredType */))
|
|
260
261
|
return c.errorType;
|
|
261
262
|
let declaration;
|
|
262
|
-
for (const d of symbol
|
|
263
|
+
for (const d of getDeclarations(symbol))
|
|
263
264
|
if (d.kind === 266 /* SyntaxKind.TypeAliasDeclaration */ || d.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */) {
|
|
264
265
|
declaration = d;
|
|
265
266
|
break;
|
|
@@ -292,7 +293,7 @@ export function getDeclaredTypeOfEnum(c, symbol) {
|
|
|
292
293
|
if (links.declaredType !== undefined)
|
|
293
294
|
return links.declaredType;
|
|
294
295
|
const memberTypes = [];
|
|
295
|
-
for (const declaration of symbol
|
|
296
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
296
297
|
if (declaration.kind !== 267 /* SyntaxKind.EnumDeclaration */)
|
|
297
298
|
continue;
|
|
298
299
|
for (const member of declaration.members.nodes) {
|
|
@@ -454,7 +455,7 @@ export function getBaseTypes(c, t) {
|
|
|
454
455
|
resolveBaseTypesOfInterface(c, t);
|
|
455
456
|
}
|
|
456
457
|
if (!popTypeResolution(c))
|
|
457
|
-
for (const declaration of t.symbol
|
|
458
|
+
for (const declaration of getDeclarations(t.symbol))
|
|
458
459
|
if (declaration.kind === 264 /* SyntaxKind.ClassDeclaration */ || declaration.kind === 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
459
460
|
reportCircularBaseType(c, declaration, t);
|
|
460
461
|
// Circular defaults may leave members partially resolved; reset them.
|
|
@@ -528,7 +529,7 @@ function isInJS(node) {
|
|
|
528
529
|
return (node.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0;
|
|
529
530
|
}
|
|
530
531
|
function resolveBaseTypesOfInterface(c, t) {
|
|
531
|
-
for (const declaration of t.symbol
|
|
532
|
+
for (const declaration of getDeclarations(t.symbol)) {
|
|
532
533
|
if (declaration.kind !== 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
533
534
|
continue;
|
|
534
535
|
for (const node of getExtendsHeritageClauseElements(declaration)) {
|
|
@@ -666,7 +667,7 @@ export function hasNonCircularBaseConstraint(c, t) {
|
|
|
666
667
|
}
|
|
667
668
|
export function getConstraintDeclaration(t) {
|
|
668
669
|
if (t.symbol !== undefined)
|
|
669
|
-
for (const d of t.symbol
|
|
670
|
+
for (const d of getDeclarations(t.symbol))
|
|
670
671
|
if (d.kind === 169 /* SyntaxKind.TypeParameter */) {
|
|
671
672
|
const constraint = d.constraint;
|
|
672
673
|
if (constraint !== undefined)
|
|
@@ -723,7 +724,7 @@ export function getResolvedTypeParameterDefault(c, t) {
|
|
|
723
724
|
side.resolvedDefaultType = c.resolvingDefaultType;
|
|
724
725
|
let defaultType = c.noConstraintType;
|
|
725
726
|
if (t.symbol !== undefined)
|
|
726
|
-
for (const d of t.symbol
|
|
727
|
+
for (const d of getDeclarations(t.symbol))
|
|
727
728
|
if (d.kind === 169 /* SyntaxKind.TypeParameter */) {
|
|
728
729
|
const node = d.defaultType;
|
|
729
730
|
if (node !== undefined) {
|
|
@@ -753,7 +754,7 @@ export function getMinTypeArgumentCount(c, typeParameters) {
|
|
|
753
754
|
function hasTypeParameterDefault(t) {
|
|
754
755
|
if (t.symbol === undefined)
|
|
755
756
|
return false;
|
|
756
|
-
for (const d of t.symbol
|
|
757
|
+
for (const d of getDeclarations(t.symbol))
|
|
757
758
|
if (d.kind === 169 /* SyntaxKind.TypeParameter */ && d.defaultType !== undefined)
|
|
758
759
|
return true;
|
|
759
760
|
return false;
|
|
@@ -5,7 +5,6 @@ import { checkDeprecatedSignature } from './checker-deprecation.js';
|
|
|
5
5
|
import { FunctionTypeNode, KeywordTypeNode, NodeList, getBody, getDotDotDotToken, getModifiers, getName, getParameters, getText, getType, getInitializer, getMembers, } from './ast.js';
|
|
6
6
|
import { canHaveDecorators } from './ast-utilities.js';
|
|
7
7
|
import { getDeclarationOfKind, getSourceFileOfNode, getSourceTextOfNode, hasStaticModifier, hasSyntacticModifier, isClassLike, isStatic, isPrivateIdentifierClassElementDeclaration, isAutoAccessorPropertyDeclaration, } from './binder-utilities.js';
|
|
8
|
-
import { getSymbolId } from './symbol.js';
|
|
9
8
|
import { createDiagnosticForNode } from './checker.js';
|
|
10
9
|
import { ModuleKind, getEmitModuleKind, ScriptTarget, getUseDefineForClassFields } from './options.js';
|
|
11
10
|
import { getFirstConstructorWithBody, getRestParameterElementType, classElementOrClassElementParameterIsDecorated, classOrConstructorParameterIsDecorated, } from './transformers/decorator-utilities.js';
|
|
@@ -20,6 +19,7 @@ import { getOrCreateTypeFromSignature, getParameterCount, getReturnTypeOfSignatu
|
|
|
20
19
|
import { checkTypeAssignableTo } from './relations.js';
|
|
21
20
|
import { getResolvedSignature } from './checker-calls.js';
|
|
22
21
|
import { getGlobalClassAccessorDecoratorContextType, getGlobalClassAccessorDecoratorResultType, getGlobalClassAccessorDecoratorTargetType, getGlobalClassDecoratorContextType, getGlobalClassFieldDecoratorContextType, getGlobalClassGetterDecoratorContextType, getGlobalClassMethodDecoratorContextType, getGlobalClassSetterDecoratorContextType, getGlobalTypedPropertyDescriptorType, } from './checker-globals.js';
|
|
22
|
+
import { getDeclarations, getSymbolId } from './symbol.js';
|
|
23
23
|
// ---- Checks
|
|
24
24
|
/** Resolves the decorators of `node` as calls and checks their return types. */
|
|
25
25
|
export function checkDecorators(c, node) {
|
|
@@ -160,10 +160,10 @@ function checkMetadataTypeImport(c, typeNode) {
|
|
|
160
160
|
const rootSymbol = resolveName(c, rootName, getText(rootName), meaning, undefined, true, false);
|
|
161
161
|
if (rootSymbol === undefined || (rootSymbol.flags & 2097152 /* SymbolFlags.Alias */) === 0 || symbolIsValue(c, rootSymbol))
|
|
162
162
|
return;
|
|
163
|
-
if (rootSymbol.
|
|
163
|
+
if (getDeclarations(rootSymbol).some(isTypeOnlyImportOrExportDeclaration))
|
|
164
164
|
return;
|
|
165
165
|
const diagnostic = c.error(typeName, 221 /* Diagnostics.A_type_referenced_in_a_decorated_signature_must_be_imported_with_import_type_or_a_namespace_import_when_isolatedModules_and_emitDecoratorMetadata_are_enabled */);
|
|
166
|
-
const aliasDeclaration = rootSymbol.
|
|
166
|
+
const aliasDeclaration = getDeclarations(rootSymbol).find(isAliasSymbolDeclaration);
|
|
167
167
|
if (aliasDeclaration !== undefined)
|
|
168
168
|
diagnostic.addRelatedInfo(createDiagnosticForNode(aliasDeclaration, 305 /* Diagnostics.X_0_was_imported_here */, [getText(rootName)]));
|
|
169
169
|
}
|
|
@@ -12,6 +12,7 @@ import { entityNameToString } from './checker-expressions.js';
|
|
|
12
12
|
import { isErrorType } from './checker-type-factory.js';
|
|
13
13
|
import { getPropertyOfType } from './checker-members.js';
|
|
14
14
|
import { signatureToString } from './type-printer.js';
|
|
15
|
+
import { declarationCount, getDeclarations } from './symbol.js';
|
|
15
16
|
/** Whether `declaration`, or the statement it belongs to, has a `@deprecated` JSDoc tag. */
|
|
16
17
|
export function isDeprecatedDeclaration(declaration) {
|
|
17
18
|
if ((getCombinedNodeFlags(declaration) & 67108864 /* NodeFlags.PossiblyContainsDeprecatedTag */) === 0)
|
|
@@ -37,7 +38,7 @@ function getJSDocDeprecatedTag(node) {
|
|
|
37
38
|
* members when all are.
|
|
38
39
|
*/
|
|
39
40
|
export function isDeprecatedSymbol(c, symbol) {
|
|
40
|
-
const declarations = symbol
|
|
41
|
+
const declarations = getDeclarations(symbol);
|
|
41
42
|
const parentSymbol = getParentOfSymbol(c, symbol);
|
|
42
43
|
if (parentSymbol !== undefined && declarations.length > 1)
|
|
43
44
|
return (parentSymbol.flags & 64 /* SymbolFlags.Interface */) !== 0
|
|
@@ -177,7 +178,7 @@ function isUncalledFunctionReference(c, node, symbol) {
|
|
|
177
178
|
return ((parent.kind === 214 /* SyntaxKind.CallExpression */ || parent.kind === 215 /* SyntaxKind.NewExpression */) &&
|
|
178
179
|
node.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
179
180
|
hasMatchingArgument(c, parent, node));
|
|
180
|
-
for (const d of symbol
|
|
181
|
+
for (const d of getDeclarations(symbol))
|
|
181
182
|
if (isFunctionLikeKind(d.kind) && !isDeprecatedDeclaration(d))
|
|
182
183
|
return false;
|
|
183
184
|
return true;
|
|
@@ -231,9 +232,9 @@ export function resolveAliasWithDeprecationCheck(c, symbol, location) {
|
|
|
231
232
|
const target = getImmediateAliasedSymbol(c, current);
|
|
232
233
|
if (target === undefined || target === targetSymbol)
|
|
233
234
|
break;
|
|
234
|
-
if (target
|
|
235
|
+
if (declarationCount(target) !== 0) {
|
|
235
236
|
if (isDeprecatedSymbol(c, target)) {
|
|
236
|
-
addDeprecatedSuggestion(c, location, target
|
|
237
|
+
addDeprecatedSuggestion(c, location, getDeclarations(target), target.name);
|
|
237
238
|
break;
|
|
238
239
|
}
|
|
239
240
|
if (current === targetSymbol)
|
|
@@ -253,18 +254,18 @@ function getImmediateAliasedSymbol(c, symbol) {
|
|
|
253
254
|
/** Resolves the alias an identifier refers to and reports a deprecated target. */
|
|
254
255
|
export function checkDeprecatedIdentifier(c, node, localOrExportSymbol) {
|
|
255
256
|
const targetSymbol = resolveAliasWithDeprecationCheck(c, localOrExportSymbol, node);
|
|
256
|
-
if (targetSymbol
|
|
257
|
+
if (declarationCount(targetSymbol) !== 0 &&
|
|
257
258
|
isDeprecatedSymbol(c, targetSymbol) &&
|
|
258
259
|
isUncalledFunctionReference(c, node, targetSymbol))
|
|
259
|
-
addDeprecatedSuggestion(c, node, targetSymbol
|
|
260
|
+
addDeprecatedSuggestion(c, node, getDeclarations(targetSymbol), getText(node));
|
|
260
261
|
}
|
|
261
262
|
/** Reports a property access to a deprecated property. */
|
|
262
263
|
export function checkDeprecatedProperty(c, node, right, prop) {
|
|
263
264
|
const targetPropSymbol = resolveAliasWithDeprecationCheck(c, prop, right);
|
|
264
265
|
if (isDeprecatedSymbol(c, targetPropSymbol) &&
|
|
265
266
|
isUncalledFunctionReference(c, node, targetPropSymbol) &&
|
|
266
|
-
targetPropSymbol
|
|
267
|
-
addDeprecatedSuggestion(c, right, targetPropSymbol
|
|
267
|
+
declarationCount(targetPropSymbol) !== 0)
|
|
268
|
+
addDeprecatedSuggestion(c, right, getDeclarations(targetPropSymbol), getText(right));
|
|
268
269
|
}
|
|
269
270
|
/** Reports a property access resolved through a deprecated index signature. */
|
|
270
271
|
export function checkDeprecatedIndexSignature(c, right, declaration) {
|
|
@@ -273,16 +274,14 @@ export function checkDeprecatedIndexSignature(c, right, declaration) {
|
|
|
273
274
|
}
|
|
274
275
|
/** Reports an element access or indexed access type selecting a deprecated property. */
|
|
275
276
|
export function checkDeprecatedIndexedAccess(c, accessNode, prop, propName) {
|
|
276
|
-
if (prop
|
|
277
|
-
!isDeprecatedSymbol(c, prop) ||
|
|
278
|
-
!isUncalledFunctionReference(c, accessNode, prop))
|
|
277
|
+
if (declarationCount(prop) === 0 || !isDeprecatedSymbol(c, prop) || !isUncalledFunctionReference(c, accessNode, prop))
|
|
279
278
|
return;
|
|
280
279
|
const deprecatedNode = accessNode.kind === 213 /* SyntaxKind.ElementAccessExpression */
|
|
281
280
|
? accessNode.argumentExpression
|
|
282
281
|
: accessNode.kind === 200 /* SyntaxKind.IndexedAccessType */
|
|
283
282
|
? accessNode.indexType
|
|
284
283
|
: accessNode;
|
|
285
|
-
addDeprecatedSuggestion(c, deprecatedNode, prop
|
|
284
|
+
addDeprecatedSuggestion(c, deprecatedNode, getDeclarations(prop), propName);
|
|
286
285
|
}
|
|
287
286
|
/** Reports a type reference or import type naming a deprecated type. */
|
|
288
287
|
export function checkDeprecatedTypeReference(c, node, type) {
|
|
@@ -291,9 +290,9 @@ export function checkDeprecatedTypeReference(c, node, type) {
|
|
|
291
290
|
const symbol = c.resolvedSymbols.get(node.id);
|
|
292
291
|
if (symbol === undefined)
|
|
293
292
|
return;
|
|
294
|
-
for (const d of symbol
|
|
293
|
+
for (const d of getDeclarations(symbol)) {
|
|
295
294
|
if (isTypeDeclaration(d) && isDeprecatedDeclaration(d)) {
|
|
296
|
-
addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), symbol
|
|
295
|
+
addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), getDeclarations(symbol), symbol.name);
|
|
297
296
|
return;
|
|
298
297
|
}
|
|
299
298
|
}
|
|
@@ -301,8 +300,8 @@ export function checkDeprecatedTypeReference(c, node, type) {
|
|
|
301
300
|
/** Reports an import specifier importing a deprecated declaration. */
|
|
302
301
|
export function checkDeprecatedImportSpecifier(c, node, symbol) {
|
|
303
302
|
const targetSymbol = resolveAliasWithDeprecationCheck(c, symbol, node);
|
|
304
|
-
if (isDeprecatedSymbol(c, targetSymbol) && targetSymbol
|
|
305
|
-
addDeprecatedSuggestion(c, node, targetSymbol
|
|
303
|
+
if (isDeprecatedSymbol(c, targetSymbol) && declarationCount(targetSymbol) !== 0)
|
|
304
|
+
addDeprecatedSuggestion(c, node, getDeclarations(targetSymbol), targetSymbol.name);
|
|
306
305
|
}
|
|
307
306
|
/** Reports a JSX attribute setting a deprecated property of the element's contextual props type. */
|
|
308
307
|
export function checkDeprecatedJsxAttribute(c, contextualType, attribute) {
|
|
@@ -310,6 +309,6 @@ export function checkDeprecatedJsxAttribute(c, contextualType, attribute) {
|
|
|
310
309
|
if (name.kind !== 79 /* SyntaxKind.Identifier */)
|
|
311
310
|
return;
|
|
312
311
|
const prop = getPropertyOfType(c, contextualType, getText(name));
|
|
313
|
-
if (prop !== undefined && prop
|
|
314
|
-
addDeprecatedSuggestion(c, name, prop
|
|
312
|
+
if (prop !== undefined && declarationCount(prop) !== 0 && isDeprecatedSymbol(c, prop))
|
|
313
|
+
addDeprecatedSuggestion(c, name, getDeclarations(prop), getText(name));
|
|
315
314
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BindingElement, type Node } from './ast.js';
|
|
2
|
-
import { type Symbol } from './symbol.js';
|
|
3
2
|
import type { Checker } from './checker.js';
|
|
4
3
|
import { CheckMode, type Type } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
/** The type of a binding element, from the type of the declaration it destructures. */
|
|
6
6
|
export declare function getTypeForBindingElement(c: Checker, declaration: Node): Type | undefined;
|
|
7
7
|
export declare function getTypeForBindingElementParent(c: Checker, node: Node, checkMode: CheckMode): Type | undefined;
|
|
@@ -6,7 +6,6 @@ import { getElements, getInitializer, getName, getProperties, getSymbol, getType
|
|
|
6
6
|
import { isLeftHandSideExpression } from './ast-utilities.js';
|
|
7
7
|
import { getFlowTypeOfReference, getDestructuringPropertyName, getTypeOfInitializer } from './checker-narrowing.js';
|
|
8
8
|
import { getRootDeclaration, isClassLike, isPartOfParameterDeclaration, isPrivateIdentifierClassElementDeclaration, } from './binder-utilities.js';
|
|
9
|
-
import { getSymbolId } from './symbol.js';
|
|
10
9
|
import { TupleElementInfo, } from './checker-types.js';
|
|
11
10
|
import { cloneTypeReference, createAnonymousType, createArrayType, createTupleTypeEx, getElementTypes, getTypeReferenceArity, tupleTargetOf, everyType, filterType, getNumberLiteralType, getUnionType, getUnionTypeEx, isTupleType, mapType, newIndexInfo, someType, typesOf, } from './checker-type-factory.js';
|
|
12
11
|
import { getIndexedAccessTypeEx, getIndexedAccessTypeOrUndefinedEx, getLiteralTypeFromProperty, getLiteralTypeFromPropertyName, isGenericIndexType, isGenericObjectType, } from './checker-type-operators.js';
|
|
@@ -23,6 +22,7 @@ import { getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-fl
|
|
|
23
22
|
import { sliceTupleType } from './checker-signatures.js';
|
|
24
23
|
import { getPropertyNameFromType, isTypeUsableAsPropertyName, maybeTypeOfKind } from './checker-utilities.js';
|
|
25
24
|
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
25
|
+
import { copyDeclarations, getDeclarations, getSymbolId } from './symbol.js';
|
|
26
26
|
function isBindingPatternNode(node) {
|
|
27
27
|
return (node !== undefined &&
|
|
28
28
|
(node.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || node.kind === 208 /* SyntaxKind.ArrayBindingPattern */));
|
|
@@ -548,7 +548,7 @@ export function isSpreadableProperty(prop) {
|
|
|
548
548
|
const notMethodOrAccessor = (prop.flags & (8192 /* SymbolFlags.Method */ | 32768 /* SymbolFlags.GetAccessor */ | 65536 /* SymbolFlags.SetAccessor */)) === 0;
|
|
549
549
|
let hasPrivateName = false;
|
|
550
550
|
let inClass = false;
|
|
551
|
-
for (const d of prop
|
|
551
|
+
for (const d of getDeclarations(prop)) {
|
|
552
552
|
if (isPrivateIdentifierClassElementDeclaration(d))
|
|
553
553
|
hasPrivateName = true;
|
|
554
554
|
if (d.parent !== undefined && isClassLike(d.parent))
|
|
@@ -564,7 +564,7 @@ export function getSpreadSymbol(c, prop, readonly) {
|
|
|
564
564
|
const result = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */ | (prop.flags & 16777216 /* SymbolFlags.Optional */), prop.name, (prop.checkFlags & 4096 /* CheckFlags.Late */) | (readonly ? 8 /* CheckFlags.Readonly */ : 0));
|
|
565
565
|
const id = getSymbolId(result);
|
|
566
566
|
c.symbolTypes.set(id, isSetonlyAccessor ? c.undefinedType : getTypeOfSymbol(c, prop));
|
|
567
|
-
result
|
|
567
|
+
copyDeclarations(result, prop);
|
|
568
568
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
569
569
|
c.symbolSyntheticOrigins.set(id, prop);
|
|
570
570
|
return result;
|