tsc-ts 0.0.6 → 0.0.8
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 +57 -18
- package/dist/api/compiler/ast.js +134 -39
- package/dist/api/compiler/binder-utilities.js +2 -2
- package/dist/api/compiler/binder.js +6 -6
- package/dist/api/compiler/checker-calls.js +4 -4
- package/dist/api/compiler/checker-contextual.js +1 -1
- package/dist/api/compiler/checker-declaration-order.js +3 -2
- package/dist/api/compiler/checker-declared-types.js +6 -3
- package/dist/api/compiler/checker-deprecation.js +14 -13
- package/dist/api/compiler/checker-destructuring.js +3 -2
- 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-grammar.js +5 -5
- package/dist/api/compiler/checker-inference.d.ts +20 -10
- package/dist/api/compiler/checker-inference.js +48 -25
- package/dist/api/compiler/checker-members.d.ts +27 -0
- package/dist/api/compiler/checker-members.js +165 -0
- package/dist/api/compiler/checker-modules.d.ts +14 -0
- package/dist/api/compiler/checker-modules.js +73 -1
- package/dist/api/compiler/checker-symbol-types.js +5 -5
- package/dist/api/compiler/checker-symbols.js +3 -1
- package/dist/api/compiler/checker.d.ts +16 -0
- package/dist/api/compiler/checker.js +17 -0
- package/dist/api/compiler/diagnostics.js +9 -5
- package/dist/api/compiler/parallel-parse.js +3 -1
- package/dist/api/compiler/parser.d.ts +7 -0
- package/dist/api/compiler/parser.js +73 -41
- 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 +11 -1
- package/dist/api/compiler/relations.js +8 -3
- package/dist/api/compiler/reparser.js +13 -5
- 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-pseudo.js +2 -2
- package/dist/api/compiler/transformers/module.js +2 -2
- package/dist/api/compiler/transformers/optional-chain.js +3 -3
- package/dist/api/compiler/transformers/subtree-facts.js +2 -2
- 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/visitor-base.js +3 -3
- package/dist/api/compiler/tsconfig.js +2 -2
- package/package.json +9 -9
- package/src/compiler/ast.ts +184 -59
- package/src/compiler/binder-utilities.ts +2 -1
- package/src/compiler/binder.ts +11 -5
- package/src/compiler/checker-calls.ts +5 -3
- package/src/compiler/checker-contextual.ts +1 -1
- package/src/compiler/checker-declaration-order.ts +3 -2
- package/src/compiler/checker-declared-types.ts +6 -3
- package/src/compiler/checker-deprecation.ts +13 -11
- package/src/compiler/checker-destructuring.ts +11 -2
- package/src/compiler/checker-emit-helpers.ts +5 -4
- package/src/compiler/checker-grammar.ts +5 -3
- package/src/compiler/checker-inference.ts +49 -25
- package/src/compiler/checker-members.ts +164 -0
- package/src/compiler/checker-modules.ts +92 -1
- package/src/compiler/checker-symbol-types.ts +14 -4
- package/src/compiler/checker-symbols.ts +4 -1
- package/src/compiler/checker.ts +19 -0
- package/src/compiler/decoder.ts +5 -4
- package/src/compiler/diagnostics.ts +10 -5
- package/src/compiler/encoder.ts +10 -5
- package/src/compiler/parallel-parse.ts +3 -1
- package/src/compiler/parser.ts +93 -39
- 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 +10 -1
- package/src/compiler/relations.ts +10 -2
- package/src/compiler/reparser.ts +14 -4
- package/src/compiler/transformers/class-fields.ts +12 -2
- package/src/compiler/transformers/commonjs-module.ts +3 -2
- package/src/compiler/transformers/declarations-pseudo.ts +2 -1
- package/src/compiler/transformers/declarations.ts +1 -1
- package/src/compiler/transformers/module.ts +2 -1
- package/src/compiler/transformers/optional-chain.ts +5 -2
- package/src/compiler/transformers/subtree-facts.ts +2 -1
- package/src/compiler/transformers/tagged-template.ts +2 -2
- package/src/compiler/transformers/type-eraser.ts +2 -1
- package/src/compiler/transformers/visitor-base.ts +10 -5
- package/src/compiler/tsconfig.ts +2 -1
|
@@ -12,7 +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
|
+
import { declarationAt, declarationCount, getDeclarations } from './symbol.js';
|
|
16
16
|
/** Whether `declaration`, or the statement it belongs to, has a `@deprecated` JSDoc tag. */
|
|
17
17
|
export function isDeprecatedDeclaration(declaration) {
|
|
18
18
|
if ((getCombinedNodeFlags(declaration) & 67108864 /* NodeFlags.PossiblyContainsDeprecatedTag */) === 0)
|
|
@@ -38,24 +38,24 @@ function getJSDocDeprecatedTag(node) {
|
|
|
38
38
|
* members when all are.
|
|
39
39
|
*/
|
|
40
40
|
export function isDeprecatedSymbol(c, symbol) {
|
|
41
|
-
const
|
|
41
|
+
const count = declarationCount(symbol);
|
|
42
42
|
const parentSymbol = getParentOfSymbol(c, symbol);
|
|
43
|
-
if (parentSymbol !== undefined &&
|
|
43
|
+
if (parentSymbol !== undefined && count > 1)
|
|
44
44
|
return (parentSymbol.flags & 64 /* SymbolFlags.Interface */) !== 0
|
|
45
|
-
? someDeprecatedDeclaration(
|
|
46
|
-
: everyDeprecatedDeclaration(
|
|
45
|
+
? someDeprecatedDeclaration(symbol)
|
|
46
|
+
: everyDeprecatedDeclaration(symbol);
|
|
47
47
|
return ((symbol.valueDeclaration !== undefined && isDeprecatedDeclaration(symbol.valueDeclaration)) ||
|
|
48
|
-
(
|
|
48
|
+
(count !== 0 && everyDeprecatedDeclaration(symbol)));
|
|
49
49
|
}
|
|
50
|
-
function someDeprecatedDeclaration(
|
|
51
|
-
for (
|
|
52
|
-
if (isDeprecatedDeclaration(
|
|
50
|
+
function someDeprecatedDeclaration(symbol) {
|
|
51
|
+
for (let i = 0; i < declarationCount(symbol); i++)
|
|
52
|
+
if (isDeprecatedDeclaration(declarationAt(symbol, i)))
|
|
53
53
|
return true;
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
-
function everyDeprecatedDeclaration(
|
|
57
|
-
for (
|
|
58
|
-
if (!isDeprecatedDeclaration(
|
|
56
|
+
function everyDeprecatedDeclaration(symbol) {
|
|
57
|
+
for (let i = 0; i < declarationCount(symbol); i++)
|
|
58
|
+
if (!isDeprecatedDeclaration(declarationAt(symbol, i)))
|
|
59
59
|
return false;
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
@@ -290,7 +290,8 @@ export function checkDeprecatedTypeReference(c, node, type) {
|
|
|
290
290
|
const symbol = c.resolvedSymbols.get(node.id);
|
|
291
291
|
if (symbol === undefined)
|
|
292
292
|
return;
|
|
293
|
-
for (
|
|
293
|
+
for (let i = 0; i < declarationCount(symbol); i++) {
|
|
294
|
+
const d = declarationAt(symbol, i);
|
|
294
295
|
if (isTypeDeclaration(d) && isDeprecatedDeclaration(d)) {
|
|
295
296
|
addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), getDeclarations(symbol), symbol.name);
|
|
296
297
|
return;
|
|
@@ -22,7 +22,7 @@ import { getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-fl
|
|
|
22
22
|
import { sliceTupleType } from './checker-signatures.js';
|
|
23
23
|
import { getPropertyNameFromType, isTypeUsableAsPropertyName, maybeTypeOfKind } from './checker-utilities.js';
|
|
24
24
|
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
25
|
-
import { copyDeclarations,
|
|
25
|
+
import { copyDeclarations, declarationAt, declarationCount, 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,8 @@ 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 (
|
|
551
|
+
for (let i = 0; i < declarationCount(prop); i++) {
|
|
552
|
+
const d = declarationAt(prop, i);
|
|
552
553
|
if (isPrivateIdentifierClassElementDeclaration(d))
|
|
553
554
|
hasPrivateName = true;
|
|
554
555
|
if (d.parent !== undefined && isClassLike(d.parent))
|
|
@@ -45,7 +45,8 @@ declare class PendingHelperCheck {
|
|
|
45
45
|
export declare class EmitHelperFileLinks {
|
|
46
46
|
helpersModule: Symbol | undefined;
|
|
47
47
|
requestedHelpers: number;
|
|
48
|
-
|
|
48
|
+
/** Created on the first check; most files have none. */
|
|
49
|
+
pending: PendingHelperCheck[] | undefined;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Under --importHelpers, the emit of the syntax at `location` calls `helpers` from tslib. Reports TS2354 when
|
|
@@ -16,7 +16,8 @@ class PendingHelperCheck {
|
|
|
16
16
|
export class EmitHelperFileLinks {
|
|
17
17
|
helpersModule = undefined;
|
|
18
18
|
requestedHelpers = 0 /* ExternalEmitHelpers.None */;
|
|
19
|
-
|
|
19
|
+
/** Created on the first check; most files have none. */
|
|
20
|
+
pending = undefined;
|
|
20
21
|
}
|
|
21
22
|
function fileLinks(c, file) {
|
|
22
23
|
let links = c.emitHelperFileLinks.get(file);
|
|
@@ -45,7 +46,7 @@ export function checkExternalEmitHelpers(c, location, helpers) {
|
|
|
45
46
|
const fileIndex = c.fileIndex.get(file);
|
|
46
47
|
const checkingIndex = c.fileIndex.get(checking);
|
|
47
48
|
if (fileIndex !== undefined && checkingIndex !== undefined && fileIndex < checkingIndex) {
|
|
48
|
-
fileLinks(c, file).pending.push(new PendingHelperCheck(location, helpers));
|
|
49
|
+
(fileLinks(c, file).pending ??= []).push(new PendingHelperCheck(location, helpers));
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -78,10 +79,10 @@ export function checkExternalEmitHelpers(c, location, helpers) {
|
|
|
78
79
|
/** Runs the helper checks for nodes of `file` that were reached while checking later files. */
|
|
79
80
|
export function checkPendingExternalEmitHelpers(c, file) {
|
|
80
81
|
const links = c.emitHelperFileLinks.get(file);
|
|
81
|
-
if (links === undefined
|
|
82
|
+
if (links?.pending === undefined)
|
|
82
83
|
return;
|
|
83
84
|
const pending = links.pending;
|
|
84
|
-
links.pending =
|
|
85
|
+
links.pending = undefined;
|
|
85
86
|
for (const check of pending)
|
|
86
87
|
checkExternalEmitHelpers(c, check.location, check.helpers);
|
|
87
88
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// `checkGrammarSourceFile` walks a file once after it is type checked and runs the grammar checks
|
|
4
4
|
// of each node in the order tsgo's checker runs them. Checks that need types read the checker's
|
|
5
5
|
// caches. Errors reported with `grammarError*` are dropped when the file has parse errors.
|
|
6
|
-
import { ElementAccessExpression, Identifier, NodeVisitor, StringLiteral, getAsteriskToken, getBody, getElements, getExpression, getHeritageClauses, getInitializer, getLabel, getIsTypeOnly, getLocals, getMembers, getModifiers, getName, getNodeId, getParameters, getPostfixToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, isDeclarationNode, } from './ast.js';
|
|
6
|
+
import { ElementAccessExpression, Identifier, NodeVisitor, StringLiteral, getAsteriskToken, getBody, getElements, getExpression, getHeritageClauses, getInitializer, getLabel, getIsTypeOnly, getLocals, getMembers, getModifiers, getName, getNodeId, getParameters, getPostfixToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, isDeclarationNode, callQuestionDotToken, callTypeArguments, } from './ast.js';
|
|
7
7
|
import { canHaveDecorators, canHaveIllegalDecorators, getExternalModuleName, getTextOfNodeFromSourceText, isAmbientModule, isFunctionLike, isFunctionLikeDeclarationKind, isModifierKind, isStringLiteralLike, modifierToFlag, nodeIsPresent, isInJSFile, } from './ast-utilities.js';
|
|
8
8
|
import { getCombinedModifierFlags, getCombinedNodeFlags, getContainingClass, getRangeOfTokenAtPosition, getSourceFileOfNode, hasSyntacticModifier, isAutoAccessorPropertyDeclaration, isClassLike, isDynamicName, isEntityNameExpression, isExternalModule, isInTopLevelContext, isModuleAugmentationExternal, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, } from './binder-utilities.js';
|
|
9
9
|
import { findUseStrictPrologue } from './binder.js';
|
|
@@ -858,8 +858,8 @@ function checkGrammarDecorator(g, decorator) {
|
|
|
858
858
|
if (!canHaveCallExpression)
|
|
859
859
|
errorNode = node;
|
|
860
860
|
// A `?.` token comes first, so it wins over an earlier error node.
|
|
861
|
-
if (call
|
|
862
|
-
errorNode = call
|
|
861
|
+
if (callQuestionDotToken(call) !== undefined)
|
|
862
|
+
errorNode = callQuestionDotToken(call);
|
|
863
863
|
node = call.expression;
|
|
864
864
|
canHaveCallExpression = false;
|
|
865
865
|
continue;
|
|
@@ -2380,7 +2380,7 @@ function checkGrammarCallExpression(g, node) {
|
|
|
2380
2380
|
if (isImportCall)
|
|
2381
2381
|
checkGrammarImportCallExpression(g, node);
|
|
2382
2382
|
else
|
|
2383
|
-
checkGrammarTypeArguments(g, node
|
|
2383
|
+
checkGrammarTypeArguments(g, callTypeArguments(node));
|
|
2384
2384
|
}
|
|
2385
2385
|
function checkGrammarImportCallExpression(g, node) {
|
|
2386
2386
|
const moduleKind = g.moduleKind;
|
|
@@ -2394,7 +2394,7 @@ function checkGrammarImportCallExpression(g, node) {
|
|
|
2394
2394
|
}
|
|
2395
2395
|
else if (moduleKind === ModuleKind.ES2015)
|
|
2396
2396
|
return grammarErrorOnNode(g, node, 259 /* Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node16_node18_node20_or_nodenext */);
|
|
2397
|
-
if (node
|
|
2397
|
+
if (callTypeArguments(node) !== undefined)
|
|
2398
2398
|
return grammarErrorOnNode(g, node, 262 /* Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments */);
|
|
2399
2399
|
const args = node.arguments;
|
|
2400
2400
|
const argumentNodes = args.nodes;
|
|
@@ -56,28 +56,38 @@ export declare class IntraExpressionInferenceSite {
|
|
|
56
56
|
readonly type: Type;
|
|
57
57
|
constructor(node: Node, type: Type);
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The inferences for a set of type parameters. The context is its own fixing mapper (`mapper`), and
|
|
61
|
+
* each read of `nonFixingMapper` returns a new mapper that reads the context: no mapper the context
|
|
62
|
+
* holds refers back to it, so a context whose inference is done is freed by reference counting
|
|
63
|
+
* rather than by the cycle collector.
|
|
64
|
+
*/
|
|
65
|
+
export declare class InferenceContext extends TypeMapper {
|
|
66
|
+
readonly c: Checker;
|
|
60
67
|
inferences: InferenceInfo[];
|
|
61
68
|
/** The generic signature inferences are made for, if any. */
|
|
62
69
|
readonly signature: Signature | undefined;
|
|
63
70
|
flags: InferenceFlags;
|
|
64
71
|
readonly compareTypes: TypeComparer;
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
nonFixingMapper: TypeMapper;
|
|
72
|
+
/** Combined after the non-fixing mapper (conditional types' `infer` constraints), if any. */
|
|
73
|
+
nonFixingOuter: TypeMapper | undefined;
|
|
68
74
|
/** Maps to inferences from the return type, if any. */
|
|
69
75
|
returnMapper: TypeMapper | undefined;
|
|
70
76
|
outerReturnMapper: TypeMapper | undefined;
|
|
71
77
|
inferredTypeParameters: Type[] | undefined;
|
|
72
|
-
|
|
78
|
+
/** Created on the first site; most contexts get none. */
|
|
79
|
+
intraExpressionInferenceSites: IntraExpressionInferenceSite[] | undefined;
|
|
73
80
|
constructor(c: Checker, inferences: InferenceInfo[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer);
|
|
81
|
+
/** Fixes inferences. */
|
|
82
|
+
get mapper(): TypeMapper;
|
|
83
|
+
/** Maps to the current inferences without fixing them. */
|
|
84
|
+
get nonFixingMapper(): TypeMapper;
|
|
85
|
+
map(type: Type): Type;
|
|
74
86
|
}
|
|
75
|
-
/** Maps a context's type parameters to their inferred types
|
|
76
|
-
export declare class
|
|
77
|
-
readonly c: Checker;
|
|
87
|
+
/** Maps a context's type parameters to their inferred types without fixing them. */
|
|
88
|
+
export declare class NonFixingInferenceMapper extends TypeMapper {
|
|
78
89
|
readonly context: InferenceContext;
|
|
79
|
-
|
|
80
|
-
constructor(c: Checker, context: InferenceContext, fixing: boolean);
|
|
90
|
+
constructor(context: InferenceContext);
|
|
81
91
|
map(type: Type): Type;
|
|
82
92
|
}
|
|
83
93
|
export declare function createInferenceContext(c: Checker, typeParameters: readonly Type[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer | undefined): InferenceContext;
|
|
@@ -61,57 +61,78 @@ export class IntraExpressionInferenceSite {
|
|
|
61
61
|
this.type = type;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The inferences for a set of type parameters. The context is its own fixing mapper (`mapper`), and
|
|
66
|
+
* each read of `nonFixingMapper` returns a new mapper that reads the context: no mapper the context
|
|
67
|
+
* holds refers back to it, so a context whose inference is done is freed by reference counting
|
|
68
|
+
* rather than by the cycle collector.
|
|
69
|
+
*/
|
|
70
|
+
export class InferenceContext extends TypeMapper {
|
|
71
|
+
c;
|
|
65
72
|
inferences;
|
|
66
73
|
/** The generic signature inferences are made for, if any. */
|
|
67
74
|
signature;
|
|
68
75
|
flags;
|
|
69
76
|
compareTypes;
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
nonFixingMapper;
|
|
77
|
+
/** Combined after the non-fixing mapper (conditional types' `infer` constraints), if any. */
|
|
78
|
+
nonFixingOuter = undefined;
|
|
73
79
|
/** Maps to inferences from the return type, if any. */
|
|
74
80
|
returnMapper = undefined;
|
|
75
81
|
outerReturnMapper = undefined;
|
|
76
82
|
inferredTypeParameters = undefined;
|
|
77
|
-
|
|
83
|
+
/** Created on the first site; most contexts get none. */
|
|
84
|
+
intraExpressionInferenceSites = undefined;
|
|
78
85
|
constructor(c, inferences, signature, flags, compareTypes) {
|
|
86
|
+
super();
|
|
87
|
+
this.c = c;
|
|
79
88
|
this.inferences = inferences;
|
|
80
89
|
this.signature = signature;
|
|
81
90
|
this.flags = flags;
|
|
82
91
|
this.compareTypes = compareTypes;
|
|
83
|
-
this.mapper = new InferenceTypeMapper(c, this, true);
|
|
84
|
-
this.nonFixingMapper = new InferenceTypeMapper(c, this, false);
|
|
85
92
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.c
|
|
95
|
-
this.context = context;
|
|
96
|
-
this.fixing = fixing;
|
|
93
|
+
/** Fixes inferences. */
|
|
94
|
+
get mapper() {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** Maps to the current inferences without fixing them. */
|
|
98
|
+
get nonFixingMapper() {
|
|
99
|
+
const mapper = new NonFixingInferenceMapper(this);
|
|
100
|
+
const outer = this.nonFixingOuter;
|
|
101
|
+
return outer !== undefined ? combineTypeMappers(this.c, mapper, outer) : mapper;
|
|
97
102
|
}
|
|
98
103
|
map(type) {
|
|
99
|
-
const inferences = this.
|
|
104
|
+
const inferences = this.inferences;
|
|
100
105
|
for (let i = 0; i < inferences.length; i++) {
|
|
101
106
|
const inference = inferences[i];
|
|
102
107
|
if (type !== inference.typeParameter)
|
|
103
108
|
continue;
|
|
104
|
-
if (
|
|
109
|
+
if (!inference.isFixed) {
|
|
105
110
|
// Infer from intra-expression sites before committing to an inference.
|
|
106
|
-
inferFromIntraExpressionSites(this.c, this
|
|
111
|
+
inferFromIntraExpressionSites(this.c, this);
|
|
107
112
|
clearCachedInferences(inferences);
|
|
108
113
|
inference.isFixed = true;
|
|
109
114
|
}
|
|
110
|
-
return getInferredType(this.c, this
|
|
115
|
+
return getInferredType(this.c, this, i);
|
|
111
116
|
}
|
|
112
117
|
return type;
|
|
113
118
|
}
|
|
114
119
|
}
|
|
120
|
+
/** Maps a context's type parameters to their inferred types without fixing them. */
|
|
121
|
+
export class NonFixingInferenceMapper extends TypeMapper {
|
|
122
|
+
context;
|
|
123
|
+
constructor(context) {
|
|
124
|
+
super();
|
|
125
|
+
this.context = context;
|
|
126
|
+
}
|
|
127
|
+
map(type) {
|
|
128
|
+
const context = this.context;
|
|
129
|
+
const inferences = context.inferences;
|
|
130
|
+
for (let i = 0; i < inferences.length; i++)
|
|
131
|
+
if (type === inferences[i].typeParameter)
|
|
132
|
+
return getInferredType(context.c, context, i);
|
|
133
|
+
return type;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
115
136
|
export function createInferenceContext(c, typeParameters, signature, flags, compareTypes) {
|
|
116
137
|
const inferences = [];
|
|
117
138
|
for (const tp of typeParameters)
|
|
@@ -144,7 +165,7 @@ export function createOuterReturnMapper(c, context) {
|
|
|
144
165
|
return context.outerReturnMapper;
|
|
145
166
|
}
|
|
146
167
|
export function addIntraExpressionInferenceSite(context, node, type) {
|
|
147
|
-
context.intraExpressionInferenceSites.push(new IntraExpressionInferenceSite(node, type));
|
|
168
|
+
(context.intraExpressionInferenceSites ??= []).push(new IntraExpressionInferenceSite(node, type));
|
|
148
169
|
}
|
|
149
170
|
export function clearCachedInferences(inferences) {
|
|
150
171
|
for (const inference of inferences)
|
|
@@ -1678,7 +1699,9 @@ export function instantiateReverseMappedType(c, t, mapper) {
|
|
|
1678
1699
|
/** Infers early from intra-expression sites (context-sensitive elements of object and array literals). */
|
|
1679
1700
|
export function inferFromIntraExpressionSites(c, context) {
|
|
1680
1701
|
const sites = context.intraExpressionInferenceSites;
|
|
1681
|
-
|
|
1702
|
+
if (sites === undefined)
|
|
1703
|
+
return;
|
|
1704
|
+
context.intraExpressionInferenceSites = undefined;
|
|
1682
1705
|
for (const site of sites) {
|
|
1683
1706
|
const contextualType = getContextualTypeForInference(c, site.node);
|
|
1684
1707
|
if (contextualType !== undefined)
|
|
@@ -1940,7 +1963,7 @@ export function inferTypesForConditional(c, root, checkType, extendsType, mapper
|
|
|
1940
1963
|
// so the non-fixing mapper combines with `mapper`.
|
|
1941
1964
|
const context = createInferenceContext(c, root.inferTypeParameters, undefined, 0 /* InferenceFlags.None */, undefined);
|
|
1942
1965
|
if (mapper !== undefined)
|
|
1943
|
-
context.
|
|
1966
|
+
context.nonFixingOuter = mapper;
|
|
1944
1967
|
// Inferences from constraints could eagerly resolve what should defer; contravariance is always strict.
|
|
1945
1968
|
if (!checkTypeDeferred)
|
|
1946
1969
|
inferTypes(c, context.inferences, checkType, extendsType, 512 /* InferencePriority.NoConstraints */ | 1024 /* InferencePriority.AlwaysStrict */, false);
|
|
@@ -142,6 +142,33 @@ export declare function getPropertyOfType(c: Checker, t: Type, name: string): Sy
|
|
|
142
142
|
* primitives and type parameters, and falls back to Object and Function members.
|
|
143
143
|
*/
|
|
144
144
|
export declare function getPropertyOfTypeEx(c: Checker, t: Type, name: string, skipObjectFunctionPropertyAugment: boolean, includeTypeOnlyMembers: boolean): Symbol | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* A long property list that `propertiesRelatedTo` walks: the position of each name, and the positions of
|
|
147
|
+
* the static private properties, which `getUnmatchedProperty` never reports, and of the required ones.
|
|
148
|
+
*/
|
|
149
|
+
export declare class PropertyListIndex {
|
|
150
|
+
readonly positions: Map<string, number>;
|
|
151
|
+
readonly staticPrivate: number[];
|
|
152
|
+
readonly required: number[];
|
|
153
|
+
constructor(positions: Map<string, number>, staticPrivate: number[], required: number[]);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `getUnmatchedProperty(c, source, target, requireOptionalProperties, false)` where `targetProperties` are
|
|
157
|
+
* the target's properties and `found` the positions of the names the source has
|
|
158
|
+
* (`positionsOfNamesFoundInSource`): the first property that is not static private, and is required unless
|
|
159
|
+
* `requireOptionalProperties`, at a position not in `found`.
|
|
160
|
+
*/
|
|
161
|
+
export declare function firstUnmatchedProperty(c: Checker, targetProperties: Symbol[], found: number[], requireOptionalProperties: boolean): Symbol | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* The positions in `targetProperties`, the properties of `target`, ascending, of the names
|
|
164
|
+
* `getPropertyOfType(c, source, name)` finds: the names of the source's properties and of the Function and
|
|
165
|
+
* Object members its lookups fall back to. `getPropertyOfType` answers undefined for the names at every
|
|
166
|
+
* other position. Undefined where the answer cannot be read from resolved property lists without resolving
|
|
167
|
+
* anything (not an object type, an apparent type, members not resolved or not instantiated yet, a module),
|
|
168
|
+
* where the target list is too short or the source list too long to save lookups, and where the target
|
|
169
|
+
* list has no index (yet: `propertyListIndex`).
|
|
170
|
+
*/
|
|
171
|
+
export declare function positionsOfNamesFoundInSource(c: Checker, source: Type, target: Type, targetProperties: Symbol[]): number[] | undefined;
|
|
145
172
|
export declare function getPropertyOfObjectType(c: Checker, t: Type, name: string): Symbol | undefined;
|
|
146
173
|
export declare function getTypeOfPropertyOfType(c: Checker, t: Type, name: string): Type | undefined;
|
|
147
174
|
export declare function getPropertyOfUnionOrIntersectionType(c: Checker, t: UnionOrIntersectionType, name: string, skipObjectFunctionPropertyAugment: boolean): Symbol | undefined;
|
|
@@ -1305,6 +1305,171 @@ export function getPropertyOfTypeEx(c, t, name, skipObjectFunctionPropertyAugmen
|
|
|
1305
1305
|
return getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1306
1306
|
return undefined;
|
|
1307
1307
|
}
|
|
1308
|
+
/**
|
|
1309
|
+
* A long property list that `propertiesRelatedTo` walks: the position of each name, and the positions of
|
|
1310
|
+
* the static private properties, which `getUnmatchedProperty` never reports, and of the required ones.
|
|
1311
|
+
*/
|
|
1312
|
+
export class PropertyListIndex {
|
|
1313
|
+
positions;
|
|
1314
|
+
staticPrivate;
|
|
1315
|
+
required;
|
|
1316
|
+
constructor(positions, staticPrivate, required) {
|
|
1317
|
+
this.positions = positions;
|
|
1318
|
+
this.staticPrivate = staticPrivate;
|
|
1319
|
+
this.required = required;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
/** The uses of a long property list after which `propertyListIndex` indexes it by a table of its own. */
|
|
1323
|
+
const propertyListUsesBeforeIndex = 3;
|
|
1324
|
+
/**
|
|
1325
|
+
* The index of `properties`, the properties of `target`. Where the members of `target` are properties
|
|
1326
|
+
* with shared names (`PropertyMembers` with `MemberNames`), the index reads the positions of those names.
|
|
1327
|
+
* Other lists get a positions table of their own on the use after the first `propertyListUsesBeforeIndex`:
|
|
1328
|
+
* most long lists are related only a few times, and the lists related many times hold most of the lookups
|
|
1329
|
+
* the index saves. Undefined before that, and where the list repeats a name.
|
|
1330
|
+
*/
|
|
1331
|
+
function propertyListIndex(c, target, properties) {
|
|
1332
|
+
const known = c.propertyListIndexes.get(properties);
|
|
1333
|
+
if (known instanceof PropertyListIndex)
|
|
1334
|
+
return known;
|
|
1335
|
+
if (known === null)
|
|
1336
|
+
return undefined;
|
|
1337
|
+
let positions;
|
|
1338
|
+
const pending = (target.flags & 1048576 /* TypeFlags.Object */) !== 0 ? membersHolder(c, target).pendingMembers : undefined;
|
|
1339
|
+
if (pending instanceof PropertyMembers &&
|
|
1340
|
+
pending.materializedProperties === properties &&
|
|
1341
|
+
pending.names !== undefined) {
|
|
1342
|
+
// The names are the names of the properties, in order (hasMemberNames).
|
|
1343
|
+
positions = pending.names.positions;
|
|
1344
|
+
if (positions.size !== properties.length) {
|
|
1345
|
+
c.propertyListIndexes.set(properties, null);
|
|
1346
|
+
return undefined;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
else {
|
|
1350
|
+
const uses = known ?? 0;
|
|
1351
|
+
if (uses < propertyListUsesBeforeIndex) {
|
|
1352
|
+
c.propertyListIndexes.set(properties, uses + 1);
|
|
1353
|
+
return undefined;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
const own = positions === undefined ? new Map() : undefined;
|
|
1357
|
+
const staticPrivate = [];
|
|
1358
|
+
const required = [];
|
|
1359
|
+
for (let i = 0; i < properties.length; i++) {
|
|
1360
|
+
const p = properties[i];
|
|
1361
|
+
if (own !== undefined) {
|
|
1362
|
+
if (own.has(p.name)) {
|
|
1363
|
+
c.propertyListIndexes.set(properties, null);
|
|
1364
|
+
return undefined;
|
|
1365
|
+
}
|
|
1366
|
+
own.set(p.name, i);
|
|
1367
|
+
}
|
|
1368
|
+
if (isStaticPrivateIdentifierProperty(p))
|
|
1369
|
+
staticPrivate.push(i);
|
|
1370
|
+
else if ((p.flags & 16777216 /* SymbolFlags.Optional */) === 0 && (p.checkFlags & 48 /* CheckFlags.Partial */) === 0)
|
|
1371
|
+
required.push(i);
|
|
1372
|
+
}
|
|
1373
|
+
const index = new PropertyListIndex((positions ?? own), staticPrivate, required);
|
|
1374
|
+
c.propertyListIndexes.set(properties, index);
|
|
1375
|
+
return index;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* `getUnmatchedProperty(c, source, target, requireOptionalProperties, false)` where `targetProperties` are
|
|
1379
|
+
* the target's properties and `found` the positions of the names the source has
|
|
1380
|
+
* (`positionsOfNamesFoundInSource`): the first property that is not static private, and is required unless
|
|
1381
|
+
* `requireOptionalProperties`, at a position not in `found`.
|
|
1382
|
+
*/
|
|
1383
|
+
export function firstUnmatchedProperty(c, targetProperties, found, requireOptionalProperties) {
|
|
1384
|
+
const index = c.propertyListIndexes.get(targetProperties);
|
|
1385
|
+
let next = 0;
|
|
1386
|
+
if (!requireOptionalProperties) {
|
|
1387
|
+
for (const position of index.required) {
|
|
1388
|
+
while (next < found.length && found[next] < position)
|
|
1389
|
+
next++;
|
|
1390
|
+
if (next === found.length || found[next] !== position)
|
|
1391
|
+
return targetProperties[position];
|
|
1392
|
+
}
|
|
1393
|
+
return undefined;
|
|
1394
|
+
}
|
|
1395
|
+
const staticPrivate = index.staticPrivate;
|
|
1396
|
+
let nextPrivate = 0;
|
|
1397
|
+
for (let position = 0; position < targetProperties.length; position++) {
|
|
1398
|
+
// A position can be both found and static private: both lists move past it.
|
|
1399
|
+
const isFound = next < found.length && found[next] === position;
|
|
1400
|
+
if (isFound)
|
|
1401
|
+
next++;
|
|
1402
|
+
const isStaticPrivate = nextPrivate < staticPrivate.length && staticPrivate[nextPrivate] === position;
|
|
1403
|
+
if (isStaticPrivate)
|
|
1404
|
+
nextPrivate++;
|
|
1405
|
+
if (!isFound && !isStaticPrivate)
|
|
1406
|
+
return targetProperties[position];
|
|
1407
|
+
}
|
|
1408
|
+
return undefined;
|
|
1409
|
+
}
|
|
1410
|
+
/** The shortest target property list that `positionsOfNamesFoundInSource` indexes. */
|
|
1411
|
+
const indexedTargetPropertiesMinimum = 32;
|
|
1412
|
+
/** The properties of `t` where its members are resolved and instantiated, else undefined. */
|
|
1413
|
+
function resolvedPropertiesIfAny(c, t) {
|
|
1414
|
+
const holder = (t.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) !== 0 ? t : membersHolder(c, t);
|
|
1415
|
+
if ((holder.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) === 0)
|
|
1416
|
+
return undefined;
|
|
1417
|
+
const pending = holder.pendingMembers;
|
|
1418
|
+
return pending === undefined || pending.materializedProperties !== undefined ? holder.properties : undefined;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* The positions in `targetProperties`, the properties of `target`, ascending, of the names
|
|
1422
|
+
* `getPropertyOfType(c, source, name)` finds: the names of the source's properties and of the Function and
|
|
1423
|
+
* Object members its lookups fall back to. `getPropertyOfType` answers undefined for the names at every
|
|
1424
|
+
* other position. Undefined where the answer cannot be read from resolved property lists without resolving
|
|
1425
|
+
* anything (not an object type, an apparent type, members not resolved or not instantiated yet, a module),
|
|
1426
|
+
* where the target list is too short or the source list too long to save lookups, and where the target
|
|
1427
|
+
* list has no index (yet: `propertyListIndex`).
|
|
1428
|
+
*/
|
|
1429
|
+
export function positionsOfNamesFoundInSource(c, source, target, targetProperties) {
|
|
1430
|
+
if (targetProperties.length < indexedTargetPropertiesMinimum)
|
|
1431
|
+
return undefined;
|
|
1432
|
+
if ((source.flags & 1048576 /* TypeFlags.Object */) === 0 || !isOwnReducedApparentType(source))
|
|
1433
|
+
return undefined;
|
|
1434
|
+
// A module's member that only an `export type *` declaration exports is not found.
|
|
1435
|
+
if (source.symbol !== undefined && (source.symbol.flags & 512 /* SymbolFlags.ValueModule */) !== 0)
|
|
1436
|
+
return undefined;
|
|
1437
|
+
const sourceProperties = resolvedPropertiesIfAny(c, source);
|
|
1438
|
+
if (sourceProperties === undefined)
|
|
1439
|
+
return undefined;
|
|
1440
|
+
const resolved = membersHolder(c, source);
|
|
1441
|
+
let functionType;
|
|
1442
|
+
if (source === c.anyFunctionType)
|
|
1443
|
+
functionType = c.globalFunctionType;
|
|
1444
|
+
else if (resolved.callSignatures.length !== 0)
|
|
1445
|
+
functionType = c.globalCallableFunctionType;
|
|
1446
|
+
else if (resolved.constructSignatures.length !== 0)
|
|
1447
|
+
functionType = c.globalNewableFunctionType;
|
|
1448
|
+
let functionProperties = emptySymbols;
|
|
1449
|
+
if (functionType !== undefined && (functionType.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
1450
|
+
const properties = resolvedPropertiesIfAny(c, functionType);
|
|
1451
|
+
if (properties === undefined)
|
|
1452
|
+
return undefined;
|
|
1453
|
+
functionProperties = properties;
|
|
1454
|
+
}
|
|
1455
|
+
const objectProperties = (c.globalObjectType.flags & 1048576 /* TypeFlags.Object */) !== 0 ? resolvedPropertiesIfAny(c, c.globalObjectType) : emptySymbols;
|
|
1456
|
+
if (objectProperties === undefined)
|
|
1457
|
+
return undefined;
|
|
1458
|
+
if ((sourceProperties.length + functionProperties.length + objectProperties.length) * 4 > targetProperties.length)
|
|
1459
|
+
return undefined;
|
|
1460
|
+
const index = propertyListIndex(c, target, targetProperties);
|
|
1461
|
+
if (index === undefined)
|
|
1462
|
+
return undefined;
|
|
1463
|
+
const positions = index.positions;
|
|
1464
|
+
const found = [];
|
|
1465
|
+
for (const list of [sourceProperties, functionProperties, objectProperties])
|
|
1466
|
+
for (const p of list) {
|
|
1467
|
+
const position = positions.get(p.name);
|
|
1468
|
+
if (position !== undefined && !found.includes(position))
|
|
1469
|
+
found.push(position);
|
|
1470
|
+
}
|
|
1471
|
+
return found.sort((a, b) => a - b);
|
|
1472
|
+
}
|
|
1308
1473
|
export function getPropertyOfObjectType(c, t, name) {
|
|
1309
1474
|
if ((t.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
1310
1475
|
return undefined;
|
|
@@ -7,6 +7,20 @@ import { type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
|
7
7
|
/** The module symbol `moduleReference` names, reporting it when it isn't found unless `ignoreErrors`. */
|
|
8
8
|
export declare function resolveExternalModuleName(c: Checker, location: Node, moduleReference: Node | undefined, ignoreErrors: boolean): Symbol | undefined;
|
|
9
9
|
export declare function resolveExternalModuleNameWorker(c: Checker, location: Node, moduleReference: Node | undefined, moduleNotFoundError: DiagnosticMessage | undefined, ignoreErrors: boolean, isForAugmentation: boolean): Symbol | undefined;
|
|
10
|
+
/** A `resolveExternalModule` result that reported nothing, and the arguments it was computed for. */
|
|
11
|
+
export declare class ModuleResolution {
|
|
12
|
+
readonly moduleReference: string;
|
|
13
|
+
readonly moduleNotFoundError: DiagnosticMessage | undefined;
|
|
14
|
+
readonly isForAugmentation: boolean;
|
|
15
|
+
readonly symbol: Symbol | undefined;
|
|
16
|
+
constructor(moduleReference: string, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation: boolean, symbol: Symbol | undefined);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The module symbol `moduleReference` resolves to from `location`, reporting resolution errors at
|
|
20
|
+
* `errorNode`. Each name an import or export declaration lists resolves its module specifier again,
|
|
21
|
+
* with the same result and the same diagnostics: a result that reported nothing is kept for the
|
|
22
|
+
* specifier and returned to later calls from the same declaration (`sharesSpecifierContext`).
|
|
23
|
+
*/
|
|
10
24
|
export declare function resolveExternalModule(c: Checker, location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage | undefined, errorNode: Node | undefined, isForAugmentation: boolean): Symbol | undefined;
|
|
11
25
|
/** A message with its arguments, the elaboration of a diagnostic before it has a location. */
|
|
12
26
|
export declare class DiagnosticDetails {
|