mambascript 0.5.5 → 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-checker.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// Generated by MambaScript 0.
|
|
2
|
-
var
|
|
3
|
-
// Generated by MambaScript 0.5.2
|
|
4
|
-
var _, checkType, checkTypeAnnotation, correctExtends, CS, debug, formatType, ImplicitAny, isAcceptable, isAcceptableExtends, isAcceptableFunctionType, isAcceptablePrimitiveSymbol, isAcceptableStruct, reporter, typeErrorText, util, util;
|
|
1
|
+
// Generated by MambaScript 2.0.0
|
|
2
|
+
var _, arrayOf, checkType, checkTypeAnnotation, comparing, correctExtends, CS, debug, depthOf, elementOf, formatType, ImplicitAny, inlineType, isAcceptable, isAcceptableExtends, isAcceptableFunctionType, isAcceptableNow, isAcceptablePrimitiveSymbol, isAcceptableStruct, mixedListText, reporter, reportMismatch, targetName, typeErrorText, typeMismatch, util;
|
|
5
3
|
debug = require('./helpers').debug;
|
|
6
4
|
util = require('util');
|
|
7
5
|
reporter = require('./reporter');
|
|
8
6
|
CS = require('./nodes');
|
|
9
|
-
_ = require('
|
|
7
|
+
_ = require('./underscore');
|
|
10
8
|
ImplicitAny = require('./types').ImplicitAny;
|
|
11
9
|
correctExtends = function (scope, annotation) {
|
|
12
10
|
var cur, extendList, next;
|
|
@@ -28,6 +26,50 @@ isAcceptableExtends = function (scope, left, right) {
|
|
|
28
26
|
return le.identifier.typeRef === right.identifier.typeRef;
|
|
29
27
|
}));
|
|
30
28
|
};
|
|
29
|
+
depthOf = function (id) {
|
|
30
|
+
if (null != id ? id.isArray : void 0) {
|
|
31
|
+
if (null != id.arrayDepth)
|
|
32
|
+
return id.arrayDepth;
|
|
33
|
+
else
|
|
34
|
+
return 1;
|
|
35
|
+
} else {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
elementOf = function (ann) {
|
|
40
|
+
var d, e;
|
|
41
|
+
e = _.cloneDeep(ann);
|
|
42
|
+
if (!(null != (null != e ? e.identifier : void 0)))
|
|
43
|
+
return e;
|
|
44
|
+
d = depthOf(e.identifier) - 1;
|
|
45
|
+
if (d > 0) {
|
|
46
|
+
e.identifier.arrayDepth = d;
|
|
47
|
+
} else {
|
|
48
|
+
delete e.identifier.isArray;
|
|
49
|
+
}
|
|
50
|
+
if (d <= 1)
|
|
51
|
+
delete e.identifier.arrayDepth;
|
|
52
|
+
delete e.identifier.wholeNullable;
|
|
53
|
+
delete e.mixed;
|
|
54
|
+
delete e.memberTypes;
|
|
55
|
+
return e;
|
|
56
|
+
};
|
|
57
|
+
arrayOf = function (ann) {
|
|
58
|
+
var a, d;
|
|
59
|
+
a = _.cloneDeep(ann);
|
|
60
|
+
if (null != a.identifier)
|
|
61
|
+
a.identifier;
|
|
62
|
+
else
|
|
63
|
+
a.identifier = { typeRef: 'Any' };
|
|
64
|
+
d = depthOf(a.identifier) + 1;
|
|
65
|
+
a.identifier.isArray = true;
|
|
66
|
+
if (d > 1) {
|
|
67
|
+
a.identifier.arrayDepth = d;
|
|
68
|
+
} else {
|
|
69
|
+
delete a.identifier.arrayDepth;
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
72
|
+
};
|
|
31
73
|
isAcceptablePrimitiveSymbol = function (scope, left, right, nullable, isArray) {
|
|
32
74
|
if (null == nullable)
|
|
33
75
|
nullable = false;
|
|
@@ -42,27 +84,20 @@ isAcceptablePrimitiveSymbol = function (scope, left, right, nullable, isArray) {
|
|
|
42
84
|
return true;
|
|
43
85
|
return false;
|
|
44
86
|
}
|
|
45
|
-
if (
|
|
46
|
-
if (null != (null != right && null != right.identifier ? right.identifier.isArray : void 0)) {
|
|
47
|
-
if (!!(null != right && null != right.identifier ? right.identifier.isArray : void 0) !== true) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
} else if (!!(null != right && null != right.identifier ? right.identifier.isArray : void 0) !== false) {
|
|
87
|
+
if (!(depthOf(left.identifier) === depthOf(null != right ? right.identifier : void 0)))
|
|
54
88
|
return false;
|
|
55
|
-
}
|
|
56
89
|
return true;
|
|
57
90
|
};
|
|
58
91
|
isAcceptableStruct = function (scope, left, right) {
|
|
59
92
|
return _.every(left.properties.map(function (lprop, n) {
|
|
60
|
-
var rprop;
|
|
93
|
+
var id, rprop;
|
|
61
94
|
rprop = _.find(right.properties, function (rp) {
|
|
62
95
|
return (null != rp.identifier ? rp.identifier.typeRef : void 0) === (null != lprop.identifier ? lprop.identifier.typeRef : void 0);
|
|
63
96
|
});
|
|
64
|
-
if (!(null != rprop))
|
|
65
|
-
|
|
97
|
+
if (!(null != rprop)) {
|
|
98
|
+
id = null != lprop.typeAnnotation ? lprop.typeAnnotation.identifier : void 0;
|
|
99
|
+
return !!((null != id ? id.nullable : void 0) || (null != id ? id.wholeNullable : void 0));
|
|
100
|
+
}
|
|
66
101
|
return isAcceptable(scope, lprop.typeAnnotation, rprop.typeAnnotation);
|
|
67
102
|
}));
|
|
68
103
|
};
|
|
@@ -90,8 +125,29 @@ isAcceptableFunctionType = function (scope, left, right) {
|
|
|
90
125
|
return true;
|
|
91
126
|
return isAcceptable(scope, left.returnType, right.returnType);
|
|
92
127
|
};
|
|
128
|
+
comparing = [];
|
|
93
129
|
isAcceptable = function (scope, left, right) {
|
|
94
|
-
var
|
|
130
|
+
var pair;
|
|
131
|
+
if (!(null != left) || !(null != right))
|
|
132
|
+
return true;
|
|
133
|
+
for (var i$ = 0, length$ = comparing.length; i$ < length$; ++i$) {
|
|
134
|
+
pair = comparing[i$];
|
|
135
|
+
if (!(pair[0] === left && pair[1] === right))
|
|
136
|
+
continue;
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
comparing.push([
|
|
140
|
+
left,
|
|
141
|
+
right
|
|
142
|
+
]);
|
|
143
|
+
try {
|
|
144
|
+
return isAcceptableNow(scope, left, right);
|
|
145
|
+
} finally {
|
|
146
|
+
comparing.pop();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
isAcceptableNow = function (scope, left, right) {
|
|
150
|
+
var cache$, elementType, isAny, isAnyArray, isSameArrayFlag, leftAnnotation, leftNullable, leftWholeNullable, ret, rightAnnotation, rightName, rightNullable;
|
|
95
151
|
if (!(null != left) || !(null != right))
|
|
96
152
|
return true;
|
|
97
153
|
cache$ = [
|
|
@@ -104,10 +160,30 @@ isAcceptable = function (scope, left, right) {
|
|
|
104
160
|
});
|
|
105
161
|
leftAnnotation = cache$[0];
|
|
106
162
|
rightAnnotation = cache$[1];
|
|
107
|
-
if (null != leftAnnotation.identifier && null != leftAnnotation.identifier.identifier && null != leftAnnotation.identifier.identifier.typeArguments ? leftAnnotation.identifier.identifier.typeArguments.length : void 0)
|
|
108
|
-
console.error(leftAnnotation.identifier.identifier.typeArguments);
|
|
109
163
|
if (!(null != leftAnnotation) || !(null != rightAnnotation))
|
|
110
164
|
return true;
|
|
165
|
+
isAny = function (ann) {
|
|
166
|
+
return (null != ann && null != ann.identifier ? ann.identifier.typeRef : void 0) === 'Any' && !ann.identifier.isArray;
|
|
167
|
+
};
|
|
168
|
+
if (isAny(leftAnnotation) || isAny(rightAnnotation))
|
|
169
|
+
return true;
|
|
170
|
+
isAnyArray = function (ann) {
|
|
171
|
+
return (null != ann && null != ann.identifier ? ann.identifier.typeRef : void 0) === 'Any' && !!ann.identifier.isArray;
|
|
172
|
+
};
|
|
173
|
+
if (isAnyArray(leftAnnotation) || isAnyArray(rightAnnotation))
|
|
174
|
+
if (!!(null != leftAnnotation.identifier ? leftAnnotation.identifier.isArray : void 0) && !!(null != rightAnnotation.identifier ? rightAnnotation.identifier.isArray : void 0)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
if (rightAnnotation.mixed && null != rightAnnotation.memberTypes && (null != leftAnnotation.identifier ? leftAnnotation.identifier.isArray : void 0)) {
|
|
178
|
+
elementType = elementOf(leftAnnotation);
|
|
179
|
+
return _.every(rightAnnotation.memberTypes, function (t) {
|
|
180
|
+
return isAcceptable(scope, elementType, t);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if ((null != leftAnnotation.identifier ? leftAnnotation.identifier.typeRef : void 0) === 'Object' && !leftAnnotation.identifier.isArray)
|
|
184
|
+
if (rightAnnotation.nodeType === 'members') {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
111
187
|
if (leftAnnotation.nodeType === 'primitiveIdentifier')
|
|
112
188
|
if (leftAnnotation.identifier.typeRef === 'Any') {
|
|
113
189
|
return true;
|
|
@@ -116,12 +192,13 @@ isAcceptable = function (scope, left, right) {
|
|
|
116
192
|
leftWholeNullable = left.identifier.wholeNullable;
|
|
117
193
|
if (leftWholeNullable && (rightAnnotation.identifier.typeRef === 'Undefined' || rightAnnotation.identifier.typeRef === 'Null'))
|
|
118
194
|
return true;
|
|
119
|
-
isSameArrayFlag =
|
|
195
|
+
isSameArrayFlag = depthOf(left.identifier) === depthOf(right.identifier) || depthOf(left.identifier) === depthOf(rightAnnotation.identifier);
|
|
120
196
|
if (!isSameArrayFlag)
|
|
121
197
|
return false;
|
|
122
198
|
}
|
|
123
199
|
if (leftAnnotation.nodeType === 'identifier') {
|
|
124
|
-
|
|
200
|
+
rightName = null != rightAnnotation && null != rightAnnotation.identifier ? rightAnnotation.identifier.typeRef : void 0;
|
|
201
|
+
if (null != rightName && (null != leftAnnotation.identifier ? leftAnnotation.identifier.typeRef : void 0) === rightName) {
|
|
125
202
|
return true;
|
|
126
203
|
} else {
|
|
127
204
|
return false;
|
|
@@ -138,8 +215,8 @@ isAcceptable = function (scope, left, right) {
|
|
|
138
215
|
if (rightAnnotation.nodeType === 'primitiveIdentifier') {
|
|
139
216
|
if (leftAnnotation.identifier.typeRef === 'Void')
|
|
140
217
|
return true;
|
|
141
|
-
leftNullable = !!left.identifier.nullable;
|
|
142
|
-
rightNullable = !!right.identifier.nullable;
|
|
218
|
+
leftNullable = !!(left.identifier.nullable || left.identifier.wholeNullable);
|
|
219
|
+
rightNullable = !!(right.identifier.nullable || right.identifier.wholeNullable);
|
|
143
220
|
if (!leftNullable && rightNullable)
|
|
144
221
|
return false;
|
|
145
222
|
return isAcceptablePrimitiveSymbol(scope, leftAnnotation, rightAnnotation, leftNullable);
|
|
@@ -154,6 +231,11 @@ isAcceptable = function (scope, left, right) {
|
|
|
154
231
|
} else {
|
|
155
232
|
return false;
|
|
156
233
|
}
|
|
234
|
+
reporter.add_warning(node, 'the type checker does not know this type pattern and assumed it is compatible', {
|
|
235
|
+
code: 'MS2004',
|
|
236
|
+
why: 'Neither side of this check is a primitive, array, function, struct or class type the checker understands, so it let the value through.',
|
|
237
|
+
fix: 'write the type with the forms the checker knows (Int, String[], (Int) -> String, struct names), or remove the annotation.'
|
|
238
|
+
});
|
|
157
239
|
return true;
|
|
158
240
|
};
|
|
159
241
|
util = require('util');
|
|
@@ -169,7 +251,7 @@ formatType = function (node, prefix) {
|
|
|
169
251
|
} else if (node.nodeType === 'primitiveIdentifier') {
|
|
170
252
|
return prefix + node.identifier.typeRef;
|
|
171
253
|
} else if (node.nodeType === 'identifier') {
|
|
172
|
-
array =
|
|
254
|
+
array = '[]'.repeat(depthOf(node.identifier));
|
|
173
255
|
if (null != node.typeAnnotation) {
|
|
174
256
|
return node.identifier.typeRef + array + ' :: ' + formatType(node.typeAnnotation, prefix);
|
|
175
257
|
} else {
|
|
@@ -186,45 +268,177 @@ formatType = function (node, prefix) {
|
|
|
186
268
|
return util.inspect(node, false, null);
|
|
187
269
|
}
|
|
188
270
|
};
|
|
271
|
+
inlineType = function (t) {
|
|
272
|
+
var a, p, suffix;
|
|
273
|
+
if (!(null != t))
|
|
274
|
+
return 'Any';
|
|
275
|
+
switch (t.nodeType) {
|
|
276
|
+
case 'primitiveIdentifier':
|
|
277
|
+
return t.identifier.typeRef;
|
|
278
|
+
case 'identifier':
|
|
279
|
+
suffix = (t.identifier.nullable ? '?' : '') + '[]'.repeat(depthOf(t.identifier)) + (t.identifier.wholeNullable ? '?' : '');
|
|
280
|
+
if (null != t.identifier.typeArguments ? t.identifier.typeArguments.length : void 0) {
|
|
281
|
+
return '' + t.identifier.typeRef + '<' + function (accum$) {
|
|
282
|
+
for (var i$ = 0, length$ = t.identifier.typeArguments.length; i$ < length$; ++i$) {
|
|
283
|
+
a = t.identifier.typeArguments[i$];
|
|
284
|
+
accum$.push(inlineType(a));
|
|
285
|
+
}
|
|
286
|
+
return accum$;
|
|
287
|
+
}.call(this, []).join(', ') + '>' + suffix;
|
|
288
|
+
} else {
|
|
289
|
+
return t.identifier.typeRef + suffix;
|
|
290
|
+
}
|
|
291
|
+
case 'functionType':
|
|
292
|
+
return '(' + function (accum$1) {
|
|
293
|
+
for (var i$1 = 0, length$1 = t['arguments'].length; i$1 < length$1; ++i$1) {
|
|
294
|
+
a = t['arguments'][i$1];
|
|
295
|
+
accum$1.push(inlineType(a));
|
|
296
|
+
}
|
|
297
|
+
return accum$1;
|
|
298
|
+
}.call(this, []).join(', ') + ') -> ' + inlineType(t.returnType);
|
|
299
|
+
case 'members':
|
|
300
|
+
return '{' + function (accum$2) {
|
|
301
|
+
for (var i$2 = 0, length$2 = t.properties.length; i$2 < length$2; ++i$2) {
|
|
302
|
+
p = t.properties[i$2];
|
|
303
|
+
accum$2.push('' + p.identifier.typeRef + ' :: ' + inlineType(p.typeAnnotation));
|
|
304
|
+
}
|
|
305
|
+
return accum$2;
|
|
306
|
+
}.call(this, []).join(', ') + '}';
|
|
307
|
+
default:
|
|
308
|
+
return formatType(t, '').replace(/\s+/g, ' ').trim();
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
targetName = function (node) {
|
|
312
|
+
var a;
|
|
313
|
+
a = null != (null != node ? node.assignee : void 0) ? null != node ? node.assignee : void 0 : null != node ? node.param : void 0;
|
|
314
|
+
if (null != (null != a ? a.data : void 0) && typeof a.data === 'string')
|
|
315
|
+
return a.data;
|
|
316
|
+
if (null != (null != a ? a.memberName : void 0) && (null != a.expression ? a.expression.className : void 0) === 'This')
|
|
317
|
+
return '@' + a.memberName;
|
|
318
|
+
if (null != (null != a ? a.memberName : void 0))
|
|
319
|
+
return a.memberName;
|
|
320
|
+
};
|
|
321
|
+
mixedListText = function (right) {
|
|
322
|
+
var n, names, t;
|
|
323
|
+
if (!((null != right && null != right.identifier ? right.identifier.isArray : void 0) && (right.mixed || right.identifier.typeRef === 'Mixed')))
|
|
324
|
+
return null;
|
|
325
|
+
names = [];
|
|
326
|
+
for (var cache$ = null != right.memberTypes ? right.memberTypes : [], i$ = 0, length$ = cache$.length; i$ < length$; ++i$) {
|
|
327
|
+
t = cache$[i$];
|
|
328
|
+
n = inlineType(t);
|
|
329
|
+
if (!(null != n && n !== 'Mixed' && n !== 'Any'))
|
|
330
|
+
continue;
|
|
331
|
+
if (!in$(n, names))
|
|
332
|
+
names.push(n);
|
|
333
|
+
}
|
|
334
|
+
if (names.length) {
|
|
335
|
+
return 'a list of mixed values (' + names.join(', ') + ')';
|
|
336
|
+
} else {
|
|
337
|
+
return 'a list of mixed values';
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
typeMismatch = function (node, left, right) {
|
|
341
|
+
var described, l, name, r, suggestion;
|
|
342
|
+
l = inlineType(left);
|
|
343
|
+
described = mixedListText(right);
|
|
344
|
+
r = null != described ? described : inlineType(right);
|
|
345
|
+
name = targetName(node);
|
|
346
|
+
if (null != described) {
|
|
347
|
+
if (null != name) {
|
|
348
|
+
return {
|
|
349
|
+
headline: '' + name + ' is declared as ' + l + ', but this value is ' + described,
|
|
350
|
+
why: '' + name + ' :: ' + l + ' means every value assigned to ' + name + ' must be ' + l + '. This list holds values that do not share one type.',
|
|
351
|
+
fix: 'make the values agree, or change the annotation to ' + name + ' :: Any[] if a mixed list is what you meant.',
|
|
352
|
+
code: 'MS2001'
|
|
353
|
+
};
|
|
354
|
+
} else {
|
|
355
|
+
return {
|
|
356
|
+
headline: 'expected ' + l + ', but this value is ' + described,
|
|
357
|
+
why: 'The declared type here is ' + l + '. The values do not share one type, so they do not fit ' + l + '.',
|
|
358
|
+
fix: 'make the values agree, or change the declaration to Any[] if a mixed list is what you meant.',
|
|
359
|
+
code: 'MS2001'
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
} else if (null != name) {
|
|
363
|
+
suggestion = (null != right && null != right.identifier ? right.identifier.typeRef : void 0) === 'Mixed' ? 'Any' : r;
|
|
364
|
+
return {
|
|
365
|
+
headline: '' + name + ' is declared as ' + l + ', but this value is ' + r,
|
|
366
|
+
why: '' + name + ' :: ' + l + ' means every value assigned to ' + name + ' must be ' + l + '. The value on this line is ' + r + '.',
|
|
367
|
+
fix: 'make the value ' + l + ', or change the annotation to ' + name + ' :: ' + suggestion + ' if ' + suggestion + ' is what you meant.',
|
|
368
|
+
code: 'MS2001'
|
|
369
|
+
};
|
|
370
|
+
} else {
|
|
371
|
+
suggestion = (null != right && null != right.identifier ? right.identifier.typeRef : void 0) === 'Mixed' ? 'Any' : r;
|
|
372
|
+
return {
|
|
373
|
+
headline: 'expected ' + l + ', but this value is ' + r,
|
|
374
|
+
why: 'The declared type here is ' + l + '; the value is ' + r + ', and ' + r + ' is not accepted where ' + l + ' is required.',
|
|
375
|
+
fix: 'make the value ' + l + ', or change the declaration to ' + suggestion + ' if that is what you meant.',
|
|
376
|
+
code: 'MS2001'
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
};
|
|
189
380
|
typeErrorText = function (left, right) {
|
|
190
|
-
var
|
|
191
|
-
header = '\nTypeError:';
|
|
381
|
+
var l, r;
|
|
192
382
|
l = formatType(left, ' ');
|
|
193
383
|
r = formatType(right, ' ');
|
|
194
|
-
return '
|
|
384
|
+
return 'required:\n' + l + '\nassignee:\n' + r + '';
|
|
385
|
+
};
|
|
386
|
+
reportMismatch = function (node, left, right, warnOnly) {
|
|
387
|
+
var cache$, code, fix, headline, why;
|
|
388
|
+
cache$ = typeMismatch(node, left, right);
|
|
389
|
+
headline = cache$.headline;
|
|
390
|
+
why = cache$.why;
|
|
391
|
+
fix = cache$.fix;
|
|
392
|
+
code = cache$.code;
|
|
393
|
+
if (warnOnly) {
|
|
394
|
+
return reporter.add_warning(node, headline, {
|
|
395
|
+
why: why,
|
|
396
|
+
fix: fix,
|
|
397
|
+
code: code
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
return reporter.add_error(node, headline, {
|
|
401
|
+
why: why,
|
|
402
|
+
fix: fix,
|
|
403
|
+
code: code
|
|
404
|
+
});
|
|
405
|
+
}
|
|
195
406
|
};
|
|
196
407
|
checkType = function (scope, node, left, right) {
|
|
197
|
-
var
|
|
408
|
+
var ret;
|
|
198
409
|
ret = isAcceptable(scope, left.typeAnnotation, right.typeAnnotation);
|
|
410
|
+
if ((null != left.typeAnnotation ? left.typeAnnotation.unknownType : void 0) || (null != right.typeAnnotation ? right.typeAnnotation.unknownType : void 0))
|
|
411
|
+
return false;
|
|
199
412
|
if (ret) {
|
|
200
413
|
return true;
|
|
201
414
|
} else {
|
|
202
|
-
|
|
203
|
-
if (left.implicit && right.implicit) {
|
|
204
|
-
reporter.add_warning(node, err);
|
|
205
|
-
} else {
|
|
206
|
-
reporter.add_error(node, err);
|
|
207
|
-
}
|
|
415
|
+
reportMismatch(node, left.typeAnnotation, right.typeAnnotation, left.implicit && right.implicit);
|
|
208
416
|
return false;
|
|
209
417
|
}
|
|
210
418
|
};
|
|
211
419
|
checkTypeAnnotation = function (scope, node, left, right) {
|
|
212
|
-
var
|
|
420
|
+
var ret;
|
|
213
421
|
ret = isAcceptable(scope, left, right);
|
|
422
|
+
if ((null != left ? left.unknownType : void 0) || (null != right ? right.unknownType : void 0))
|
|
423
|
+
return false;
|
|
214
424
|
if (ret) {
|
|
215
425
|
return true;
|
|
216
426
|
} else {
|
|
217
|
-
|
|
218
|
-
if (left.implicit && right.implicit) {
|
|
219
|
-
reporter.add_warning(node, err);
|
|
220
|
-
} else {
|
|
221
|
-
reporter.add_error(node, err);
|
|
222
|
-
}
|
|
427
|
+
reportMismatch(node, left, right, left.implicit && right.implicit);
|
|
223
428
|
return false;
|
|
224
429
|
}
|
|
225
430
|
};
|
|
226
431
|
module.exports = {
|
|
227
432
|
checkType: checkType,
|
|
228
433
|
checkTypeAnnotation: checkTypeAnnotation,
|
|
229
|
-
isAcceptable: isAcceptable
|
|
434
|
+
isAcceptable: isAcceptable,
|
|
435
|
+
depthOf: depthOf,
|
|
436
|
+
elementOf: elementOf,
|
|
437
|
+
arrayOf: arrayOf
|
|
230
438
|
};
|
|
439
|
+
function in$(member, list) {
|
|
440
|
+
for (var i = 0, length = list.length; i < length; ++i)
|
|
441
|
+
if (i in list && list[i] === member)
|
|
442
|
+
return true;
|
|
443
|
+
return false;
|
|
444
|
+
}
|
package/lib/type-helpers.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// Generated by MambaScript 0.
|
|
2
|
-
var
|
|
3
|
-
// Generated by MambaScript 0.5.2
|
|
4
|
-
var ArrayInterface, clone, NumberInterface, ObjectInterface, rewrite;
|
|
1
|
+
// Generated by MambaScript 2.0.0
|
|
2
|
+
var ArrayInterface, clone, NumberInterface, ObjectInterface, rewrite, TypeError;
|
|
5
3
|
this.clone = clone = function (obj) {
|
|
6
4
|
var flags, key, newInstance;
|
|
7
5
|
if (!(null != obj) || typeof obj !== 'object')
|
|
@@ -38,12 +36,32 @@ this.rewrite = rewrite = function (obj, replacer) {
|
|
|
38
36
|
return accum$;
|
|
39
37
|
}.call(this, []);
|
|
40
38
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
TypeError = function (message, errors, file) {
|
|
40
|
+
var err;
|
|
41
|
+
if (null == errors)
|
|
42
|
+
errors = [];
|
|
43
|
+
if (null == file)
|
|
44
|
+
file = null;
|
|
45
|
+
err = new Error(message);
|
|
46
|
+
err.name = 'MambaTypeError';
|
|
47
|
+
err.errors = errors;
|
|
48
|
+
err.file = file;
|
|
49
|
+
Object.setPrototypeOf(err, TypeError.prototype);
|
|
50
|
+
return err;
|
|
51
|
+
};
|
|
52
|
+
TypeError.prototype = Object.create(Error.prototype, {
|
|
53
|
+
constructor: {
|
|
54
|
+
value: TypeError,
|
|
55
|
+
writable: true,
|
|
56
|
+
configurable: true
|
|
57
|
+
},
|
|
58
|
+
name: {
|
|
59
|
+
value: 'MambaTypeError',
|
|
60
|
+
writable: true,
|
|
61
|
+
configurable: true
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
});
|
|
64
|
+
this.TypeError = TypeError;
|
|
47
65
|
NumberInterface = {
|
|
48
66
|
toString: {
|
|
49
67
|
name: 'function',
|
|
@@ -87,4 +105,4 @@ ObjectInterface = function () {
|
|
|
87
105
|
returnType: { array: 'String' }
|
|
88
106
|
}
|
|
89
107
|
};
|
|
90
|
-
};
|
|
108
|
+
};
|