mambascript 0.5.4 → 2.0.0
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/CHANGELOG.md +326 -0
- package/README.md +509 -267
- package/bin/mamba +1 -258
- package/decision.js +1 -246
- package/docs/coverage.md +70 -0
- package/docs/features.md +3348 -0
- package/docs/perf.md +94 -0
- package/docs/reference.md +1295 -0
- package/docs/vs-coffeescript.md +1593 -0
- package/docs/vs-iced-coffeescript.md +626 -0
- package/docs/vs-typescript.md +107 -0
- package/esm.js +8 -0
- package/jest.js +33 -0
- package/lib/black.js +17 -13
- package/lib/browser.js +2 -4
- package/lib/cli.js +207 -136
- package/lib/compiler.js +1162 -93
- package/lib/decision.js +10 -10
- package/lib/diagnostics.js +219 -0
- package/lib/esm-hooks.js +60 -0
- package/lib/fast-parser.js +3469 -0
- package/lib/functional-helpers.js +26 -9
- package/lib/helpers.js +67 -50
- package/lib/js-nodes.js +151 -12
- package/lib/lexer.js +1499 -0
- package/lib/light-module.js +200 -63
- package/lib/mamba.js +372 -0
- package/lib/module.js +23 -172
- package/lib/nodes.js +84 -21
- package/lib/optimiser.js +29 -9
- package/lib/optparse.js +32 -15
- package/lib/parser.js +9433 -4840
- package/lib/preprocessor.js +3 -5
- package/lib/register.js +49 -56
- package/lib/repl.js +28 -9
- package/lib/reporter.js +106 -69
- package/lib/run.js +3 -5
- package/lib/string-scanner.js +94 -0
- package/lib/syntax-tables.js +480 -0
- package/lib/type-checker.js +258 -44
- package/lib/type-helpers.js +28 -10
- package/lib/type-resolver.js +256 -34
- package/lib/type-scope.js +10 -6
- package/lib/type-walker.js +664 -85
- package/lib/types.js +17 -7
- package/lib/underscore.js +170 -76
- package/lib/unicode-classes.js +122 -0
- package/mambaview.js +1 -0
- package/package.json +49 -46
- package/stdlib.js +1 -0
- package/vendor/README.md +40 -0
- package/vendor/escodegen/LICENSE.BSD +19 -0
- package/vendor/escodegen/escodegen.js +2289 -0
- package/vendor/estraverse/LICENSE.BSD +19 -0
- package/vendor/estraverse/estraverse.js +706 -0
- package/vendor/mambacodegen/LICENSE +24 -0
- package/vendor/mambacodegen/lib/mscodegen.js +620 -0
- package/vendor/patches/escodegen.diff +130 -0
- package/vendor/patches/estraverse.diff +51 -0
- package/vendor/patches/pegjs.diff +70 -0
- package/vendor/patches/source-map.diff +160 -0
- package/vendor/source-map/LICENSE +28 -0
- package/vendor/source-map/lib/source-map/array-set.js +92 -0
- package/vendor/source-map/lib/source-map/base64-vlq.js +140 -0
- package/vendor/source-map/lib/source-map/base64.js +38 -0
- package/vendor/source-map/lib/source-map/binary-search.js +77 -0
- package/vendor/source-map/lib/source-map/source-map-consumer.js +404 -0
- package/vendor/source-map/lib/source-map/source-map-generator.js +229 -0
- package/vendor/source-map/lib/source-map/source-node.js +201 -0
- package/vendor/source-map/lib/source-map/util.js +57 -0
- package/vendor/source-map/lib/source-map.js +8 -0
- package/bin/fix +0 -17
- package/bin/updateImports +0 -46
- package/build.js +0 -25
- package/lib/module-esm.js +0 -901
- package/lib/pegjs-kofu-plugin.js +0 -35
- package/lib/pegjs-mamba-plugin.js +0 -35
- package/lib/processor-esm.js +0 -507
- package/mamba +0 -259
- package/msast.js +0 -1
- package/utils/gulp-mamba.js +0 -29
- /package/{lib/esm.js → vendor/patches/mambacodegen.diff} +0 -0
package/lib/type-walker.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
// Generated by MambaScript 0.
|
|
2
|
-
var
|
|
3
|
-
// Generated by MambaScript 0.5.2
|
|
4
|
-
var _, addValuesByInitializer, checkNodes, checkType, checkTypeAnnotation, ClassScope, createIdentifier, debug, extendType, fromMemberAccessToRef, FunctionScope, ImplicitAny, initializeGlobalTypes, mergeStruct, ModuleScope, moduleToProperties, MS, reporter, resolveType, Scope, walk, walkArrayInializer, walkAssignOp, walkBinOp, walkBlock, walkBool, walkClass, walkClassProtoAssignOp, walkCompoundAssignOp, walkConditional, walkDynamicMemberAccessOp, walkDynamicProtoMemberAccessOp, walkFloat, walkFor, walkFunction, walkFunctionApplication, walkIdentifier, walkInt, walkMemberAccess, walkModule, walkNewOp, walkNull, walkNumbers, walkObjectInitializer, walkOfOp, walkPrimitives, walkProgram, walkProtoMemberAccessOp, walkRange, walkReturn, walkString, walkStruct, walkSwitch, walkThis, walkUndefined, walkVardef;
|
|
1
|
+
// Generated by MambaScript 2.0.0
|
|
2
|
+
var _, addValuesByInitializer, arrayOf, assignedMembers, BooleanType, cache$, cache$1, cache$2, cache$3, checkKnownMember, checkNodes, checkType, checkTypeAnnotation, ClassScope, collectAssignedMembers, createIdentifier, debug, depthOf, elementOf, extendType, fromMemberAccessToRef, FunctionScope, hasDynamicPrototype, ImplicitAny, initializeGlobalTypes, isAcceptable, mergeStruct, ModuleScope, moduleToProperties, MS, OBJECT_MEMBERS, popOpenTypeParameters, pushOpenTypeParameters, reporter, resetUnknownTypes, resolveType, restArrayType, Scope, walk, walkArrayInializer, walkAssignChecked, walkAssignOp, walkAwaitOp, walkBigInt, walkBinOp, walkBinOpGeneric, walkBlock, walkBool, walkClass, walkClassProtoAssignOp, walkCompoundAssignOp, walkConditional, walkDynamicImport, walkDynamicMemberAccessOp, walkDynamicProtoMemberAccessOp, walkFloat, walkFor, walkFunction, walkFunctionApplication, walkGeneric, walkIdentifier, walkInt, walkLogicalNotOp, walkMemberAccess, walkModule, walkNewOp, walkNull, walkNumbers, walkObjectInitializer, walkOfOp, walkPrimitives, walkProgram, walkProtoMemberAccessOp, walkRange, walkReturn, walkSoakedFunctionApplication, walkString, walkStruct, walkSwitch, walkThis, walkTry, walkUndefined, walkVardef, walkWhile, walkYield;
|
|
5
3
|
debug = require('./helpers').debug;
|
|
6
4
|
reporter = require('./reporter');
|
|
7
5
|
MS = require('./nodes');
|
|
8
|
-
_ = require('
|
|
6
|
+
_ = require('./underscore');
|
|
9
7
|
cache$ = require('./type-checker');
|
|
10
8
|
checkType = cache$.checkType;
|
|
11
9
|
checkTypeAnnotation = cache$.checkTypeAnnotation;
|
|
10
|
+
isAcceptable = cache$.isAcceptable;
|
|
11
|
+
depthOf = cache$.depthOf;
|
|
12
|
+
elementOf = cache$.elementOf;
|
|
13
|
+
arrayOf = cache$.arrayOf;
|
|
12
14
|
cache$1 = require('./type-resolver');
|
|
13
15
|
resolveType = cache$1.resolveType;
|
|
14
16
|
extendType = cache$1.extendType;
|
|
17
|
+
resetUnknownTypes = cache$1.resetUnknownTypes;
|
|
18
|
+
pushOpenTypeParameters = cache$1.pushOpenTypeParameters;
|
|
19
|
+
popOpenTypeParameters = cache$1.popOpenTypeParameters;
|
|
15
20
|
cache$2 = require('./type-scope');
|
|
16
21
|
Scope = cache$2.Scope;
|
|
17
22
|
ClassScope = cache$2.ClassScope;
|
|
@@ -20,12 +25,17 @@ ModuleScope = cache$2.ModuleScope;
|
|
|
20
25
|
cache$3 = require('./types');
|
|
21
26
|
initializeGlobalTypes = cache$3.initializeGlobalTypes;
|
|
22
27
|
ImplicitAny = cache$3.ImplicitAny;
|
|
23
|
-
checkNodes = function (cs_ast) {
|
|
28
|
+
checkNodes = function (cs_ast, options) {
|
|
24
29
|
var g, root;
|
|
30
|
+
if (null == options)
|
|
31
|
+
options = {};
|
|
32
|
+
resetUnknownTypes();
|
|
33
|
+
assignedMembers.clear();
|
|
34
|
+
collectAssignedMembers(cs_ast);
|
|
25
35
|
g = 'undefined' !== typeof window && null != window ? window : global;
|
|
26
36
|
if (!(null != (null != cs_ast.body ? cs_ast.body.statements : void 0)))
|
|
27
37
|
return;
|
|
28
|
-
if (g._root_) {
|
|
38
|
+
if (options.persistScope && g._root_) {
|
|
29
39
|
root = g._root_;
|
|
30
40
|
} else {
|
|
31
41
|
g._root_ = root = new Scope;
|
|
@@ -112,7 +122,12 @@ walkVardef = function (node, scope) {
|
|
|
112
122
|
if (scope instanceof ClassScope || scope instanceof ModuleScope) {
|
|
113
123
|
if (symbol === 'constructor')
|
|
114
124
|
symbol = '_constructor_';
|
|
115
|
-
|
|
125
|
+
val = scope.getThis(symbol);
|
|
126
|
+
if (null != val ? val.placeholder : void 0) {
|
|
127
|
+
scope._this.splice(scope._this.indexOf(val), 1);
|
|
128
|
+
val = null;
|
|
129
|
+
}
|
|
130
|
+
if (!val) {
|
|
116
131
|
if (!node.isStatic) {
|
|
117
132
|
return scope.addThis({
|
|
118
133
|
nodeType: 'variable',
|
|
@@ -134,8 +149,14 @@ walkVardef = function (node, scope) {
|
|
|
134
149
|
}
|
|
135
150
|
} else if (val.typeAnnotation.implicit && val.typeAnnotation.identifier.typeRef === 'Any') {
|
|
136
151
|
return val.typeAnnotation = node.expr;
|
|
152
|
+
} else if (isAcceptable(scope, val.typeAnnotation, node.expr)) {
|
|
153
|
+
return val.typeAnnotation = node.expr;
|
|
137
154
|
} else {
|
|
138
|
-
return reporter.add_error(node, '
|
|
155
|
+
return reporter.add_error(node, '' + symbol + ' is declared again with a different type', {
|
|
156
|
+
code: 'MS2002',
|
|
157
|
+
why: 'A name keeps the type of its first declaration; ' + symbol + ' already has one, and this declaration gives it a type the first one does not accept.',
|
|
158
|
+
fix: 'keep one annotation for ' + symbol + ', or use a different name for the second value.'
|
|
159
|
+
});
|
|
139
160
|
}
|
|
140
161
|
} else if (!(val = scope.getVar(symbol))) {
|
|
141
162
|
return scope.addVar({
|
|
@@ -149,7 +170,11 @@ walkVardef = function (node, scope) {
|
|
|
149
170
|
} else if (val.typeAnnotation.implicit && val.typeAnnotation.identifier.typeRef === 'Any') {
|
|
150
171
|
return val.typeAnnotation = node.expr;
|
|
151
172
|
} else {
|
|
152
|
-
return reporter.add_error(node, '
|
|
173
|
+
return reporter.add_error(node, '' + symbol + ' is declared again with a different type', {
|
|
174
|
+
code: 'MS2002',
|
|
175
|
+
why: 'A name keeps the type of its first declaration; ' + symbol + ' already has one, and this declaration gives it a type the first one does not accept.',
|
|
176
|
+
fix: 'keep one annotation for ' + symbol + ', or use a different name for the second value.'
|
|
177
|
+
});
|
|
153
178
|
}
|
|
154
179
|
};
|
|
155
180
|
walkProgram = function (node, scope) {
|
|
@@ -174,7 +199,7 @@ walkReturn = function (node, scope) {
|
|
|
174
199
|
}
|
|
175
200
|
};
|
|
176
201
|
walkBinOp = function (node, scope) {
|
|
177
|
-
var cache$4, leftAnnotation, leftRef, rightAnnotation, rightRef;
|
|
202
|
+
var cache$4, leftAnnotation, leftRef, numeric, rightAnnotation, rightRef;
|
|
178
203
|
walk(node.left, scope);
|
|
179
204
|
walk(node.right, scope);
|
|
180
205
|
cache$4 = [
|
|
@@ -200,7 +225,25 @@ walkBinOp = function (node, scope) {
|
|
|
200
225
|
leftRef = null != leftAnnotation && null != leftAnnotation.identifier ? leftAnnotation.identifier.typeRef : void 0;
|
|
201
226
|
rightRef = null != rightAnnotation && null != rightAnnotation.identifier ? rightAnnotation.identifier.typeRef : void 0;
|
|
202
227
|
if (leftRef && rightRef) {
|
|
203
|
-
|
|
228
|
+
numeric = [
|
|
229
|
+
'Int',
|
|
230
|
+
'Float',
|
|
231
|
+
'Number'
|
|
232
|
+
];
|
|
233
|
+
if (leftRef === 'BigInt' && in$(rightRef, numeric) || rightRef === 'BigInt' && in$(leftRef, numeric)) {
|
|
234
|
+
reporter.add_error(node, 'BigInt and Int cannot be mixed', {
|
|
235
|
+
code: 'MS2007',
|
|
236
|
+
why: 'JavaScript throws a TypeError when a BigInt meets a Number in arithmetic; the two kinds of number never convert on their own.',
|
|
237
|
+
fix: 'write both operands as BigInt (1n + 1n), or convert explicitly: Number(big) + 1.'
|
|
238
|
+
});
|
|
239
|
+
return node.typeAnnotation = ImplicitAny;
|
|
240
|
+
} else if (leftRef === 'BigInt' && rightRef === 'BigInt') {
|
|
241
|
+
return node.typeAnnotation = {
|
|
242
|
+
implicit: true,
|
|
243
|
+
nodeType: 'primitiveIdentifier',
|
|
244
|
+
identifier: createIdentifier('BigInt')
|
|
245
|
+
};
|
|
246
|
+
} else if (leftRef === 'String' || rightRef === 'String') {
|
|
204
247
|
return node.typeAnnotation = {
|
|
205
248
|
implicit: true,
|
|
206
249
|
nodeType: 'primitiveIdentifier',
|
|
@@ -281,7 +324,7 @@ walkSwitch = function (node, scope) {
|
|
|
281
324
|
c = node.cases[i$];
|
|
282
325
|
for (var i$1 = 0, length$1 = c.conditions.length; i$1 < length$1; ++i$1) {
|
|
283
326
|
cond = c.conditions[i$1];
|
|
284
|
-
walk(
|
|
327
|
+
walk(cond, scope);
|
|
285
328
|
}
|
|
286
329
|
if (c.consequent) {
|
|
287
330
|
walk(c.consequent, scope);
|
|
@@ -301,18 +344,22 @@ walkSwitch = function (node, scope) {
|
|
|
301
344
|
}
|
|
302
345
|
};
|
|
303
346
|
walkNewOp = function (node, scope) {
|
|
304
|
-
var ann, arg, args, ctor, ctorAnnotation, givenArgs, left, n, ns, parentScope, right;
|
|
347
|
+
var ann, arg, args, ctor, ctorAnnotation, e, givenArgs, left, n, ns, parentScope, right, splatsType;
|
|
305
348
|
ctor = null != (null != node.ctor ? node.ctor.ctor : void 0) ? null != node.ctor ? node.ctor.ctor : void 0 : node.ctor;
|
|
306
349
|
args = null != (null != node.ctor ? node.ctor['arguments'] : void 0) ? null != node.ctor ? node.ctor['arguments'] : void 0 : node['arguments'];
|
|
307
350
|
if (ctor instanceof MS.Identifier) {
|
|
308
351
|
ann = scope.getTypeByIdentifier(createIdentifier(ctor));
|
|
309
352
|
} else if (ctor instanceof MS.MemberAccessOp) {
|
|
310
|
-
if (null != ctor.expression)
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
353
|
+
if (null != ctor.expression)
|
|
354
|
+
try {
|
|
355
|
+
ns = fromMemberAccessToRef(ctor.expression);
|
|
356
|
+
parentScope = scope.getParentModule().resolveNamespace(ns);
|
|
357
|
+
if (parentScope)
|
|
358
|
+
ann = parentScope.getType(ctor.memberName);
|
|
359
|
+
} catch (e$) {
|
|
360
|
+
e = e$;
|
|
361
|
+
ann = ImplicitAny;
|
|
362
|
+
}
|
|
316
363
|
if (null != ann)
|
|
317
364
|
ann;
|
|
318
365
|
else
|
|
@@ -326,12 +373,25 @@ walkNewOp = function (node, scope) {
|
|
|
326
373
|
ctorAnnotation = _.find(ann.properties, function (i) {
|
|
327
374
|
return (null != i.identifier ? i.identifier.typeRef : void 0) === '_constructor_';
|
|
328
375
|
});
|
|
376
|
+
splatsType = null;
|
|
329
377
|
for (var i$ = 0, length$ = args.length; i$ < length$; ++i$) {
|
|
330
378
|
arg = args[i$];
|
|
331
379
|
n = i$;
|
|
332
380
|
walk(arg, scope);
|
|
333
381
|
left = null != ctorAnnotation && null != ctorAnnotation.typeAnnotation && null != ctorAnnotation.typeAnnotation['arguments'] ? ctorAnnotation.typeAnnotation['arguments'][n] : void 0;
|
|
334
382
|
right = 'undefined' !== typeof arg && null != arg ? arg.typeAnnotation : void 0;
|
|
383
|
+
if (null != left && null != left.identifier ? left.identifier.splats : void 0) {
|
|
384
|
+
splatsType = _.cloneDeep(left);
|
|
385
|
+
delete splatsType.identifier.splats;
|
|
386
|
+
if (splatsType.identifier.isArray)
|
|
387
|
+
splatsType = elementOf(splatsType);
|
|
388
|
+
left = splatsType;
|
|
389
|
+
} else {
|
|
390
|
+
if (null != left)
|
|
391
|
+
left;
|
|
392
|
+
else
|
|
393
|
+
left = splatsType;
|
|
394
|
+
}
|
|
335
395
|
if (left && right)
|
|
336
396
|
checkTypeAnnotation(scope, node, left, right);
|
|
337
397
|
}
|
|
@@ -360,7 +420,7 @@ walkModule = function (node, scope) {
|
|
|
360
420
|
return walk(node.body, moduleScope);
|
|
361
421
|
};
|
|
362
422
|
walkFor = function (node, scope) {
|
|
363
|
-
var bodyType, preAnnotation
|
|
423
|
+
var bodyType, preAnnotation;
|
|
364
424
|
walk(node.target, scope);
|
|
365
425
|
if (null != node.valAssignee) {
|
|
366
426
|
preAnnotation = null != node && null != node.valAssignee ? node.valAssignee.typeAnnotation : void 0;
|
|
@@ -368,9 +428,7 @@ walkFor = function (node, scope) {
|
|
|
368
428
|
if (preAnnotation) {
|
|
369
429
|
node.valAssignee.typeAnnotation = preAnnotation;
|
|
370
430
|
} else if (null != node.target.typeAnnotation && null != node.target.typeAnnotation.identifier ? node.target.typeAnnotation.identifier.isArray : void 0) {
|
|
371
|
-
|
|
372
|
-
delete targetType.identifier.isArray;
|
|
373
|
-
node.valAssignee.typeAnnotation = targetType;
|
|
431
|
+
node.valAssignee.typeAnnotation = elementOf(node.target.typeAnnotation);
|
|
374
432
|
} else {
|
|
375
433
|
node.valAssignee.typeAnnotation = ImplicitAny;
|
|
376
434
|
}
|
|
@@ -413,7 +471,7 @@ walkFor = function (node, scope) {
|
|
|
413
471
|
bodyType = _.cloneDeep(node.body.typeAnnotation);
|
|
414
472
|
if (null != bodyType ? bodyType.identifier : void 0) {
|
|
415
473
|
if (null != node.body) {
|
|
416
|
-
bodyType
|
|
474
|
+
bodyType = arrayOf(bodyType);
|
|
417
475
|
return node.typeAnnotation = bodyType;
|
|
418
476
|
} else {
|
|
419
477
|
return node.typeAnnotation = ImplicitAny;
|
|
@@ -423,11 +481,16 @@ walkFor = function (node, scope) {
|
|
|
423
481
|
}
|
|
424
482
|
};
|
|
425
483
|
walkClassProtoAssignOp = function (node, scope) {
|
|
426
|
-
var annotation, cache$4, left, right, symbol;
|
|
484
|
+
var annotation, cache$4, existing, left, right, symbol;
|
|
427
485
|
left = node.assignee;
|
|
428
486
|
right = node.expression;
|
|
429
487
|
symbol = left.data;
|
|
430
|
-
|
|
488
|
+
existing = scope.getThis(symbol);
|
|
489
|
+
if (null != existing ? existing.placeholder : void 0) {
|
|
490
|
+
scope._this.splice(scope._this.indexOf(existing), 1);
|
|
491
|
+
existing = null;
|
|
492
|
+
}
|
|
493
|
+
if (right['instanceof'](MS.Function) && existing) {
|
|
431
494
|
annotation = null != (cache$4 = scope.getThis(symbol)) ? cache$4.typeAnnotation : void 0;
|
|
432
495
|
if (null != annotation) {
|
|
433
496
|
left.typeAnnotation = annotation;
|
|
@@ -457,11 +520,20 @@ walkCompoundAssignOp = function (node, scope) {
|
|
|
457
520
|
node.typeAnnotation = ImplicitAny;
|
|
458
521
|
};
|
|
459
522
|
walkAssignOp = function (node, scope) {
|
|
460
|
-
var
|
|
523
|
+
var opened;
|
|
524
|
+
opened = pushOpenTypeParameters(null != node.assignee ? node.assignee.typeArguments : void 0);
|
|
525
|
+
try {
|
|
526
|
+
return walkAssignChecked(node, scope);
|
|
527
|
+
} finally {
|
|
528
|
+
popOpenTypeParameters(opened);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
walkAssignChecked = function (node, scope) {
|
|
532
|
+
var cache$4, cache$5, ident, left, lprop, member, n, preAnnotation, right, rprop, rpropAnn, symbol, t, target, v, value;
|
|
461
533
|
left = node.assignee;
|
|
462
534
|
right = node.expression;
|
|
463
535
|
symbol = left.data;
|
|
464
|
-
preAnnotation = left.typeAnnotation;
|
|
536
|
+
preAnnotation = (null != left.typeAnnotation ? left.typeAnnotation.implicit : void 0) ? null : left.typeAnnotation;
|
|
465
537
|
walk(left, scope);
|
|
466
538
|
if (right['instanceof'](MS.Function) && scope.getVarInScope(symbol)) {
|
|
467
539
|
v = scope.getVarInScope(symbol);
|
|
@@ -486,8 +558,7 @@ walkAssignOp = function (node, scope) {
|
|
|
486
558
|
for (var i$1 = 0, length$1 = left.members.length; i$1 < length$1; ++i$1) {
|
|
487
559
|
lprop = left.members[i$1];
|
|
488
560
|
n = i$1;
|
|
489
|
-
rpropAnn =
|
|
490
|
-
delete rpropAnn.identifier.isArray;
|
|
561
|
+
rpropAnn = elementOf(right.typeAnnotation);
|
|
491
562
|
if (lprop && rpropAnn)
|
|
492
563
|
checkTypeAnnotation(scope, node, lprop.typeAnnotation, rpropAnn);
|
|
493
564
|
}
|
|
@@ -495,11 +566,14 @@ walkAssignOp = function (node, scope) {
|
|
|
495
566
|
return function (accum$) {
|
|
496
567
|
for (var i$2 = 0, length$2 = left.members.length; i$2 < length$2; ++i$2) {
|
|
497
568
|
member = left.members[i$2];
|
|
498
|
-
|
|
569
|
+
target = member instanceof MS.DefaultParam ? member.param : member;
|
|
570
|
+
if (member instanceof MS.DefaultParam)
|
|
571
|
+
walk(member['default'], scope);
|
|
572
|
+
symbol = target.data;
|
|
499
573
|
accum$.push(!scope.getVarInScope(symbol) ? scope.addVar({
|
|
500
574
|
nodeType: 'variable',
|
|
501
575
|
identifier: createIdentifier(left),
|
|
502
|
-
typeAnnotation:
|
|
576
|
+
typeAnnotation: target.typeAnnotation
|
|
503
577
|
}) : void 0);
|
|
504
578
|
}
|
|
505
579
|
return accum$;
|
|
@@ -513,22 +587,65 @@ walkAssignOp = function (node, scope) {
|
|
|
513
587
|
return function (accum$1) {
|
|
514
588
|
for (var i$3 = 0, length$3 = left.members.length; i$3 < length$3; ++i$3) {
|
|
515
589
|
member = left.members[i$3];
|
|
516
|
-
|
|
590
|
+
if (member.computed) {
|
|
591
|
+
walk(member.key, scope);
|
|
592
|
+
if (member.expression instanceof MS.Identifier && !scope.getVarInScope(member.expression.data))
|
|
593
|
+
scope.addVar({
|
|
594
|
+
nodeType: 'variable',
|
|
595
|
+
identifier: createIdentifier(left),
|
|
596
|
+
typeAnnotation: ImplicitAny
|
|
597
|
+
});
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (member instanceof MS.Rest) {
|
|
601
|
+
symbol = member.expression.data;
|
|
602
|
+
if (!scope.getVarInScope(symbol))
|
|
603
|
+
scope.addVar({
|
|
604
|
+
nodeType: 'variable',
|
|
605
|
+
identifier: createIdentifier(left),
|
|
606
|
+
typeAnnotation: ImplicitAny
|
|
607
|
+
});
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
value = member.expression;
|
|
611
|
+
if (value instanceof MS.DefaultParam)
|
|
612
|
+
value = value.param;
|
|
613
|
+
if (member.expression instanceof MS.DefaultParam)
|
|
614
|
+
walk(member.expression['default'], scope);
|
|
615
|
+
symbol = value instanceof MS.Identifier ? value.data : member.key.data;
|
|
517
616
|
accum$1.push(!scope.getVarInScope(symbol) ? scope.addVar({
|
|
518
617
|
nodeType: 'variable',
|
|
519
618
|
identifier: createIdentifier(left),
|
|
520
|
-
typeAnnotation: member.typeAnnotation
|
|
619
|
+
typeAnnotation: null != value.typeAnnotation ? value.typeAnnotation : member.typeAnnotation
|
|
521
620
|
}) : void 0);
|
|
522
621
|
}
|
|
523
622
|
return accum$1;
|
|
524
623
|
}.call(this, []);
|
|
624
|
+
} else if (left['instanceof'](MS.ProtoMemberAccessOp)) {
|
|
625
|
+
if (left.expression instanceof MS.Identifier && null != (null != (cache$4 = t = scope.getTypeByIdentifier(createIdentifier(left.expression))) ? cache$4.properties : void 0))
|
|
626
|
+
if (!_.find(t.properties, function (prop) {
|
|
627
|
+
return (null != prop.identifier ? prop.identifier.typeRef : void 0) === left.memberName;
|
|
628
|
+
})) {
|
|
629
|
+
t.properties.push({
|
|
630
|
+
nodeType: 'identifier',
|
|
631
|
+
identifier: { typeRef: left.memberName },
|
|
632
|
+
typeAnnotation: null != right.typeAnnotation ? right.typeAnnotation : ImplicitAny
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
if (!checkType(scope, node, left, right))
|
|
636
|
+
return;
|
|
525
637
|
} else if (left['instanceof'](MS.MemberAccessOp)) {
|
|
526
|
-
if (
|
|
638
|
+
if (null != (cache$5 = t = scope.getTypeByNode(null != left.expression ? left.expression.typeAnnotation : void 0)) ? cache$5.closed : void 0)
|
|
639
|
+
checkKnownMember(node, scope, t, left.memberName);
|
|
640
|
+
if (!checkType(scope, node, left, right))
|
|
527
641
|
return;
|
|
528
|
-
}
|
|
529
642
|
} else if (left['instanceof'](MS.Identifier)) {
|
|
530
643
|
if (scope.getVarInScope(symbol) && preAnnotation)
|
|
531
|
-
return reporter.add_error(node, '
|
|
644
|
+
return reporter.add_error(node, '' + symbol + ' is declared again with a different type', {
|
|
645
|
+
code: 'MS2002',
|
|
646
|
+
why: 'A name keeps the type of its first declaration; ' + symbol + ' already has one, and this declaration gives it a type the first one does not accept.',
|
|
647
|
+
fix: 'keep one annotation for ' + symbol + ', or use a different name for the second value.'
|
|
648
|
+
});
|
|
532
649
|
if (null != left.typeAnnotation && null != right.typeAnnotation)
|
|
533
650
|
if (null != (null != left.typeAnnotation ? left.typeAnnotation.properties : void 0)) {
|
|
534
651
|
if (!checkType(scope, node, left, right)) {
|
|
@@ -538,9 +655,12 @@ walkAssignOp = function (node, scope) {
|
|
|
538
655
|
return;
|
|
539
656
|
}
|
|
540
657
|
if (null != preAnnotation) {
|
|
658
|
+
ident = createIdentifier(left);
|
|
659
|
+
if (null != left.typeArguments ? left.typeArguments.length : void 0)
|
|
660
|
+
ident.typeArguments = left.typeArguments;
|
|
541
661
|
return scope.addVar({
|
|
542
662
|
nodeType: 'variable',
|
|
543
|
-
identifier:
|
|
663
|
+
identifier: ident,
|
|
544
664
|
typeAnnotation: preAnnotation
|
|
545
665
|
});
|
|
546
666
|
} else if (null != right.typeAnnotation && !right.typeAnnotation.implicit && (null != left ? left.typeAnnotation.implicit : void 0)) {
|
|
@@ -573,6 +693,8 @@ walkPrimitives = function (node, scope) {
|
|
|
573
693
|
return walkBool(node, scope);
|
|
574
694
|
case !node['instanceof'](MS.Int):
|
|
575
695
|
return walkInt(node, scope);
|
|
696
|
+
case !node['instanceof'](MS.BigInt):
|
|
697
|
+
return walkBigInt(node, scope);
|
|
576
698
|
case !node['instanceof'](MS.Float):
|
|
577
699
|
return walkFloat(node, scope);
|
|
578
700
|
case !node['instanceof'](MS.Numbers):
|
|
@@ -604,6 +726,13 @@ walkString = function (node, scope) {
|
|
|
604
726
|
identifier: createIdentifier('String')
|
|
605
727
|
};
|
|
606
728
|
};
|
|
729
|
+
walkBigInt = function (node, scope) {
|
|
730
|
+
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = {
|
|
731
|
+
nodeType: 'identifier',
|
|
732
|
+
implicit: true,
|
|
733
|
+
identifier: createIdentifier('BigInt')
|
|
734
|
+
};
|
|
735
|
+
};
|
|
607
736
|
walkInt = function (node, scope) {
|
|
608
737
|
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = {
|
|
609
738
|
nodeType: 'identifier',
|
|
@@ -634,7 +763,7 @@ walkNumbers = function (node, scope) {
|
|
|
634
763
|
};
|
|
635
764
|
moduleToProperties = function (mod) {
|
|
636
765
|
var properties;
|
|
637
|
-
properties =
|
|
766
|
+
properties = mod._this.slice();
|
|
638
767
|
mod._modules.forEach(function (param$) {
|
|
639
768
|
var cache$4, identifier, scope;
|
|
640
769
|
{
|
|
@@ -648,7 +777,7 @@ moduleToProperties = function (mod) {
|
|
|
648
777
|
moduleId: scope.id
|
|
649
778
|
});
|
|
650
779
|
});
|
|
651
|
-
return
|
|
780
|
+
return properties;
|
|
652
781
|
};
|
|
653
782
|
walkIdentifier = function (node, scope) {
|
|
654
783
|
var mod, properties, typeAnnotation, val;
|
|
@@ -670,11 +799,16 @@ walkIdentifier = function (node, scope) {
|
|
|
670
799
|
}
|
|
671
800
|
};
|
|
672
801
|
walkThis = function (node, scope) {
|
|
802
|
+
if (scope.thisUnknown) {
|
|
803
|
+
node.typeAnnotation = ImplicitAny;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
673
806
|
return node.typeAnnotation = {
|
|
674
807
|
nodeType: 'members',
|
|
675
808
|
implicit: true,
|
|
676
|
-
identifier: createIdentifier('[this]'),
|
|
677
|
-
properties:
|
|
809
|
+
identifier: createIdentifier(null != scope.thisName ? scope.thisName : '[this]'),
|
|
810
|
+
properties: scope._this.slice(),
|
|
811
|
+
closed: !!scope.thisClosed
|
|
678
812
|
};
|
|
679
813
|
};
|
|
680
814
|
walkDynamicMemberAccessOp = function (node, scope) {
|
|
@@ -695,13 +829,129 @@ walkProtoMemberAccessOp = function (node, scope) {
|
|
|
695
829
|
else
|
|
696
830
|
node.typeAnnotation = ImplicitAny;
|
|
697
831
|
};
|
|
832
|
+
restArrayType = function (ann) {
|
|
833
|
+
if (null != ann && !(ann.implicit && ann.nodeType === 'primitiveIdentifier')) {
|
|
834
|
+
return arrayOf(ann);
|
|
835
|
+
} else {
|
|
836
|
+
return {
|
|
837
|
+
nodeType: 'identifier',
|
|
838
|
+
implicit: true,
|
|
839
|
+
identifier: {
|
|
840
|
+
typeRef: 'Any',
|
|
841
|
+
isArray: true
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
hasDynamicPrototype = function (node) {
|
|
847
|
+
var c, child, childName;
|
|
848
|
+
if (!(null != node && typeof node['instanceof'] === 'function'))
|
|
849
|
+
return false;
|
|
850
|
+
if (node instanceof MS.DynamicProtoMemberAccessOp)
|
|
851
|
+
return true;
|
|
852
|
+
for (var cache$4 = null != node.childNodes ? node.childNodes : [], i$ = 0, length$ = cache$4.length; i$ < length$; ++i$) {
|
|
853
|
+
childName = cache$4[i$];
|
|
854
|
+
child = node[childName];
|
|
855
|
+
if (!(null != child))
|
|
856
|
+
continue;
|
|
857
|
+
if (in$(childName, null != node.listMembers ? node.listMembers : [])) {
|
|
858
|
+
for (var i$1 = 0, length$1 = child.length; i$1 < length$1; ++i$1) {
|
|
859
|
+
c = child[i$1];
|
|
860
|
+
if (hasDynamicPrototype(c))
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
} else if (hasDynamicPrototype(child)) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return false;
|
|
868
|
+
};
|
|
869
|
+
OBJECT_MEMBERS = [
|
|
870
|
+
'toString',
|
|
871
|
+
'valueOf',
|
|
872
|
+
'hasOwnProperty',
|
|
873
|
+
'constructor',
|
|
874
|
+
'isPrototypeOf',
|
|
875
|
+
'propertyIsEnumerable',
|
|
876
|
+
'toLocaleString',
|
|
877
|
+
'__proto__'
|
|
878
|
+
];
|
|
879
|
+
assignedMembers = new Set;
|
|
880
|
+
collectAssignedMembers = function (node) {
|
|
881
|
+
var byName, c, child, childName, fn, onThis;
|
|
882
|
+
if (!(null != node && typeof node['instanceof'] === 'function'))
|
|
883
|
+
return;
|
|
884
|
+
if ((node instanceof MS.AssignOp || node instanceof MS.CompoundAssignOp) && node.assignee instanceof MS.MemberAccessOp && !(node.assignee.expression instanceof MS.This))
|
|
885
|
+
assignedMembers.add(node.assignee.memberName);
|
|
886
|
+
if (node instanceof MS.FunctionApplication && (null != node['arguments'] ? node['arguments'][1] : void 0) instanceof MS.String) {
|
|
887
|
+
fn = node['function'];
|
|
888
|
+
byName = fn instanceof MS.MemberAccessOp && (fn.memberName === 'defineProperty' || fn.memberName === 'defineProperties');
|
|
889
|
+
onThis = node['arguments'][0] instanceof MS.This || node['arguments'][0] instanceof MS.Identifier;
|
|
890
|
+
if (byName || onThis)
|
|
891
|
+
assignedMembers.add(node['arguments'][1].data);
|
|
892
|
+
}
|
|
893
|
+
for (var cache$4 = null != node.childNodes ? node.childNodes : [], i$ = 0, length$ = cache$4.length; i$ < length$; ++i$) {
|
|
894
|
+
childName = cache$4[i$];
|
|
895
|
+
child = node[childName];
|
|
896
|
+
if (!(null != child))
|
|
897
|
+
continue;
|
|
898
|
+
if (in$(childName, null != node.listMembers ? node.listMembers : [])) {
|
|
899
|
+
for (var i$1 = 0, length$1 = child.length; i$1 < length$1; ++i$1) {
|
|
900
|
+
c = child[i$1];
|
|
901
|
+
collectAssignedMembers(c);
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
collectAssignedMembers(child);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
checkKnownMember = function (node, scope, type, name) {
|
|
909
|
+
var known, members, prop, typeName;
|
|
910
|
+
if (!((null != type ? type.closed : void 0) && null != name && !in$(name, OBJECT_MEMBERS)))
|
|
911
|
+
return;
|
|
912
|
+
if (scope.checkingSoak)
|
|
913
|
+
return;
|
|
914
|
+
if (_.find(type.properties, function (prop) {
|
|
915
|
+
return (null != prop.identifier ? prop.identifier.typeRef : void 0) === name;
|
|
916
|
+
}))
|
|
917
|
+
return;
|
|
918
|
+
if ((type.newable || (null != type.identifier ? type.identifier.typeRef : void 0) === scope.thisName || type.implicit) && assignedMembers.has(name))
|
|
919
|
+
return;
|
|
920
|
+
typeName = null != (null != type.identifier ? type.identifier.typeRef : void 0) ? null != type.identifier ? type.identifier.typeRef : void 0 : 'this';
|
|
921
|
+
if (null != (null != typeName ? typeName.right : void 0))
|
|
922
|
+
typeName = typeName.right;
|
|
923
|
+
known = function (accum$) {
|
|
924
|
+
for (var i$ = 0, length$ = type.properties.length; i$ < length$; ++i$) {
|
|
925
|
+
prop = type.properties[i$];
|
|
926
|
+
if (!(null != (null != prop.identifier ? prop.identifier.typeRef : void 0)))
|
|
927
|
+
continue;
|
|
928
|
+
accum$.push(null != prop.identifier ? prop.identifier.typeRef : void 0);
|
|
929
|
+
}
|
|
930
|
+
return accum$;
|
|
931
|
+
}.call(this, []);
|
|
932
|
+
members = known.length ? 'its members are ' + known.join(', ') : 'it has no members';
|
|
933
|
+
return reporter.add_error(node, '' + typeName + ' has no member ' + name, {
|
|
934
|
+
code: 'MS2009',
|
|
935
|
+
why: '' + typeName + ' declares every member it has (' + members + '); ' + name + ' is not one of them, so this is a typo or a member that was never declared.',
|
|
936
|
+
fix: 'use one of ' + typeName + "'s members, or declare " + name + ' (a field ' + name + ' :: Type, a constructor @' + name + ', or a method).'
|
|
937
|
+
});
|
|
938
|
+
};
|
|
698
939
|
walkMemberAccess = function (node, scope) {
|
|
699
940
|
var member, mod, props, type;
|
|
700
941
|
walk(node.expression, scope);
|
|
942
|
+
if (null != node.expression.typeAnnotation && null != node.expression.typeAnnotation.identifier ? node.expression.typeAnnotation.identifier.isArray : void 0) {
|
|
943
|
+
if (null != node.typeAnnotation)
|
|
944
|
+
node.typeAnnotation;
|
|
945
|
+
else
|
|
946
|
+
node.typeAnnotation = ImplicitAny;
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
701
949
|
if (type = scope.getTypeByNode(node.expression.typeAnnotation)) {
|
|
702
950
|
member = _.find(type.properties, function (prop) {
|
|
703
951
|
return (null != prop.identifier ? prop.identifier.typeRef : void 0) === node.memberName;
|
|
704
952
|
});
|
|
953
|
+
if (!(null != member))
|
|
954
|
+
checkKnownMember(node, scope, type, node.memberName);
|
|
705
955
|
if (null != member)
|
|
706
956
|
if (member.nodeType === 'moduleRef') {
|
|
707
957
|
mod = scope.findModuleById(member.moduleId);
|
|
@@ -724,16 +974,19 @@ walkMemberAccess = function (node, scope) {
|
|
|
724
974
|
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = ImplicitAny;
|
|
725
975
|
};
|
|
726
976
|
walkArrayInializer = function (node, scope) {
|
|
727
|
-
var ann, member;
|
|
977
|
+
var ann, member, memberTypes;
|
|
728
978
|
for (var i$ = 0, length$ = node.members.length; i$ < length$; ++i$) {
|
|
729
979
|
member = node.members[i$];
|
|
730
980
|
walk(member, scope);
|
|
731
981
|
}
|
|
732
|
-
|
|
982
|
+
memberTypes = node.members.map(function (m) {
|
|
733
983
|
return m.typeAnnotation;
|
|
734
|
-
})
|
|
984
|
+
});
|
|
985
|
+
ann = scope.getHighestCommonType(memberTypes);
|
|
735
986
|
if (null != (null != ann ? ann.identifier : void 0))
|
|
736
|
-
ann
|
|
987
|
+
ann = arrayOf(ann);
|
|
988
|
+
if (null != ann ? ann.mixed : void 0)
|
|
989
|
+
ann.memberTypes = memberTypes;
|
|
737
990
|
return node.typeAnnotation = ann;
|
|
738
991
|
};
|
|
739
992
|
walkRange = function (node, scope) {
|
|
@@ -747,25 +1000,43 @@ walkRange = function (node, scope) {
|
|
|
747
1000
|
};
|
|
748
1001
|
};
|
|
749
1002
|
walkObjectInitializer = function (node, scope) {
|
|
750
|
-
var cache$4, expression, key, nextScope, obj, props;
|
|
1003
|
+
var ann, cache$4, computed, expression, key, member, nextScope, obj, props;
|
|
751
1004
|
obj = {};
|
|
752
1005
|
nextScope = new Scope(scope);
|
|
753
1006
|
nextScope.name = 'object';
|
|
754
1007
|
props = [];
|
|
755
1008
|
for (var i$ = 0, length$ = node.members.length; i$ < length$; ++i$) {
|
|
1009
|
+
member = node.members[i$];
|
|
1010
|
+
if (!(!(null != member.key) || member.computed))
|
|
1011
|
+
continue;
|
|
1012
|
+
if (member.computed)
|
|
1013
|
+
walk(member.key, nextScope);
|
|
1014
|
+
walk(member.expression, nextScope);
|
|
1015
|
+
}
|
|
1016
|
+
for (var i$1 = 0, length$1 = node.members.length; i$1 < length$1; ++i$1) {
|
|
756
1017
|
{
|
|
757
|
-
cache$4 = node.members[i$];
|
|
1018
|
+
cache$4 = node.members[i$1];
|
|
758
1019
|
expression = cache$4.expression;
|
|
759
1020
|
key = cache$4.key;
|
|
1021
|
+
computed = cache$4.computed;
|
|
760
1022
|
}
|
|
761
|
-
if (!('undefined' !== typeof key && null != key))
|
|
1023
|
+
if (!('undefined' !== typeof key && null != key && !computed))
|
|
762
1024
|
continue;
|
|
763
1025
|
walk(expression, nextScope);
|
|
1026
|
+
ann = expression.typeAnnotation;
|
|
1027
|
+
if (expression instanceof MS.DefaultParam) {
|
|
1028
|
+
ann = _.cloneDeep(null != (null != expression.param ? expression.param.typeAnnotation : void 0) ? null != expression.param ? expression.param.typeAnnotation : void 0 : ImplicitAny);
|
|
1029
|
+
if (null != ann.identifier)
|
|
1030
|
+
ann.identifier;
|
|
1031
|
+
else
|
|
1032
|
+
ann.identifier = { typeRef: 'Any' };
|
|
1033
|
+
ann.identifier.nullable = true;
|
|
1034
|
+
}
|
|
764
1035
|
props.push({
|
|
765
1036
|
implicit: true,
|
|
766
1037
|
identifier: createIdentifier(key),
|
|
767
1038
|
nodeType: 'identifier',
|
|
768
|
-
typeAnnotation:
|
|
1039
|
+
typeAnnotation: ann
|
|
769
1040
|
});
|
|
770
1041
|
}
|
|
771
1042
|
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = {
|
|
@@ -776,7 +1047,7 @@ walkObjectInitializer = function (node, scope) {
|
|
|
776
1047
|
};
|
|
777
1048
|
};
|
|
778
1049
|
walkClass = function (node, scope) {
|
|
779
|
-
var arg, className, classScope, ident, implArg, isThis, ns, parentAnnotation, parentScope, parentStaticAnnotation, prop, ref, statement, staticAnn, val;
|
|
1050
|
+
var addInstanceMember, ann, arg, className, classScope, collectAtTarget, collectThisAssignments, copy, entry, ident, implArg, implementsPending, isThis, name, ns, param, parentAnnotation, parentKnown, parentScope, parentStaticAnnotation, prop, ref, registered, rest, statement, staticAnn, target, val;
|
|
780
1051
|
classScope = new ClassScope(scope);
|
|
781
1052
|
className = null;
|
|
782
1053
|
isThis = false;
|
|
@@ -814,6 +1085,7 @@ walkClass = function (node, scope) {
|
|
|
814
1085
|
identifier: { typeRef: arg.identifier.typeRef }
|
|
815
1086
|
});
|
|
816
1087
|
}
|
|
1088
|
+
implementsPending = {};
|
|
817
1089
|
if (null != node.implementArguments ? node.implementArguments.length : void 0)
|
|
818
1090
|
for (var i$1 = 0, length$1 = node.implementArguments.length; i$1 < length$1; ++i$1) {
|
|
819
1091
|
implArg = node.implementArguments[i$1];
|
|
@@ -821,7 +1093,11 @@ walkClass = function (node, scope) {
|
|
|
821
1093
|
if (null != parentAnnotation && null != parentAnnotation.properties ? parentAnnotation.properties.length : void 0)
|
|
822
1094
|
if (null != parentAnnotation && null != parentAnnotation.properties) {
|
|
823
1095
|
parentAnnotation.properties.map(function (prop) {
|
|
824
|
-
|
|
1096
|
+
var entry;
|
|
1097
|
+
entry = _.clone(prop);
|
|
1098
|
+
entry.pendingImplements = implArg.identifier.typeRef;
|
|
1099
|
+
implementsPending[null != prop.identifier ? prop.identifier.typeRef : void 0] = entry;
|
|
1100
|
+
return classScope.addThis(entry);
|
|
825
1101
|
});
|
|
826
1102
|
}
|
|
827
1103
|
}
|
|
@@ -830,20 +1106,36 @@ walkClass = function (node, scope) {
|
|
|
830
1106
|
if (null != parentStaticAnnotation && null != parentStaticAnnotation.typeAnnotation && null != parentStaticAnnotation.typeAnnotation.properties ? parentStaticAnnotation.typeAnnotation.properties.length : void 0) {
|
|
831
1107
|
for (var i$2 = 0, length$2 = parentStaticAnnotation.typeAnnotation.properties.length; i$2 < length$2; ++i$2) {
|
|
832
1108
|
prop = parentStaticAnnotation.typeAnnotation.properties[i$2];
|
|
833
|
-
staticAnn.properties.push(_.
|
|
1109
|
+
staticAnn.properties.push(_.clone(prop));
|
|
834
1110
|
}
|
|
835
1111
|
}
|
|
836
1112
|
parentAnnotation = scope.getTypeByIdentifier(createIdentifier(node.parent));
|
|
837
|
-
if (parentAnnotation)
|
|
1113
|
+
if (null != (null != parentAnnotation ? parentAnnotation.properties : void 0))
|
|
838
1114
|
parentAnnotation.properties.map(function (prop) {
|
|
839
|
-
return classScope.addThis(_.
|
|
1115
|
+
return classScope.addThis(_.clone(prop));
|
|
840
1116
|
});
|
|
841
1117
|
}
|
|
842
1118
|
if (null != (null != node.body ? node.body.statements : void 0))
|
|
843
1119
|
for (var i$3 = 0, length$3 = node.body.statements.length; i$3 < length$3; ++i$3) {
|
|
844
1120
|
statement = node.body.statements[i$3];
|
|
1121
|
+
if (!(statement instanceof MS.ClassProtoAssignOp && statement.assignee instanceof MS.Identifier))
|
|
1122
|
+
continue;
|
|
1123
|
+
name = statement.assignee.data;
|
|
1124
|
+
if (!classScope.getThis(name))
|
|
1125
|
+
classScope.addThis({
|
|
1126
|
+
nodeType: 'variable',
|
|
1127
|
+
identifier: { typeRef: name },
|
|
1128
|
+
typeAnnotation: ImplicitAny,
|
|
1129
|
+
placeholder: true
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
if (null != (null != node.body ? node.body.statements : void 0))
|
|
1133
|
+
for (var i$4 = 0, length$4 = node.body.statements.length; i$4 < length$4; ++i$4) {
|
|
1134
|
+
statement = node.body.statements[i$4];
|
|
845
1135
|
if (!(statement.nodeType === 'vardef'))
|
|
846
1136
|
continue;
|
|
1137
|
+
if (!statement.isStatic)
|
|
1138
|
+
delete implementsPending[null != statement.name && null != statement.name.identifier ? statement.name.identifier.typeRef : void 0];
|
|
847
1139
|
if (statement.isStatic) {
|
|
848
1140
|
staticAnn.properties.push({
|
|
849
1141
|
nodeType: 'variable',
|
|
@@ -854,6 +1146,116 @@ walkClass = function (node, scope) {
|
|
|
854
1146
|
walkVardef(statement, classScope);
|
|
855
1147
|
}
|
|
856
1148
|
}
|
|
1149
|
+
addInstanceMember = function (name, ann) {
|
|
1150
|
+
if (!(null != name))
|
|
1151
|
+
return;
|
|
1152
|
+
delete implementsPending[name];
|
|
1153
|
+
if (classScope.getThis(name))
|
|
1154
|
+
return;
|
|
1155
|
+
return classScope.addThis({
|
|
1156
|
+
nodeType: 'variable',
|
|
1157
|
+
identifier: { typeRef: name },
|
|
1158
|
+
typeAnnotation: null != ann ? ann : ImplicitAny
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
if ((null != node.ctor ? node.ctor.expression : void 0) instanceof MS.Function)
|
|
1162
|
+
for (var cache$4 = null != node.ctor.expression.parameters ? node.ctor.expression.parameters : [], i$5 = 0, length$5 = cache$4.length; i$5 < length$5; ++i$5) {
|
|
1163
|
+
param = cache$4[i$5];
|
|
1164
|
+
target = param instanceof MS.DefaultParam ? param.param : param;
|
|
1165
|
+
rest = target instanceof MS.Rest;
|
|
1166
|
+
if (rest)
|
|
1167
|
+
target = target.expression;
|
|
1168
|
+
if (target instanceof MS.MemberAccessOp && target.expression instanceof MS.This) {
|
|
1169
|
+
ann = rest ? restArrayType(target.typeAnnotation) : target.typeAnnotation;
|
|
1170
|
+
addInstanceMember(target.memberName, ann);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
collectThisAssignments = function (n) {
|
|
1174
|
+
var c, child, childName;
|
|
1175
|
+
if (!(null != n && typeof n['instanceof'] === 'function'))
|
|
1176
|
+
return;
|
|
1177
|
+
if (n instanceof MS.Class && n !== node)
|
|
1178
|
+
return;
|
|
1179
|
+
if (n instanceof MS.AssignOp || n instanceof MS.CompoundAssignOp)
|
|
1180
|
+
collectAtTarget(n.assignee);
|
|
1181
|
+
for (var cache$5 = null != n.childNodes ? n.childNodes : [], i$6 = 0, length$6 = cache$5.length; i$6 < length$6; ++i$6) {
|
|
1182
|
+
childName = cache$5[i$6];
|
|
1183
|
+
child = n[childName];
|
|
1184
|
+
if (!(null != child))
|
|
1185
|
+
continue;
|
|
1186
|
+
if (in$(childName, null != n.listMembers ? n.listMembers : [])) {
|
|
1187
|
+
for (var i$7 = 0, length$7 = child.length; i$7 < length$7; ++i$7) {
|
|
1188
|
+
c = child[i$7];
|
|
1189
|
+
collectThisAssignments(c);
|
|
1190
|
+
}
|
|
1191
|
+
} else {
|
|
1192
|
+
collectThisAssignments(child);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
collectAtTarget = function (target) {
|
|
1197
|
+
var member;
|
|
1198
|
+
if (!(null != target))
|
|
1199
|
+
return;
|
|
1200
|
+
if (target instanceof MS.DefaultParam) {
|
|
1201
|
+
collectAtTarget(target.param);
|
|
1202
|
+
} else if (target instanceof MS.Rest) {
|
|
1203
|
+
collectAtTarget(target.expression);
|
|
1204
|
+
} else if (target instanceof MS.MemberAccessOp && target.expression instanceof MS.This) {
|
|
1205
|
+
addInstanceMember(target.memberName, target.typeAnnotation);
|
|
1206
|
+
} else if (target instanceof MS.ObjectInitialiser) {
|
|
1207
|
+
for (var cache$5 = null != target.members ? target.members : [], i$6 = 0, length$6 = cache$5.length; i$6 < length$6; ++i$6) {
|
|
1208
|
+
member = cache$5[i$6];
|
|
1209
|
+
collectAtTarget(member.expression);
|
|
1210
|
+
}
|
|
1211
|
+
} else if (target instanceof MS.ArrayInitialiser) {
|
|
1212
|
+
for (var cache$6 = null != target.members ? target.members : [], i$7 = 0, length$7 = cache$6.length; i$7 < length$7; ++i$7) {
|
|
1213
|
+
member = cache$6[i$7];
|
|
1214
|
+
collectAtTarget(member);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
collectThisAssignments(null != node.ctor ? node.ctor.expression : void 0);
|
|
1219
|
+
collectThisAssignments(node.body);
|
|
1220
|
+
parentKnown = !(null != node.parent) || null != parentAnnotation;
|
|
1221
|
+
classScope.thisClosed = parentKnown && !isThis && !hasDynamicPrototype(node.body);
|
|
1222
|
+
classScope.thisName = className;
|
|
1223
|
+
if (null != node.ctor && !(null != classScope.getConstructorType()))
|
|
1224
|
+
(function () {
|
|
1225
|
+
var argTypes, params;
|
|
1226
|
+
params = null != (null != node.ctor.expression ? node.ctor.expression.parameters : void 0) ? null != node.ctor.expression ? node.ctor.expression.parameters : void 0 : [];
|
|
1227
|
+
argTypes = function (accum$) {
|
|
1228
|
+
for (var i$6 = 0, length$6 = params.length; i$6 < length$6; ++i$6) {
|
|
1229
|
+
param = params[i$6];
|
|
1230
|
+
target = param instanceof MS.DefaultParam ? param.param : param;
|
|
1231
|
+
rest = target instanceof MS.Rest;
|
|
1232
|
+
if (rest)
|
|
1233
|
+
target = target.expression;
|
|
1234
|
+
ann = rest ? restArrayType(null != target ? target.typeAnnotation : void 0) : null != (null != target ? target.typeAnnotation : void 0) ? null != target ? target.typeAnnotation : void 0 : ImplicitAny;
|
|
1235
|
+
if (rest) {
|
|
1236
|
+
ann = _.cloneDeep(ann);
|
|
1237
|
+
ann.identifier.splats = true;
|
|
1238
|
+
}
|
|
1239
|
+
accum$.push(ann);
|
|
1240
|
+
}
|
|
1241
|
+
return accum$;
|
|
1242
|
+
}.call(this, []);
|
|
1243
|
+
if (_.some(argTypes, function (t) {
|
|
1244
|
+
return !t.implicit;
|
|
1245
|
+
}))
|
|
1246
|
+
return classScope.addThis({
|
|
1247
|
+
nodeType: 'variable',
|
|
1248
|
+
identifier: { typeRef: '_constructor_' },
|
|
1249
|
+
typeAnnotation: {
|
|
1250
|
+
nodeType: 'functionType',
|
|
1251
|
+
'arguments': argTypes,
|
|
1252
|
+
returnType: {
|
|
1253
|
+
nodeType: 'identifier',
|
|
1254
|
+
identifier: { typeRef: 'Void' }
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
}());
|
|
857
1259
|
val = {
|
|
858
1260
|
nodeType: 'variable',
|
|
859
1261
|
identifier: { typeRef: className },
|
|
@@ -869,6 +1271,7 @@ walkClass = function (node, scope) {
|
|
|
869
1271
|
(null != parentScope ? parentScope : scope).addType({
|
|
870
1272
|
nodeType: 'members',
|
|
871
1273
|
newable: true,
|
|
1274
|
+
closed: classScope.thisClosed,
|
|
872
1275
|
identifier: {
|
|
873
1276
|
typeRef: className,
|
|
874
1277
|
typeArguments: null != node.typeArguments ? node.typeArguments : []
|
|
@@ -881,24 +1284,51 @@ walkClass = function (node, scope) {
|
|
|
881
1284
|
if (null != node.ctor)
|
|
882
1285
|
walkFunction(node.ctor.expression, classScope, classScope.getConstructorType());
|
|
883
1286
|
if (node.body instanceof MS.Block)
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1287
|
+
for (var i$6 = 0, length$6 = node.body.statements.length; i$6 < length$6; ++i$6) {
|
|
1288
|
+
statement = node.body.statements[i$6];
|
|
1289
|
+
if (!(statement.nodeType !== 'vardef'))
|
|
1290
|
+
continue;
|
|
1291
|
+
walk(statement, classScope);
|
|
1292
|
+
if (statement instanceof MS.ClassProtoAssignOp && statement.assignee instanceof MS.Identifier) {
|
|
1293
|
+
delete implementsPending[statement.assignee.data];
|
|
1294
|
+
} else if (statement instanceof MS.AssignOp && statement.assignee instanceof MS.MemberAccessOp && statement.assignee.expression instanceof MS.This) {
|
|
1295
|
+
delete implementsPending[statement.assignee.memberName];
|
|
890
1296
|
}
|
|
891
|
-
|
|
892
|
-
|
|
1297
|
+
}
|
|
1298
|
+
if (registered = (null != parentScope ? parentScope : scope).getTypeByString(className))
|
|
1299
|
+
for (var i$7 = 0, length$7 = classScope._this.length; i$7 < length$7; ++i$7) {
|
|
1300
|
+
entry = classScope._this[i$7];
|
|
1301
|
+
name = null != entry.identifier ? entry.identifier.typeRef : void 0;
|
|
1302
|
+
if (!(null != name) || _.find(registered.properties, function (prop) {
|
|
1303
|
+
return (null != prop.identifier ? prop.identifier.typeRef : void 0) === name;
|
|
1304
|
+
}))
|
|
1305
|
+
continue;
|
|
1306
|
+
copy = _.clone(entry);
|
|
1307
|
+
copy.nodeType = 'identifier';
|
|
1308
|
+
registered.properties.push(copy);
|
|
1309
|
+
}
|
|
1310
|
+
return function (accum$) {
|
|
1311
|
+
for (name in implementsPending) {
|
|
1312
|
+
entry = implementsPending[name];
|
|
1313
|
+
accum$.push(reporter.add_error(node, '' + className + ' implements ' + entry.pendingImplements + ' but does not define ' + name, {
|
|
1314
|
+
code: 'MS2008',
|
|
1315
|
+
why: 'implements promises every member of ' + entry.pendingImplements + '; ' + name + ' is in the struct but nothing in ' + className + ' defines it: no field (' + name + ' :: \u2026), no @' + name + ' in the constructor, no method named ' + name + '.',
|
|
1316
|
+
fix: 'define ' + name + ' in ' + className + ', or drop it from the struct.'
|
|
1317
|
+
}));
|
|
1318
|
+
}
|
|
1319
|
+
return accum$;
|
|
1320
|
+
}.call(this, []);
|
|
893
1321
|
};
|
|
894
1322
|
addValuesByInitializer = function (scope, initializerNode, preAnnotation) {
|
|
895
|
-
var member, symbol;
|
|
1323
|
+
var member, symbol, target;
|
|
896
1324
|
if (null == preAnnotation)
|
|
897
1325
|
preAnnotation = null;
|
|
898
1326
|
if (initializerNode instanceof MS.ArrayInitialiser) {
|
|
899
1327
|
return function (accum$) {
|
|
900
1328
|
for (var i$ = 0, length$ = initializerNode.members.length; i$ < length$; ++i$) {
|
|
901
1329
|
member = initializerNode.members[i$];
|
|
1330
|
+
if (member instanceof MS.DefaultParam)
|
|
1331
|
+
member = member.param;
|
|
902
1332
|
symbol = member.data;
|
|
903
1333
|
accum$.push(!scope.getVar(symbol) ? scope.addVar({
|
|
904
1334
|
nodeType: 'variable',
|
|
@@ -912,10 +1342,23 @@ addValuesByInitializer = function (scope, initializerNode, preAnnotation) {
|
|
|
912
1342
|
return function (accum$1) {
|
|
913
1343
|
for (var i$1 = 0, length$1 = initializerNode.members.length; i$1 < length$1; ++i$1) {
|
|
914
1344
|
member = initializerNode.members[i$1];
|
|
1345
|
+
if (member instanceof MS.Rest) {
|
|
1346
|
+
if (!scope.getVar(member.expression.data))
|
|
1347
|
+
scope.addVar({
|
|
1348
|
+
nodeType: 'variable',
|
|
1349
|
+
identifier: createIdentifier(member.expression),
|
|
1350
|
+
typeAnnotation: ImplicitAny
|
|
1351
|
+
});
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
target = member.expression;
|
|
1355
|
+
if (target instanceof MS.DefaultParam)
|
|
1356
|
+
target = target.param;
|
|
1357
|
+
symbol = target instanceof MS.Identifier ? target.data : member.key.data;
|
|
915
1358
|
accum$1.push(!scope.getVar(symbol) ? scope.addVar({
|
|
916
1359
|
nodeType: 'variable',
|
|
917
|
-
identifier: createIdentifier(member.key),
|
|
918
|
-
typeAnnotation: null != member.typeAnnotation ? member.typeAnnotation : ImplicitAny
|
|
1360
|
+
identifier: createIdentifier(target instanceof MS.Identifier ? target : member.key),
|
|
1361
|
+
typeAnnotation: null != target.typeAnnotation ? target.typeAnnotation : null != member.typeAnnotation ? member.typeAnnotation : ImplicitAny
|
|
919
1362
|
}) : void 0);
|
|
920
1363
|
}
|
|
921
1364
|
return accum$1;
|
|
@@ -927,10 +1370,18 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
927
1370
|
if (null == preAnnotation)
|
|
928
1371
|
preAnnotation = null;
|
|
929
1372
|
functionScope = new Scope(scope);
|
|
930
|
-
if (scope instanceof ClassScope)
|
|
1373
|
+
if (scope instanceof ClassScope) {
|
|
931
1374
|
functionScope._this = scope._this;
|
|
932
|
-
|
|
1375
|
+
functionScope.thisClosed = scope.thisClosed;
|
|
1376
|
+
functionScope.thisName = scope.thisName;
|
|
1377
|
+
} else if (node instanceof MS.BoundFunction) {
|
|
933
1378
|
functionScope._this = scope._this;
|
|
1379
|
+
functionScope.thisUnknown = scope.thisUnknown;
|
|
1380
|
+
functionScope.thisClosed = scope.thisClosed;
|
|
1381
|
+
functionScope.thisName = scope.thisName;
|
|
1382
|
+
} else {
|
|
1383
|
+
functionScope.thisUnknown = true;
|
|
1384
|
+
}
|
|
934
1385
|
if (null != preAnnotation) {
|
|
935
1386
|
if (null != node.typeAnnotation) {
|
|
936
1387
|
annotation = _.cloneDeep(node.typeAnnotation);
|
|
@@ -954,9 +1405,9 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
954
1405
|
node.typeAnnotation = preAnnotation;
|
|
955
1406
|
if (null != node.parameters)
|
|
956
1407
|
node.parameters.map(function (param, n) {
|
|
957
|
-
var argType, member, memberAnn, preAnn, preLastArg,
|
|
1408
|
+
var argType, member, memberAnn, preAnn, preLastArg, type;
|
|
958
1409
|
if (null != param.typeAnnotation)
|
|
959
|
-
if (!checkTypeAnnotation(scope, node, preAnnotation['arguments'][n], param.typeAnnotation)) {
|
|
1410
|
+
if (!checkTypeAnnotation(scope, node, null != preAnnotation['arguments'] ? preAnnotation['arguments'][n] : void 0, param.typeAnnotation)) {
|
|
960
1411
|
return;
|
|
961
1412
|
}
|
|
962
1413
|
if (param instanceof MS.MemberAccessOp)
|
|
@@ -972,10 +1423,23 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
972
1423
|
typeAnnotation: param.typeAnnotation
|
|
973
1424
|
});
|
|
974
1425
|
} else if (param instanceof MS.Rest) {
|
|
975
|
-
preLastArg = preAnnotation['arguments'][n];
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1426
|
+
preLastArg = null != preAnnotation['arguments'] ? preAnnotation['arguments'][n] : void 0;
|
|
1427
|
+
if (null != preLastArg && null != preLastArg.identifier ? preLastArg.identifier.isArray : void 0) {
|
|
1428
|
+
argType = _.cloneDeep(preLastArg);
|
|
1429
|
+
delete argType.identifier.splats;
|
|
1430
|
+
} else if (null != (null != preLastArg ? preLastArg.identifier : void 0)) {
|
|
1431
|
+
argType = arrayOf(preLastArg);
|
|
1432
|
+
delete argType.identifier.splats;
|
|
1433
|
+
} else {
|
|
1434
|
+
argType = {
|
|
1435
|
+
nodeType: 'identifier',
|
|
1436
|
+
implicit: true,
|
|
1437
|
+
identifier: {
|
|
1438
|
+
typeRef: 'Any',
|
|
1439
|
+
isArray: true
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
979
1443
|
param.typeAnnotation = argType;
|
|
980
1444
|
return functionScope.addVar({
|
|
981
1445
|
nodeType: 'variable',
|
|
@@ -987,12 +1451,9 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
987
1451
|
if (preAnn)
|
|
988
1452
|
for (var i$ = 0, length$ = param.members.length; i$ < length$; ++i$) {
|
|
989
1453
|
member = param.members[i$];
|
|
990
|
-
type =
|
|
991
|
-
type.identifier.isArray = false;
|
|
1454
|
+
type = elementOf(resolveType(scope, preAnn));
|
|
992
1455
|
if (type.nodeType === 'primitiveIdentifier') {
|
|
993
|
-
|
|
994
|
-
delete t.identifier.isArray;
|
|
995
|
-
member.typeAnnotation = t;
|
|
1456
|
+
member.typeAnnotation = elementOf(preAnn);
|
|
996
1457
|
} else {
|
|
997
1458
|
member.typeAnnotation = null != type ? type : ImplicitAny;
|
|
998
1459
|
}
|
|
@@ -1038,7 +1499,10 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
1038
1499
|
}
|
|
1039
1500
|
if (!preAnnotation)
|
|
1040
1501
|
if (null != node.typeAnnotation) {
|
|
1041
|
-
node.typeAnnotation.returnType
|
|
1502
|
+
if (null != node.typeAnnotation.returnType)
|
|
1503
|
+
node.typeAnnotation.returnType;
|
|
1504
|
+
else
|
|
1505
|
+
node.typeAnnotation.returnType = node.body.typeAnnotation;
|
|
1042
1506
|
}
|
|
1043
1507
|
if (null != node.typeAnnotation)
|
|
1044
1508
|
node.typeAnnotation;
|
|
@@ -1055,14 +1519,30 @@ walkFunction = function (node, scope, preAnnotation) {
|
|
|
1055
1519
|
return;
|
|
1056
1520
|
}
|
|
1057
1521
|
};
|
|
1522
|
+
walkSoakedFunctionApplication = function (node, scope) {
|
|
1523
|
+
scope.checkingSoak = true;
|
|
1524
|
+
walk(node['function'], scope);
|
|
1525
|
+
scope.checkingSoak = false;
|
|
1526
|
+
if (null != node['arguments'])
|
|
1527
|
+
walk(node['arguments'], scope);
|
|
1528
|
+
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = ImplicitAny;
|
|
1529
|
+
};
|
|
1058
1530
|
walkFunctionApplication = function (node, scope) {
|
|
1059
|
-
var a, arg, givenArg, i, left, n, param, preAnn, right, splatsType, type, typeArguments, typeScope;
|
|
1531
|
+
var a, arg, givenArg, i, left, n, opened, param, preAnn, right, splatsType, target, type, typeArguments, typeScope;
|
|
1060
1532
|
walk(node['function'], scope);
|
|
1061
1533
|
for (var i$ = 0, length$ = node['arguments'].length; i$ < length$; ++i$) {
|
|
1062
1534
|
arg = node['arguments'][i$];
|
|
1063
1535
|
n = i$;
|
|
1064
1536
|
walk(arg, scope);
|
|
1065
1537
|
}
|
|
1538
|
+
if (node['function'] instanceof MS.MemberAccessOp && node['function'].memberName === 'assign') {
|
|
1539
|
+
target = null != node['arguments'] ? node['arguments'][0] : void 0;
|
|
1540
|
+
if (target instanceof MS.MemberAccessOp && target.memberName === 'prototype' && target.expression instanceof MS.Identifier) {
|
|
1541
|
+
opened = scope.getTypeByIdentifier(createIdentifier(target.expression));
|
|
1542
|
+
if (null != opened)
|
|
1543
|
+
opened.closed = false;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1066
1546
|
type = scope.getVarInScope(node['function'].data);
|
|
1067
1547
|
if (null != type && null != type.identifier && null != type.identifier.typeArguments ? type.identifier.typeArguments.length : void 0) {
|
|
1068
1548
|
typeScope = new Scope(scope);
|
|
@@ -1070,7 +1550,10 @@ walkFunctionApplication = function (node, scope) {
|
|
|
1070
1550
|
for (var i$1 = 0, length$1 = (null != type.identifier ? type.identifier.typeArguments : void 0).length; i$1 < length$1; ++i$1) {
|
|
1071
1551
|
arg = (null != type.identifier ? type.identifier.typeArguments : void 0)[i$1];
|
|
1072
1552
|
n = i$1;
|
|
1073
|
-
givenArg = null != typeArguments ? typeArguments[n] : void 0
|
|
1553
|
+
givenArg = null != (null != typeArguments ? typeArguments[n] : void 0) ? null != typeArguments ? typeArguments[n] : void 0 : {
|
|
1554
|
+
nodeType: 'identifier',
|
|
1555
|
+
identifier: { typeRef: 'Any' }
|
|
1556
|
+
};
|
|
1074
1557
|
typeScope.addType({
|
|
1075
1558
|
nodeType: 'identifier',
|
|
1076
1559
|
identifier: _.cloneDeep(arg.identifier),
|
|
@@ -1095,6 +1578,8 @@ walkFunctionApplication = function (node, scope) {
|
|
|
1095
1578
|
for (var i$2 = 0, length$2 = node['arguments'].length; i$2 < length$2; ++i$2) {
|
|
1096
1579
|
arg = node['arguments'][i$2];
|
|
1097
1580
|
n = i$2;
|
|
1581
|
+
if (arg instanceof MS.Spread)
|
|
1582
|
+
break;
|
|
1098
1583
|
left = null != node['function'].typeAnnotation && null != node['function'].typeAnnotation['arguments'] ? node['function'].typeAnnotation['arguments'][n] : void 0;
|
|
1099
1584
|
right = null != arg ? arg.typeAnnotation : void 0;
|
|
1100
1585
|
if (null != left && null != left.identifier ? left.identifier.splats : void 0) {
|
|
@@ -1126,6 +1611,72 @@ walkFunctionApplication = function (node, scope) {
|
|
|
1126
1611
|
return accum$;
|
|
1127
1612
|
}.call(this, []);
|
|
1128
1613
|
};
|
|
1614
|
+
walkDynamicImport = function (node, scope) {
|
|
1615
|
+
walk(node.expression, scope);
|
|
1616
|
+
return node.typeAnnotation = ImplicitAny;
|
|
1617
|
+
};
|
|
1618
|
+
walkYield = function (node, scope) {
|
|
1619
|
+
if (null != node.expression)
|
|
1620
|
+
walk(node.expression, scope);
|
|
1621
|
+
return node.typeAnnotation = ImplicitAny;
|
|
1622
|
+
};
|
|
1623
|
+
walkAwaitOp = function (node, scope) {
|
|
1624
|
+
var t;
|
|
1625
|
+
walk(node.expression, scope);
|
|
1626
|
+
t = null != node.expression ? node.expression.typeAnnotation : void 0;
|
|
1627
|
+
return node.typeAnnotation = (null != t && null != t.identifier ? t.identifier.typeRef : void 0) === 'Promise' && (null != t.identifier.typeArguments ? t.identifier.typeArguments[0] : void 0) ? t.identifier.typeArguments[0] : ImplicitAny;
|
|
1628
|
+
};
|
|
1629
|
+
walkWhile = function (node, scope) {
|
|
1630
|
+
walk(node.condition, scope);
|
|
1631
|
+
walk(node.body, scope);
|
|
1632
|
+
return node.typeAnnotation = ImplicitAny;
|
|
1633
|
+
};
|
|
1634
|
+
walkTry = function (node, scope) {
|
|
1635
|
+
walk(node.body, scope);
|
|
1636
|
+
if (node.catchAssignee instanceof MS.Identifier)
|
|
1637
|
+
if (!scope.getVar(node.catchAssignee.data)) {
|
|
1638
|
+
scope.addVar({
|
|
1639
|
+
nodeType: 'variable',
|
|
1640
|
+
identifier: createIdentifier(node.catchAssignee),
|
|
1641
|
+
typeAnnotation: ImplicitAny
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
walk(node.catchBody, scope);
|
|
1645
|
+
walk(node.finallyBody, scope);
|
|
1646
|
+
return node.typeAnnotation = ImplicitAny;
|
|
1647
|
+
};
|
|
1648
|
+
BooleanType = {
|
|
1649
|
+
implicit: true,
|
|
1650
|
+
nodeType: 'primitiveIdentifier',
|
|
1651
|
+
isPrimitive: true,
|
|
1652
|
+
identifier: { typeRef: 'Boolean' }
|
|
1653
|
+
};
|
|
1654
|
+
walkBinOpGeneric = function (node, scope) {
|
|
1655
|
+
walk(node.left, scope);
|
|
1656
|
+
walk(node.right, scope);
|
|
1657
|
+
return node.typeAnnotation = node['instanceof'](MS.ComparisonOps, MS.InOp, MS.InstanceofOp) ? BooleanType : node['instanceof'](MS.LogicalOps, MS.ExistsOp) ? ImplicitAny : ImplicitAny;
|
|
1658
|
+
};
|
|
1659
|
+
walkLogicalNotOp = function (node, scope) {
|
|
1660
|
+
walk(node.expression, scope);
|
|
1661
|
+
return node.typeAnnotation = BooleanType;
|
|
1662
|
+
};
|
|
1663
|
+
walkGeneric = function (node, scope) {
|
|
1664
|
+
var child, childName;
|
|
1665
|
+
for (var i$ = 0, length$ = node.childNodes.length; i$ < length$; ++i$) {
|
|
1666
|
+
childName = node.childNodes[i$];
|
|
1667
|
+
if (!(null != node[childName]))
|
|
1668
|
+
continue;
|
|
1669
|
+
if (in$(childName, node.listMembers)) {
|
|
1670
|
+
for (var i$1 = 0, length$1 = node[childName].length; i$1 < length$1; ++i$1) {
|
|
1671
|
+
child = node[childName][i$1];
|
|
1672
|
+
walk(child, scope);
|
|
1673
|
+
}
|
|
1674
|
+
} else {
|
|
1675
|
+
walk(node[childName], scope);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return null != node.typeAnnotation ? node.typeAnnotation : node.typeAnnotation = ImplicitAny;
|
|
1679
|
+
};
|
|
1129
1680
|
walk = function (node, scope) {
|
|
1130
1681
|
var s;
|
|
1131
1682
|
if (!(null != node))
|
|
@@ -1141,6 +1692,8 @@ walk = function (node, scope) {
|
|
|
1141
1692
|
}
|
|
1142
1693
|
return accum$;
|
|
1143
1694
|
}.call(this, []);
|
|
1695
|
+
case !(typeof node['instanceof'] !== 'function' && !(node.nodeType === 'struct' || node.nodeType === 'vardef')):
|
|
1696
|
+
return;
|
|
1144
1697
|
case !(node.nodeType === 'struct'):
|
|
1145
1698
|
return walkStruct(node, scope);
|
|
1146
1699
|
case !(node.nodeType === 'vardef'):
|
|
@@ -1157,6 +1710,20 @@ walk = function (node, scope) {
|
|
|
1157
1710
|
return walkNewOp(node, scope);
|
|
1158
1711
|
case !(node['instanceof'](MS.PlusOp) || node['instanceof'](MS.MultiplyOp) || node['instanceof'](MS.DivideOp) || node['instanceof'](MS.SubtractOp)):
|
|
1159
1712
|
return walkBinOp(node, scope);
|
|
1713
|
+
case !node['instanceof'](MS.AwaitOp):
|
|
1714
|
+
return walkAwaitOp(node, scope);
|
|
1715
|
+
case !node['instanceof'](MS.Yield):
|
|
1716
|
+
return walkYield(node, scope);
|
|
1717
|
+
case !node['instanceof'](MS.Grab, MS.Share):
|
|
1718
|
+
return walk(node.cjs, scope);
|
|
1719
|
+
case !node['instanceof'](MS.DynamicImport):
|
|
1720
|
+
return walkDynamicImport(node, scope);
|
|
1721
|
+
case !node['instanceof'](MS.LogicalNotOp):
|
|
1722
|
+
return walkLogicalNotOp(node, scope);
|
|
1723
|
+
case !node['instanceof'](MS.While):
|
|
1724
|
+
return walkWhile(node, scope);
|
|
1725
|
+
case !node['instanceof'](MS.Try):
|
|
1726
|
+
return walkTry(node, scope);
|
|
1160
1727
|
case !node['instanceof'](MS.Switch):
|
|
1161
1728
|
return walkSwitch(node, scope);
|
|
1162
1729
|
case !node['instanceof'](MS.Conditional):
|
|
@@ -1165,7 +1732,7 @@ walk = function (node, scope) {
|
|
|
1165
1732
|
return walkUndefined(node, scope);
|
|
1166
1733
|
case !node['instanceof'](MS.OfOp):
|
|
1167
1734
|
return walkOfOp(node, scope);
|
|
1168
|
-
case !(node['instanceof'](MS.ForIn) || node['instanceof'](MS.ForOf)):
|
|
1735
|
+
case !(node['instanceof'](MS.ForIn) || node['instanceof'](MS.ForOf, MS.ForFrom)):
|
|
1169
1736
|
return walkFor(node, scope);
|
|
1170
1737
|
case !node['instanceof'](MS.Primitives):
|
|
1171
1738
|
return walkPrimitives(node, scope);
|
|
@@ -1195,12 +1762,24 @@ walk = function (node, scope) {
|
|
|
1195
1762
|
return walkClass(node, scope);
|
|
1196
1763
|
case !(node['instanceof'](MS.Function) || node['instanceof'](MS.BoundFunction)):
|
|
1197
1764
|
return walkFunction(node, scope);
|
|
1198
|
-
case !node['instanceof'](MS.
|
|
1765
|
+
case !node['instanceof'](MS.SoakedFunctionApplication):
|
|
1766
|
+
return walkSoakedFunctionApplication(node, scope);
|
|
1767
|
+
case !node['instanceof'](MS.FunctionApplications):
|
|
1199
1768
|
return walkFunctionApplication(node, scope);
|
|
1200
1769
|
case !node['instanceof'](MS.CompoundAssignOp):
|
|
1201
1770
|
return walkCompoundAssignOp(node, scope);
|
|
1202
1771
|
case !node['instanceof'](MS.AssignOp):
|
|
1203
1772
|
return walkAssignOp(node, scope);
|
|
1773
|
+
case !node['instanceof'](MS.BinOps):
|
|
1774
|
+
return walkBinOpGeneric(node, scope);
|
|
1775
|
+
case !(null != node.childNodes):
|
|
1776
|
+
return walkGeneric(node, scope);
|
|
1204
1777
|
}
|
|
1205
1778
|
};
|
|
1206
1779
|
module.exports = { checkNodes: checkNodes };
|
|
1780
|
+
function in$(member, list) {
|
|
1781
|
+
for (var i = 0, length = list.length; i < length; ++i)
|
|
1782
|
+
if (i in list && list[i] === member)
|
|
1783
|
+
return true;
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|