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
|
@@ -18,6 +18,7 @@ import { getFlowTypeOfReference, isMatchingReference } from './checker-narrowing
|
|
|
18
18
|
import { isEmptyArrayLiteralType } from './relations.js';
|
|
19
19
|
import { getTypeOfSymbol, getWidenedType, reportImplicitAny } from './checker-symbol-types.js';
|
|
20
20
|
import { getFlowTypeInConstructor, getFlowTypeOfProperty, getTypeOfPropertyInBaseClass, isAutoTypedProperty, } from './checker-classes.js';
|
|
21
|
+
import { declarationCount, getDeclarations } from './symbol.js';
|
|
21
22
|
/** The type of the CommonJS `module` symbol or its `exports` property. */
|
|
22
23
|
export function getTypeOfModuleExportsSymbol(c, symbol) {
|
|
23
24
|
if (symbol.name === 'exports') {
|
|
@@ -39,7 +40,7 @@ export function getWidenedTypeForAssignmentDeclaration(c, symbol) {
|
|
|
39
40
|
t = getTypeOfPropertyInBaseClass(c, symbol);
|
|
40
41
|
if (t === undefined) {
|
|
41
42
|
const types = [];
|
|
42
|
-
const declarations = symbol
|
|
43
|
+
const declarations = getDeclarations(symbol);
|
|
43
44
|
for (let i = 0; i < declarations.length; i++) {
|
|
44
45
|
const declaration = declarations[i];
|
|
45
46
|
const declaredType = declaration instanceof BinaryExpression ? declaration.type : undefined;
|
|
@@ -170,7 +171,7 @@ function getThisAssignmentKind(c, symbol) {
|
|
|
170
171
|
return (links.thisAssignmentKind - 1);
|
|
171
172
|
let allThis = true;
|
|
172
173
|
let typeAnnotation;
|
|
173
|
-
for (const declaration of symbol
|
|
174
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
174
175
|
if (!(declaration instanceof BinaryExpression)) {
|
|
175
176
|
allThis = false;
|
|
176
177
|
break;
|
|
@@ -210,7 +211,7 @@ export function isConstructorDeclaredThisProperty(c, symbol) {
|
|
|
210
211
|
return getThisAssignmentKind(c, symbol) === 2 /* ThisAssignmentKind.Constructor */;
|
|
211
212
|
}
|
|
212
213
|
function getDeclaringConstructor(symbol) {
|
|
213
|
-
for (const declaration of symbol
|
|
214
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
214
215
|
const container = getThisContainer(declaration, false, false);
|
|
215
216
|
if (container.kind === 177 /* SyntaxKind.Constructor */)
|
|
216
217
|
return container;
|
|
@@ -437,5 +438,5 @@ export function isUndefinedAssignmentToCommonJSExport(c, left, rightType) {
|
|
|
437
438
|
if (getAssignmentDeclarationKind(assignment) !== 2 /* JSDeclarationKind.ExportsProperty */)
|
|
438
439
|
return false;
|
|
439
440
|
const symbol = c.resolvedSymbols.get(left.id);
|
|
440
|
-
return symbol !== undefined && symbol
|
|
441
|
+
return symbol !== undefined && declarationCount(symbol) > 1 && (rightType.flags & 4 /* TypeFlags.Undefined */) !== 0;
|
|
441
442
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type JsxAttributes, type Node, type SourceFile } from './ast.js';
|
|
2
2
|
import { Diagnostic } from './diagnostics.js';
|
|
3
|
-
import { type Symbol } from './symbol.js';
|
|
4
3
|
import { type Checker } from './checker.js';
|
|
5
4
|
import { CheckMode, type Signature, type Type } from './checker-types.js';
|
|
6
5
|
import { type Relation } from './relations.js';
|
|
7
6
|
import { ContextFlags } from './checker-contextual.js';
|
|
8
7
|
import { type InferenceContext } from './checker-inference.js';
|
|
8
|
+
import { type Symbol } from './symbol.js';
|
|
9
9
|
declare const enum JsxFlags {
|
|
10
10
|
None = 0,
|
|
11
11
|
/** An element from a named property of `JSX.IntrinsicElements`. */
|
|
@@ -6,7 +6,6 @@ import { Diagnostic, chainDiagnostic } from './diagnostics.js';
|
|
|
6
6
|
import { JsxEmit } from './options.js';
|
|
7
7
|
import { parseIsolatedEntityName } from './parser.js';
|
|
8
8
|
import { skipTrivia } from './scanner.js';
|
|
9
|
-
import { getSymbolId } from './symbol.js';
|
|
10
9
|
import { createDiagnosticForNode } from './checker.js';
|
|
11
10
|
import { newTypeMapper, } from './checker-types.js';
|
|
12
11
|
import { createAnonymousType, createArrayType, createTupleType, createTypeReference, getIntersectionType, getPropagatingFlagsOfTypes, getStringLiteralType, getUnionType, intersectTypes, isErrorType, everyType, isArrayType, mapTypeEx, someType, typesOf, } from './checker-type-factory.js';
|
|
@@ -38,6 +37,7 @@ import { getIndexedAccessType } from './checker-type-operators.js';
|
|
|
38
37
|
import { filterType, isTupleType } from './checker-type-factory.js';
|
|
39
38
|
import { createTypeFromGenericGlobalType } from './checker-type-factory.js';
|
|
40
39
|
import { isTypeAssignableTo } from './relations.js';
|
|
40
|
+
import { copyDeclarations, declarationCount, getSymbolId, } from './symbol.js';
|
|
41
41
|
// Names in the `JSX` namespace.
|
|
42
42
|
const jsxNamespaceName = 'JSX';
|
|
43
43
|
const jsxIntrinsicElementsName = 'IntrinsicElements';
|
|
@@ -384,8 +384,8 @@ function getNameFromJsxElementAttributesContainer(c, containerName, ns) {
|
|
|
384
384
|
return '';
|
|
385
385
|
if (props.length === 1)
|
|
386
386
|
return props[0].name;
|
|
387
|
-
if (sym
|
|
388
|
-
c.error(sym.
|
|
387
|
+
if (declarationCount(sym) !== 0)
|
|
388
|
+
c.error(sym.declaration, 752 /* Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property */, containerName);
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
return "\uFFFEmissing" /* InternalSymbolName.Missing */;
|
|
@@ -733,7 +733,7 @@ export function createJsxAttributesTypeFromAttributesProperty(c, openingLikeElem
|
|
|
733
733
|
const exprType = checkJsxAttribute(c, attributeDecl, checkMode);
|
|
734
734
|
objectFlags |= exprType.objectFlags & 458752 /* ObjectFlags.PropagatingFlags */;
|
|
735
735
|
const attributeSymbol = c.newSymbol(4 /* SymbolFlags.Property */ | member.flags, member.name);
|
|
736
|
-
attributeSymbol
|
|
736
|
+
copyDeclarations(attributeSymbol, member);
|
|
737
737
|
attributeSymbol.parent = member.parent;
|
|
738
738
|
if (member.valueDeclaration !== undefined)
|
|
739
739
|
attributeSymbol.valueDeclaration = member.valueDeclaration;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSymbolId } from './symbol.js';
|
|
1
|
+
import { copyDeclarations, getSymbolId } from './symbol.js';
|
|
2
2
|
import { cachedTypeKey } from './checker-types.js';
|
|
3
3
|
import { createAnonymousType } from './checker-type-factory.js';
|
|
4
4
|
import { getPropertiesOfObjectType, resolveStructuredTypeMembers } from './checker-members.js';
|
|
@@ -29,7 +29,7 @@ export function getRegularTypeOfObjectLiteral(c, t) {
|
|
|
29
29
|
}
|
|
30
30
|
function createSymbolWithTypeLocal(c, source, t) {
|
|
31
31
|
const symbol = c.newSymbolWithCheckFlags(source.flags, source.name, source.checkFlags & 8 /* CheckFlags.Readonly */);
|
|
32
|
-
symbol
|
|
32
|
+
copyDeclarations(symbol, source);
|
|
33
33
|
symbol.parent = source.parent;
|
|
34
34
|
symbol.valueDeclaration = source.valueDeclaration;
|
|
35
35
|
const id = getSymbolId(symbol);
|
|
@@ -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. */
|
|
@@ -140,6 +142,33 @@ export declare function getPropertyOfType(c: Checker, t: Type, name: string): Sy
|
|
|
140
142
|
* primitives and type parameters, and falls back to Object and Function members.
|
|
141
143
|
*/
|
|
142
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;
|
|
143
172
|
export declare function getPropertyOfObjectType(c: Checker, t: Type, name: string): Symbol | undefined;
|
|
144
173
|
export declare function getTypeOfPropertyOfType(c: Checker, t: Type, name: string): Type | undefined;
|
|
145
174
|
export declare function getPropertyOfUnionOrIntersectionType(c: Checker, t: UnionOrIntersectionType, name: string, skipObjectFunctionPropertyAugment: boolean): Symbol | undefined;
|
|
@@ -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);
|
|
@@ -1290,6 +1305,171 @@ export function getPropertyOfTypeEx(c, t, name, skipObjectFunctionPropertyAugmen
|
|
|
1290
1305
|
return getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1291
1306
|
return undefined;
|
|
1292
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
|
+
}
|
|
1293
1473
|
export function getPropertyOfObjectType(c, t, name) {
|
|
1294
1474
|
if ((t.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
1295
1475
|
return undefined;
|
|
@@ -1316,18 +1496,24 @@ export function getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunct
|
|
|
1316
1496
|
* property twice.
|
|
1317
1497
|
*/
|
|
1318
1498
|
export function getUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment) {
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1499
|
+
const known = sideOf(c, t).membersOf;
|
|
1500
|
+
if (known !== undefined) {
|
|
1501
|
+
const cached = (skipObjectFunctionPropertyAugment ? known.propertyCacheWithoutFunctionPropertyAugment : known.propertyCache)?.get(name);
|
|
1502
|
+
if (cached !== undefined)
|
|
1503
|
+
return cached;
|
|
1504
|
+
if (!skipObjectFunctionPropertyAugment) {
|
|
1505
|
+
const withoutAugment = known.propertyCacheWithoutFunctionPropertyAugment?.get(name);
|
|
1506
|
+
if (withoutAugment !== undefined && (withoutAugment.checkFlags & 48 /* CheckFlags.Partial */) === 0)
|
|
1507
|
+
return withoutAugment;
|
|
1508
|
+
}
|
|
1328
1509
|
}
|
|
1329
1510
|
const prop = createUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1330
1511
|
if (prop !== undefined) {
|
|
1512
|
+
// Creating the property may have created the holder and its caches.
|
|
1513
|
+
const side = unionOrIntersectionMembers(sideOf(c, t));
|
|
1514
|
+
let cache = skipObjectFunctionPropertyAugment
|
|
1515
|
+
? side.propertyCacheWithoutFunctionPropertyAugment
|
|
1516
|
+
: side.propertyCache;
|
|
1331
1517
|
if (cache === undefined) {
|
|
1332
1518
|
cache = new Map();
|
|
1333
1519
|
if (skipObjectFunctionPropertyAugment)
|
|
@@ -1483,7 +1669,7 @@ export function createUnionOrIntersectionProperty(c, containingType, name, skipO
|
|
|
1483
1669
|
firstValueDeclaration = prop.valueDeclaration;
|
|
1484
1670
|
else if (prop.valueDeclaration !== undefined && prop.valueDeclaration !== firstValueDeclaration)
|
|
1485
1671
|
hasNonUniformValueDeclaration = true;
|
|
1486
|
-
for (const d of prop
|
|
1672
|
+
for (const d of getDeclarations(prop))
|
|
1487
1673
|
declarations.push(d);
|
|
1488
1674
|
const t = getTypeOfSymbol(c, prop);
|
|
1489
1675
|
if (firstType === undefined) {
|
|
@@ -1507,7 +1693,7 @@ export function createUnionOrIntersectionProperty(c, containingType, name, skipO
|
|
|
1507
1693
|
for (const t of indexTypes)
|
|
1508
1694
|
propTypes.push(t);
|
|
1509
1695
|
const result = c.newSymbolWithCheckFlags(propFlags | optionalFlag, name, checkFlags | syntheticFlag);
|
|
1510
|
-
result
|
|
1696
|
+
setDeclarations(result, declarations);
|
|
1511
1697
|
if (!hasNonUniformValueDeclaration && firstValueDeclaration !== undefined) {
|
|
1512
1698
|
result.valueDeclaration = firstValueDeclaration;
|
|
1513
1699
|
result.parent = getSymbol(firstValueDeclaration)?.parent;
|
|
@@ -1541,14 +1727,14 @@ export function isPrototypeProperty(symbol) {
|
|
|
1541
1727
|
function hasCommonDeclaration(symbols) {
|
|
1542
1728
|
let common;
|
|
1543
1729
|
for (const symbol of symbols) {
|
|
1544
|
-
if (symbol
|
|
1730
|
+
if (declarationCount(symbol) === 0)
|
|
1545
1731
|
return false;
|
|
1546
1732
|
if (common === undefined) {
|
|
1547
|
-
common = new Set(symbol
|
|
1733
|
+
common = new Set(getDeclarations(symbol));
|
|
1548
1734
|
continue;
|
|
1549
1735
|
}
|
|
1550
1736
|
const next = new Set();
|
|
1551
|
-
for (const d of symbol
|
|
1737
|
+
for (const d of getDeclarations(symbol))
|
|
1552
1738
|
if (common.has(d))
|
|
1553
1739
|
next.add(d);
|
|
1554
1740
|
if (next.size === 0)
|
|
@@ -1559,7 +1745,7 @@ function hasCommonDeclaration(symbols) {
|
|
|
1559
1745
|
}
|
|
1560
1746
|
export function createSymbolWithType(c, source, t) {
|
|
1561
1747
|
const symbol = c.newSymbolWithCheckFlags(source.flags, source.name, source.checkFlags & 8 /* CheckFlags.Readonly */);
|
|
1562
|
-
symbol
|
|
1748
|
+
copyDeclarations(symbol, source);
|
|
1563
1749
|
symbol.parent = source.parent;
|
|
1564
1750
|
symbol.valueDeclaration = source.valueDeclaration;
|
|
1565
1751
|
const id = getSymbolId(symbol);
|
|
@@ -1819,7 +2005,8 @@ export function getReducedType(c, t) {
|
|
|
1819
2005
|
* private, are combined, and the costliest constituent's properties are only looked up by name.
|
|
1820
2006
|
*/
|
|
1821
2007
|
function hasNeverReducedProperty(c, t) {
|
|
1822
|
-
const
|
|
2008
|
+
const members = sideOf(c, t).membersOf;
|
|
2009
|
+
const resolved = members !== undefined ? members.resolvedProperties : undefined;
|
|
1823
2010
|
if (resolved !== undefined) {
|
|
1824
2011
|
for (const p of resolved)
|
|
1825
2012
|
if (isNeverReducedProperty(c, p))
|