tsc-ts 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api/compiler/ast.d.ts +10 -9
- package/dist/api/compiler/ast.js +22 -16
- package/dist/api/compiler/binder-utilities.js +2 -1
- package/dist/api/compiler/binder.js +9 -8
- package/dist/api/compiler/checker-calls.js +3 -2
- package/dist/api/compiler/checker-declaration-order.js +2 -1
- package/dist/api/compiler/checker-declarations.js +14 -14
- package/dist/api/compiler/checker-declared-types.d.ts +1 -1
- package/dist/api/compiler/checker-declared-types.js +12 -11
- package/dist/api/compiler/checker-decorators.js +3 -3
- package/dist/api/compiler/checker-deprecation.js +17 -18
- package/dist/api/compiler/checker-destructuring.d.ts +1 -1
- package/dist/api/compiler/checker-destructuring.js +3 -3
- package/dist/api/compiler/checker-elaboration.js +8 -7
- package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
- package/dist/api/compiler/checker-emit-resolver.js +5 -4
- package/dist/api/compiler/checker-grammar.js +18 -4
- package/dist/api/compiler/checker-heritage.d.ts +1 -1
- package/dist/api/compiler/checker-heritage.js +14 -13
- package/dist/api/compiler/checker-inference.d.ts +1 -1
- package/dist/api/compiler/checker-inference.js +9 -9
- package/dist/api/compiler/checker-javascript.d.ts +1 -1
- package/dist/api/compiler/checker-javascript.js +5 -4
- package/dist/api/compiler/checker-jsx.d.ts +1 -1
- package/dist/api/compiler/checker-jsx.js +4 -4
- package/dist/api/compiler/checker-literals.js +2 -2
- package/dist/api/compiler/checker-members.d.ts +5 -3
- package/dist/api/compiler/checker-members.js +75 -53
- package/dist/api/compiler/checker-modules.d.ts +1 -1
- package/dist/api/compiler/checker-modules.js +13 -13
- package/dist/api/compiler/checker-object-literals.d.ts +1 -1
- package/dist/api/compiler/checker-object-literals.js +11 -7
- package/dist/api/compiler/checker-overloads.d.ts +1 -1
- package/dist/api/compiler/checker-overloads.js +4 -3
- package/dist/api/compiler/checker-property-access.d.ts +1 -1
- package/dist/api/compiler/checker-property-access.js +2 -2
- package/dist/api/compiler/checker-services.js +2 -2
- package/dist/api/compiler/checker-signatures.d.ts +1 -1
- package/dist/api/compiler/checker-signatures.js +9 -8
- package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
- package/dist/api/compiler/checker-symbol-types.js +22 -952
- package/dist/api/compiler/checker-symbols.d.ts +2 -2
- package/dist/api/compiler/checker-symbols.js +29 -27
- package/dist/api/compiler/checker-type-factory.d.ts +2 -2
- package/dist/api/compiler/checker-type-factory.js +57 -16
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
- package/dist/api/compiler/checker-type-nodes.js +2 -2
- package/dist/api/compiler/checker-type-operators.d.ts +1 -1
- package/dist/api/compiler/checker-type-operators.js +5 -5
- package/dist/api/compiler/checker-types.d.ts +73 -7
- package/dist/api/compiler/checker-types.js +220 -43
- package/dist/api/compiler/checker-unused.d.ts +1 -1
- package/dist/api/compiler/checker-unused.js +3 -3
- package/dist/api/compiler/checker.d.ts +29 -8
- package/dist/api/compiler/checker.js +29 -9
- package/dist/api/compiler/diagnostics.d.ts +2 -8
- package/dist/api/compiler/diagnostics.js +4 -40
- package/dist/api/compiler/file-include.d.ts +35 -8
- package/dist/api/compiler/file-include.js +81 -18
- package/dist/api/compiler/file-loader.d.ts +33 -4
- package/dist/api/compiler/file-loader.js +90 -24
- package/dist/api/compiler/instantiation.d.ts +1 -1
- package/dist/api/compiler/instantiation.js +86 -50
- package/dist/api/compiler/link-tables.d.ts +69 -0
- package/dist/api/compiler/link-tables.js +236 -0
- package/dist/api/compiler/name-resolver.js +3 -3
- package/dist/api/compiler/node-builder-names.d.ts +1 -1
- package/dist/api/compiler/node-builder-names.js +12 -12
- package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
- package/dist/api/compiler/node-builder-pseudo.js +2 -1
- package/dist/api/compiler/node-builder.d.ts +1 -1
- package/dist/api/compiler/node-builder.js +16 -16
- package/dist/api/compiler/parallel-parse.d.ts +2 -0
- package/dist/api/compiler/parallel-parse.js +4 -0
- package/dist/api/compiler/parser.d.ts +33 -16
- package/dist/api/compiler/parser.js +95 -76
- package/dist/api/compiler/printer/emit-context.d.ts +5 -2
- package/dist/api/compiler/printer/emit-context.js +19 -13
- package/dist/api/compiler/program-checker.js +3 -0
- package/dist/api/compiler/program.js +9 -1
- package/dist/api/compiler/relations.d.ts +1 -1
- package/dist/api/compiler/relations.js +10 -10
- package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
- package/dist/api/compiler/symbol-accessibility.js +123 -26
- package/dist/api/compiler/symbol.d.ts +45 -3
- package/dist/api/compiler/symbol.js +121 -10
- package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
- package/dist/api/compiler/transformers/alias-references.js +2 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
- package/dist/api/compiler/transformers/declarations-pseudo.js +4 -2
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
- package/dist/api/compiler/transformers/declarations.js +6 -5
- package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
- package/dist/api/compiler/transformers/reference-resolver.js +26 -24
- package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/subtree-facts.js +7 -5
- package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/syntax-facts.js +9 -5
- package/dist/api/compiler/transformers/type-serialization.js +12 -12
- package/package.json +9 -9
- package/src/compiler/ast.ts +27 -19
- package/src/compiler/binder-utilities.ts +2 -2
- package/src/compiler/binder.ts +15 -11
- package/src/compiler/checker-calls.ts +3 -3
- package/src/compiler/checker-declaration-order.ts +2 -2
- package/src/compiler/checker-declarations.ts +21 -14
- package/src/compiler/checker-declared-types.ts +12 -12
- package/src/compiler/checker-decorators.ts +3 -3
- package/src/compiler/checker-deprecation.ts +17 -21
- package/src/compiler/checker-destructuring.ts +3 -3
- package/src/compiler/checker-elaboration.ts +8 -8
- package/src/compiler/checker-emit-resolver.ts +5 -5
- package/src/compiler/checker-grammar.ts +17 -5
- package/src/compiler/checker-heritage.ts +21 -14
- package/src/compiler/checker-inference.ts +17 -9
- package/src/compiler/checker-javascript.ts +5 -5
- package/src/compiler/checker-jsx.ts +12 -8
- package/src/compiler/checker-literals.ts +2 -2
- package/src/compiler/checker-members.ts +91 -47
- package/src/compiler/checker-modules.ts +23 -13
- package/src/compiler/checker-object-literals.ts +22 -6
- package/src/compiler/checker-overloads.ts +6 -6
- package/src/compiler/checker-property-access.ts +2 -2
- package/src/compiler/checker-services.ts +2 -2
- package/src/compiler/checker-signatures.ts +9 -9
- package/src/compiler/checker-symbol-types.ts +20 -940
- package/src/compiler/checker-symbols.ts +42 -35
- package/src/compiler/checker-type-factory.ts +53 -16
- package/src/compiler/checker-type-nodes.ts +2 -2
- package/src/compiler/checker-type-operators.ts +13 -5
- package/src/compiler/checker-types.ts +223 -43
- package/src/compiler/checker-unused.ts +3 -3
- package/src/compiler/checker.ts +31 -9
- package/src/compiler/diagnostics.ts +5 -44
- package/src/compiler/file-include.ts +85 -17
- package/src/compiler/file-loader.ts +104 -35
- package/src/compiler/incremental.ts +39 -5
- package/src/compiler/instantiation.ts +99 -55
- package/src/compiler/link-tables.ts +245 -0
- package/src/compiler/name-resolver.ts +3 -3
- package/src/compiler/node-builder-names.ts +21 -19
- package/src/compiler/node-builder-pseudo.ts +2 -2
- package/src/compiler/node-builder.ts +24 -16
- package/src/compiler/parallel-check.ts +11 -8
- package/src/compiler/parallel-parse.ts +5 -0
- package/src/compiler/parse-thread.ts +0 -4
- package/src/compiler/parser.ts +120 -70
- package/src/compiler/printer/emit-context.ts +20 -15
- package/src/compiler/program-checker.ts +2 -0
- package/src/compiler/program.ts +8 -1
- package/src/compiler/relations.ts +10 -10
- package/src/compiler/symbol-accessibility.ts +120 -25
- package/src/compiler/symbol.ts +127 -9
- package/src/compiler/transformers/alias-references.ts +2 -2
- package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
- package/src/compiler/transformers/declarations-pseudo.ts +7 -4
- package/src/compiler/transformers/declarations-syntactic.ts +17 -9
- package/src/compiler/transformers/declarations-tracker.ts +3 -3
- package/src/compiler/transformers/declarations.ts +6 -6
- package/src/compiler/transformers/reference-resolver.ts +37 -25
- package/src/compiler/transformers/subtree-facts.ts +13 -5
- package/src/compiler/transformers/syntax-facts.ts +10 -5
- package/src/compiler/transformers/type-serialization.ts +12 -12
- package/src/compiler/tsc-build.ts +17 -13
- package/src/compiler/tsc-cli.ts +9 -6
- package/src/compiler/tsc-compile.ts +16 -7
- package/src/compiler/tsc-watch.ts +94 -26
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Node } from './ast.js';
|
|
2
2
|
import { ModifierFlags } from './ast.js';
|
|
3
|
-
import { type Symbol, type SymbolTable } from './symbol.js';
|
|
4
3
|
import type { Checker } from './checker.js';
|
|
5
4
|
import { IndexInfo, type InterfaceType, MemberNames, ObjectFlags, type Signature, SignatureKind, type StructuredType, type Type, type TypeMapper, type UnionOrIntersectionType, PendingMembers } from './checker-types.js';
|
|
6
5
|
import { getUnionTypeEx, mapType } from './checker-type-factory.js';
|
|
@@ -8,6 +7,7 @@ import { getLateBoundSymbol, getSymbolOfDeclaration } from './checker-symbols.js
|
|
|
8
7
|
import { instantiateTypes } from './instantiation.js';
|
|
9
8
|
import { type RecursionId } from './relations.js';
|
|
10
9
|
import { createSignatureInstantiation, getReturnTypeOfSignature } from './checker-signatures.js';
|
|
10
|
+
import { type Symbol, type SymbolTable } from './symbol.js';
|
|
11
11
|
/**
|
|
12
12
|
* `t` with its members resolved. The test is small enough to inline into callers, so a resolved
|
|
13
13
|
* type (almost every call) costs no call; the resolution itself is out of line.
|
|
@@ -97,11 +97,13 @@ export declare class PropertyMembers extends PendingMembers {
|
|
|
97
97
|
materializeTable(t: StructuredType): void;
|
|
98
98
|
get(name: string): Symbol | undefined;
|
|
99
99
|
}
|
|
100
|
+
/** The most properties of an object literal's table that `keepPropertiesOnly` drops: literals are looked up often. */
|
|
101
|
+
export declare const scannedLiteralPropertiesLimit = 4;
|
|
100
102
|
/**
|
|
101
103
|
* After `setStructuredTypeMembers(c, t, members, ...)`: drops `members` where it holds only the
|
|
102
|
-
* type's properties, at most `
|
|
104
|
+
* type's properties, at most `limit` of them (`PropertyMembers`).
|
|
103
105
|
*/
|
|
104
|
-
export declare function keepPropertiesOnly(c: Checker, t: StructuredType, members: SymbolTable): void;
|
|
106
|
+
export declare function keepPropertiesOnly(c: Checker, t: StructuredType, members: SymbolTable, limit?: number): void;
|
|
105
107
|
/** `t.members?.get(name)` of a type whose members are resolved, without building a pending table. */
|
|
106
108
|
export declare function getResolvedMember(t: StructuredType, name: string): Symbol | undefined;
|
|
107
109
|
/** `t.properties.length !== 0` of a type whose members are resolved, without building a pending table. */
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getCombinedModifierFlags, getDeclarationOfKind } from './binder-utilities.js';
|
|
2
2
|
import { getSymbol, getName } from './ast.js';
|
|
3
|
-
import {
|
|
4
|
-
import { cachedTypeKey, CompositeSignature, IndexInfo, MemberNames, emptyIndexInfos, emptySignatures, emptySymbols, emptyTypes, newTypeMapper, prependTypeMapping, PendingMembers, } from './checker-types.js';
|
|
3
|
+
import { cachedTypeKey, CompositeSignature, IndexInfo, MemberNames, unionOrIntersectionMembers, emptyIndexInfos, emptySignatures, emptySymbols, emptyTypes, newThisArgumentTypeMapper, newTypeMapper, prependTypeMapping, PendingMembers, } from './checker-types.js';
|
|
5
4
|
import { createArrayTypeEx, createTupleTypeEx, createTypeReference, everyType, getElementTypes, getIntersectionType, getStringLiteralType, getTemplateLiteralType, getTypeArguments, getUnionOrIntersectionType, getUnionType, getUnionTypeEx, isArrayOrTupleType, isErrorType, isGenericTupleType, isLiteralType, isPatternLiteralType, isReadonlyArrayType, isTupleType, mapType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
6
5
|
import { getRestTypeOfTupleType, mappedTypeTarget } from './checker-type-operators.js';
|
|
7
6
|
import { isAmbientModule } from './ast-utilities.js';
|
|
@@ -17,7 +16,8 @@ import { cloneSignature, createSignatureInstantiation, getDefaultConstructSignat
|
|
|
17
16
|
import { getConstraintFromConditionalType, getHomomorphicTypeVariable, getIndexForMappedType, getIndexedAccessTypeOrUndefined, getModifiersTypeFromMappedType, getNameTypeFromMappedType, getSimplifiedType, getStringMappingType, getSubstitutionIntersection, isGenericMappedType, isMappedTypeGenericIndexedAccess, isMappedTypeWithKeyofConstraintDeclaration, resolveMappedTypeMembers, resolveReverseMappedTypeMembers, substituteIndexedMappedType, } from './checker-type-operators.js';
|
|
18
17
|
import { getGlobalBigIntType, getGlobalESSymbolType } from './checker-globals.js';
|
|
19
18
|
import { isLateBoundName, isNumericLiteralName } from './checker-utilities.js';
|
|
20
|
-
import { lazyObjectFlags, sideOf } from './side-state.js';
|
|
19
|
+
import { lazyObjectFlags, sideOf, sideOfIfAny } from './side-state.js';
|
|
20
|
+
import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, setDeclarations, } from './symbol.js';
|
|
21
21
|
// ---- Resolution
|
|
22
22
|
/**
|
|
23
23
|
* `t` with its members resolved. The test is small enough to inline into callers, so a resolved
|
|
@@ -37,11 +37,18 @@ export function resolveStructuredTypeMembers(c, t) {
|
|
|
37
37
|
* `t` writes them there; `t` keeps its identity and is never written.
|
|
38
38
|
*/
|
|
39
39
|
export function membersHolder(c, t) {
|
|
40
|
-
|
|
40
|
+
const side = sideOf(c, t);
|
|
41
|
+
if ((side.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
|
|
42
|
+
return unionOrIntersectionMembers(side);
|
|
43
|
+
return side;
|
|
41
44
|
}
|
|
42
45
|
/** The `objectFlags` of `t` that resolving its members sets (MembersResolved, UnresolvedMembers). */
|
|
43
46
|
export function memberResolutionFlags(c, t) {
|
|
44
|
-
|
|
47
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0)
|
|
48
|
+
return lazyObjectFlags(c, t);
|
|
49
|
+
const side = sideOfIfAny(c, t);
|
|
50
|
+
const members = side !== undefined ? side.membersOf : undefined;
|
|
51
|
+
return members !== undefined ? members.objectFlags : 0 /* ObjectFlags.None */;
|
|
45
52
|
}
|
|
46
53
|
function resolveMembersOfType(c, t) {
|
|
47
54
|
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
@@ -49,7 +56,7 @@ function resolveMembersOfType(c, t) {
|
|
|
49
56
|
if ((objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
|
|
50
57
|
resolveTypeReferenceMembers(c, t);
|
|
51
58
|
else if ((objectFlags & 3 /* ObjectFlags.ClassOrInterface */) !== 0)
|
|
52
|
-
resolveObjectTypeMembers(c, membersHolder(c, t), t, emptyTypes, emptyTypes);
|
|
59
|
+
resolveObjectTypeMembers(c, membersHolder(c, t), t, emptyTypes, emptyTypes, undefined);
|
|
53
60
|
else if ((objectFlags & 1024 /* ObjectFlags.ReverseMapped */) !== 0)
|
|
54
61
|
resolveReverseMappedTypeMembers(c, t);
|
|
55
62
|
else if ((objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0)
|
|
@@ -66,26 +73,25 @@ function resolveTypeReferenceMembers(c, t) {
|
|
|
66
73
|
const source = t.target;
|
|
67
74
|
const typeParameters = source.allTypeParameters;
|
|
68
75
|
const typeArguments = getTypeArguments(c, t);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
resolveObjectTypeMembers(c, membersHolder(c, t), source, typeParameters, padded);
|
|
78
|
-
}
|
|
79
|
-
function sameTypes(a, b) {
|
|
80
|
-
if (a.length !== b.length)
|
|
76
|
+
// With one type argument fewer than parameters, the reference itself is the `this` type argument.
|
|
77
|
+
const thisArgument = typeArguments.length === typeParameters.length - 1 ? t : undefined;
|
|
78
|
+
resolveObjectTypeMembers(c, membersHolder(c, t), source, typeParameters, typeArguments, thisArgument);
|
|
79
|
+
}
|
|
80
|
+
/** Whether `b`, followed by `last` where given, is the list `a`. */
|
|
81
|
+
function sameTypes(a, b, last) {
|
|
82
|
+
const count = b.length;
|
|
83
|
+
if (a.length !== (last !== undefined ? count + 1 : count))
|
|
81
84
|
return false;
|
|
82
|
-
for (let i = 0; i <
|
|
85
|
+
for (let i = 0; i < count; i++)
|
|
83
86
|
if (a[i] !== b[i])
|
|
84
87
|
return false;
|
|
85
|
-
return
|
|
88
|
+
return last === undefined || a[count] === last;
|
|
86
89
|
}
|
|
87
|
-
/**
|
|
88
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the members of an instantiation of `source` into `t`, the holder of its members: with
|
|
92
|
+
* `typeArguments` for its type parameters, followed by `thisArgument` where given.
|
|
93
|
+
*/
|
|
94
|
+
function resolveObjectTypeMembers(c, t, source, typeParameters, typeArguments, thisArgument) {
|
|
89
95
|
const declared = resolveDeclaredMembers(c, source);
|
|
90
96
|
let mapper;
|
|
91
97
|
let members;
|
|
@@ -95,7 +101,7 @@ function resolveObjectTypeMembers(c, t, source, typeParameters, typeArguments) {
|
|
|
95
101
|
let instantiated = false;
|
|
96
102
|
// The member symbols of an instantiation are instantiated on demand (PendingInstantiatedMembers).
|
|
97
103
|
let pending;
|
|
98
|
-
if (sameTypes(typeParameters, typeArguments)) {
|
|
104
|
+
if (sameTypes(typeParameters, typeArguments, thisArgument)) {
|
|
99
105
|
members = declared.declaredMembers;
|
|
100
106
|
callSignatures = declared.declaredCallSignatures;
|
|
101
107
|
constructSignatures = declared.declaredConstructSignatures;
|
|
@@ -103,7 +109,10 @@ function resolveObjectTypeMembers(c, t, source, typeParameters, typeArguments) {
|
|
|
103
109
|
}
|
|
104
110
|
else {
|
|
105
111
|
instantiated = true;
|
|
106
|
-
mapper =
|
|
112
|
+
mapper =
|
|
113
|
+
thisArgument !== undefined
|
|
114
|
+
? newThisArgumentTypeMapper(typeParameters, typeArguments, thisArgument)
|
|
115
|
+
: newTypeMapper(typeParameters, typeArguments);
|
|
107
116
|
pending = pendingInstantiatedTable(c, source, mapper);
|
|
108
117
|
members = pending === undefined ? instantiateSymbolTable(c, declared.declaredMembers, mapper) : undefined;
|
|
109
118
|
callSignatures = instantiateSignatures(c, declared.declaredCallSignatures, mapper);
|
|
@@ -111,18 +120,19 @@ function resolveObjectTypeMembers(c, t, source, typeParameters, typeArguments) {
|
|
|
111
120
|
indexInfos = instantiateIndexInfos(c, declared.declaredIndexInfos, mapper);
|
|
112
121
|
}
|
|
113
122
|
const baseTypes = getBaseTypes(c, source);
|
|
123
|
+
// The last type argument, the `this` type argument where the reference has one.
|
|
124
|
+
const lastArgument = thisArgument ?? (typeArguments.length !== 0 ? typeArguments[typeArguments.length - 1] : undefined);
|
|
114
125
|
if (pending !== undefined) {
|
|
115
|
-
resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper,
|
|
126
|
+
resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper, lastArgument, callSignatures, constructSignatures, indexInfos);
|
|
116
127
|
return;
|
|
117
128
|
}
|
|
118
129
|
if (baseTypes.length !== 0) {
|
|
119
130
|
members = !instantiated || members === undefined ? new Map(members ?? []) : members;
|
|
120
131
|
setStructuredTypeMembers(c, t, members, callSignatures, constructSignatures, indexInfos);
|
|
121
|
-
const thisArgument = typeArguments.length !== 0 ? typeArguments[typeArguments.length - 1] : undefined;
|
|
122
132
|
t.objectFlags |= 536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
123
133
|
for (const baseType of baseTypes) {
|
|
124
|
-
const instantiatedBaseType =
|
|
125
|
-
? getTypeWithThisArgument(c, instantiateType(c, baseType, mapper),
|
|
134
|
+
const instantiatedBaseType = lastArgument !== undefined
|
|
135
|
+
? getTypeWithThisArgument(c, instantiateType(c, baseType, mapper), lastArgument, false)
|
|
126
136
|
: baseType;
|
|
127
137
|
addInheritedMembers(members, getPropertiesOfType(c, instantiatedBaseType));
|
|
128
138
|
// A base without signatures adds none: no copy of the list then.
|
|
@@ -397,14 +407,16 @@ export class PropertyMembers extends PendingMembers {
|
|
|
397
407
|
}
|
|
398
408
|
/** The most properties of a table that `keepPropertiesOnly` drops: a lookup compares that many names at most. */
|
|
399
409
|
const scannedPropertiesLimit = 8;
|
|
410
|
+
/** The most properties of an object literal's table that `keepPropertiesOnly` drops: literals are looked up often. */
|
|
411
|
+
export const scannedLiteralPropertiesLimit = 4;
|
|
400
412
|
/**
|
|
401
413
|
* After `setStructuredTypeMembers(c, t, members, ...)`: drops `members` where it holds only the
|
|
402
|
-
* type's properties, at most `
|
|
414
|
+
* type's properties, at most `limit` of them (`PropertyMembers`).
|
|
403
415
|
*/
|
|
404
|
-
export function keepPropertiesOnly(c, t, members) {
|
|
416
|
+
export function keepPropertiesOnly(c, t, members, limit = scannedPropertiesLimit) {
|
|
405
417
|
const resolved = membersHolder(c, t);
|
|
406
418
|
const properties = resolved.propertiesValue;
|
|
407
|
-
if (members.size === 0 || members.size >
|
|
419
|
+
if (members.size === 0 || members.size > limit || properties.length !== members.size)
|
|
408
420
|
return;
|
|
409
421
|
resolved.membersValue = undefined;
|
|
410
422
|
resolved.pendingMembers = new PropertyMembers(properties, undefined);
|
|
@@ -616,13 +628,12 @@ export function resolvedPropertiesAreOptional(t) {
|
|
|
616
628
|
return true;
|
|
617
629
|
}
|
|
618
630
|
/** resolveObjectTypeMembers for an instantiation whose member symbols are instantiated on demand. */
|
|
619
|
-
function resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper,
|
|
631
|
+
function resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper, thisArgument, callSignatures, constructSignatures, indexInfos) {
|
|
620
632
|
setPendingStructuredTypeMembers(c, t, pending, callSignatures, constructSignatures, indexInfos);
|
|
621
633
|
if (baseTypes.length === 0)
|
|
622
634
|
return;
|
|
623
635
|
pending.hasBases = true;
|
|
624
636
|
pending.resolving = true;
|
|
625
|
-
const thisArgument = typeArguments.length !== 0 ? typeArguments[typeArguments.length - 1] : undefined;
|
|
626
637
|
t.objectFlags |= 536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
627
638
|
for (const baseType of baseTypes) {
|
|
628
639
|
const instantiatedBaseType = thisArgument !== undefined
|
|
@@ -786,7 +797,7 @@ function resolveAnonymousTypeMembers(c, t) {
|
|
|
786
797
|
for (const p of members.values()) {
|
|
787
798
|
if ((p.flags & 418 /* SymbolFlags.BlockScoped */) !== 0)
|
|
788
799
|
continue;
|
|
789
|
-
if ((p.flags & 512 /* SymbolFlags.ValueModule */) !== 0 && isOnlyAmbientModuleDeclarations(p
|
|
800
|
+
if ((p.flags & 512 /* SymbolFlags.ValueModule */) !== 0 && isOnlyAmbientModuleDeclarations(getDeclarations(p)))
|
|
790
801
|
continue;
|
|
791
802
|
varsOnly.set(p.name, p);
|
|
792
803
|
}
|
|
@@ -1217,8 +1228,10 @@ export function getPropertiesOfObjectType(c, t) {
|
|
|
1217
1228
|
return (t.flags & 1048576 /* TypeFlags.Object */) !== 0 ? resolveStructuredTypeMembers(c, t).properties : emptySymbols;
|
|
1218
1229
|
}
|
|
1219
1230
|
export function getPropertiesOfUnionOrIntersectionType(c, t) {
|
|
1220
|
-
const
|
|
1221
|
-
if (
|
|
1231
|
+
const known = sideOf(c, t).membersOf;
|
|
1232
|
+
if (known !== undefined && known.resolvedProperties !== undefined)
|
|
1233
|
+
return known.resolvedProperties;
|
|
1234
|
+
{
|
|
1222
1235
|
const checked = new Set();
|
|
1223
1236
|
const props = [];
|
|
1224
1237
|
for (const current of t.types) {
|
|
@@ -1234,9 +1247,11 @@ export function getPropertiesOfUnionOrIntersectionType(c, t) {
|
|
|
1234
1247
|
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0 && getIndexInfosOfType(c, current).length === 0)
|
|
1235
1248
|
break;
|
|
1236
1249
|
}
|
|
1250
|
+
// Resolving the properties may have created the holder.
|
|
1251
|
+
const side = unionOrIntersectionMembers(sideOf(c, t));
|
|
1237
1252
|
side.resolvedProperties = props;
|
|
1253
|
+
return props;
|
|
1238
1254
|
}
|
|
1239
|
-
return side.resolvedProperties;
|
|
1240
1255
|
}
|
|
1241
1256
|
export function getPropertyOfType(c, t, name) {
|
|
1242
1257
|
return getPropertyOfTypeEx(c, t, name, false, false);
|
|
@@ -1316,18 +1331,24 @@ export function getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunct
|
|
|
1316
1331
|
* property twice.
|
|
1317
1332
|
*/
|
|
1318
1333
|
export function getUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment) {
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1334
|
+
const known = sideOf(c, t).membersOf;
|
|
1335
|
+
if (known !== undefined) {
|
|
1336
|
+
const cached = (skipObjectFunctionPropertyAugment ? known.propertyCacheWithoutFunctionPropertyAugment : known.propertyCache)?.get(name);
|
|
1337
|
+
if (cached !== undefined)
|
|
1338
|
+
return cached;
|
|
1339
|
+
if (!skipObjectFunctionPropertyAugment) {
|
|
1340
|
+
const withoutAugment = known.propertyCacheWithoutFunctionPropertyAugment?.get(name);
|
|
1341
|
+
if (withoutAugment !== undefined && (withoutAugment.checkFlags & 48 /* CheckFlags.Partial */) === 0)
|
|
1342
|
+
return withoutAugment;
|
|
1343
|
+
}
|
|
1328
1344
|
}
|
|
1329
1345
|
const prop = createUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1330
1346
|
if (prop !== undefined) {
|
|
1347
|
+
// Creating the property may have created the holder and its caches.
|
|
1348
|
+
const side = unionOrIntersectionMembers(sideOf(c, t));
|
|
1349
|
+
let cache = skipObjectFunctionPropertyAugment
|
|
1350
|
+
? side.propertyCacheWithoutFunctionPropertyAugment
|
|
1351
|
+
: side.propertyCache;
|
|
1331
1352
|
if (cache === undefined) {
|
|
1332
1353
|
cache = new Map();
|
|
1333
1354
|
if (skipObjectFunctionPropertyAugment)
|
|
@@ -1483,7 +1504,7 @@ export function createUnionOrIntersectionProperty(c, containingType, name, skipO
|
|
|
1483
1504
|
firstValueDeclaration = prop.valueDeclaration;
|
|
1484
1505
|
else if (prop.valueDeclaration !== undefined && prop.valueDeclaration !== firstValueDeclaration)
|
|
1485
1506
|
hasNonUniformValueDeclaration = true;
|
|
1486
|
-
for (const d of prop
|
|
1507
|
+
for (const d of getDeclarations(prop))
|
|
1487
1508
|
declarations.push(d);
|
|
1488
1509
|
const t = getTypeOfSymbol(c, prop);
|
|
1489
1510
|
if (firstType === undefined) {
|
|
@@ -1507,7 +1528,7 @@ export function createUnionOrIntersectionProperty(c, containingType, name, skipO
|
|
|
1507
1528
|
for (const t of indexTypes)
|
|
1508
1529
|
propTypes.push(t);
|
|
1509
1530
|
const result = c.newSymbolWithCheckFlags(propFlags | optionalFlag, name, checkFlags | syntheticFlag);
|
|
1510
|
-
result
|
|
1531
|
+
setDeclarations(result, declarations);
|
|
1511
1532
|
if (!hasNonUniformValueDeclaration && firstValueDeclaration !== undefined) {
|
|
1512
1533
|
result.valueDeclaration = firstValueDeclaration;
|
|
1513
1534
|
result.parent = getSymbol(firstValueDeclaration)?.parent;
|
|
@@ -1541,14 +1562,14 @@ export function isPrototypeProperty(symbol) {
|
|
|
1541
1562
|
function hasCommonDeclaration(symbols) {
|
|
1542
1563
|
let common;
|
|
1543
1564
|
for (const symbol of symbols) {
|
|
1544
|
-
if (symbol
|
|
1565
|
+
if (declarationCount(symbol) === 0)
|
|
1545
1566
|
return false;
|
|
1546
1567
|
if (common === undefined) {
|
|
1547
|
-
common = new Set(symbol
|
|
1568
|
+
common = new Set(getDeclarations(symbol));
|
|
1548
1569
|
continue;
|
|
1549
1570
|
}
|
|
1550
1571
|
const next = new Set();
|
|
1551
|
-
for (const d of symbol
|
|
1572
|
+
for (const d of getDeclarations(symbol))
|
|
1552
1573
|
if (common.has(d))
|
|
1553
1574
|
next.add(d);
|
|
1554
1575
|
if (next.size === 0)
|
|
@@ -1559,7 +1580,7 @@ function hasCommonDeclaration(symbols) {
|
|
|
1559
1580
|
}
|
|
1560
1581
|
export function createSymbolWithType(c, source, t) {
|
|
1561
1582
|
const symbol = c.newSymbolWithCheckFlags(source.flags, source.name, source.checkFlags & 8 /* CheckFlags.Readonly */);
|
|
1562
|
-
symbol
|
|
1583
|
+
copyDeclarations(symbol, source);
|
|
1563
1584
|
symbol.parent = source.parent;
|
|
1564
1585
|
symbol.valueDeclaration = source.valueDeclaration;
|
|
1565
1586
|
const id = getSymbolId(symbol);
|
|
@@ -1819,7 +1840,8 @@ export function getReducedType(c, t) {
|
|
|
1819
1840
|
* private, are combined, and the costliest constituent's properties are only looked up by name.
|
|
1820
1841
|
*/
|
|
1821
1842
|
function hasNeverReducedProperty(c, t) {
|
|
1822
|
-
const
|
|
1843
|
+
const members = sideOf(c, t).membersOf;
|
|
1844
|
+
const resolved = members !== undefined ? members.resolvedProperties : undefined;
|
|
1823
1845
|
if (resolved !== undefined) {
|
|
1824
1846
|
for (const p of resolved)
|
|
1825
1847
|
if (isNeverReducedProperty(c, p))
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Node, type SourceFile } from './ast.js';
|
|
2
2
|
import { type DiagnosticMessage } from './diagnostics.js';
|
|
3
3
|
import { ModuleKind } from './options.js';
|
|
4
|
-
import { type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
5
4
|
import { type Checker, type CheckerHost } from './checker.js';
|
|
6
5
|
import { type Type } from './checker-types.js';
|
|
6
|
+
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;
|
|
@@ -15,7 +15,6 @@ import { getResolutionModeOverride, moduleKindName } from './program-utilities.j
|
|
|
15
15
|
import { hasExtension } from './vfs-match.js';
|
|
16
16
|
import { isNodeCoreModule } from './parser.js';
|
|
17
17
|
import { combinePaths, extensionIsTs, fileExtensionIsOneOf, getDeclarationFileExtension, getDirectoryPath, getNormalizedAbsolutePath, isDeclarationFileName, isExternalModuleNameRelative, pathIsRelative, removeExtension, supportedTSExtensionsFlat, tryExtractTSExtension, tryGetExtensionFromPath, } from './path.js';
|
|
18
|
-
import { getSymbolId } from './symbol.js';
|
|
19
18
|
import { isExpressionNode } from './transformers/alias-references.js';
|
|
20
19
|
import { createDiagnosticForNode } from './checker.js';
|
|
21
20
|
import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
@@ -35,6 +34,7 @@ import { createPromiseType } from './checker-iteration.js';
|
|
|
35
34
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
36
35
|
import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
|
|
37
36
|
import { grammarErrorOnNode } from './checker-operators.js';
|
|
37
|
+
import { declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, } from './symbol.js';
|
|
38
38
|
// ---- Resolution
|
|
39
39
|
/** The module symbol `moduleReference` names, reporting it when it isn't found unless `ignoreErrors`. */
|
|
40
40
|
export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors) {
|
|
@@ -496,7 +496,7 @@ function isOnlyImportableAsDefault(c, usage, resolvedModule) {
|
|
|
496
496
|
function getSourceFileOfModuleSymbol(symbol) {
|
|
497
497
|
let declaration = symbol.valueDeclaration;
|
|
498
498
|
if (declaration === undefined)
|
|
499
|
-
for (const d of symbol
|
|
499
|
+
for (const d of getDeclarations(symbol))
|
|
500
500
|
if (!(isAmbientModule(d) && isModuleAugmentationExternal(d)) && !isGlobalScopeAugmentation(d)) {
|
|
501
501
|
declaration = d;
|
|
502
502
|
break;
|
|
@@ -549,7 +549,7 @@ function createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonym
|
|
|
549
549
|
}
|
|
550
550
|
function cloneTypeAsModuleType(c, symbol, moduleType) {
|
|
551
551
|
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
552
|
-
result
|
|
552
|
+
setDeclarations(result, getDeclarations(symbol).slice());
|
|
553
553
|
result.valueDeclaration = symbol.valueDeclaration;
|
|
554
554
|
if (symbol.members !== undefined)
|
|
555
555
|
result.members = new Map(symbol.members);
|
|
@@ -563,7 +563,7 @@ function cloneTypeAsModuleType(c, symbol, moduleType) {
|
|
|
563
563
|
function getSourceFileDeclaration(symbol) {
|
|
564
564
|
if (symbol === undefined)
|
|
565
565
|
return undefined;
|
|
566
|
-
for (const d of symbol
|
|
566
|
+
for (const d of getDeclarations(symbol))
|
|
567
567
|
if (d.kind === 307 /* SyntaxKind.SourceFile */)
|
|
568
568
|
return d;
|
|
569
569
|
return undefined;
|
|
@@ -605,7 +605,7 @@ function canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, usage)
|
|
|
605
605
|
resolveExportByName(c, moduleSymbol, '__esModule', undefined, dontResolveAlias) === undefined);
|
|
606
606
|
}
|
|
607
607
|
function hasSyntacticDefault(symbol) {
|
|
608
|
-
for (const d of symbol
|
|
608
|
+
for (const d of getDeclarations(symbol))
|
|
609
609
|
if (isSyntacticDefault(d))
|
|
610
610
|
return true;
|
|
611
611
|
return false;
|
|
@@ -780,7 +780,7 @@ function reportNonDefaultExport(c, moduleSymbol, node) {
|
|
|
780
780
|
const exportStar = moduleSymbol.exports?.get("\uFFFEexport" /* InternalSymbolName.ExportStar */);
|
|
781
781
|
if (exportStar === undefined)
|
|
782
782
|
return;
|
|
783
|
-
for (const d of exportStar
|
|
783
|
+
for (const d of getDeclarations(exportStar)) {
|
|
784
784
|
const specifier = getModuleSpecifier(d);
|
|
785
785
|
if (d.kind !== 279 /* SyntaxKind.ExportDeclaration */ || specifier === undefined)
|
|
786
786
|
continue;
|
|
@@ -896,11 +896,11 @@ function combineValueAndTypeSymbols(c, valueSymbol, typeSymbol) {
|
|
|
896
896
|
if ((valueSymbol.flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) !== 0)
|
|
897
897
|
return valueSymbol;
|
|
898
898
|
const result = c.newSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
|
|
899
|
-
const declarations = valueSymbol.
|
|
900
|
-
for (const d of typeSymbol
|
|
899
|
+
const declarations = getDeclarations(valueSymbol).slice();
|
|
900
|
+
for (const d of getDeclarations(typeSymbol))
|
|
901
901
|
if (!declarations.includes(d))
|
|
902
902
|
declarations.push(d);
|
|
903
|
-
result
|
|
903
|
+
setDeclarations(result, declarations);
|
|
904
904
|
result.parent = valueSymbol.parent ?? typeSymbol.parent;
|
|
905
905
|
result.valueDeclaration = valueSymbol.valueDeclaration;
|
|
906
906
|
if (typeSymbol.members !== undefined)
|
|
@@ -963,8 +963,8 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
|
|
|
963
963
|
const diagnostic = exportedSymbol !== undefined
|
|
964
964
|
? c.error(name, 626 /* Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2 */, moduleName, declarationName, symbolToString(c, exportedSymbol))
|
|
965
965
|
: c.error(name, 625 /* Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported */, moduleName, declarationName);
|
|
966
|
-
for (let i = 0; i < localSymbol
|
|
967
|
-
diagnostic.addRelatedInfo(createDiagnosticForNode(localSymbol
|
|
966
|
+
for (let i = 0; i < declarationCount(localSymbol); i++)
|
|
967
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(declarationAt(localSymbol, i), i === 0 ? 860 /* Diagnostics.X_0_is_declared_here */ : 1357 /* Diagnostics.X_and_here */, [declarationName]));
|
|
968
968
|
}
|
|
969
969
|
function isSameReference(c, s1, s2) {
|
|
970
970
|
return (getMergedSymbol(c, resolveSymbol(c, getMergedSymbol(c, s1))) ===
|
|
@@ -1436,7 +1436,7 @@ class ExportCollector {
|
|
|
1436
1436
|
if (exportStars !== undefined) {
|
|
1437
1437
|
const nested = new Map();
|
|
1438
1438
|
const lookupTable = new Map();
|
|
1439
|
-
for (const node of exportStars
|
|
1439
|
+
for (const node of getDeclarations(exportStars)) {
|
|
1440
1440
|
const specifier = node.moduleSpecifier;
|
|
1441
1441
|
const resolved = resolveExternalModuleName(this.c, node, specifier, false);
|
|
1442
1442
|
const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
|
|
@@ -1890,7 +1890,7 @@ function checkExportSpecifier(c, node) {
|
|
|
1890
1890
|
if (symbol !== undefined &&
|
|
1891
1891
|
(symbol === c.undefinedSymbol ||
|
|
1892
1892
|
symbol === c.globalThisSymbol ||
|
|
1893
|
-
(symbol
|
|
1893
|
+
(declarationCount(symbol) > 0 && isGlobalSourceFile(getDeclarationContainer(symbol.declaration)))))
|
|
1894
1894
|
c.error(exportedName, 795 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, getText(exportedName));
|
|
1895
1895
|
else
|
|
1896
1896
|
markExportSpecifierAliasReferenced(c, node, symbol, exportedName);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Node, type PropertyAssignment, type ShorthandPropertyAssignment } from './ast.js';
|
|
2
2
|
import { type Checker } from './checker.js';
|
|
3
|
-
import { type Symbol } from './symbol.js';
|
|
4
3
|
import { CheckMode, ObjectFlags, type Type } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
export declare function checkObjectLiteral(c: Checker, node: Node, checkMode: CheckMode): Type;
|
|
6
6
|
export declare function checkPropertyAssignment(c: Checker, node: PropertyAssignment, checkMode: CheckMode): Type;
|
|
7
7
|
export declare function checkShorthandPropertyAssignment(c: Checker, node: ShorthandPropertyAssignment, inDestructuringPattern: boolean, checkMode: CheckMode): Type;
|
|
@@ -3,10 +3,9 @@ import { checkGrammarObjectLiteralOfExpression } from './checker-grammar.js';
|
|
|
3
3
|
import { getExpression, getName, getProperties, getSymbol, getText, getType, } from './ast.js';
|
|
4
4
|
import { isAssignmentTarget } from './binder-utilities.js';
|
|
5
5
|
import { createDiagnosticForNode } from './checker.js';
|
|
6
|
-
import { internalSymbolNamePrefix, getSymbolId } from './symbol.js';
|
|
7
6
|
import { emptyIndexInfos, emptySignatures, IndexInfo, } from './checker-types.js';
|
|
8
7
|
import { checkCrossProductUnion, createAnonymousType, getIntersectionType, getUnionType, getUnionTypeEx, isErrorType, mapType, typesOf, } from './checker-type-factory.js';
|
|
9
|
-
import { getDeclarationModifierFlagsFromSymbol, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getPropertiesOfType, getPropertyOfType, getReducedType, } from './checker-members.js';
|
|
8
|
+
import { getDeclarationModifierFlagsFromSymbol, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getPropertiesOfType, getPropertyOfType, getReducedType, keepPropertiesOnly, scannedLiteralPropertiesLimit, } from './checker-members.js';
|
|
10
9
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
11
10
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
12
11
|
import { addOptionality, getTypeOfSymbol, removeMissingOrUndefinedType } from './checker-symbol-types.js';
|
|
@@ -21,6 +20,7 @@ import { getApparentTypeOfContextualType, getInferenceContext, popContextualType
|
|
|
21
20
|
import { addIntraExpressionInferenceSite } from './checker-inference.js';
|
|
22
21
|
import { isEmptyObjectType } from './checker-type-factory.js';
|
|
23
22
|
import { getTypeOfExpandoObjectLiteral, isJSObjectLiteral } from './checker-javascript.js';
|
|
23
|
+
import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, internalSymbolNamePrefix, setDeclarations, } from './symbol.js';
|
|
24
24
|
/** Builds the type of the members collected since the last spread. */
|
|
25
25
|
class ObjectLiteralBuilder {
|
|
26
26
|
node;
|
|
@@ -63,6 +63,8 @@ class ObjectLiteralBuilder {
|
|
|
63
63
|
result.objectFlags |= 512 /* ObjectFlags.ObjectLiteralPatternWithComputedProperties */;
|
|
64
64
|
if (this.inDestructuringPattern)
|
|
65
65
|
c.patternForType.set(result, this.node);
|
|
66
|
+
// A literal of a few properties keeps them as a list; a lookup by name compares their names.
|
|
67
|
+
keepPropertiesOnly(c, result, this.members, scannedLiteralPropertiesLimit);
|
|
66
68
|
return result;
|
|
67
69
|
}
|
|
68
70
|
reset() {
|
|
@@ -147,7 +149,7 @@ export function checkObjectLiteral(c, node, checkMode) {
|
|
|
147
149
|
else if (getIndexInfoOfType(c, contextualType, c.stringType) === undefined)
|
|
148
150
|
c.error(getName(memberDecl), 529 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */, symbolToString(c, member), typeToString(c, contextualType));
|
|
149
151
|
}
|
|
150
|
-
prop
|
|
152
|
+
copyDeclarations(prop, member);
|
|
151
153
|
prop.parent = member.parent;
|
|
152
154
|
prop.valueDeclaration = member.valueDeclaration;
|
|
153
155
|
c.symbolTypes.set(id, t);
|
|
@@ -243,7 +245,7 @@ function getObjectLiteralIndexInfo(c, isReadonly, properties, keyType) {
|
|
|
243
245
|
(keyType === c.esSymbolType && isSymbolWithSymbolName(c, prop))) {
|
|
244
246
|
propTypes.push(getTypeOfSymbol(c, prop));
|
|
245
247
|
if (isSymbolWithComputedName(prop))
|
|
246
|
-
components.push(prop.
|
|
248
|
+
components.push(prop.declaration);
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
const unionType = propTypes.length !== 0
|
|
@@ -252,7 +254,7 @@ function getObjectLiteralIndexInfo(c, isReadonly, properties, keyType) {
|
|
|
252
254
|
return new IndexInfo(keyType, unionType, isReadonly, undefined, components);
|
|
253
255
|
}
|
|
254
256
|
function getFirstDeclarationName(symbol) {
|
|
255
|
-
return symbol
|
|
257
|
+
return declarationCount(symbol) !== 0 ? getName(symbol.declaration) : undefined;
|
|
256
258
|
}
|
|
257
259
|
function isSymbolWithSymbolName(c, symbol) {
|
|
258
260
|
if (symbol.name.startsWith(internalSymbolNamePrefix + '@'))
|
|
@@ -381,7 +383,7 @@ export function getSpreadType(c, leftIn, rightIn, symbol, objectFlags, readonly)
|
|
|
381
383
|
: getUnionTypeEx(c, [leftType, rightTypeWithoutUndefined], 2 /* UnionReduction.Subtype */, undefined, undefined));
|
|
382
384
|
c.symbolLeftSpreads.set(id, leftProp);
|
|
383
385
|
c.symbolRightSpreads.set(id, rightProp);
|
|
384
|
-
result
|
|
386
|
+
setDeclarations(result, getDeclarations(leftProp).concat(getDeclarations(rightProp)));
|
|
385
387
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(leftProp)));
|
|
386
388
|
members.set(leftProp.name, result);
|
|
387
389
|
}
|
|
@@ -391,6 +393,7 @@ export function getSpreadType(c, leftIn, rightIn, symbol, objectFlags, readonly)
|
|
|
391
393
|
const spread = createAnonymousType(c, symbol, members, [], [], spreadIndexInfos);
|
|
392
394
|
spread.objectFlags |=
|
|
393
395
|
128 /* ObjectFlags.ObjectLiteral */ | 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */ | 4194304 /* ObjectFlags.ContainsSpread */ | objectFlags;
|
|
396
|
+
keepPropertiesOnly(c, spread, members, scannedLiteralPropertiesLimit);
|
|
394
397
|
return spread;
|
|
395
398
|
}
|
|
396
399
|
function getIndexInfoWithReadonly(info, readonly) {
|
|
@@ -468,12 +471,13 @@ function tryMergeUnionOfObjectTypeAndEmptyObject(c, t, readonly) {
|
|
|
468
471
|
const result = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */ | 16777216 /* SymbolFlags.Optional */, prop.name, (prop.checkFlags & 4096 /* CheckFlags.Late */) | (readonly ? 8 /* CheckFlags.Readonly */ : 0));
|
|
469
472
|
const id = getSymbolId(result);
|
|
470
473
|
c.symbolTypes.set(id, isSetonlyAccessor ? c.undefinedType : addOptionality(c, getTypeOfSymbol(c, prop), true, true));
|
|
471
|
-
result
|
|
474
|
+
copyDeclarations(result, prop);
|
|
472
475
|
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
473
476
|
c.symbolSyntheticOrigins.set(id, prop);
|
|
474
477
|
members.set(prop.name, result);
|
|
475
478
|
}
|
|
476
479
|
const spread = createAnonymousType(c, firstType.symbol, members, [], [], getIndexInfosOfType(c, firstType));
|
|
477
480
|
spread.objectFlags |= 128 /* ObjectFlags.ObjectLiteral */ | 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */;
|
|
481
|
+
keepPropertiesOnly(c, spread, members, scannedLiteralPropertiesLimit);
|
|
478
482
|
return spread;
|
|
479
483
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
|
-
import { type Symbol } from './symbol.js';
|
|
3
2
|
import { type Checker } from './checker.js';
|
|
3
|
+
import { type Symbol } from './symbol.js';
|
|
4
4
|
/** Checks the overloads of a function or method declaration's local and export symbols. */
|
|
5
5
|
export declare function checkFunctionOrMethodSymbols(c: Checker, node: Node): void;
|
|
6
6
|
/** Checks a function, method or constructor symbol's overloads and implementations, once. */
|
|
@@ -11,6 +11,7 @@ import { checkComputedPropertyName } from './checker-expressions.js';
|
|
|
11
11
|
import { hasDynamicName, hasLateBindableName } from './checker-utilities.js';
|
|
12
12
|
import { isSignatureAssignableTo, isTypeIdenticalTo, isTypeRelatedTo } from './relations.js';
|
|
13
13
|
import { getEffectiveDeclarationFlags } from './checker-declarations.js';
|
|
14
|
+
import { getDeclarations } from './symbol.js';
|
|
14
15
|
/** Checks the overloads of a function or method declaration's local and export symbols. */
|
|
15
16
|
export function checkFunctionOrMethodSymbols(c, node) {
|
|
16
17
|
if (hasDynamicName(node) && !hasLateBindableName(c, node))
|
|
@@ -52,7 +53,7 @@ class OverloadChecker {
|
|
|
52
53
|
}
|
|
53
54
|
check() {
|
|
54
55
|
const c = this.c;
|
|
55
|
-
const declarations = this.symbol
|
|
56
|
+
const declarations = getDeclarations(this.symbol);
|
|
56
57
|
let someNodeFlags = 0 /* ModifierFlags.None */;
|
|
57
58
|
let allNodeFlags = flagsToCheck();
|
|
58
59
|
let someHaveQuestionToken = false;
|
|
@@ -149,10 +150,10 @@ class OverloadChecker {
|
|
|
149
150
|
reportClassMergedWithFunction() {
|
|
150
151
|
const c = this.c;
|
|
151
152
|
const classes = [];
|
|
152
|
-
for (const d of this.symbol
|
|
153
|
+
for (const d of getDeclarations(this.symbol))
|
|
153
154
|
if (d.kind === 264 /* SyntaxKind.ClassDeclaration */)
|
|
154
155
|
classes.push(d);
|
|
155
|
-
for (const d of this.symbol
|
|
156
|
+
for (const d of getDeclarations(this.symbol)) {
|
|
156
157
|
let message;
|
|
157
158
|
if (d.kind === 264 /* SyntaxKind.ClassDeclaration */)
|
|
158
159
|
message = 944 /* Diagnostics.Class_declaration_cannot_implement_overload_list_for_0 */;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
2
|
import { type Checker } from './checker.js';
|
|
3
3
|
import { type Diagnostic } from './diagnostics.js';
|
|
4
|
-
import { type Symbol } from './symbol.js';
|
|
5
4
|
import { CheckMode, type Type } from './checker-types.js';
|
|
6
5
|
import { AssignmentKind } from './checker-narrowing.js';
|
|
6
|
+
import { type Symbol } from './symbol.js';
|
|
7
7
|
export declare function checkPropertyAccessExpressionOrQualifiedName(c: Checker, node: Node, left: Node, leftType: Type, right: Node, writeOnly: boolean, checkMode?: CheckMode): Type;
|
|
8
8
|
/** A private name used as an expression, as in `#x in obj`; records its declaration. */
|
|
9
9
|
export declare function checkPrivateIdentifierExpression(c: Checker, node: Node): Type;
|
|
@@ -6,7 +6,6 @@ import { getBody, getExpression, getName, getParameters, getSymbol, getText, get
|
|
|
6
6
|
import { declarationNameToString, getContainingClass, getSourceFileOfNode, getThisContainer, isAccessExpression, hasSyntacticModifier, isClassLike, isOptionalChain, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, getElementOrPropertyAccessName, isBindableStaticAccessExpression, isBindableStaticNameExpression, } from './binder-utilities.js';
|
|
7
7
|
import { isFunctionLike, isInJSFile } from './ast-utilities.js';
|
|
8
8
|
import { createDiagnosticForNode } from './checker.js';
|
|
9
|
-
import { getSymbolId } from './symbol.js';
|
|
10
9
|
import { everyContainedType, getTargetType, getUnionType, isEmptyObjectType, isErrorType, typesOf, } from './checker-type-factory.js';
|
|
11
10
|
import { getApparentType, getApplicableIndexInfoForName, getDeclarationModifierFlagsFromSymbol, getPropertiesOfType, getPropertiesOfUnionOrIntersectionType, getPropertyOfType, getPropertyOfTypeEx, isConflictingPrivateProperty, isDiscriminantWithNeverType, } from './checker-members.js';
|
|
12
11
|
import { getDeclarationOfAliasSymbol, getParentOfSymbol, getSpellingSuggestionForName, getSymbolOfDeclaration, } from './checker-symbols.js';
|
|
@@ -29,6 +28,7 @@ import { checkDeprecatedIndexSignature, checkDeprecatedProperty } from './checke
|
|
|
29
28
|
import { isSelfTypeAccess, markPropertyAsReferenced } from './checker-unused.js';
|
|
30
29
|
import { getContextualThisParameterType, getFlowTypeOfAccessExpression, getResolvedSymbol, } from './checker-expressions.js';
|
|
31
30
|
import { isJSLiteralType, isThisPropertyAccessInConstructor } from './checker-javascript.js';
|
|
31
|
+
import { getDeclarations, getSymbolId } from './symbol.js';
|
|
32
32
|
export function checkPropertyAccessExpressionOrQualifiedName(c, node, left, leftType, right, writeOnly, checkMode = 0 /* CheckMode.Normal */) {
|
|
33
33
|
const parentSymbol = c.resolvedSymbols.get(left.id);
|
|
34
34
|
const assignmentKind = getAssignmentTargetKind(node);
|
|
@@ -409,7 +409,7 @@ function checkPropertyAccessibilityAtLocation(c, location, isSuper, writing, con
|
|
|
409
409
|
return true;
|
|
410
410
|
}
|
|
411
411
|
function hasClassInstancePropertyDeclaration(symbol) {
|
|
412
|
-
for (const d of symbol
|
|
412
|
+
for (const d of getDeclarations(symbol))
|
|
413
413
|
if (isClassInstanceProperty(d))
|
|
414
414
|
return true;
|
|
415
415
|
return false;
|
|
@@ -20,7 +20,7 @@ import { createAnonymousType, getRegularTypeOfLiteralType, isErrorType } from '.
|
|
|
20
20
|
import { getLiteralTypeFromPropertyName } from './checker-type-operators.js';
|
|
21
21
|
import { getTypeFromThisTypeNode, getTypeFromTypeNode, getUnresolvedSymbolForEntityName, } from './checker-type-nodes.js';
|
|
22
22
|
import { getNodeAtPosition } from './parser.js';
|
|
23
|
-
import { getSymbolId } from './symbol.js';
|
|
23
|
+
import { getSymbolId, setDeclarations } from './symbol.js';
|
|
24
24
|
// ---- Symbols at locations
|
|
25
25
|
/** The symbol a name, keyword or literal at `node` refers to. */
|
|
26
26
|
export function getSymbolAtLocation(c, node) {
|
|
@@ -295,7 +295,7 @@ function getApplicableIndexSymbol(c, t, keyType) {
|
|
|
295
295
|
declarations.push(other.declaration);
|
|
296
296
|
if (declarations.length !== 0) {
|
|
297
297
|
const symbol = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */, "\uFFFEindex" /* InternalSymbolName.Index */, 8388608 /* CheckFlags.IndexSymbol */);
|
|
298
|
-
symbol
|
|
298
|
+
setDeclarations(symbol, declarations);
|
|
299
299
|
symbol.valueDeclaration = declarations[0];
|
|
300
300
|
symbol.parent = t.symbol;
|
|
301
301
|
c.symbolTypes.set(getSymbolId(symbol), info.valueType);
|