@tslite/binder 1.16.0 → 1.16.1
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/NOTICE +3 -1
- package/dist/_namespaces/ts.js +1726 -2
- package/dist/binder.d.ts +2 -2
- package/package.json +3 -3
- package/dist/binder.js +0 -1743
- package/dist/index.js +0 -4
package/dist/_namespaces/ts.js
CHANGED
|
@@ -1,3 +1,1727 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10 (Apache-2.0): o binder de src/compiler da tag, convertido e cortado até a Linguagem do TSLite. Ver o NOTICE.
|
|
2
|
+
|
|
3
|
+
// src/_namespaces/ts.ts
|
|
2
4
|
export * from "@tslite/parser";
|
|
3
|
-
|
|
5
|
+
|
|
6
|
+
// src/binder.ts
|
|
7
|
+
import {
|
|
8
|
+
Debug,
|
|
9
|
+
DiagnosticCategory,
|
|
10
|
+
Diagnostics,
|
|
11
|
+
FlowFlags,
|
|
12
|
+
InternalSymbolName,
|
|
13
|
+
ModifierFlags,
|
|
14
|
+
NodeFlags,
|
|
15
|
+
SymbolFlags,
|
|
16
|
+
SyntaxKind,
|
|
17
|
+
TokenFlags,
|
|
18
|
+
addRelatedInfo,
|
|
19
|
+
append,
|
|
20
|
+
appendIfUnique,
|
|
21
|
+
concatenate,
|
|
22
|
+
contains,
|
|
23
|
+
createDiagnosticForNodeInSourceFile,
|
|
24
|
+
createFileDiagnostic,
|
|
25
|
+
createMap,
|
|
26
|
+
createSymbolTable,
|
|
27
|
+
createUnderscoreEscapedMap,
|
|
28
|
+
declarationNameToString,
|
|
29
|
+
escapeLeadingUnderscores,
|
|
30
|
+
exportAssignmentIsAlias,
|
|
31
|
+
findAncestor,
|
|
32
|
+
forEach,
|
|
33
|
+
forEachChild,
|
|
34
|
+
getCombinedModifierFlags,
|
|
35
|
+
getCombinedNodeFlags,
|
|
36
|
+
getErrorSpanForNode,
|
|
37
|
+
getEscapedTextOfIdentifierOrLiteral,
|
|
38
|
+
getImmediatelyInvokedFunctionExpression,
|
|
39
|
+
getNameOfDeclaration,
|
|
40
|
+
getNodeId,
|
|
41
|
+
getPropertyNameForKnownSymbolName,
|
|
42
|
+
getRangesWhere,
|
|
43
|
+
getSourceFileOfNode,
|
|
44
|
+
getSpanOfTokenAtPosition,
|
|
45
|
+
getTokenPosOfNode,
|
|
46
|
+
hasDynamicName,
|
|
47
|
+
hasModifier,
|
|
48
|
+
idText,
|
|
49
|
+
isAmbientModule,
|
|
50
|
+
isAssignmentOperator,
|
|
51
|
+
isAssignmentTarget,
|
|
52
|
+
isBinaryExpression,
|
|
53
|
+
isBindingPattern,
|
|
54
|
+
isBlock,
|
|
55
|
+
isBlockOrCatchScoped,
|
|
56
|
+
isConditionalTypeNode,
|
|
57
|
+
isDottedName,
|
|
58
|
+
isElementAccessExpression,
|
|
59
|
+
isExportAssignment,
|
|
60
|
+
isExportDeclaration,
|
|
61
|
+
isExportSpecifier,
|
|
62
|
+
isExpression,
|
|
63
|
+
isExpressionOfOptionalChainRoot,
|
|
64
|
+
isExternalModule,
|
|
65
|
+
isForInOrOfStatement,
|
|
66
|
+
isFunctionLike,
|
|
67
|
+
isIdentifier,
|
|
68
|
+
isIdentifierName,
|
|
69
|
+
isLeftHandSideExpression,
|
|
70
|
+
isModuleAugmentationExternal,
|
|
71
|
+
isModuleBlock,
|
|
72
|
+
isNamedDeclaration,
|
|
73
|
+
isNamespaceExport,
|
|
74
|
+
isNullishCoalesce,
|
|
75
|
+
isOmittedExpression,
|
|
76
|
+
isOptionalChain,
|
|
77
|
+
isOptionalChainRoot,
|
|
78
|
+
isOutermostOptionalChain,
|
|
79
|
+
isParameterDeclaration,
|
|
80
|
+
isParenthesizedExpression,
|
|
81
|
+
isPrefixUnaryExpression,
|
|
82
|
+
isPropertyAccessExpression,
|
|
83
|
+
isPropertyNameLiteral,
|
|
84
|
+
isSignedNumericLiteral,
|
|
85
|
+
isSourceFile,
|
|
86
|
+
isStatement,
|
|
87
|
+
isStatementButNotDeclaration,
|
|
88
|
+
isStringLiteralLike,
|
|
89
|
+
isStringOrNumericLiteralLike,
|
|
90
|
+
isTypeAliasDeclaration,
|
|
91
|
+
isVariableStatement,
|
|
92
|
+
isTypeOfExpression,
|
|
93
|
+
isWellKnownSymbolSyntactically,
|
|
94
|
+
length,
|
|
95
|
+
nodeHasName,
|
|
96
|
+
nodeIsMissing,
|
|
97
|
+
nodeIsPresent,
|
|
98
|
+
objectAllocator,
|
|
99
|
+
perfLogger,
|
|
100
|
+
performance,
|
|
101
|
+
removeFileExtension,
|
|
102
|
+
setValueDeclaration,
|
|
103
|
+
skipParentheses,
|
|
104
|
+
sliceAfter,
|
|
105
|
+
tokenToString,
|
|
106
|
+
tryCast,
|
|
107
|
+
unescapeLeadingUnderscores,
|
|
108
|
+
unreachableCodeIsError
|
|
109
|
+
} from "@tslite/parser";
|
|
110
|
+
var ModuleInstanceState = /* @__PURE__ */ ((ModuleInstanceState2) => {
|
|
111
|
+
ModuleInstanceState2[ModuleInstanceState2["NonInstantiated"] = 0] = "NonInstantiated";
|
|
112
|
+
ModuleInstanceState2[ModuleInstanceState2["Instantiated"] = 1] = "Instantiated";
|
|
113
|
+
return ModuleInstanceState2;
|
|
114
|
+
})(ModuleInstanceState || {});
|
|
115
|
+
function getModuleInstanceState(node, visited) {
|
|
116
|
+
if (node.body && !node.body.parent) {
|
|
117
|
+
setParentPointers(node, node.body);
|
|
118
|
+
}
|
|
119
|
+
return node.body ? getModuleInstanceStateCached(node.body, visited) : 1 /* Instantiated */;
|
|
120
|
+
}
|
|
121
|
+
function getModuleInstanceStateCached(node, visited = createMap()) {
|
|
122
|
+
const nodeId = "" + getNodeId(node);
|
|
123
|
+
if (visited.has(nodeId)) {
|
|
124
|
+
return visited.get(nodeId) || 0 /* NonInstantiated */;
|
|
125
|
+
}
|
|
126
|
+
visited.set(nodeId, void 0);
|
|
127
|
+
const result = getModuleInstanceStateWorker(node, visited);
|
|
128
|
+
visited.set(nodeId, result);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function getModuleInstanceStateWorker(node, visited) {
|
|
132
|
+
switch (node.kind) {
|
|
133
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
134
|
+
return 0 /* NonInstantiated */;
|
|
135
|
+
case SyntaxKind.ImportDeclaration:
|
|
136
|
+
if (!hasModifier(node, ModifierFlags.Export)) {
|
|
137
|
+
return 0 /* NonInstantiated */;
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case SyntaxKind.ExportDeclaration:
|
|
141
|
+
const exportDeclaration = node;
|
|
142
|
+
if (!exportDeclaration.moduleSpecifier && exportDeclaration.exportClause && exportDeclaration.exportClause.kind === SyntaxKind.NamedExports) {
|
|
143
|
+
let state = 0 /* NonInstantiated */;
|
|
144
|
+
for (const specifier of exportDeclaration.exportClause.elements) {
|
|
145
|
+
const specifierState = getModuleInstanceStateForAliasTarget(specifier, visited);
|
|
146
|
+
if (specifierState > state) {
|
|
147
|
+
state = specifierState;
|
|
148
|
+
}
|
|
149
|
+
if (state === 1 /* Instantiated */) {
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return state;
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case SyntaxKind.ModuleBlock: {
|
|
157
|
+
let state = 0 /* NonInstantiated */;
|
|
158
|
+
forEachChild(node, (n) => {
|
|
159
|
+
const childState = getModuleInstanceStateCached(n, visited);
|
|
160
|
+
switch (childState) {
|
|
161
|
+
case 0 /* NonInstantiated */:
|
|
162
|
+
return;
|
|
163
|
+
case 1 /* Instantiated */:
|
|
164
|
+
state = 1 /* Instantiated */;
|
|
165
|
+
return true;
|
|
166
|
+
default:
|
|
167
|
+
Debug.assertNever(childState);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return state;
|
|
171
|
+
}
|
|
172
|
+
case SyntaxKind.ModuleDeclaration:
|
|
173
|
+
return getModuleInstanceState(node, visited);
|
|
174
|
+
}
|
|
175
|
+
return 1 /* Instantiated */;
|
|
176
|
+
}
|
|
177
|
+
function getModuleInstanceStateForAliasTarget(specifier, visited) {
|
|
178
|
+
const name = specifier.propertyName || specifier.name;
|
|
179
|
+
let p = specifier.parent;
|
|
180
|
+
while (p) {
|
|
181
|
+
if (isBlock(p) || isModuleBlock(p) || isSourceFile(p)) {
|
|
182
|
+
const statements = p.statements;
|
|
183
|
+
let found;
|
|
184
|
+
for (const statement of statements) {
|
|
185
|
+
if (nodeHasName(statement, name)) {
|
|
186
|
+
if (!statement.parent) {
|
|
187
|
+
setParentPointers(p, statement);
|
|
188
|
+
}
|
|
189
|
+
const state = getModuleInstanceStateCached(statement, visited);
|
|
190
|
+
if (found === void 0 || state > found) {
|
|
191
|
+
found = state;
|
|
192
|
+
}
|
|
193
|
+
if (found === 1 /* Instantiated */) {
|
|
194
|
+
return found;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (found !== void 0) {
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
p = p.parent;
|
|
203
|
+
}
|
|
204
|
+
return 1 /* Instantiated */;
|
|
205
|
+
}
|
|
206
|
+
function initFlowNode(node) {
|
|
207
|
+
Debug.attachFlowNodeDebugInfo(node);
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
var binder = createBinder();
|
|
211
|
+
function bindSourceFile(file, options) {
|
|
212
|
+
performance.mark("beforeBind");
|
|
213
|
+
perfLogger.logStartBindFile("" + file.fileName);
|
|
214
|
+
binder(file, options);
|
|
215
|
+
perfLogger.logStopBindFile();
|
|
216
|
+
performance.mark("afterBind");
|
|
217
|
+
performance.measure("Bind", "beforeBind", "afterBind");
|
|
218
|
+
}
|
|
219
|
+
function createBinder() {
|
|
220
|
+
let file;
|
|
221
|
+
let options;
|
|
222
|
+
let parent;
|
|
223
|
+
let container;
|
|
224
|
+
let blockScopeContainer;
|
|
225
|
+
let lastContainer;
|
|
226
|
+
let currentFlow;
|
|
227
|
+
let currentBreakTarget;
|
|
228
|
+
let currentContinueTarget;
|
|
229
|
+
let currentReturnTarget;
|
|
230
|
+
let currentTrueTarget;
|
|
231
|
+
let currentFalseTarget;
|
|
232
|
+
let currentExceptionTarget;
|
|
233
|
+
let preSwitchCaseFlow;
|
|
234
|
+
let hasExplicitReturn;
|
|
235
|
+
let inStrictMode;
|
|
236
|
+
let Symbol;
|
|
237
|
+
let classifiableNames;
|
|
238
|
+
const unreachableFlow = { flags: FlowFlags.Unreachable };
|
|
239
|
+
const reportedUnreachableFlow = { flags: FlowFlags.Unreachable };
|
|
240
|
+
function createDiagnosticForNode(node, message, arg0, arg1, arg2) {
|
|
241
|
+
return createDiagnosticForNodeInSourceFile(getSourceFileOfNode(node) || file, node, message, arg0, arg1, arg2);
|
|
242
|
+
}
|
|
243
|
+
function bindSourceFile2(f, opts) {
|
|
244
|
+
file = f;
|
|
245
|
+
options = opts;
|
|
246
|
+
inStrictMode = bindInStrictMode(file);
|
|
247
|
+
classifiableNames = createUnderscoreEscapedMap();
|
|
248
|
+
Symbol = objectAllocator.getSymbolConstructor();
|
|
249
|
+
Debug.attachFlowNodeDebugInfo(unreachableFlow);
|
|
250
|
+
Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
|
|
251
|
+
if (!file.locals) {
|
|
252
|
+
bind(file);
|
|
253
|
+
file.classifiableNames = classifiableNames;
|
|
254
|
+
}
|
|
255
|
+
file = void 0;
|
|
256
|
+
options = void 0;
|
|
257
|
+
parent = void 0;
|
|
258
|
+
container = void 0;
|
|
259
|
+
blockScopeContainer = void 0;
|
|
260
|
+
lastContainer = void 0;
|
|
261
|
+
currentFlow = void 0;
|
|
262
|
+
currentBreakTarget = void 0;
|
|
263
|
+
currentContinueTarget = void 0;
|
|
264
|
+
currentReturnTarget = void 0;
|
|
265
|
+
currentTrueTarget = void 0;
|
|
266
|
+
currentFalseTarget = void 0;
|
|
267
|
+
currentExceptionTarget = void 0;
|
|
268
|
+
hasExplicitReturn = false;
|
|
269
|
+
}
|
|
270
|
+
return bindSourceFile2;
|
|
271
|
+
function bindInStrictMode(file2) {
|
|
272
|
+
return !file2.isDeclarationFile || !!file2.externalModuleIndicator;
|
|
273
|
+
}
|
|
274
|
+
function createSymbol(flags, name) {
|
|
275
|
+
return new Symbol(flags, name);
|
|
276
|
+
}
|
|
277
|
+
function addDeclarationToSymbol(symbol, node, symbolFlags) {
|
|
278
|
+
symbol.flags |= symbolFlags;
|
|
279
|
+
node.symbol = symbol;
|
|
280
|
+
symbol.declarations = appendIfUnique(symbol.declarations, node);
|
|
281
|
+
if (symbolFlags & (SymbolFlags.Module | SymbolFlags.Variable) && !symbol.exports) {
|
|
282
|
+
symbol.exports = createSymbolTable();
|
|
283
|
+
}
|
|
284
|
+
if (symbolFlags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && !symbol.members) {
|
|
285
|
+
symbol.members = createSymbolTable();
|
|
286
|
+
}
|
|
287
|
+
if (symbolFlags & SymbolFlags.Value) {
|
|
288
|
+
setValueDeclaration(symbol, node);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function getDeclarationName(node) {
|
|
292
|
+
if (node.kind === SyntaxKind.ExportAssignment) {
|
|
293
|
+
return InternalSymbolName.Default;
|
|
294
|
+
}
|
|
295
|
+
const name = getNameOfDeclaration(node);
|
|
296
|
+
if (name) {
|
|
297
|
+
if (isAmbientModule(node)) {
|
|
298
|
+
return "__global";
|
|
299
|
+
}
|
|
300
|
+
if (name.kind === SyntaxKind.ComputedPropertyName) {
|
|
301
|
+
const nameExpression = name.expression;
|
|
302
|
+
if (isStringOrNumericLiteralLike(nameExpression)) {
|
|
303
|
+
return escapeLeadingUnderscores(nameExpression.text);
|
|
304
|
+
}
|
|
305
|
+
if (isSignedNumericLiteral(nameExpression)) {
|
|
306
|
+
return tokenToString(nameExpression.operator) + nameExpression.operand.text;
|
|
307
|
+
}
|
|
308
|
+
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
|
|
309
|
+
return getPropertyNameForKnownSymbolName(idText(nameExpression.name));
|
|
310
|
+
}
|
|
311
|
+
if (isWellKnownSymbolSyntactically(name)) {
|
|
312
|
+
return getPropertyNameForKnownSymbolName(idText(name.name));
|
|
313
|
+
}
|
|
314
|
+
return isPropertyNameLiteral(name) ? getEscapedTextOfIdentifierOrLiteral(name) : void 0;
|
|
315
|
+
}
|
|
316
|
+
switch (node.kind) {
|
|
317
|
+
case SyntaxKind.FunctionType:
|
|
318
|
+
case SyntaxKind.CallSignature:
|
|
319
|
+
return InternalSymbolName.Call;
|
|
320
|
+
case SyntaxKind.IndexSignature:
|
|
321
|
+
return InternalSymbolName.Index;
|
|
322
|
+
case SyntaxKind.ExportDeclaration:
|
|
323
|
+
return InternalSymbolName.ExportStar;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function getDisplayName(node) {
|
|
327
|
+
return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(Debug.checkDefined(getDeclarationName(node)));
|
|
328
|
+
}
|
|
329
|
+
function declareSymbol(symbolTable, parent2, node, includes, excludes) {
|
|
330
|
+
Debug.assert(!hasDynamicName(node));
|
|
331
|
+
const isDefaultExport = isExportSpecifier(node) && node.name.escapedText === "default";
|
|
332
|
+
const name = isDefaultExport && parent2 ? InternalSymbolName.Default : getDeclarationName(node);
|
|
333
|
+
let symbol;
|
|
334
|
+
if (name === void 0) {
|
|
335
|
+
symbol = createSymbol(SymbolFlags.None, InternalSymbolName.Missing);
|
|
336
|
+
} else {
|
|
337
|
+
symbol = symbolTable.get(name);
|
|
338
|
+
if (includes & SymbolFlags.Classifiable) {
|
|
339
|
+
classifiableNames.set(name, true);
|
|
340
|
+
}
|
|
341
|
+
if (!symbol) {
|
|
342
|
+
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
|
|
343
|
+
} else if (symbol.flags & excludes) {
|
|
344
|
+
if (isNamedDeclaration(node)) {
|
|
345
|
+
node.name.parent = node;
|
|
346
|
+
}
|
|
347
|
+
let message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;
|
|
348
|
+
let messageNeedsName = true;
|
|
349
|
+
let multipleDefaultExports = false;
|
|
350
|
+
if (length(symbol.declarations)) {
|
|
351
|
+
if (isDefaultExport) {
|
|
352
|
+
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
|
|
353
|
+
messageNeedsName = false;
|
|
354
|
+
multipleDefaultExports = true;
|
|
355
|
+
} else {
|
|
356
|
+
if (symbol.declarations && symbol.declarations.length && node.kind === SyntaxKind.ExportAssignment) {
|
|
357
|
+
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
|
|
358
|
+
messageNeedsName = false;
|
|
359
|
+
multipleDefaultExports = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const relatedInformation = [];
|
|
364
|
+
if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) {
|
|
365
|
+
relatedInformation.push(createDiagnosticForNode(node, Diagnostics.Did_you_mean_0, `export type { ${unescapeLeadingUnderscores(node.name.escapedText)} }`));
|
|
366
|
+
}
|
|
367
|
+
const declarationName = getNameOfDeclaration(node) || node;
|
|
368
|
+
forEach(symbol.declarations, (declaration, index) => {
|
|
369
|
+
const decl = getNameOfDeclaration(declaration) || declaration;
|
|
370
|
+
const diag2 = createDiagnosticForNode(decl, message, messageNeedsName ? getDisplayName(declaration) : void 0);
|
|
371
|
+
file.bindDiagnostics.push(
|
|
372
|
+
multipleDefaultExports ? addRelatedInfo(diag2, createDiagnosticForNode(declarationName, index === 0 ? Diagnostics.Another_export_default_is_here : Diagnostics.and_here)) : diag2
|
|
373
|
+
);
|
|
374
|
+
if (multipleDefaultExports) {
|
|
375
|
+
relatedInformation.push(createDiagnosticForNode(decl, Diagnostics.The_first_export_default_is_here));
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const diag = createDiagnosticForNode(declarationName, message, messageNeedsName ? getDisplayName(node) : void 0);
|
|
379
|
+
file.bindDiagnostics.push(addRelatedInfo(diag, ...relatedInformation));
|
|
380
|
+
symbol = createSymbol(SymbolFlags.None, name);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
addDeclarationToSymbol(symbol, node, includes);
|
|
384
|
+
if (symbol.parent) {
|
|
385
|
+
Debug.assert(symbol.parent === parent2, "Existing symbol parent should match new one");
|
|
386
|
+
} else {
|
|
387
|
+
symbol.parent = parent2;
|
|
388
|
+
}
|
|
389
|
+
return symbol;
|
|
390
|
+
}
|
|
391
|
+
function declareModuleMember(node, symbolFlags, symbolExcludes) {
|
|
392
|
+
const hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export;
|
|
393
|
+
if (symbolFlags & SymbolFlags.Alias) {
|
|
394
|
+
if (node.kind === SyntaxKind.ExportSpecifier) {
|
|
395
|
+
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
|
|
396
|
+
} else {
|
|
397
|
+
return declareSymbol(
|
|
398
|
+
container.locals,
|
|
399
|
+
/*parent*/
|
|
400
|
+
void 0,
|
|
401
|
+
node,
|
|
402
|
+
symbolFlags,
|
|
403
|
+
symbolExcludes
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
} else {
|
|
407
|
+
if (!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) {
|
|
408
|
+
if (!container.locals) {
|
|
409
|
+
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
|
|
410
|
+
}
|
|
411
|
+
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
|
|
412
|
+
const local = declareSymbol(
|
|
413
|
+
container.locals,
|
|
414
|
+
/*parent*/
|
|
415
|
+
void 0,
|
|
416
|
+
node,
|
|
417
|
+
exportKind,
|
|
418
|
+
symbolExcludes
|
|
419
|
+
);
|
|
420
|
+
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
|
|
421
|
+
node.localSymbol = local;
|
|
422
|
+
return local;
|
|
423
|
+
} else {
|
|
424
|
+
return declareSymbol(
|
|
425
|
+
container.locals,
|
|
426
|
+
/*parent*/
|
|
427
|
+
void 0,
|
|
428
|
+
node,
|
|
429
|
+
symbolFlags,
|
|
430
|
+
symbolExcludes
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function bindContainer(node, containerFlags) {
|
|
436
|
+
const saveContainer = container;
|
|
437
|
+
const savedBlockScopeContainer = blockScopeContainer;
|
|
438
|
+
if (containerFlags & 1 /* IsContainer */) {
|
|
439
|
+
container = blockScopeContainer = node;
|
|
440
|
+
if (containerFlags & 32 /* HasLocals */) {
|
|
441
|
+
container.locals = createSymbolTable();
|
|
442
|
+
}
|
|
443
|
+
addToContainerChain(container);
|
|
444
|
+
} else if (containerFlags & 2 /* IsBlockScopedContainer */) {
|
|
445
|
+
blockScopeContainer = node;
|
|
446
|
+
blockScopeContainer.locals = void 0;
|
|
447
|
+
}
|
|
448
|
+
if (containerFlags & 4 /* IsControlFlowContainer */) {
|
|
449
|
+
const saveCurrentFlow = currentFlow;
|
|
450
|
+
const saveBreakTarget = currentBreakTarget;
|
|
451
|
+
const saveContinueTarget = currentContinueTarget;
|
|
452
|
+
const saveReturnTarget = currentReturnTarget;
|
|
453
|
+
const saveExceptionTarget = currentExceptionTarget;
|
|
454
|
+
const saveHasExplicitReturn = hasExplicitReturn;
|
|
455
|
+
const isIIFE = containerFlags & 16 /* IsFunctionExpression */ && !hasModifier(node, ModifierFlags.Async) && !!getImmediatelyInvokedFunctionExpression(node);
|
|
456
|
+
if (!isIIFE) {
|
|
457
|
+
currentFlow = initFlowNode({ flags: FlowFlags.Start });
|
|
458
|
+
if (containerFlags & 16 /* IsFunctionExpression */) {
|
|
459
|
+
currentFlow.node = node;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
currentReturnTarget = isIIFE ? createBranchLabel() : void 0;
|
|
463
|
+
currentExceptionTarget = void 0;
|
|
464
|
+
currentBreakTarget = void 0;
|
|
465
|
+
currentContinueTarget = void 0;
|
|
466
|
+
hasExplicitReturn = false;
|
|
467
|
+
bindChildren(node);
|
|
468
|
+
node.flags &= ~NodeFlags.ReachabilityAndEmitFlags;
|
|
469
|
+
if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & 8 /* IsFunctionLike */ && nodeIsPresent(node.body)) {
|
|
470
|
+
node.flags |= NodeFlags.HasImplicitReturn;
|
|
471
|
+
if (hasExplicitReturn) node.flags |= NodeFlags.HasExplicitReturn;
|
|
472
|
+
node.endFlowNode = currentFlow;
|
|
473
|
+
}
|
|
474
|
+
if (currentReturnTarget) {
|
|
475
|
+
addAntecedent(currentReturnTarget, currentFlow);
|
|
476
|
+
currentFlow = finishFlowLabel(currentReturnTarget);
|
|
477
|
+
}
|
|
478
|
+
if (!isIIFE) {
|
|
479
|
+
currentFlow = saveCurrentFlow;
|
|
480
|
+
}
|
|
481
|
+
currentBreakTarget = saveBreakTarget;
|
|
482
|
+
currentContinueTarget = saveContinueTarget;
|
|
483
|
+
currentReturnTarget = saveReturnTarget;
|
|
484
|
+
currentExceptionTarget = saveExceptionTarget;
|
|
485
|
+
hasExplicitReturn = saveHasExplicitReturn;
|
|
486
|
+
} else {
|
|
487
|
+
bindChildren(node);
|
|
488
|
+
}
|
|
489
|
+
container = saveContainer;
|
|
490
|
+
blockScopeContainer = savedBlockScopeContainer;
|
|
491
|
+
}
|
|
492
|
+
function bindChildren(node) {
|
|
493
|
+
bindChildrenWorker(node);
|
|
494
|
+
}
|
|
495
|
+
function bindEach(nodes, bindFunction = bind) {
|
|
496
|
+
if (nodes === void 0) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
forEach(nodes, bindFunction);
|
|
500
|
+
}
|
|
501
|
+
function bindEachChild(node) {
|
|
502
|
+
forEachChild(node, bind, bindEach);
|
|
503
|
+
}
|
|
504
|
+
function bindChildrenWorker(node) {
|
|
505
|
+
if (checkUnreachable(node)) {
|
|
506
|
+
bindEachChild(node);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (node.kind >= SyntaxKind.FirstStatement && node.kind <= SyntaxKind.LastStatement && !options.allowUnreachableCode) {
|
|
510
|
+
node.flowNode = currentFlow;
|
|
511
|
+
}
|
|
512
|
+
switch (node.kind) {
|
|
513
|
+
case SyntaxKind.WhileStatement:
|
|
514
|
+
bindWhileStatement(node);
|
|
515
|
+
break;
|
|
516
|
+
case SyntaxKind.DoStatement:
|
|
517
|
+
bindDoStatement(node);
|
|
518
|
+
break;
|
|
519
|
+
case SyntaxKind.ForStatement:
|
|
520
|
+
bindForStatement(node);
|
|
521
|
+
break;
|
|
522
|
+
case SyntaxKind.ForInStatement:
|
|
523
|
+
case SyntaxKind.ForOfStatement:
|
|
524
|
+
bindForInOrForOfStatement(node);
|
|
525
|
+
break;
|
|
526
|
+
case SyntaxKind.IfStatement:
|
|
527
|
+
bindIfStatement(node);
|
|
528
|
+
break;
|
|
529
|
+
case SyntaxKind.ReturnStatement:
|
|
530
|
+
case SyntaxKind.ThrowStatement:
|
|
531
|
+
bindReturnOrThrow(node);
|
|
532
|
+
break;
|
|
533
|
+
case SyntaxKind.BreakStatement:
|
|
534
|
+
case SyntaxKind.ContinueStatement:
|
|
535
|
+
bindBreakOrContinueStatement(node);
|
|
536
|
+
break;
|
|
537
|
+
case SyntaxKind.TryStatement:
|
|
538
|
+
bindTryStatement(node);
|
|
539
|
+
break;
|
|
540
|
+
case SyntaxKind.SwitchStatement:
|
|
541
|
+
bindSwitchStatement(node);
|
|
542
|
+
break;
|
|
543
|
+
case SyntaxKind.CaseBlock:
|
|
544
|
+
bindCaseBlock(node);
|
|
545
|
+
break;
|
|
546
|
+
case SyntaxKind.CaseClause:
|
|
547
|
+
bindCaseClause(node);
|
|
548
|
+
break;
|
|
549
|
+
case SyntaxKind.ExpressionStatement:
|
|
550
|
+
bindExpressionStatement(node);
|
|
551
|
+
break;
|
|
552
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
553
|
+
bindPrefixUnaryExpressionFlow(node);
|
|
554
|
+
break;
|
|
555
|
+
case SyntaxKind.PostfixUnaryExpression:
|
|
556
|
+
bindPostfixUnaryExpressionFlow(node);
|
|
557
|
+
break;
|
|
558
|
+
case SyntaxKind.BinaryExpression:
|
|
559
|
+
bindBinaryExpressionFlow(node);
|
|
560
|
+
break;
|
|
561
|
+
case SyntaxKind.DeleteExpression:
|
|
562
|
+
bindDeleteExpressionFlow(node);
|
|
563
|
+
break;
|
|
564
|
+
case SyntaxKind.ConditionalExpression:
|
|
565
|
+
bindConditionalExpressionFlow(node);
|
|
566
|
+
break;
|
|
567
|
+
case SyntaxKind.VariableDeclaration:
|
|
568
|
+
bindVariableDeclarationFlow(node);
|
|
569
|
+
break;
|
|
570
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
571
|
+
case SyntaxKind.ElementAccessExpression:
|
|
572
|
+
bindAccessExpressionFlow(node);
|
|
573
|
+
break;
|
|
574
|
+
case SyntaxKind.CallExpression:
|
|
575
|
+
bindCallExpressionFlow(node);
|
|
576
|
+
break;
|
|
577
|
+
default:
|
|
578
|
+
bindEachChild(node);
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function isNarrowingExpression(expr) {
|
|
583
|
+
switch (expr.kind) {
|
|
584
|
+
case SyntaxKind.Identifier:
|
|
585
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
586
|
+
case SyntaxKind.ElementAccessExpression:
|
|
587
|
+
return containsNarrowableReference(expr);
|
|
588
|
+
case SyntaxKind.CallExpression:
|
|
589
|
+
return hasNarrowableArgument(expr);
|
|
590
|
+
case SyntaxKind.ParenthesizedExpression:
|
|
591
|
+
return isNarrowingExpression(expr.expression);
|
|
592
|
+
case SyntaxKind.BinaryExpression:
|
|
593
|
+
return isNarrowingBinaryExpression(expr);
|
|
594
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
595
|
+
return expr.operator === SyntaxKind.ExclamationToken && isNarrowingExpression(expr.operand);
|
|
596
|
+
case SyntaxKind.TypeOfExpression:
|
|
597
|
+
return isNarrowingExpression(expr.expression);
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
function isNarrowableReference(expr) {
|
|
602
|
+
return expr.kind === SyntaxKind.Identifier || (isPropertyAccessExpression(expr) || isParenthesizedExpression(expr)) && isNarrowableReference(expr.expression) || isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression);
|
|
603
|
+
}
|
|
604
|
+
function containsNarrowableReference(expr) {
|
|
605
|
+
return isNarrowableReference(expr) || isOptionalChain(expr) && containsNarrowableReference(expr.expression);
|
|
606
|
+
}
|
|
607
|
+
function hasNarrowableArgument(expr) {
|
|
608
|
+
if (expr.arguments) {
|
|
609
|
+
for (const argument of expr.arguments) {
|
|
610
|
+
if (containsNarrowableReference(argument)) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (expr.expression.kind === SyntaxKind.PropertyAccessExpression && containsNarrowableReference(expr.expression.expression)) {
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
function isNarrowingTypeofOperands(expr1, expr2) {
|
|
621
|
+
return isTypeOfExpression(expr1) && isNarrowableOperand(expr1.expression) && isStringLiteralLike(expr2);
|
|
622
|
+
}
|
|
623
|
+
function isNarrowableInOperands(left, right) {
|
|
624
|
+
return isStringLiteralLike(left) && isNarrowingExpression(right);
|
|
625
|
+
}
|
|
626
|
+
function isNarrowingBinaryExpression(expr) {
|
|
627
|
+
switch (expr.operatorToken.kind) {
|
|
628
|
+
case SyntaxKind.EqualsToken:
|
|
629
|
+
return containsNarrowableReference(expr.left);
|
|
630
|
+
case SyntaxKind.EqualsEqualsToken:
|
|
631
|
+
case SyntaxKind.ExclamationEqualsToken:
|
|
632
|
+
return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) || isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right);
|
|
633
|
+
case SyntaxKind.InKeyword:
|
|
634
|
+
return isNarrowableInOperands(expr.left, expr.right);
|
|
635
|
+
}
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
function isNarrowableOperand(expr) {
|
|
639
|
+
switch (expr.kind) {
|
|
640
|
+
case SyntaxKind.ParenthesizedExpression:
|
|
641
|
+
return isNarrowableOperand(expr.expression);
|
|
642
|
+
case SyntaxKind.BinaryExpression:
|
|
643
|
+
switch (expr.operatorToken.kind) {
|
|
644
|
+
case SyntaxKind.EqualsToken:
|
|
645
|
+
return isNarrowableOperand(expr.left);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return containsNarrowableReference(expr);
|
|
649
|
+
}
|
|
650
|
+
function createBranchLabel() {
|
|
651
|
+
return initFlowNode({ flags: FlowFlags.BranchLabel, antecedents: void 0 });
|
|
652
|
+
}
|
|
653
|
+
function createLoopLabel() {
|
|
654
|
+
return initFlowNode({ flags: FlowFlags.LoopLabel, antecedents: void 0 });
|
|
655
|
+
}
|
|
656
|
+
function createReduceLabel(target, antecedents, antecedent) {
|
|
657
|
+
return initFlowNode({ flags: FlowFlags.ReduceLabel, target, antecedents, antecedent });
|
|
658
|
+
}
|
|
659
|
+
function setFlowNodeReferenced(flow) {
|
|
660
|
+
flow.flags |= flow.flags & FlowFlags.Referenced ? FlowFlags.Shared : FlowFlags.Referenced;
|
|
661
|
+
}
|
|
662
|
+
function addAntecedent(label, antecedent) {
|
|
663
|
+
if (!(antecedent.flags & FlowFlags.Unreachable) && !contains(label.antecedents, antecedent)) {
|
|
664
|
+
(label.antecedents || (label.antecedents = [])).push(antecedent);
|
|
665
|
+
setFlowNodeReferenced(antecedent);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function createFlowCondition(flags, antecedent, expression) {
|
|
669
|
+
if (antecedent.flags & FlowFlags.Unreachable) {
|
|
670
|
+
return antecedent;
|
|
671
|
+
}
|
|
672
|
+
if (!expression) {
|
|
673
|
+
return flags & FlowFlags.TrueCondition ? antecedent : unreachableFlow;
|
|
674
|
+
}
|
|
675
|
+
if ((expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition || expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) && !isExpressionOfOptionalChainRoot(expression) && !isNullishCoalesce(expression.parent)) {
|
|
676
|
+
return unreachableFlow;
|
|
677
|
+
}
|
|
678
|
+
if (!isNarrowingExpression(expression)) {
|
|
679
|
+
return antecedent;
|
|
680
|
+
}
|
|
681
|
+
setFlowNodeReferenced(antecedent);
|
|
682
|
+
return initFlowNode({ flags, antecedent, node: expression });
|
|
683
|
+
}
|
|
684
|
+
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
|
|
685
|
+
setFlowNodeReferenced(antecedent);
|
|
686
|
+
return initFlowNode({ flags: FlowFlags.SwitchClause, antecedent, switchStatement, clauseStart, clauseEnd });
|
|
687
|
+
}
|
|
688
|
+
function createFlowMutation(flags, antecedent, node) {
|
|
689
|
+
setFlowNodeReferenced(antecedent);
|
|
690
|
+
const result = initFlowNode({ flags, antecedent, node });
|
|
691
|
+
if (currentExceptionTarget) {
|
|
692
|
+
addAntecedent(currentExceptionTarget, result);
|
|
693
|
+
}
|
|
694
|
+
return result;
|
|
695
|
+
}
|
|
696
|
+
function createFlowCall(antecedent, node) {
|
|
697
|
+
setFlowNodeReferenced(antecedent);
|
|
698
|
+
return initFlowNode({ flags: FlowFlags.Call, antecedent, node });
|
|
699
|
+
}
|
|
700
|
+
function finishFlowLabel(flow) {
|
|
701
|
+
const antecedents = flow.antecedents;
|
|
702
|
+
if (!antecedents) {
|
|
703
|
+
return unreachableFlow;
|
|
704
|
+
}
|
|
705
|
+
if (antecedents.length === 1) {
|
|
706
|
+
return antecedents[0];
|
|
707
|
+
}
|
|
708
|
+
return flow;
|
|
709
|
+
}
|
|
710
|
+
function isStatementCondition(node) {
|
|
711
|
+
const parent2 = node.parent;
|
|
712
|
+
switch (parent2.kind) {
|
|
713
|
+
case SyntaxKind.IfStatement:
|
|
714
|
+
case SyntaxKind.WhileStatement:
|
|
715
|
+
case SyntaxKind.DoStatement:
|
|
716
|
+
return parent2.expression === node;
|
|
717
|
+
case SyntaxKind.ForStatement:
|
|
718
|
+
case SyntaxKind.ConditionalExpression:
|
|
719
|
+
return parent2.condition === node;
|
|
720
|
+
}
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
function isLogicalExpression(node) {
|
|
724
|
+
while (true) {
|
|
725
|
+
if (node.kind === SyntaxKind.ParenthesizedExpression) {
|
|
726
|
+
node = node.expression;
|
|
727
|
+
} else if (node.kind === SyntaxKind.PrefixUnaryExpression && node.operator === SyntaxKind.ExclamationToken) {
|
|
728
|
+
node = node.operand;
|
|
729
|
+
} else {
|
|
730
|
+
return node.kind === SyntaxKind.BinaryExpression && (node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken || node.operatorToken.kind === SyntaxKind.BarBarToken || node.operatorToken.kind === SyntaxKind.QuestionQuestionToken);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function isTopLevelLogicalExpression(node) {
|
|
735
|
+
while (isParenthesizedExpression(node.parent) || isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.ExclamationToken) {
|
|
736
|
+
node = node.parent;
|
|
737
|
+
}
|
|
738
|
+
return !isStatementCondition(node) && !isLogicalExpression(node.parent) && !(isOptionalChain(node.parent) && node.parent.expression === node);
|
|
739
|
+
}
|
|
740
|
+
function doWithConditionalBranches(action, value, trueTarget, falseTarget) {
|
|
741
|
+
const savedTrueTarget = currentTrueTarget;
|
|
742
|
+
const savedFalseTarget = currentFalseTarget;
|
|
743
|
+
currentTrueTarget = trueTarget;
|
|
744
|
+
currentFalseTarget = falseTarget;
|
|
745
|
+
action(value);
|
|
746
|
+
currentTrueTarget = savedTrueTarget;
|
|
747
|
+
currentFalseTarget = savedFalseTarget;
|
|
748
|
+
}
|
|
749
|
+
function bindCondition(node, trueTarget, falseTarget) {
|
|
750
|
+
doWithConditionalBranches(bind, node, trueTarget, falseTarget);
|
|
751
|
+
if (!node || !isLogicalExpression(node) && !(isOptionalChain(node) && isOutermostOptionalChain(node))) {
|
|
752
|
+
addAntecedent(trueTarget, createFlowCondition(FlowFlags.TrueCondition, currentFlow, node));
|
|
753
|
+
addAntecedent(falseTarget, createFlowCondition(FlowFlags.FalseCondition, currentFlow, node));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function bindIterativeStatement(node, breakTarget, continueTarget) {
|
|
757
|
+
const saveBreakTarget = currentBreakTarget;
|
|
758
|
+
const saveContinueTarget = currentContinueTarget;
|
|
759
|
+
currentBreakTarget = breakTarget;
|
|
760
|
+
currentContinueTarget = continueTarget;
|
|
761
|
+
bind(node);
|
|
762
|
+
currentBreakTarget = saveBreakTarget;
|
|
763
|
+
currentContinueTarget = saveContinueTarget;
|
|
764
|
+
}
|
|
765
|
+
function bindWhileStatement(node) {
|
|
766
|
+
const preWhileLabel = createLoopLabel();
|
|
767
|
+
const preBodyLabel = createBranchLabel();
|
|
768
|
+
const postWhileLabel = createBranchLabel();
|
|
769
|
+
addAntecedent(preWhileLabel, currentFlow);
|
|
770
|
+
currentFlow = preWhileLabel;
|
|
771
|
+
bindCondition(node.expression, preBodyLabel, postWhileLabel);
|
|
772
|
+
currentFlow = finishFlowLabel(preBodyLabel);
|
|
773
|
+
bindIterativeStatement(node.statement, postWhileLabel, preWhileLabel);
|
|
774
|
+
addAntecedent(preWhileLabel, currentFlow);
|
|
775
|
+
currentFlow = finishFlowLabel(postWhileLabel);
|
|
776
|
+
}
|
|
777
|
+
function bindDoStatement(node) {
|
|
778
|
+
const preDoLabel = createLoopLabel();
|
|
779
|
+
const preConditionLabel = createBranchLabel();
|
|
780
|
+
const postDoLabel = createBranchLabel();
|
|
781
|
+
addAntecedent(preDoLabel, currentFlow);
|
|
782
|
+
currentFlow = preDoLabel;
|
|
783
|
+
bindIterativeStatement(node.statement, postDoLabel, preConditionLabel);
|
|
784
|
+
addAntecedent(preConditionLabel, currentFlow);
|
|
785
|
+
currentFlow = finishFlowLabel(preConditionLabel);
|
|
786
|
+
bindCondition(node.expression, preDoLabel, postDoLabel);
|
|
787
|
+
currentFlow = finishFlowLabel(postDoLabel);
|
|
788
|
+
}
|
|
789
|
+
function bindForStatement(node) {
|
|
790
|
+
const preLoopLabel = createLoopLabel();
|
|
791
|
+
const preBodyLabel = createBranchLabel();
|
|
792
|
+
const postLoopLabel = createBranchLabel();
|
|
793
|
+
bind(node.initializer);
|
|
794
|
+
addAntecedent(preLoopLabel, currentFlow);
|
|
795
|
+
currentFlow = preLoopLabel;
|
|
796
|
+
bindCondition(node.condition, preBodyLabel, postLoopLabel);
|
|
797
|
+
currentFlow = finishFlowLabel(preBodyLabel);
|
|
798
|
+
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
|
|
799
|
+
bind(node.incrementor);
|
|
800
|
+
addAntecedent(preLoopLabel, currentFlow);
|
|
801
|
+
currentFlow = finishFlowLabel(postLoopLabel);
|
|
802
|
+
}
|
|
803
|
+
function bindForInOrForOfStatement(node) {
|
|
804
|
+
const preLoopLabel = createLoopLabel();
|
|
805
|
+
const postLoopLabel = createBranchLabel();
|
|
806
|
+
bind(node.expression);
|
|
807
|
+
addAntecedent(preLoopLabel, currentFlow);
|
|
808
|
+
currentFlow = preLoopLabel;
|
|
809
|
+
if (node.kind === SyntaxKind.ForOfStatement) {
|
|
810
|
+
bind(node.awaitModifier);
|
|
811
|
+
}
|
|
812
|
+
addAntecedent(postLoopLabel, currentFlow);
|
|
813
|
+
bind(node.initializer);
|
|
814
|
+
if (node.initializer.kind !== SyntaxKind.VariableDeclarationList) {
|
|
815
|
+
bindAssignmentTargetFlow(node.initializer);
|
|
816
|
+
}
|
|
817
|
+
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
|
|
818
|
+
addAntecedent(preLoopLabel, currentFlow);
|
|
819
|
+
currentFlow = finishFlowLabel(postLoopLabel);
|
|
820
|
+
}
|
|
821
|
+
function bindIfStatement(node) {
|
|
822
|
+
const thenLabel = createBranchLabel();
|
|
823
|
+
const elseLabel = createBranchLabel();
|
|
824
|
+
const postIfLabel = createBranchLabel();
|
|
825
|
+
bindCondition(node.expression, thenLabel, elseLabel);
|
|
826
|
+
currentFlow = finishFlowLabel(thenLabel);
|
|
827
|
+
bind(node.thenStatement);
|
|
828
|
+
addAntecedent(postIfLabel, currentFlow);
|
|
829
|
+
currentFlow = finishFlowLabel(elseLabel);
|
|
830
|
+
bind(node.elseStatement);
|
|
831
|
+
addAntecedent(postIfLabel, currentFlow);
|
|
832
|
+
currentFlow = finishFlowLabel(postIfLabel);
|
|
833
|
+
}
|
|
834
|
+
function bindReturnOrThrow(node) {
|
|
835
|
+
bind(node.expression);
|
|
836
|
+
if (node.kind === SyntaxKind.ReturnStatement) {
|
|
837
|
+
hasExplicitReturn = true;
|
|
838
|
+
if (currentReturnTarget) {
|
|
839
|
+
addAntecedent(currentReturnTarget, currentFlow);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
currentFlow = unreachableFlow;
|
|
843
|
+
}
|
|
844
|
+
function bindBreakOrContinueFlow(node, breakTarget, continueTarget) {
|
|
845
|
+
const flowLabel = node.kind === SyntaxKind.BreakStatement ? breakTarget : continueTarget;
|
|
846
|
+
if (flowLabel) {
|
|
847
|
+
addAntecedent(flowLabel, currentFlow);
|
|
848
|
+
currentFlow = unreachableFlow;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function bindBreakOrContinueStatement(node) {
|
|
852
|
+
bindBreakOrContinueFlow(node, currentBreakTarget, currentContinueTarget);
|
|
853
|
+
}
|
|
854
|
+
function bindTryStatement(node) {
|
|
855
|
+
const saveReturnTarget = currentReturnTarget;
|
|
856
|
+
const saveExceptionTarget = currentExceptionTarget;
|
|
857
|
+
const normalExitLabel = createBranchLabel();
|
|
858
|
+
const returnLabel = createBranchLabel();
|
|
859
|
+
let exceptionLabel = createBranchLabel();
|
|
860
|
+
if (node.finallyBlock) {
|
|
861
|
+
currentReturnTarget = returnLabel;
|
|
862
|
+
}
|
|
863
|
+
addAntecedent(exceptionLabel, currentFlow);
|
|
864
|
+
currentExceptionTarget = exceptionLabel;
|
|
865
|
+
bind(node.tryBlock);
|
|
866
|
+
addAntecedent(normalExitLabel, currentFlow);
|
|
867
|
+
if (node.catchClause) {
|
|
868
|
+
currentFlow = finishFlowLabel(exceptionLabel);
|
|
869
|
+
exceptionLabel = createBranchLabel();
|
|
870
|
+
addAntecedent(exceptionLabel, currentFlow);
|
|
871
|
+
currentExceptionTarget = exceptionLabel;
|
|
872
|
+
bind(node.catchClause);
|
|
873
|
+
addAntecedent(normalExitLabel, currentFlow);
|
|
874
|
+
}
|
|
875
|
+
currentReturnTarget = saveReturnTarget;
|
|
876
|
+
currentExceptionTarget = saveExceptionTarget;
|
|
877
|
+
if (node.finallyBlock) {
|
|
878
|
+
const finallyLabel = createBranchLabel();
|
|
879
|
+
finallyLabel.antecedents = concatenate(concatenate(normalExitLabel.antecedents, exceptionLabel.antecedents), returnLabel.antecedents);
|
|
880
|
+
currentFlow = finallyLabel;
|
|
881
|
+
bind(node.finallyBlock);
|
|
882
|
+
if (currentFlow.flags & FlowFlags.Unreachable) {
|
|
883
|
+
currentFlow = unreachableFlow;
|
|
884
|
+
} else {
|
|
885
|
+
if (currentReturnTarget && returnLabel.antecedents) {
|
|
886
|
+
addAntecedent(currentReturnTarget, createReduceLabel(finallyLabel, returnLabel.antecedents, currentFlow));
|
|
887
|
+
}
|
|
888
|
+
currentFlow = normalExitLabel.antecedents ? createReduceLabel(finallyLabel, normalExitLabel.antecedents, currentFlow) : unreachableFlow;
|
|
889
|
+
}
|
|
890
|
+
} else {
|
|
891
|
+
currentFlow = finishFlowLabel(normalExitLabel);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function bindSwitchStatement(node) {
|
|
895
|
+
const postSwitchLabel = createBranchLabel();
|
|
896
|
+
bind(node.expression);
|
|
897
|
+
const saveBreakTarget = currentBreakTarget;
|
|
898
|
+
const savePreSwitchCaseFlow = preSwitchCaseFlow;
|
|
899
|
+
currentBreakTarget = postSwitchLabel;
|
|
900
|
+
preSwitchCaseFlow = currentFlow;
|
|
901
|
+
bind(node.caseBlock);
|
|
902
|
+
addAntecedent(postSwitchLabel, currentFlow);
|
|
903
|
+
const hasDefault = forEach(node.caseBlock.clauses, (c) => c.kind === SyntaxKind.DefaultClause);
|
|
904
|
+
node.possiblyExhaustive = !hasDefault && !postSwitchLabel.antecedents;
|
|
905
|
+
if (!hasDefault) {
|
|
906
|
+
addAntecedent(postSwitchLabel, createFlowSwitchClause(preSwitchCaseFlow, node, 0, 0));
|
|
907
|
+
}
|
|
908
|
+
currentBreakTarget = saveBreakTarget;
|
|
909
|
+
preSwitchCaseFlow = savePreSwitchCaseFlow;
|
|
910
|
+
currentFlow = finishFlowLabel(postSwitchLabel);
|
|
911
|
+
}
|
|
912
|
+
function bindCaseBlock(node) {
|
|
913
|
+
const clauses = node.clauses;
|
|
914
|
+
const isNarrowingSwitch = isNarrowingExpression(node.parent.expression);
|
|
915
|
+
let fallthroughFlow = unreachableFlow;
|
|
916
|
+
for (let i = 0; i < clauses.length; i++) {
|
|
917
|
+
const clauseStart = i;
|
|
918
|
+
while (!clauses[i].statements.length && i + 1 < clauses.length) {
|
|
919
|
+
bind(clauses[i]);
|
|
920
|
+
i++;
|
|
921
|
+
}
|
|
922
|
+
const preCaseLabel = createBranchLabel();
|
|
923
|
+
addAntecedent(preCaseLabel, isNarrowingSwitch ? createFlowSwitchClause(preSwitchCaseFlow, node.parent, clauseStart, i + 1) : preSwitchCaseFlow);
|
|
924
|
+
addAntecedent(preCaseLabel, fallthroughFlow);
|
|
925
|
+
currentFlow = finishFlowLabel(preCaseLabel);
|
|
926
|
+
const clause = clauses[i];
|
|
927
|
+
bind(clause);
|
|
928
|
+
fallthroughFlow = currentFlow;
|
|
929
|
+
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
|
|
930
|
+
clause.fallthroughFlowNode = currentFlow;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function bindCaseClause(node) {
|
|
935
|
+
const saveCurrentFlow = currentFlow;
|
|
936
|
+
currentFlow = preSwitchCaseFlow;
|
|
937
|
+
bind(node.expression);
|
|
938
|
+
currentFlow = saveCurrentFlow;
|
|
939
|
+
bindEach(node.statements);
|
|
940
|
+
}
|
|
941
|
+
function bindExpressionStatement(node) {
|
|
942
|
+
bind(node.expression);
|
|
943
|
+
if (node.expression.kind === SyntaxKind.CallExpression) {
|
|
944
|
+
const call = node.expression;
|
|
945
|
+
if (isDottedName(call.expression)) {
|
|
946
|
+
currentFlow = createFlowCall(currentFlow, call);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function bindDestructuringTargetFlow(node) {
|
|
951
|
+
if (node.kind === SyntaxKind.BinaryExpression && node.operatorToken.kind === SyntaxKind.EqualsToken) {
|
|
952
|
+
bindAssignmentTargetFlow(node.left);
|
|
953
|
+
} else {
|
|
954
|
+
bindAssignmentTargetFlow(node);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function bindAssignmentTargetFlow(node) {
|
|
958
|
+
if (isNarrowableReference(node)) {
|
|
959
|
+
currentFlow = createFlowMutation(FlowFlags.Assignment, currentFlow, node);
|
|
960
|
+
} else if (node.kind === SyntaxKind.ArrayLiteralExpression) {
|
|
961
|
+
for (const e of node.elements) {
|
|
962
|
+
if (e.kind === SyntaxKind.SpreadElement) {
|
|
963
|
+
bindAssignmentTargetFlow(e.expression);
|
|
964
|
+
} else {
|
|
965
|
+
bindDestructuringTargetFlow(e);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
} else if (node.kind === SyntaxKind.ObjectLiteralExpression) {
|
|
969
|
+
for (const p of node.properties) {
|
|
970
|
+
if (p.kind === SyntaxKind.PropertyAssignment) {
|
|
971
|
+
bindDestructuringTargetFlow(p.initializer);
|
|
972
|
+
} else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
|
973
|
+
bindAssignmentTargetFlow(p.name);
|
|
974
|
+
} else if (p.kind === SyntaxKind.SpreadAssignment) {
|
|
975
|
+
bindAssignmentTargetFlow(p.expression);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
function bindLogicalExpression(node, trueTarget, falseTarget) {
|
|
981
|
+
const preRightLabel = createBranchLabel();
|
|
982
|
+
if (node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
|
|
983
|
+
bindCondition(node.left, preRightLabel, falseTarget);
|
|
984
|
+
} else {
|
|
985
|
+
bindCondition(node.left, trueTarget, preRightLabel);
|
|
986
|
+
}
|
|
987
|
+
currentFlow = finishFlowLabel(preRightLabel);
|
|
988
|
+
bind(node.operatorToken);
|
|
989
|
+
bindCondition(node.right, trueTarget, falseTarget);
|
|
990
|
+
}
|
|
991
|
+
function bindPrefixUnaryExpressionFlow(node) {
|
|
992
|
+
if (node.operator === SyntaxKind.ExclamationToken) {
|
|
993
|
+
const saveTrueTarget = currentTrueTarget;
|
|
994
|
+
currentTrueTarget = currentFalseTarget;
|
|
995
|
+
currentFalseTarget = saveTrueTarget;
|
|
996
|
+
bindEachChild(node);
|
|
997
|
+
currentFalseTarget = currentTrueTarget;
|
|
998
|
+
currentTrueTarget = saveTrueTarget;
|
|
999
|
+
} else {
|
|
1000
|
+
bindEachChild(node);
|
|
1001
|
+
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
|
1002
|
+
bindAssignmentTargetFlow(node.operand);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function bindPostfixUnaryExpressionFlow(node) {
|
|
1007
|
+
bindEachChild(node);
|
|
1008
|
+
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
|
1009
|
+
bindAssignmentTargetFlow(node.operand);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
let BindBinaryExpressionFlowState;
|
|
1013
|
+
((BindBinaryExpressionFlowState2) => {
|
|
1014
|
+
BindBinaryExpressionFlowState2[BindBinaryExpressionFlowState2["BindThenBindChildren"] = 0] = "BindThenBindChildren";
|
|
1015
|
+
BindBinaryExpressionFlowState2[BindBinaryExpressionFlowState2["MaybeBindLeft"] = 1] = "MaybeBindLeft";
|
|
1016
|
+
BindBinaryExpressionFlowState2[BindBinaryExpressionFlowState2["BindToken"] = 2] = "BindToken";
|
|
1017
|
+
BindBinaryExpressionFlowState2[BindBinaryExpressionFlowState2["BindRight"] = 3] = "BindRight";
|
|
1018
|
+
BindBinaryExpressionFlowState2[BindBinaryExpressionFlowState2["FinishBind"] = 4] = "FinishBind";
|
|
1019
|
+
})(BindBinaryExpressionFlowState || (BindBinaryExpressionFlowState = {}));
|
|
1020
|
+
function bindBinaryExpressionFlow(node) {
|
|
1021
|
+
const workStacks = {
|
|
1022
|
+
expr: [node],
|
|
1023
|
+
state: [1 /* MaybeBindLeft */],
|
|
1024
|
+
inStrictMode: [void 0],
|
|
1025
|
+
parent: [void 0]
|
|
1026
|
+
};
|
|
1027
|
+
let stackIndex = 0;
|
|
1028
|
+
while (stackIndex >= 0) {
|
|
1029
|
+
node = workStacks.expr[stackIndex];
|
|
1030
|
+
switch (workStacks.state[stackIndex]) {
|
|
1031
|
+
case 0 /* BindThenBindChildren */: {
|
|
1032
|
+
node.parent = parent;
|
|
1033
|
+
const saveInStrictMode = inStrictMode;
|
|
1034
|
+
bindWorker(node);
|
|
1035
|
+
const saveParent = parent;
|
|
1036
|
+
parent = node;
|
|
1037
|
+
advanceState(1 /* MaybeBindLeft */, saveInStrictMode, saveParent);
|
|
1038
|
+
break;
|
|
1039
|
+
}
|
|
1040
|
+
case 1 /* MaybeBindLeft */: {
|
|
1041
|
+
const operator = node.operatorToken.kind;
|
|
1042
|
+
if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.BarBarToken || operator === SyntaxKind.QuestionQuestionToken) {
|
|
1043
|
+
if (isTopLevelLogicalExpression(node)) {
|
|
1044
|
+
const postExpressionLabel = createBranchLabel();
|
|
1045
|
+
bindLogicalExpression(node, postExpressionLabel, postExpressionLabel);
|
|
1046
|
+
currentFlow = finishFlowLabel(postExpressionLabel);
|
|
1047
|
+
} else {
|
|
1048
|
+
bindLogicalExpression(node, currentTrueTarget, currentFalseTarget);
|
|
1049
|
+
}
|
|
1050
|
+
completeNode();
|
|
1051
|
+
} else {
|
|
1052
|
+
advanceState(2 /* BindToken */);
|
|
1053
|
+
maybeBind(node.left);
|
|
1054
|
+
}
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
case 2 /* BindToken */: {
|
|
1058
|
+
advanceState(3 /* BindRight */);
|
|
1059
|
+
maybeBind(node.operatorToken);
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
case 3 /* BindRight */: {
|
|
1063
|
+
advanceState(4 /* FinishBind */);
|
|
1064
|
+
maybeBind(node.right);
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
case 4 /* FinishBind */: {
|
|
1068
|
+
const operator = node.operatorToken.kind;
|
|
1069
|
+
if (isAssignmentOperator(operator) && !isAssignmentTarget(node)) {
|
|
1070
|
+
bindAssignmentTargetFlow(node.left);
|
|
1071
|
+
if (operator === SyntaxKind.EqualsToken && node.left.kind === SyntaxKind.ElementAccessExpression) {
|
|
1072
|
+
const elementAccess = node.left;
|
|
1073
|
+
if (isNarrowableOperand(elementAccess.expression)) {
|
|
1074
|
+
currentFlow = createFlowMutation(FlowFlags.ArrayMutation, currentFlow, node);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
completeNode();
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
default:
|
|
1082
|
+
return Debug.fail(`Invalid state ${workStacks.state[stackIndex]} for bindBinaryExpressionFlow`);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
function advanceState(state, isInStrictMode, parent2) {
|
|
1086
|
+
workStacks.state[stackIndex] = state;
|
|
1087
|
+
if (isInStrictMode !== void 0) {
|
|
1088
|
+
workStacks.inStrictMode[stackIndex] = isInStrictMode;
|
|
1089
|
+
}
|
|
1090
|
+
if (parent2 !== void 0) {
|
|
1091
|
+
workStacks.parent[stackIndex] = parent2;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function completeNode() {
|
|
1095
|
+
if (workStacks.inStrictMode[stackIndex] !== void 0) {
|
|
1096
|
+
inStrictMode = workStacks.inStrictMode[stackIndex];
|
|
1097
|
+
parent = workStacks.parent[stackIndex];
|
|
1098
|
+
}
|
|
1099
|
+
stackIndex--;
|
|
1100
|
+
}
|
|
1101
|
+
function maybeBind(node2) {
|
|
1102
|
+
if (node2 && isBinaryExpression(node2)) {
|
|
1103
|
+
stackIndex++;
|
|
1104
|
+
workStacks.expr[stackIndex] = node2;
|
|
1105
|
+
workStacks.state[stackIndex] = 0 /* BindThenBindChildren */;
|
|
1106
|
+
workStacks.inStrictMode[stackIndex] = void 0;
|
|
1107
|
+
workStacks.parent[stackIndex] = void 0;
|
|
1108
|
+
} else {
|
|
1109
|
+
bind(node2);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
function bindDeleteExpressionFlow(node) {
|
|
1114
|
+
bindEachChild(node);
|
|
1115
|
+
if (node.expression.kind === SyntaxKind.PropertyAccessExpression) {
|
|
1116
|
+
bindAssignmentTargetFlow(node.expression);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function bindConditionalExpressionFlow(node) {
|
|
1120
|
+
const trueLabel = createBranchLabel();
|
|
1121
|
+
const falseLabel = createBranchLabel();
|
|
1122
|
+
const postExpressionLabel = createBranchLabel();
|
|
1123
|
+
bindCondition(node.condition, trueLabel, falseLabel);
|
|
1124
|
+
currentFlow = finishFlowLabel(trueLabel);
|
|
1125
|
+
bind(node.questionToken);
|
|
1126
|
+
bind(node.whenTrue);
|
|
1127
|
+
addAntecedent(postExpressionLabel, currentFlow);
|
|
1128
|
+
currentFlow = finishFlowLabel(falseLabel);
|
|
1129
|
+
bind(node.colonToken);
|
|
1130
|
+
bind(node.whenFalse);
|
|
1131
|
+
addAntecedent(postExpressionLabel, currentFlow);
|
|
1132
|
+
currentFlow = finishFlowLabel(postExpressionLabel);
|
|
1133
|
+
}
|
|
1134
|
+
function bindInitializedVariableFlow(node) {
|
|
1135
|
+
const name = !isOmittedExpression(node) ? node.name : void 0;
|
|
1136
|
+
if (isBindingPattern(name)) {
|
|
1137
|
+
for (const child of name.elements) {
|
|
1138
|
+
bindInitializedVariableFlow(child);
|
|
1139
|
+
}
|
|
1140
|
+
} else {
|
|
1141
|
+
currentFlow = createFlowMutation(FlowFlags.Assignment, currentFlow, node);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function bindVariableDeclarationFlow(node) {
|
|
1145
|
+
bindEachChild(node);
|
|
1146
|
+
if (node.initializer || isForInOrOfStatement(node.parent.parent)) {
|
|
1147
|
+
bindInitializedVariableFlow(node);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
function bindOptionalExpression(node, trueTarget, falseTarget) {
|
|
1151
|
+
doWithConditionalBranches(bind, node, trueTarget, falseTarget);
|
|
1152
|
+
if (!isOptionalChain(node) || isOutermostOptionalChain(node)) {
|
|
1153
|
+
addAntecedent(trueTarget, createFlowCondition(FlowFlags.TrueCondition, currentFlow, node));
|
|
1154
|
+
addAntecedent(falseTarget, createFlowCondition(FlowFlags.FalseCondition, currentFlow, node));
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function bindOptionalChainRest(node) {
|
|
1158
|
+
switch (node.kind) {
|
|
1159
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
1160
|
+
bind(node.questionDotToken);
|
|
1161
|
+
bind(node.name);
|
|
1162
|
+
break;
|
|
1163
|
+
case SyntaxKind.ElementAccessExpression:
|
|
1164
|
+
bind(node.questionDotToken);
|
|
1165
|
+
bind(node.argumentExpression);
|
|
1166
|
+
break;
|
|
1167
|
+
case SyntaxKind.CallExpression:
|
|
1168
|
+
bind(node.questionDotToken);
|
|
1169
|
+
bindEach(node.typeArguments);
|
|
1170
|
+
bindEach(node.arguments);
|
|
1171
|
+
break;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function bindOptionalChain(node, trueTarget, falseTarget) {
|
|
1175
|
+
const preChainLabel = isOptionalChainRoot(node) ? createBranchLabel() : void 0;
|
|
1176
|
+
bindOptionalExpression(node.expression, preChainLabel || trueTarget, falseTarget);
|
|
1177
|
+
if (preChainLabel) {
|
|
1178
|
+
currentFlow = finishFlowLabel(preChainLabel);
|
|
1179
|
+
}
|
|
1180
|
+
doWithConditionalBranches(bindOptionalChainRest, node, trueTarget, falseTarget);
|
|
1181
|
+
if (isOutermostOptionalChain(node)) {
|
|
1182
|
+
addAntecedent(trueTarget, createFlowCondition(FlowFlags.TrueCondition, currentFlow, node));
|
|
1183
|
+
addAntecedent(falseTarget, createFlowCondition(FlowFlags.FalseCondition, currentFlow, node));
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
function bindOptionalChainFlow(node) {
|
|
1187
|
+
if (isTopLevelLogicalExpression(node)) {
|
|
1188
|
+
const postExpressionLabel = createBranchLabel();
|
|
1189
|
+
bindOptionalChain(node, postExpressionLabel, postExpressionLabel);
|
|
1190
|
+
currentFlow = finishFlowLabel(postExpressionLabel);
|
|
1191
|
+
} else {
|
|
1192
|
+
bindOptionalChain(node, currentTrueTarget, currentFalseTarget);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function bindAccessExpressionFlow(node) {
|
|
1196
|
+
if (isOptionalChain(node)) {
|
|
1197
|
+
bindOptionalChainFlow(node);
|
|
1198
|
+
} else {
|
|
1199
|
+
bindEachChild(node);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
function bindCallExpressionFlow(node) {
|
|
1203
|
+
if (isOptionalChain(node)) {
|
|
1204
|
+
bindOptionalChainFlow(node);
|
|
1205
|
+
} else {
|
|
1206
|
+
const expr = skipParentheses(node.expression);
|
|
1207
|
+
if (expr.kind === SyntaxKind.ArrowFunction) {
|
|
1208
|
+
bindEach(node.typeArguments);
|
|
1209
|
+
bindEach(node.arguments);
|
|
1210
|
+
bind(node.expression);
|
|
1211
|
+
} else {
|
|
1212
|
+
bindEachChild(node);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
function getContainerFlags(node) {
|
|
1217
|
+
switch (node.kind) {
|
|
1218
|
+
case SyntaxKind.ObjectLiteralExpression:
|
|
1219
|
+
case SyntaxKind.TypeLiteral:
|
|
1220
|
+
case SyntaxKind.JsxAttributes:
|
|
1221
|
+
return 1 /* IsContainer */;
|
|
1222
|
+
case SyntaxKind.ModuleDeclaration:
|
|
1223
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
1224
|
+
case SyntaxKind.MappedType:
|
|
1225
|
+
return 1 /* IsContainer */ | 32 /* HasLocals */;
|
|
1226
|
+
case SyntaxKind.SourceFile:
|
|
1227
|
+
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */;
|
|
1228
|
+
case SyntaxKind.CallSignature:
|
|
1229
|
+
case SyntaxKind.FunctionType:
|
|
1230
|
+
case SyntaxKind.IndexSignature:
|
|
1231
|
+
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */;
|
|
1232
|
+
case SyntaxKind.ArrowFunction:
|
|
1233
|
+
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 16 /* IsFunctionExpression */;
|
|
1234
|
+
case SyntaxKind.ModuleBlock:
|
|
1235
|
+
return 4 /* IsControlFlowContainer */;
|
|
1236
|
+
case SyntaxKind.CatchClause:
|
|
1237
|
+
case SyntaxKind.ForStatement:
|
|
1238
|
+
case SyntaxKind.ForInStatement:
|
|
1239
|
+
case SyntaxKind.ForOfStatement:
|
|
1240
|
+
case SyntaxKind.CaseBlock:
|
|
1241
|
+
return 2 /* IsBlockScopedContainer */;
|
|
1242
|
+
case SyntaxKind.Block:
|
|
1243
|
+
return isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */;
|
|
1244
|
+
}
|
|
1245
|
+
return 0 /* None */;
|
|
1246
|
+
}
|
|
1247
|
+
function addToContainerChain(next) {
|
|
1248
|
+
if (lastContainer) {
|
|
1249
|
+
lastContainer.nextContainer = next;
|
|
1250
|
+
}
|
|
1251
|
+
lastContainer = next;
|
|
1252
|
+
}
|
|
1253
|
+
function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
|
|
1254
|
+
switch (container.kind) {
|
|
1255
|
+
// o namespace e o arquivo decidem entre os `locals` e os `exports`
|
|
1256
|
+
case SyntaxKind.ModuleDeclaration:
|
|
1257
|
+
return declareModuleMember(node, symbolFlags, symbolExcludes);
|
|
1258
|
+
case SyntaxKind.SourceFile:
|
|
1259
|
+
return declareSourceFileMember(node, symbolFlags, symbolExcludes);
|
|
1260
|
+
case SyntaxKind.TypeLiteral:
|
|
1261
|
+
case SyntaxKind.ObjectLiteralExpression:
|
|
1262
|
+
case SyntaxKind.JsxAttributes:
|
|
1263
|
+
return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
|
|
1264
|
+
case SyntaxKind.FunctionType:
|
|
1265
|
+
case SyntaxKind.CallSignature:
|
|
1266
|
+
case SyntaxKind.IndexSignature:
|
|
1267
|
+
case SyntaxKind.ArrowFunction:
|
|
1268
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
1269
|
+
case SyntaxKind.MappedType:
|
|
1270
|
+
return declareSymbol(
|
|
1271
|
+
container.locals,
|
|
1272
|
+
/*parent*/
|
|
1273
|
+
void 0,
|
|
1274
|
+
node,
|
|
1275
|
+
symbolFlags,
|
|
1276
|
+
symbolExcludes
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
|
|
1281
|
+
return isExternalModule(file) ? declareModuleMember(node, symbolFlags, symbolExcludes) : declareSymbol(
|
|
1282
|
+
file.locals,
|
|
1283
|
+
/*parent*/
|
|
1284
|
+
void 0,
|
|
1285
|
+
node,
|
|
1286
|
+
symbolFlags,
|
|
1287
|
+
symbolExcludes
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
function hasExportDeclarations(node) {
|
|
1291
|
+
const body = isSourceFile(node) ? node : tryCast(node.body, isModuleBlock);
|
|
1292
|
+
return !!body && body.statements.some((s) => isExportDeclaration(s) || isExportAssignment(s));
|
|
1293
|
+
}
|
|
1294
|
+
function setExportContextFlag(node) {
|
|
1295
|
+
if (node.flags & NodeFlags.Ambient && !hasExportDeclarations(node)) {
|
|
1296
|
+
node.flags |= NodeFlags.ExportContext;
|
|
1297
|
+
} else {
|
|
1298
|
+
node.flags &= ~NodeFlags.ExportContext;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
function bindModuleDeclaration(node) {
|
|
1302
|
+
setExportContextFlag(node);
|
|
1303
|
+
if (isAmbientModule(node)) {
|
|
1304
|
+
if (hasModifier(node, ModifierFlags.Export)) {
|
|
1305
|
+
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
|
|
1306
|
+
}
|
|
1307
|
+
if (isModuleAugmentationExternal(node)) {
|
|
1308
|
+
declareModuleSymbol(node);
|
|
1309
|
+
} else {
|
|
1310
|
+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
|
|
1311
|
+
}
|
|
1312
|
+
} else {
|
|
1313
|
+
declareModuleSymbol(node);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
function declareModuleSymbol(node) {
|
|
1317
|
+
const instantiated = getModuleInstanceState(node) !== 0 /* NonInstantiated */;
|
|
1318
|
+
declareSymbolAndAddToSymbolTable(
|
|
1319
|
+
node,
|
|
1320
|
+
instantiated ? SymbolFlags.ValueModule : SymbolFlags.NamespaceModule,
|
|
1321
|
+
instantiated ? SymbolFlags.ValueModuleExcludes : SymbolFlags.NamespaceModuleExcludes
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
function bindFunctionOrConstructorType(node) {
|
|
1325
|
+
const symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
|
|
1326
|
+
addDeclarationToSymbol(symbol, node, SymbolFlags.Signature);
|
|
1327
|
+
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
|
|
1328
|
+
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
|
|
1329
|
+
typeLiteralSymbol.members = createSymbolTable();
|
|
1330
|
+
typeLiteralSymbol.members.set(symbol.escapedName, symbol);
|
|
1331
|
+
}
|
|
1332
|
+
function bindObjectLiteralExpression(node) {
|
|
1333
|
+
if (inStrictMode && !isAssignmentTarget(node)) {
|
|
1334
|
+
const seen = createUnderscoreEscapedMap();
|
|
1335
|
+
for (const prop of node.properties) {
|
|
1336
|
+
if (prop.kind === SyntaxKind.SpreadAssignment || prop.name.kind !== SyntaxKind.Identifier) {
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
const identifier = prop.name;
|
|
1340
|
+
if (!seen.has(identifier.escapedText)) {
|
|
1341
|
+
seen.set(identifier.escapedText, true);
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
const span = getErrorSpanForNode(file, identifier);
|
|
1345
|
+
file.bindDiagnostics.push(createFileDiagnostic(
|
|
1346
|
+
file,
|
|
1347
|
+
span.start,
|
|
1348
|
+
span.length,
|
|
1349
|
+
Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode
|
|
1350
|
+
));
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, InternalSymbolName.Object);
|
|
1354
|
+
}
|
|
1355
|
+
function bindJsxAttributes(node) {
|
|
1356
|
+
return bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, InternalSymbolName.JSXAttributes);
|
|
1357
|
+
}
|
|
1358
|
+
function bindJsxAttribute(node, symbolFlags, symbolExcludes) {
|
|
1359
|
+
return declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
|
|
1360
|
+
}
|
|
1361
|
+
function bindAnonymousDeclaration(node, symbolFlags, name) {
|
|
1362
|
+
const symbol = createSymbol(symbolFlags, name);
|
|
1363
|
+
if (symbolFlags & SymbolFlags.ClassMember) {
|
|
1364
|
+
symbol.parent = container.symbol;
|
|
1365
|
+
}
|
|
1366
|
+
addDeclarationToSymbol(symbol, node, symbolFlags);
|
|
1367
|
+
return symbol;
|
|
1368
|
+
}
|
|
1369
|
+
function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
|
|
1370
|
+
switch (blockScopeContainer.kind) {
|
|
1371
|
+
case SyntaxKind.ModuleDeclaration:
|
|
1372
|
+
declareModuleMember(node, symbolFlags, symbolExcludes);
|
|
1373
|
+
break;
|
|
1374
|
+
case SyntaxKind.SourceFile:
|
|
1375
|
+
if (isExternalModule(container)) {
|
|
1376
|
+
declareModuleMember(node, symbolFlags, symbolExcludes);
|
|
1377
|
+
break;
|
|
1378
|
+
}
|
|
1379
|
+
// falls through
|
|
1380
|
+
default:
|
|
1381
|
+
if (!blockScopeContainer.locals) {
|
|
1382
|
+
blockScopeContainer.locals = createSymbolTable();
|
|
1383
|
+
addToContainerChain(blockScopeContainer);
|
|
1384
|
+
}
|
|
1385
|
+
declareSymbol(
|
|
1386
|
+
blockScopeContainer.locals,
|
|
1387
|
+
/*parent*/
|
|
1388
|
+
void 0,
|
|
1389
|
+
node,
|
|
1390
|
+
symbolFlags,
|
|
1391
|
+
symbolExcludes
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function checkStrictModeIdentifier(node) {
|
|
1396
|
+
if (inStrictMode && node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord && !isIdentifierName(node) && !(node.flags & NodeFlags.Ambient)) {
|
|
1397
|
+
if (!file.parseDiagnostics.length) {
|
|
1398
|
+
file.bindDiagnostics.push(createDiagnosticForNode(
|
|
1399
|
+
node,
|
|
1400
|
+
getStrictModeIdentifierMessage(),
|
|
1401
|
+
declarationNameToString(node)
|
|
1402
|
+
));
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
function getStrictModeIdentifierMessage() {
|
|
1407
|
+
if (file.externalModuleIndicator) {
|
|
1408
|
+
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
|
|
1409
|
+
}
|
|
1410
|
+
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
|
|
1411
|
+
}
|
|
1412
|
+
function checkStrictModeBinaryExpression(node) {
|
|
1413
|
+
if (inStrictMode && isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
1414
|
+
checkStrictModeEvalOrArguments(node.left);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
function checkStrictModeCatchClause(node) {
|
|
1418
|
+
if (inStrictMode && node.variableDeclaration) {
|
|
1419
|
+
checkStrictModeEvalOrArguments(node.variableDeclaration.name);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
function checkStrictModeDeleteExpression(node) {
|
|
1423
|
+
if (inStrictMode && node.expression.kind === SyntaxKind.Identifier) {
|
|
1424
|
+
const span = getErrorSpanForNode(file, node.expression);
|
|
1425
|
+
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
function isEvalOrArgumentsIdentifier(node) {
|
|
1429
|
+
return isIdentifier(node) && (node.escapedText === "eval" || node.escapedText === "arguments");
|
|
1430
|
+
}
|
|
1431
|
+
function checkStrictModeEvalOrArguments(name) {
|
|
1432
|
+
if (name && name.kind === SyntaxKind.Identifier) {
|
|
1433
|
+
const identifier = name;
|
|
1434
|
+
if (isEvalOrArgumentsIdentifier(identifier)) {
|
|
1435
|
+
const span = getErrorSpanForNode(file, name);
|
|
1436
|
+
file.bindDiagnostics.push(createFileDiagnostic(
|
|
1437
|
+
file,
|
|
1438
|
+
span.start,
|
|
1439
|
+
span.length,
|
|
1440
|
+
getStrictModeEvalOrArgumentsMessage(),
|
|
1441
|
+
idText(identifier)
|
|
1442
|
+
));
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
function getStrictModeEvalOrArgumentsMessage() {
|
|
1447
|
+
if (file.externalModuleIndicator) {
|
|
1448
|
+
return Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
|
|
1449
|
+
}
|
|
1450
|
+
return Diagnostics.Invalid_use_of_0_in_strict_mode;
|
|
1451
|
+
}
|
|
1452
|
+
function checkStrictModeNumericLiteral(node) {
|
|
1453
|
+
if (inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) {
|
|
1454
|
+
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
function checkStrictModePostfixUnaryExpression(node) {
|
|
1458
|
+
if (inStrictMode) {
|
|
1459
|
+
checkStrictModeEvalOrArguments(node.operand);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function checkStrictModePrefixUnaryExpression(node) {
|
|
1463
|
+
if (inStrictMode) {
|
|
1464
|
+
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
|
1465
|
+
checkStrictModeEvalOrArguments(node.operand);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
function errorOnFirstToken(node, message, arg0, arg1, arg2) {
|
|
1470
|
+
const span = getSpanOfTokenAtPosition(file, node.pos);
|
|
1471
|
+
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
|
|
1472
|
+
}
|
|
1473
|
+
function errorOrSuggestionOnRange(isError, startNode, endNode, message) {
|
|
1474
|
+
addErrorOrSuggestionDiagnostic(isError, { pos: getTokenPosOfNode(startNode, file), end: endNode.end }, message);
|
|
1475
|
+
}
|
|
1476
|
+
function addErrorOrSuggestionDiagnostic(isError, range, message) {
|
|
1477
|
+
const diag = createFileDiagnostic(file, range.pos, range.end - range.pos, message);
|
|
1478
|
+
if (isError) {
|
|
1479
|
+
file.bindDiagnostics.push(diag);
|
|
1480
|
+
} else {
|
|
1481
|
+
file.bindSuggestionDiagnostics = append(file.bindSuggestionDiagnostics, { ...diag, category: DiagnosticCategory.Suggestion });
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function bind(node) {
|
|
1485
|
+
if (!node) {
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
node.parent = parent;
|
|
1489
|
+
const saveInStrictMode = inStrictMode;
|
|
1490
|
+
bindWorker(node);
|
|
1491
|
+
if (node.kind > SyntaxKind.LastToken) {
|
|
1492
|
+
const saveParent = parent;
|
|
1493
|
+
parent = node;
|
|
1494
|
+
const containerFlags = getContainerFlags(node);
|
|
1495
|
+
if (containerFlags === 0 /* None */) {
|
|
1496
|
+
bindChildren(node);
|
|
1497
|
+
} else {
|
|
1498
|
+
bindContainer(node, containerFlags);
|
|
1499
|
+
}
|
|
1500
|
+
parent = saveParent;
|
|
1501
|
+
}
|
|
1502
|
+
inStrictMode = saveInStrictMode;
|
|
1503
|
+
}
|
|
1504
|
+
function bindWorker(node) {
|
|
1505
|
+
switch (node.kind) {
|
|
1506
|
+
case SyntaxKind.Identifier:
|
|
1507
|
+
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
|
|
1508
|
+
node.flowNode = currentFlow;
|
|
1509
|
+
}
|
|
1510
|
+
return checkStrictModeIdentifier(node);
|
|
1511
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
1512
|
+
case SyntaxKind.ElementAccessExpression:
|
|
1513
|
+
const expr = node;
|
|
1514
|
+
if (currentFlow && isNarrowableReference(expr)) {
|
|
1515
|
+
expr.flowNode = currentFlow;
|
|
1516
|
+
}
|
|
1517
|
+
break;
|
|
1518
|
+
case SyntaxKind.BinaryExpression:
|
|
1519
|
+
return checkStrictModeBinaryExpression(node);
|
|
1520
|
+
case SyntaxKind.CatchClause:
|
|
1521
|
+
return checkStrictModeCatchClause(node);
|
|
1522
|
+
case SyntaxKind.DeleteExpression:
|
|
1523
|
+
return checkStrictModeDeleteExpression(node);
|
|
1524
|
+
case SyntaxKind.NumericLiteral:
|
|
1525
|
+
return checkStrictModeNumericLiteral(node);
|
|
1526
|
+
case SyntaxKind.PostfixUnaryExpression:
|
|
1527
|
+
return checkStrictModePostfixUnaryExpression(node);
|
|
1528
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
1529
|
+
return checkStrictModePrefixUnaryExpression(node);
|
|
1530
|
+
case SyntaxKind.TypePredicate:
|
|
1531
|
+
break;
|
|
1532
|
+
// os filhos resolvem
|
|
1533
|
+
case SyntaxKind.TypeParameter:
|
|
1534
|
+
return bindTypeParameter(node);
|
|
1535
|
+
case SyntaxKind.Parameter:
|
|
1536
|
+
return bindParameter(node);
|
|
1537
|
+
case SyntaxKind.VariableDeclaration:
|
|
1538
|
+
return bindVariableDeclarationOrBindingElement(node);
|
|
1539
|
+
case SyntaxKind.BindingElement:
|
|
1540
|
+
node.flowNode = currentFlow;
|
|
1541
|
+
return bindVariableDeclarationOrBindingElement(node);
|
|
1542
|
+
case SyntaxKind.PropertySignature:
|
|
1543
|
+
return bindPropertyWorker(node);
|
|
1544
|
+
case SyntaxKind.PropertyAssignment:
|
|
1545
|
+
case SyntaxKind.ShorthandPropertyAssignment:
|
|
1546
|
+
return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
|
1547
|
+
case SyntaxKind.CallSignature:
|
|
1548
|
+
case SyntaxKind.IndexSignature:
|
|
1549
|
+
return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Signature, SymbolFlags.None);
|
|
1550
|
+
case SyntaxKind.FunctionType:
|
|
1551
|
+
return bindFunctionOrConstructorType(node);
|
|
1552
|
+
case SyntaxKind.TypeLiteral:
|
|
1553
|
+
case SyntaxKind.MappedType:
|
|
1554
|
+
return bindAnonymousTypeWorker(node);
|
|
1555
|
+
case SyntaxKind.ObjectLiteralExpression:
|
|
1556
|
+
return bindObjectLiteralExpression(node);
|
|
1557
|
+
case SyntaxKind.ArrowFunction:
|
|
1558
|
+
return bindFunctionExpression(node);
|
|
1559
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
1560
|
+
return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
|
|
1561
|
+
case SyntaxKind.ModuleDeclaration:
|
|
1562
|
+
return bindModuleDeclaration(node);
|
|
1563
|
+
case SyntaxKind.JsxAttributes:
|
|
1564
|
+
return bindJsxAttributes(node);
|
|
1565
|
+
case SyntaxKind.JsxAttribute:
|
|
1566
|
+
return bindJsxAttribute(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
|
1567
|
+
case SyntaxKind.NamespaceImport:
|
|
1568
|
+
case SyntaxKind.ImportSpecifier:
|
|
1569
|
+
case SyntaxKind.ExportSpecifier:
|
|
1570
|
+
return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
|
1571
|
+
case SyntaxKind.ImportClause:
|
|
1572
|
+
return bindImportClause(node);
|
|
1573
|
+
case SyntaxKind.ExportDeclaration:
|
|
1574
|
+
return bindExportDeclaration(node);
|
|
1575
|
+
case SyntaxKind.ExportAssignment:
|
|
1576
|
+
return bindExportAssignment(node);
|
|
1577
|
+
case SyntaxKind.SourceFile:
|
|
1578
|
+
return bindSourceFileIfExternalModule();
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function bindPropertyWorker(node) {
|
|
1582
|
+
return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes);
|
|
1583
|
+
}
|
|
1584
|
+
function bindAnonymousTypeWorker(node) {
|
|
1585
|
+
return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, InternalSymbolName.Type);
|
|
1586
|
+
}
|
|
1587
|
+
function bindSourceFileIfExternalModule() {
|
|
1588
|
+
setExportContextFlag(file);
|
|
1589
|
+
if (isExternalModule(file)) {
|
|
1590
|
+
bindSourceFileAsExternalModule();
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
function bindSourceFileAsExternalModule() {
|
|
1594
|
+
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"`);
|
|
1595
|
+
}
|
|
1596
|
+
function bindExportAssignment(node) {
|
|
1597
|
+
if (!container.symbol || !container.symbol.exports) {
|
|
1598
|
+
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
|
|
1599
|
+
} else {
|
|
1600
|
+
const flags = exportAssignmentIsAlias(node) ? SymbolFlags.Alias : SymbolFlags.Property;
|
|
1601
|
+
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.All);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
function bindExportDeclaration(node) {
|
|
1605
|
+
if (!container.symbol || !container.symbol.exports) {
|
|
1606
|
+
bindAnonymousDeclaration(node, SymbolFlags.ExportStar, getDeclarationName(node));
|
|
1607
|
+
} else if (!node.exportClause) {
|
|
1608
|
+
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None);
|
|
1609
|
+
} else if (isNamespaceExport(node.exportClause)) {
|
|
1610
|
+
node.exportClause.parent = node;
|
|
1611
|
+
declareSymbol(container.symbol.exports, container.symbol, node.exportClause, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
function bindImportClause(node) {
|
|
1615
|
+
if (node.name) {
|
|
1616
|
+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
function bindVariableDeclarationOrBindingElement(node) {
|
|
1620
|
+
if (inStrictMode) {
|
|
1621
|
+
checkStrictModeEvalOrArguments(node.name);
|
|
1622
|
+
}
|
|
1623
|
+
if (!isBindingPattern(node.name)) {
|
|
1624
|
+
if (isBlockOrCatchScoped(node)) {
|
|
1625
|
+
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
|
1626
|
+
} else if (isParameterDeclaration(node)) {
|
|
1627
|
+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
function bindParameter(node) {
|
|
1632
|
+
if (inStrictMode && !(node.flags & NodeFlags.Ambient)) {
|
|
1633
|
+
checkStrictModeEvalOrArguments(node.name);
|
|
1634
|
+
}
|
|
1635
|
+
if (isBindingPattern(node.name)) {
|
|
1636
|
+
bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, "__" + node.parent.parameters.indexOf(node));
|
|
1637
|
+
} else {
|
|
1638
|
+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function bindFunctionExpression(node) {
|
|
1642
|
+
if (currentFlow) {
|
|
1643
|
+
node.flowNode = currentFlow;
|
|
1644
|
+
}
|
|
1645
|
+
return bindAnonymousDeclaration(node, SymbolFlags.Function, InternalSymbolName.Function);
|
|
1646
|
+
}
|
|
1647
|
+
function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
|
|
1648
|
+
return hasDynamicName(node) ? bindAnonymousDeclaration(node, symbolFlags, InternalSymbolName.Computed) : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
|
|
1649
|
+
}
|
|
1650
|
+
function getInferTypeContainer(node) {
|
|
1651
|
+
const extendsType = findAncestor(node, (n) => n.parent && isConditionalTypeNode(n.parent) && n.parent.extendsType === n);
|
|
1652
|
+
return extendsType && extendsType.parent;
|
|
1653
|
+
}
|
|
1654
|
+
function bindTypeParameter(node) {
|
|
1655
|
+
if (node.parent.kind === SyntaxKind.InferType) {
|
|
1656
|
+
const container2 = getInferTypeContainer(node.parent);
|
|
1657
|
+
if (container2) {
|
|
1658
|
+
if (!container2.locals) {
|
|
1659
|
+
container2.locals = createSymbolTable();
|
|
1660
|
+
}
|
|
1661
|
+
declareSymbol(
|
|
1662
|
+
container2.locals,
|
|
1663
|
+
/*parent*/
|
|
1664
|
+
void 0,
|
|
1665
|
+
node,
|
|
1666
|
+
SymbolFlags.TypeParameter,
|
|
1667
|
+
SymbolFlags.TypeParameterExcludes
|
|
1668
|
+
);
|
|
1669
|
+
} else {
|
|
1670
|
+
bindAnonymousDeclaration(node, SymbolFlags.TypeParameter, getDeclarationName(node));
|
|
1671
|
+
}
|
|
1672
|
+
} else {
|
|
1673
|
+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
function shouldReportErrorOnModuleDeclaration(node) {
|
|
1677
|
+
const instanceState = getModuleInstanceState(node);
|
|
1678
|
+
return instanceState === 1 /* Instantiated */;
|
|
1679
|
+
}
|
|
1680
|
+
function checkUnreachable(node) {
|
|
1681
|
+
if (!(currentFlow.flags & FlowFlags.Unreachable)) {
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
if (currentFlow === unreachableFlow) {
|
|
1685
|
+
const reportError = isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement || node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(node);
|
|
1686
|
+
if (reportError) {
|
|
1687
|
+
currentFlow = reportedUnreachableFlow;
|
|
1688
|
+
if (!options.allowUnreachableCode) {
|
|
1689
|
+
const isError = unreachableCodeIsError(options) && !(node.flags & NodeFlags.Ambient);
|
|
1690
|
+
eachUnreachableRange(node, (start, end) => errorOrSuggestionOnRange(isError, start, end, Diagnostics.Unreachable_code_detected));
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return true;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
function eachUnreachableRange(node, cb) {
|
|
1698
|
+
if (isStatement(node) && isExecutableStatement(node) && isBlock(node.parent)) {
|
|
1699
|
+
const { statements } = node.parent;
|
|
1700
|
+
const slice = sliceAfter(statements, node);
|
|
1701
|
+
getRangesWhere(slice, isExecutableStatement, (start, afterEnd) => cb(slice[start], slice[afterEnd - 1]));
|
|
1702
|
+
} else {
|
|
1703
|
+
cb(node, node);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
function isExecutableStatement(s) {
|
|
1707
|
+
return !isPurelyTypeDeclaration(s) && !(isVariableStatement(s) && !(getCombinedNodeFlags(s) & (NodeFlags.Let | NodeFlags.Const)) && s.declarationList.declarations.some((d) => !d.initializer));
|
|
1708
|
+
}
|
|
1709
|
+
function isPurelyTypeDeclaration(s) {
|
|
1710
|
+
switch (s.kind) {
|
|
1711
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
1712
|
+
return true;
|
|
1713
|
+
case SyntaxKind.ModuleDeclaration:
|
|
1714
|
+
return getModuleInstanceState(s) !== 1 /* Instantiated */;
|
|
1715
|
+
default:
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
function setParentPointers(parent, child) {
|
|
1720
|
+
child.parent = parent;
|
|
1721
|
+
forEachChild(child, (grandchild) => setParentPointers(child, grandchild));
|
|
1722
|
+
}
|
|
1723
|
+
export {
|
|
1724
|
+
ModuleInstanceState,
|
|
1725
|
+
bindSourceFile,
|
|
1726
|
+
getModuleInstanceState
|
|
1727
|
+
};
|