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
|
@@ -20,21 +20,6 @@ export class TypeAlias {
|
|
|
20
20
|
this.typeArguments = typeArguments;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
/** One entry of a `TypeListCache`: the parts of its key, its value, and the next entry with the same hash. */
|
|
24
|
-
class TypeListEntry {
|
|
25
|
-
types;
|
|
26
|
-
alias;
|
|
27
|
-
tag;
|
|
28
|
-
value;
|
|
29
|
-
next;
|
|
30
|
-
constructor(types, alias, tag, value) {
|
|
31
|
-
this.types = types;
|
|
32
|
-
this.alias = alias;
|
|
33
|
-
this.tag = tag;
|
|
34
|
-
this.value = value;
|
|
35
|
-
this.next = undefined;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
23
|
function sameTypeListParts(a, b) {
|
|
39
24
|
if (a.length !== b.length)
|
|
40
25
|
return false;
|
|
@@ -53,32 +38,149 @@ function sameAliasParts(a, b) {
|
|
|
53
38
|
* aliasKey(alias)` plus a suffix spelled, without building them. A lookup takes a number hashing the
|
|
54
39
|
* parts (`typeListHash`); entries keep their parts, so a match is exact and keys sharing a hash chain.
|
|
55
40
|
* Like tsgo's hashed type list keys. A list must not change after it keys an entry.
|
|
41
|
+
*
|
|
42
|
+
* Entries are numbered in the order they are added: `heads` maps a hash to its first entry, and the
|
|
43
|
+
* lists and values of the entries are kept in arrays by number. Aliases, tags and the chains of
|
|
44
|
+
* entries that share a hash get arrays once an entry needs them.
|
|
56
45
|
*/
|
|
57
46
|
export class TypeListCache {
|
|
58
|
-
|
|
47
|
+
heads;
|
|
48
|
+
lists;
|
|
49
|
+
values;
|
|
50
|
+
aliases;
|
|
51
|
+
tags;
|
|
52
|
+
/** The next entry with the same hash, or -1. */
|
|
53
|
+
nexts;
|
|
54
|
+
constructor() {
|
|
55
|
+
this.heads = new Map();
|
|
56
|
+
this.lists = [];
|
|
57
|
+
this.values = [];
|
|
58
|
+
this.aliases = undefined;
|
|
59
|
+
this.tags = undefined;
|
|
60
|
+
this.nexts = undefined;
|
|
61
|
+
}
|
|
59
62
|
get(hash, types, alias, tag) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return e.value;
|
|
63
|
-
return undefined;
|
|
63
|
+
const entry = this.find(hash, types, alias, tag);
|
|
64
|
+
return entry >= 0 ? this.values[entry] : undefined;
|
|
64
65
|
}
|
|
65
66
|
set(hash, types, alias, tag, value) {
|
|
66
|
-
const head = this.
|
|
67
|
+
const head = this.heads.get(hash);
|
|
68
|
+
if (head !== undefined) {
|
|
69
|
+
const entry = this.findFrom(head, types, alias, tag);
|
|
70
|
+
if (entry >= 0) {
|
|
71
|
+
this.values[entry] = value;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const entry = this.lists.length;
|
|
76
|
+
this.lists.push(types);
|
|
77
|
+
this.values.push(value);
|
|
78
|
+
const aliases = this.aliases;
|
|
79
|
+
if (aliases !== undefined)
|
|
80
|
+
aliases.push(alias);
|
|
81
|
+
else if (alias !== undefined) {
|
|
82
|
+
const created = [];
|
|
83
|
+
for (let i = 0; i < entry; i++)
|
|
84
|
+
created.push(undefined);
|
|
85
|
+
created.push(alias);
|
|
86
|
+
this.aliases = created;
|
|
87
|
+
}
|
|
88
|
+
const tags = this.tags;
|
|
89
|
+
if (tags !== undefined)
|
|
90
|
+
tags.push(tag);
|
|
91
|
+
else if (tag !== 0) {
|
|
92
|
+
const created = [];
|
|
93
|
+
for (let i = 0; i < entry; i++)
|
|
94
|
+
created.push(0);
|
|
95
|
+
created.push(tag);
|
|
96
|
+
this.tags = created;
|
|
97
|
+
}
|
|
98
|
+
let nexts = this.nexts;
|
|
99
|
+
if (nexts !== undefined)
|
|
100
|
+
nexts.push(-1);
|
|
67
101
|
if (head === undefined) {
|
|
68
|
-
this.
|
|
102
|
+
this.heads.set(hash, entry);
|
|
69
103
|
return;
|
|
70
104
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
105
|
+
// A second entry with this hash: chain it after the first.
|
|
106
|
+
if (nexts === undefined) {
|
|
107
|
+
nexts = [];
|
|
108
|
+
for (let i = 0; i <= entry; i++)
|
|
109
|
+
nexts.push(-1);
|
|
110
|
+
this.nexts = nexts;
|
|
111
|
+
}
|
|
112
|
+
nexts[entry] = nexts[head];
|
|
113
|
+
nexts[head] = entry;
|
|
79
114
|
}
|
|
80
115
|
clear() {
|
|
81
|
-
this.
|
|
116
|
+
this.heads = new Map();
|
|
117
|
+
this.lists = [];
|
|
118
|
+
this.values = [];
|
|
119
|
+
this.aliases = undefined;
|
|
120
|
+
this.tags = undefined;
|
|
121
|
+
this.nexts = undefined;
|
|
122
|
+
}
|
|
123
|
+
/** The number of the entry with these parts, or -1. */
|
|
124
|
+
find(hash, types, alias, tag) {
|
|
125
|
+
const head = this.heads.get(hash);
|
|
126
|
+
return head !== undefined ? this.findFrom(head, types, alias, tag) : -1;
|
|
127
|
+
}
|
|
128
|
+
findFrom(head, types, alias, tag) {
|
|
129
|
+
const tags = this.tags;
|
|
130
|
+
const aliases = this.aliases;
|
|
131
|
+
const nexts = this.nexts;
|
|
132
|
+
for (let entry = head; entry >= 0; entry = nexts !== undefined ? nexts[entry] : -1)
|
|
133
|
+
if ((tags !== undefined ? tags[entry] : 0) === tag &&
|
|
134
|
+
sameTypeListParts(this.lists[entry], types) &&
|
|
135
|
+
sameAliasParts(aliases !== undefined ? aliases[entry] : undefined, alias))
|
|
136
|
+
return entry;
|
|
137
|
+
return -1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* One list for each sequence of types that a checker keeps (`Checker.typeLists`): references and
|
|
142
|
+
* instantiation caches hold the same type arguments in many places, mostly lists of one or two types,
|
|
143
|
+
* and share one list for them. A list must not change once it is in the table.
|
|
144
|
+
*/
|
|
145
|
+
export class TypeListTable {
|
|
146
|
+
heads = new Map();
|
|
147
|
+
lists = [];
|
|
148
|
+
/** The next list with the same hash, or -1, once two lists share one. */
|
|
149
|
+
nexts = undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The list in the table with the types of `types`, in order, or `types` itself, which joins the
|
|
152
|
+
* table. `hash` is `typeListHash(types, undefined, 0)`.
|
|
153
|
+
*/
|
|
154
|
+
intern(hash, types) {
|
|
155
|
+
if (types.length === 0)
|
|
156
|
+
return types;
|
|
157
|
+
const head = this.heads.get(hash);
|
|
158
|
+
const nexts = this.nexts;
|
|
159
|
+
if (head !== undefined)
|
|
160
|
+
for (let entry = head; entry >= 0; entry = nexts !== undefined ? nexts[entry] : -1) {
|
|
161
|
+
const list = this.lists[entry];
|
|
162
|
+
if (sameTypeListParts(list, types))
|
|
163
|
+
return list;
|
|
164
|
+
}
|
|
165
|
+
const entry = this.lists.length;
|
|
166
|
+
this.lists.push(types);
|
|
167
|
+
if (nexts !== undefined)
|
|
168
|
+
nexts.push(-1);
|
|
169
|
+
if (head === undefined) {
|
|
170
|
+
this.heads.set(hash, entry);
|
|
171
|
+
return types;
|
|
172
|
+
}
|
|
173
|
+
// A second list with this hash: chain it after the first.
|
|
174
|
+
let chain = nexts;
|
|
175
|
+
if (chain === undefined) {
|
|
176
|
+
chain = [];
|
|
177
|
+
for (let i = 0; i <= entry; i++)
|
|
178
|
+
chain.push(-1);
|
|
179
|
+
this.nexts = chain;
|
|
180
|
+
}
|
|
181
|
+
chain[entry] = chain[head];
|
|
182
|
+
chain[head] = entry;
|
|
183
|
+
return types;
|
|
82
184
|
}
|
|
83
185
|
}
|
|
84
186
|
/**
|
|
@@ -133,7 +235,7 @@ export class TypeExtra {
|
|
|
133
235
|
origin;
|
|
134
236
|
keyPropertyName;
|
|
135
237
|
constituentMap;
|
|
136
|
-
|
|
238
|
+
constituentIds;
|
|
137
239
|
membershipTests;
|
|
138
240
|
// IntersectionType
|
|
139
241
|
uniqueLiteralFilledInstantiation;
|
|
@@ -146,7 +248,7 @@ export class TypeExtra {
|
|
|
146
248
|
this.origin = undefined;
|
|
147
249
|
this.keyPropertyName = '';
|
|
148
250
|
this.constituentMap = undefined;
|
|
149
|
-
this.
|
|
251
|
+
this.constituentIds = undefined;
|
|
150
252
|
this.membershipTests = 0;
|
|
151
253
|
this.uniqueLiteralFilledInstantiation = undefined;
|
|
152
254
|
}
|
|
@@ -635,19 +737,43 @@ export class EvolvingArrayType extends ObjectType {
|
|
|
635
737
|
this.finalArrayType = undefined;
|
|
636
738
|
}
|
|
637
739
|
}
|
|
638
|
-
|
|
740
|
+
/**
|
|
741
|
+
* A union or intersection. Few have their members resolved or their properties cached, so those
|
|
742
|
+
* live in `membersOf` (`UnionOrIntersectionMembers`), which is created when they are first written.
|
|
743
|
+
*/
|
|
744
|
+
export class UnionOrIntersectionType extends Type {
|
|
639
745
|
types;
|
|
640
|
-
|
|
641
|
-
propertyCacheWithoutFunctionPropertyAugment;
|
|
642
|
-
resolvedProperties;
|
|
746
|
+
membersOf;
|
|
643
747
|
constructor(flags, objectFlags, id, types) {
|
|
644
748
|
super(flags, objectFlags, id, undefined);
|
|
645
749
|
this.types = types;
|
|
750
|
+
this.membersOf = undefined;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* The resolved members of a union or intersection (`membersHolder`) and the caches of its
|
|
755
|
+
* properties, created on first use.
|
|
756
|
+
*/
|
|
757
|
+
export class UnionOrIntersectionMembers extends StructuredType {
|
|
758
|
+
propertyCache;
|
|
759
|
+
propertyCacheWithoutFunctionPropertyAugment;
|
|
760
|
+
resolvedProperties;
|
|
761
|
+
constructor(flags, id) {
|
|
762
|
+
super(flags, 0 /* ObjectFlags.None */, id, undefined);
|
|
646
763
|
this.propertyCache = undefined;
|
|
647
764
|
this.propertyCacheWithoutFunctionPropertyAugment = undefined;
|
|
648
765
|
this.resolvedProperties = undefined;
|
|
649
766
|
}
|
|
650
767
|
}
|
|
768
|
+
/** The members holder of a union or intersection, created if it has none yet. */
|
|
769
|
+
export function unionOrIntersectionMembers(t) {
|
|
770
|
+
let members = t.membersOf;
|
|
771
|
+
if (members === undefined) {
|
|
772
|
+
members = new UnionOrIntersectionMembers(t.flags, t.id);
|
|
773
|
+
t.membersOf = members;
|
|
774
|
+
}
|
|
775
|
+
return members;
|
|
776
|
+
}
|
|
651
777
|
/** A union; all of its own fields are rarely set and live in `extra`. */
|
|
652
778
|
export class UnionType extends UnionOrIntersectionType {
|
|
653
779
|
constructor(objectFlags, id, types) {
|
|
@@ -695,14 +821,18 @@ export class UnionType extends UnionOrIntersectionType {
|
|
|
695
821
|
if (map !== undefined || this.extra !== undefined)
|
|
696
822
|
typeExtra(this).constituentMap = map;
|
|
697
823
|
}
|
|
698
|
-
/**
|
|
699
|
-
|
|
824
|
+
/**
|
|
825
|
+
* A hash table of the ids of a large union's constituents, for membership tests; created on the
|
|
826
|
+
* second test (`constituentTable`). About eight bytes a constituent, where a set of them took
|
|
827
|
+
* about five times that.
|
|
828
|
+
*/
|
|
829
|
+
get constituentIds() {
|
|
700
830
|
const extra = this.extra;
|
|
701
|
-
return extra !== undefined ? extra.
|
|
831
|
+
return extra !== undefined ? extra.constituentIds : undefined;
|
|
702
832
|
}
|
|
703
|
-
set
|
|
704
|
-
if (
|
|
705
|
-
typeExtra(this).
|
|
833
|
+
set constituentIds(ids) {
|
|
834
|
+
if (ids !== undefined || this.extra !== undefined)
|
|
835
|
+
typeExtra(this).constituentIds = ids;
|
|
706
836
|
}
|
|
707
837
|
get membershipTests() {
|
|
708
838
|
const extra = this.extra;
|
|
@@ -1111,6 +1241,40 @@ export class ArrayTypeMapper extends TypeMapper {
|
|
|
1111
1241
|
mapsThisOnly() {
|
|
1112
1242
|
return this.sources.length === 1 && isThisTypeParameter(this.sources[0]);
|
|
1113
1243
|
}
|
|
1244
|
+
/** The number of targets, one per source. */
|
|
1245
|
+
targetCount() {
|
|
1246
|
+
return this.targets.length;
|
|
1247
|
+
}
|
|
1248
|
+
/** The target of the source at `index`. */
|
|
1249
|
+
targetAt(index) {
|
|
1250
|
+
return this.targets[index];
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* The mapper of a type reference's members: its type arguments, then the reference itself for the
|
|
1255
|
+
* last source, the class or interface's `this` type. `targets` holds the type arguments only, so the
|
|
1256
|
+
* reference's own list serves without a copy that adds the reference.
|
|
1257
|
+
*/
|
|
1258
|
+
export class ThisArgumentTypeMapper extends ArrayTypeMapper {
|
|
1259
|
+
thisTarget;
|
|
1260
|
+
constructor(sources, typeArguments, thisTarget) {
|
|
1261
|
+
super(sources, typeArguments);
|
|
1262
|
+
this.thisTarget = thisTarget;
|
|
1263
|
+
}
|
|
1264
|
+
map(type) {
|
|
1265
|
+
const sources = this.sources;
|
|
1266
|
+
const last = sources.length - 1;
|
|
1267
|
+
for (let i = 0; i < last; i++)
|
|
1268
|
+
if (type === sources[i])
|
|
1269
|
+
return this.targets[i];
|
|
1270
|
+
return type === sources[last] ? this.thisTarget : type;
|
|
1271
|
+
}
|
|
1272
|
+
targetCount() {
|
|
1273
|
+
return this.targets.length + 1;
|
|
1274
|
+
}
|
|
1275
|
+
targetAt(index) {
|
|
1276
|
+
return index < this.targets.length ? this.targets[index] : this.thisTarget;
|
|
1277
|
+
}
|
|
1114
1278
|
}
|
|
1115
1279
|
/**
|
|
1116
1280
|
* The number of sources from which a mapper looks types up in an index. A tuple reference with thousands of
|
|
@@ -1178,6 +1342,19 @@ export function newTypeMapper(sources, targets) {
|
|
|
1178
1342
|
? new IndexedArrayTypeMapper(sources, targets)
|
|
1179
1343
|
: new ArrayTypeMapper(sources, targets);
|
|
1180
1344
|
}
|
|
1345
|
+
/** `newTypeMapper(sources, [...typeArguments, thisTarget])`, without building that list where it can. */
|
|
1346
|
+
export function newThisArgumentTypeMapper(sources, typeArguments, thisTarget) {
|
|
1347
|
+
if (sources.length === 1)
|
|
1348
|
+
return new SimpleTypeMapper(sources[0], thisTarget);
|
|
1349
|
+
if (sources.length >= indexedTypeMapperThreshold) {
|
|
1350
|
+
const targets = [];
|
|
1351
|
+
for (const t of typeArguments)
|
|
1352
|
+
targets.push(t);
|
|
1353
|
+
targets.push(thisTarget);
|
|
1354
|
+
return new IndexedArrayTypeMapper(sources, targets);
|
|
1355
|
+
}
|
|
1356
|
+
return new ThisArgumentTypeMapper(sources, typeArguments, thisTarget);
|
|
1357
|
+
}
|
|
1181
1358
|
export function mergeTypeMappers(m1, m2) {
|
|
1182
1359
|
return m1 !== undefined ? new MergedTypeMapper(m1, m2) : m2;
|
|
1183
1360
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Node, type SourceFile } from './ast.js';
|
|
2
2
|
import { type Checker } from './checker.js';
|
|
3
|
-
import { type Symbol } from './symbol.js';
|
|
4
3
|
import type { Type } from './checker-types.js';
|
|
4
|
+
import { type Symbol } from './symbol.js';
|
|
5
5
|
/** Whether `node` is only written, as the target of `=` or of a for-in/of initializer. */
|
|
6
6
|
export declare function isWriteOnlyAccess(node: Node): boolean;
|
|
7
7
|
/** Whether `node` is written, possibly also read. */
|
|
@@ -7,7 +7,6 @@ import { isAmbientModule, isAssignmentOperator, isGlobalScopeAugmentation, isTyp
|
|
|
7
7
|
import { getCombinedNodeFlags, getModifierFlags, getRootDeclaration, getSourceFileOfNode, hasSyntacticModifier, isExternalOrCommonJSModule, isParameterPropertyDeclaration, } from './binder-utilities.js';
|
|
8
8
|
import { createDiagnosticForNode } from './checker.js';
|
|
9
9
|
import { Diagnostic } from './diagnostics.js';
|
|
10
|
-
import { getSymbolId } from './symbol.js';
|
|
11
10
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
12
11
|
import { getResolvedSymbol } from './checker-expressions.js';
|
|
13
12
|
import { skipTrivia } from './scanner.js';
|
|
@@ -17,6 +16,7 @@ import { symbolToString } from './type-printer.js';
|
|
|
17
16
|
import { getLiteralTypeFromPropertyName } from './checker-type-operators.js';
|
|
18
17
|
import { getPropertyOfType } from './checker-members.js';
|
|
19
18
|
import { getPropertyNameFromType, isTypeUsableAsPropertyName } from './checker-utilities.js';
|
|
19
|
+
import { getDeclarations, getSymbolId } from './symbol.js';
|
|
20
20
|
// ---- References
|
|
21
21
|
/** Whether `node` is only written, as the target of `=` or of a for-in/of initializer. */
|
|
22
22
|
export function isWriteOnlyAccess(node) {
|
|
@@ -342,7 +342,7 @@ function checkUnusedLocalsAndParameters(c, node) {
|
|
|
342
342
|
local.exportSymbol !== undefined ||
|
|
343
343
|
(local.flags & 134217728 /* SymbolFlags.ModuleExports */) !== 0)
|
|
344
344
|
continue;
|
|
345
|
-
for (const declaration of local
|
|
345
|
+
for (const declaration of getDeclarations(local)) {
|
|
346
346
|
switch (declaration.kind) {
|
|
347
347
|
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
348
348
|
case 170 /* SyntaxKind.Parameter */:
|
|
@@ -513,7 +513,7 @@ function isUnreferencedTypeParameter(c, typeParameter) {
|
|
|
513
513
|
return ((referenceKinds & 262144 /* SymbolFlags.TypeParameter */) === 0 && !isIdentifierThatStartsWithUnderscore(getName(typeParameter)));
|
|
514
514
|
}
|
|
515
515
|
function allDeclarationsInSameSourceFile(symbol) {
|
|
516
|
-
const declarations = symbol
|
|
516
|
+
const declarations = getDeclarations(symbol);
|
|
517
517
|
if (declarations.length <= 1)
|
|
518
518
|
return true;
|
|
519
519
|
const file = getSourceFileOfNode(declarations[0]);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DeferredCollisionCheck } from './checker-generated-code.js';
|
|
2
2
|
import type { EmitHelperFileLinks } from './checker-emit-helpers.js';
|
|
3
3
|
import type { Node, PatternAmbientModule, SourceFile } from './ast.js';
|
|
4
|
-
import { IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
|
|
4
|
+
import { CompactSymbolLinkTable, IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
|
|
5
5
|
import { Diagnostic, type DiagnosticMessage, Diagnostics } from './diagnostics.js';
|
|
6
6
|
import { type CompilerOptions, ModuleKind, ScriptTarget } from './options.js';
|
|
7
7
|
import { CheckFlags, Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
8
|
-
import { IndexInfo, IntrinsicType, LiteralType, MemberNames, NodeLinks, ObjectFlags, ObjectType, Signature, SignatureFlags, SymbolLinks, type Type, TypeFlags, TypeMapper, TypeParameter, TypePredicate, VarianceFlags, TypeListCache, type ConditionalType, type InterfaceType, type TypeChecking } from './checker-types.js';
|
|
8
|
+
import { IndexInfo, IntrinsicType, LiteralType, MemberNames, NodeLinks, ObjectFlags, ObjectType, Signature, SignatureFlags, SymbolLinks, type Type, TypeFlags, TypeMapper, TypeParameter, TypePredicate, VarianceFlags, TypeListCache, TypeListTable, type ConditionalType, type InterfaceType, type TypeChecking } from './checker-types.js';
|
|
9
9
|
import { CheckerNameResolver, type LibGlobals, type MergedGlobals, TableChanges, SuggestionNameResolver } from './checker-symbols.js';
|
|
10
10
|
import { Relation, RelationKey, type InternedRelationKey, type Relater, TypeComparer } from './relations.js';
|
|
11
11
|
import { TypeNodeVisitor } from './checker-source-file.js';
|
|
@@ -15,7 +15,6 @@ import type { FlowNode, FlowReduceLabel } from './flow.js';
|
|
|
15
15
|
import { JsxState } from './checker-jsx.js';
|
|
16
16
|
import type { DeferredIterationError, IterationTypes } from './checker-iteration.js';
|
|
17
17
|
import type { SpreadIndices } from './checker-contextual.js';
|
|
18
|
-
import type { SlotSiblingProperties } from './checker-symbol-types.js';
|
|
19
18
|
import { SourceFileMetadata } from './program-utilities.js';
|
|
20
19
|
import type { GrammarChecker } from './checker-grammar.js';
|
|
21
20
|
import type { ResolvedModule } from './module-resolution-types.js';
|
|
@@ -77,6 +76,21 @@ declare class DiagnosticCollection {
|
|
|
77
76
|
}
|
|
78
77
|
/** Maximum depth of nested `typeToString` calls before diagnostics are discarded. */
|
|
79
78
|
export declare const maxSerializationLevel = 2;
|
|
79
|
+
/**
|
|
80
|
+
* File positions per symbol id in `ExternalModuleContainerIndex.keys`. Symbol ids are int32, so the
|
|
81
|
+
* keys stay exact.
|
|
82
|
+
*/
|
|
83
|
+
export declare const fileIndexScale: number;
|
|
84
|
+
/** The modules that export each symbol, built once from every module's exports. */
|
|
85
|
+
export declare class ExternalModuleContainerIndex {
|
|
86
|
+
complete: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* One key per symbol and module that exports it, ascending: the id of the symbol the export
|
|
89
|
+
* resolves to times `fileIndexScale`, plus the module's file position in `Checker.files`. The
|
|
90
|
+
* keys of one symbol are contiguous and in program order.
|
|
91
|
+
*/
|
|
92
|
+
keys: number[];
|
|
93
|
+
}
|
|
80
94
|
/** The checker's caches for symbol accessibility. */
|
|
81
95
|
export declare class SymbolAccessibilityCaches {
|
|
82
96
|
/** Accessible chains by symbol id, then by `chainCacheKey`. */
|
|
@@ -87,6 +101,8 @@ export declare class SymbolAccessibilityCaches {
|
|
|
87
101
|
readonly containersByFile: Map<number, Map<number, Symbol[]>>;
|
|
88
102
|
/** All modules that export a symbol, by symbol id. */
|
|
89
103
|
readonly containers: Map<number, Symbol[]>;
|
|
104
|
+
/** The modules each symbol is exported from, built on the first search of all modules. */
|
|
105
|
+
externalModuleContainers: ExternalModuleContainerIndex | undefined;
|
|
90
106
|
/** The name tables of named class expressions, by node id. */
|
|
91
107
|
readonly classExpressionNames: Map<number, SymbolTable>;
|
|
92
108
|
/** Computed declaration visibility by node id (see isDeclarationVisible), 0 if not computed. */
|
|
@@ -165,7 +181,7 @@ export declare class Checker implements TypeChecking {
|
|
|
165
181
|
/** Bits of SymbolFlags for the meanings in which a symbol was referenced. */
|
|
166
182
|
readonly symbolReferenceKinds: IntLinkTable;
|
|
167
183
|
/** The resolved symbol of an identifier, entity name or call. */
|
|
168
|
-
readonly resolvedSymbols:
|
|
184
|
+
readonly resolvedSymbols: CompactSymbolLinkTable;
|
|
169
185
|
/** The resolved type of a type node or expression. */
|
|
170
186
|
readonly resolvedTypes: SparseLinkTable<Type>;
|
|
171
187
|
/** The resolved signature of a call-like node or a signature declaration. */
|
|
@@ -201,10 +217,6 @@ export declare class Checker implements TypeChecking {
|
|
|
201
217
|
readonly unresolvedSymbols: Map<string, Symbol>;
|
|
202
218
|
/** Widening's optional `undefined` properties by the id of the property each is created from. */
|
|
203
219
|
readonly undefinedProperties: Map<number, Symbol>;
|
|
204
|
-
/** By file and name, the property that widening's optional `undefined` properties are created from. */
|
|
205
|
-
readonly firstSiblingProperties: Map<SourceFile, Map<string, Node>>;
|
|
206
|
-
/** By tsgo checker, the first sibling properties of its files (firstSiblingProperty). */
|
|
207
|
-
readonly slotSiblingProperties: Map<number, SlotSiblingProperties>;
|
|
208
220
|
readonly stringLiteralTypes: Map<string, LiteralType>;
|
|
209
221
|
readonly numberLiteralTypes: Map<number, LiteralType>;
|
|
210
222
|
readonly bigintLiteralTypes: Map<string, LiteralType>;
|
|
@@ -222,6 +234,8 @@ export declare class Checker implements TypeChecking {
|
|
|
222
234
|
readonly templateLiteralTypes: Map<string, Type>;
|
|
223
235
|
/** Instantiations of template literal types: the instantiated types, tagged with the template's id. */
|
|
224
236
|
readonly templateLiteralInstantiations: TypeListCache<Type>;
|
|
237
|
+
/** The type argument lists that references and instantiations keep, one of each (`TypeListTable`). */
|
|
238
|
+
readonly typeLists: TypeListTable;
|
|
225
239
|
readonly stringMappingTypes: Map<string, Type>;
|
|
226
240
|
readonly substitutionTypes: Map<string, Type>;
|
|
227
241
|
readonly subtypeReductionCache: TypeListCache<Type[]>;
|
|
@@ -347,6 +361,13 @@ export declare class Checker implements TypeChecking {
|
|
|
347
361
|
*/
|
|
348
362
|
readonly freeMapperCaches: Map<number, Type>[];
|
|
349
363
|
freeMapperCacheCount: number;
|
|
364
|
+
/** Empty lists for type arguments that are compared with cached instantiations before any is kept. */
|
|
365
|
+
readonly freeTypeLists: Type[][];
|
|
366
|
+
/**
|
|
367
|
+
* 1 by type id for the anonymous and mapped types whose declaration has no outer type parameters
|
|
368
|
+
* to instantiate (`getObjectTypeInstantiation`).
|
|
369
|
+
*/
|
|
370
|
+
readonly withoutOuterTypeParameters: IntLinkTable;
|
|
350
371
|
conditionalConstraintDepth: number;
|
|
351
372
|
readonly suggestionResolver: SuggestionNameResolver;
|
|
352
373
|
readonly awaitedTypeStack: number[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { sideOf } from './side-state.js';
|
|
2
|
-
import { IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
|
|
2
|
+
import { CompactSymbolLinkTable, IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
|
|
3
3
|
import { getErrorRangeForNode, getSourceFileOfNode } from './binder-utilities.js';
|
|
4
4
|
import { Diagnostic, compareDiagnostics } from './diagnostics.js';
|
|
5
5
|
import { ModuleKind, ScriptTarget, getEmitScriptTarget, getIsolatedModules, getStrictOptionValue, shouldPreserveConstEnums, } from './options.js';
|
|
6
6
|
import { Symbol, getSymbolId } from './symbol.js';
|
|
7
|
-
import { IndexInfo, IntrinsicType, LiteralType, NodeLinks, Signature, SymbolLinks, TypeParameter, TypePredicate, emptyTypes, TypeListCache, } from './checker-types.js';
|
|
7
|
+
import { IndexInfo, IntrinsicType, LiteralType, NodeLinks, Signature, SymbolLinks, TypeParameter, TypePredicate, emptyTypes, TypeListCache, TypeListTable, } from './checker-types.js';
|
|
8
8
|
import { getBaseTypes } from './checker-declared-types.js';
|
|
9
9
|
import { getFalseTypeFromConditionalType, getTrueTypeFromConditionalType } from './checker-type-operators.js';
|
|
10
10
|
import { createArrayType, createTypeFromGenericGlobalType, getBigIntLiteralType, getNumberLiteralType, getStringLiteralType, getTemplateLiteralType, getUnionType, newAnonymousType, newObjectType, } from './checker-type-factory.js';
|
|
@@ -154,6 +154,21 @@ function stableSort(list) {
|
|
|
154
154
|
}
|
|
155
155
|
/** Maximum depth of nested `typeToString` calls before diagnostics are discarded. */
|
|
156
156
|
export const maxSerializationLevel = 2;
|
|
157
|
+
/**
|
|
158
|
+
* File positions per symbol id in `ExternalModuleContainerIndex.keys`. Symbol ids are int32, so the
|
|
159
|
+
* keys stay exact.
|
|
160
|
+
*/
|
|
161
|
+
export const fileIndexScale = 2 ** 21;
|
|
162
|
+
/** The modules that export each symbol, built once from every module's exports. */
|
|
163
|
+
export class ExternalModuleContainerIndex {
|
|
164
|
+
complete = false;
|
|
165
|
+
/**
|
|
166
|
+
* One key per symbol and module that exports it, ascending: the id of the symbol the export
|
|
167
|
+
* resolves to times `fileIndexScale`, plus the module's file position in `Checker.files`. The
|
|
168
|
+
* keys of one symbol are contiguous and in program order.
|
|
169
|
+
*/
|
|
170
|
+
keys = [];
|
|
171
|
+
}
|
|
157
172
|
/** The checker's caches for symbol accessibility. */
|
|
158
173
|
export class SymbolAccessibilityCaches {
|
|
159
174
|
/** Accessible chains by symbol id, then by `chainCacheKey`. */
|
|
@@ -164,6 +179,8 @@ export class SymbolAccessibilityCaches {
|
|
|
164
179
|
containersByFile = new Map();
|
|
165
180
|
/** All modules that export a symbol, by symbol id. */
|
|
166
181
|
containers = new Map();
|
|
182
|
+
/** The modules each symbol is exported from, built on the first search of all modules. */
|
|
183
|
+
externalModuleContainers = undefined;
|
|
167
184
|
/** The name tables of named class expressions, by node id. */
|
|
168
185
|
classExpressionNames = new Map();
|
|
169
186
|
/** Computed declaration visibility by node id (see isDeclarationVisible), 0 if not computed. */
|
|
@@ -246,7 +263,7 @@ export class Checker {
|
|
|
246
263
|
/** Bits of SymbolFlags for the meanings in which a symbol was referenced. */
|
|
247
264
|
symbolReferenceKinds = new IntLinkTable();
|
|
248
265
|
/** The resolved symbol of an identifier, entity name or call. */
|
|
249
|
-
resolvedSymbols = new
|
|
266
|
+
resolvedSymbols = new CompactSymbolLinkTable();
|
|
250
267
|
/** The resolved type of a type node or expression. */
|
|
251
268
|
resolvedTypes = new SparseLinkTable();
|
|
252
269
|
/** The resolved signature of a call-like node or a signature declaration. */
|
|
@@ -283,10 +300,6 @@ export class Checker {
|
|
|
283
300
|
unresolvedSymbols = new Map();
|
|
284
301
|
/** Widening's optional `undefined` properties by the id of the property each is created from. */
|
|
285
302
|
undefinedProperties = new Map();
|
|
286
|
-
/** By file and name, the property that widening's optional `undefined` properties are created from. */
|
|
287
|
-
firstSiblingProperties = new Map();
|
|
288
|
-
/** By tsgo checker, the first sibling properties of its files (firstSiblingProperty). */
|
|
289
|
-
slotSiblingProperties = new Map();
|
|
290
303
|
// Interning tables.
|
|
291
304
|
stringLiteralTypes = new Map();
|
|
292
305
|
numberLiteralTypes = new Map();
|
|
@@ -305,6 +318,8 @@ export class Checker {
|
|
|
305
318
|
templateLiteralTypes = new Map();
|
|
306
319
|
/** Instantiations of template literal types: the instantiated types, tagged with the template's id. */
|
|
307
320
|
templateLiteralInstantiations = new TypeListCache();
|
|
321
|
+
/** The type argument lists that references and instantiations keep, one of each (`TypeListTable`). */
|
|
322
|
+
typeLists = new TypeListTable();
|
|
308
323
|
stringMappingTypes = new Map();
|
|
309
324
|
substitutionTypes = new Map();
|
|
310
325
|
subtypeReductionCache = new TypeListCache();
|
|
@@ -436,6 +451,13 @@ export class Checker {
|
|
|
436
451
|
*/
|
|
437
452
|
freeMapperCaches = [];
|
|
438
453
|
freeMapperCacheCount = 0;
|
|
454
|
+
/** Empty lists for type arguments that are compared with cached instantiations before any is kept. */
|
|
455
|
+
freeTypeLists = [];
|
|
456
|
+
/**
|
|
457
|
+
* 1 by type id for the anonymous and mapped types whose declaration has no outer type parameters
|
|
458
|
+
* to instantiate (`getObjectTypeInstantiation`).
|
|
459
|
+
*/
|
|
460
|
+
withoutOuterTypeParameters = new IntLinkTable();
|
|
439
461
|
conditionalConstraintDepth = 0;
|
|
440
462
|
suggestionResolver;
|
|
441
463
|
awaitedTypeStack = [];
|
|
@@ -858,8 +880,6 @@ export function disposeChecker(c) {
|
|
|
858
880
|
c.symbolAccessibilityCaches = undefined;
|
|
859
881
|
c.unresolvedSymbols.clear();
|
|
860
882
|
c.undefinedProperties.clear();
|
|
861
|
-
c.firstSiblingProperties.clear();
|
|
862
|
-
c.slotSiblingProperties.clear();
|
|
863
883
|
c.stringLiteralTypes.clear();
|
|
864
884
|
c.numberLiteralTypes.clear();
|
|
865
885
|
c.bigintLiteralTypes.clear();
|
|
@@ -32,9 +32,8 @@ export declare function localizeMessage(locale: Locale, message: DiagnosticMessa
|
|
|
32
32
|
export declare function formatMessage(text: string, args: readonly string[]): string;
|
|
33
33
|
/**
|
|
34
34
|
* Makes this thread compute the caches of files that do not have them yet in copies of its own: the
|
|
35
|
-
* files may be published (immutable) and shared with other threads.
|
|
36
|
-
*
|
|
37
|
-
* and are rarely checked or pointed into by a diagnostic.
|
|
35
|
+
* files may be published (immutable) and shared with other threads. Files leave the parser without
|
|
36
|
+
* them (`Parser.parseSourceFile`): most files are never pointed into by a diagnostic.
|
|
38
37
|
*/
|
|
39
38
|
export declare function useThreadTextCaches(): void;
|
|
40
39
|
/** The text of a file diagnostics point into. */
|
|
@@ -51,11 +50,6 @@ export declare class DiagnosticFile {
|
|
|
51
50
|
* thread's copy where the file may be shared (`useThreadTextCaches`).
|
|
52
51
|
*/
|
|
53
52
|
computeCaches(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Like `computeCaches`, from the text's UTF-16 code units `units[0, text.length)`, so the text
|
|
56
|
-
* itself is neither searched nor copied.
|
|
57
|
-
*/
|
|
58
|
-
computeCachesFromUnits(units: Uint16Array): void;
|
|
59
53
|
/** Start offsets of each line, split at CR, LF, CRLF, LS and PS. */
|
|
60
54
|
getLineStarts(): readonly number[];
|
|
61
55
|
private nonASCIIStarts;
|
|
@@ -125,14 +125,14 @@ function toWellFormed(text) {
|
|
|
125
125
|
/**
|
|
126
126
|
* Where this thread computes the line starts and UTF-8 offsets of files that may be shared with other
|
|
127
127
|
* threads (`useThreadTextCaches`): a copy of each such file, by file, that computes them in place.
|
|
128
|
-
* Files leave the parser
|
|
128
|
+
* Files leave the parser without line starts and UTF-8 offsets, except JSON files, which have line
|
|
129
|
+
* starts.
|
|
129
130
|
*/
|
|
130
131
|
let threadCopies = undefined;
|
|
131
132
|
/**
|
|
132
133
|
* Makes this thread compute the caches of files that do not have them yet in copies of its own: the
|
|
133
|
-
* files may be published (immutable) and shared with other threads.
|
|
134
|
-
*
|
|
135
|
-
* and are rarely checked or pointed into by a diagnostic.
|
|
134
|
+
* files may be published (immutable) and shared with other threads. Files leave the parser without
|
|
135
|
+
* them (`Parser.parseSourceFile`): most files are never pointed into by a diagnostic.
|
|
136
136
|
*/
|
|
137
137
|
export function useThreadTextCaches() {
|
|
138
138
|
if (threadCopies === undefined)
|
|
@@ -152,15 +152,6 @@ function threadCopyOf(file) {
|
|
|
152
152
|
}
|
|
153
153
|
return copy;
|
|
154
154
|
}
|
|
155
|
-
/** The position of the first code unit at or after `pos` that is a CR or below, or not ASCII; or `end`. */
|
|
156
|
-
function skipPlainASCII(units, pos, end) {
|
|
157
|
-
for (let i = pos | 0; i < end; i = (i + 1) | 0) {
|
|
158
|
-
const c = units[i] | 0;
|
|
159
|
-
if (c <= 13 /* CharacterCodes.carriageReturn */ || c >= 0x80)
|
|
160
|
-
return i;
|
|
161
|
-
}
|
|
162
|
-
return end;
|
|
163
|
-
}
|
|
164
155
|
/** The text of a file diagnostics point into. */
|
|
165
156
|
export class DiagnosticFile {
|
|
166
157
|
fileName;
|
|
@@ -182,33 +173,6 @@ export class DiagnosticFile {
|
|
|
182
173
|
if (this.lineStarts.length === 0)
|
|
183
174
|
this.lineStarts = computeLineStarts(this.text);
|
|
184
175
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Like `computeCaches`, from the text's UTF-16 code units `units[0, text.length)`, so the text
|
|
187
|
-
* itself is neither searched nor copied.
|
|
188
|
-
*/
|
|
189
|
-
computeCachesFromUnits(units) {
|
|
190
|
-
const text = this.text;
|
|
191
|
-
// ASCII texts are searched faster than walked.
|
|
192
|
-
if (this.lineStarts.length !== 0 || Buffer.byteLength(text, 'utf8') === text.length) {
|
|
193
|
-
this.computeCaches();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const length = text.length | 0;
|
|
197
|
-
const lineStarts = [0];
|
|
198
|
-
// Visit only the code units that may break a line; `skipPlainASCII` runs over the rest without
|
|
199
|
-
// calls, so native builds keep its loop on registers. A CR followed by an LF leaves the line start
|
|
200
|
-
// to the LF.
|
|
201
|
-
for (let i = skipPlainASCII(units, 0, length); i < length; i = skipPlainASCII(units, (i + 1) | 0, length)) {
|
|
202
|
-
const ch = units[i] | 0;
|
|
203
|
-
if (ch === 10 /* CharacterCodes.lineFeed */ ||
|
|
204
|
-
(ch === 13 /* CharacterCodes.carriageReturn */ &&
|
|
205
|
-
(i + 1 >= length || (units[(i + 1) | 0] | 0) !== 10 /* CharacterCodes.lineFeed */)) ||
|
|
206
|
-
ch === 8232 /* CharacterCodes.lineSeparator */ ||
|
|
207
|
-
ch === 8233 /* CharacterCodes.paragraphSeparator */)
|
|
208
|
-
lineStarts.push(i + 1);
|
|
209
|
-
}
|
|
210
|
-
this.lineStarts = lineStarts;
|
|
211
|
-
}
|
|
212
176
|
/** Start offsets of each line, split at CR, LF, CRLF, LS and PS. */
|
|
213
177
|
getLineStarts() {
|
|
214
178
|
if (this.lineStarts.length === 0) {
|