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.
Files changed (82) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/README.md +509 -267
  3. package/bin/mamba +1 -258
  4. package/decision.js +1 -246
  5. package/docs/coverage.md +70 -0
  6. package/docs/features.md +3348 -0
  7. package/docs/perf.md +94 -0
  8. package/docs/reference.md +1295 -0
  9. package/docs/vs-coffeescript.md +1593 -0
  10. package/docs/vs-iced-coffeescript.md +626 -0
  11. package/docs/vs-typescript.md +107 -0
  12. package/esm.js +8 -0
  13. package/jest.js +33 -0
  14. package/lib/black.js +17 -13
  15. package/lib/browser.js +2 -4
  16. package/lib/cli.js +207 -136
  17. package/lib/compiler.js +1162 -93
  18. package/lib/decision.js +10 -10
  19. package/lib/diagnostics.js +219 -0
  20. package/lib/esm-hooks.js +60 -0
  21. package/lib/fast-parser.js +3469 -0
  22. package/lib/functional-helpers.js +26 -9
  23. package/lib/helpers.js +67 -50
  24. package/lib/js-nodes.js +151 -12
  25. package/lib/lexer.js +1499 -0
  26. package/lib/light-module.js +200 -63
  27. package/lib/mamba.js +372 -0
  28. package/lib/module.js +23 -172
  29. package/lib/nodes.js +84 -21
  30. package/lib/optimiser.js +29 -9
  31. package/lib/optparse.js +32 -15
  32. package/lib/parser.js +9433 -4840
  33. package/lib/preprocessor.js +3 -5
  34. package/lib/register.js +49 -56
  35. package/lib/repl.js +28 -9
  36. package/lib/reporter.js +106 -69
  37. package/lib/run.js +3 -5
  38. package/lib/string-scanner.js +94 -0
  39. package/lib/syntax-tables.js +480 -0
  40. package/lib/type-checker.js +258 -44
  41. package/lib/type-helpers.js +28 -10
  42. package/lib/type-resolver.js +256 -34
  43. package/lib/type-scope.js +10 -6
  44. package/lib/type-walker.js +664 -85
  45. package/lib/types.js +17 -7
  46. package/lib/underscore.js +170 -76
  47. package/lib/unicode-classes.js +122 -0
  48. package/mambaview.js +1 -0
  49. package/package.json +49 -46
  50. package/stdlib.js +1 -0
  51. package/vendor/README.md +40 -0
  52. package/vendor/escodegen/LICENSE.BSD +19 -0
  53. package/vendor/escodegen/escodegen.js +2289 -0
  54. package/vendor/estraverse/LICENSE.BSD +19 -0
  55. package/vendor/estraverse/estraverse.js +706 -0
  56. package/vendor/mambacodegen/LICENSE +24 -0
  57. package/vendor/mambacodegen/lib/mscodegen.js +620 -0
  58. package/vendor/patches/escodegen.diff +130 -0
  59. package/vendor/patches/estraverse.diff +51 -0
  60. package/vendor/patches/pegjs.diff +70 -0
  61. package/vendor/patches/source-map.diff +160 -0
  62. package/vendor/source-map/LICENSE +28 -0
  63. package/vendor/source-map/lib/source-map/array-set.js +92 -0
  64. package/vendor/source-map/lib/source-map/base64-vlq.js +140 -0
  65. package/vendor/source-map/lib/source-map/base64.js +38 -0
  66. package/vendor/source-map/lib/source-map/binary-search.js +77 -0
  67. package/vendor/source-map/lib/source-map/source-map-consumer.js +404 -0
  68. package/vendor/source-map/lib/source-map/source-map-generator.js +229 -0
  69. package/vendor/source-map/lib/source-map/source-node.js +201 -0
  70. package/vendor/source-map/lib/source-map/util.js +57 -0
  71. package/vendor/source-map/lib/source-map.js +8 -0
  72. package/bin/fix +0 -17
  73. package/bin/updateImports +0 -46
  74. package/build.js +0 -25
  75. package/lib/module-esm.js +0 -901
  76. package/lib/pegjs-kofu-plugin.js +0 -35
  77. package/lib/pegjs-mamba-plugin.js +0 -35
  78. package/lib/processor-esm.js +0 -507
  79. package/mamba +0 -259
  80. package/msast.js +0 -1
  81. package/utils/gulp-mamba.js +0 -29
  82. /package/{lib/esm.js → vendor/patches/mambacodegen.diff} +0 -0
package/lib/decision.js CHANGED
@@ -1,9 +1,7 @@
1
- // Generated by MambaScript 0.5.2
2
- var present = console.log;
3
- // Generated by MambaScript 0.5.2
4
- var Decision, elements, merge_elements, tagName, tagName;
1
+ // Generated by MambaScript 2.0.0
2
+ var Decision, elements, merge_elements, tagName;
5
3
  elements = {
6
- regular: 'a abbr address article aside audio b bdi bdo blockquote body button\n canvas caption cite code colgroup datalist dd del details dfn div dl dt em\n fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup\n html i iframe ins kbd label legend li map mark menu meter nav noscript object\n ol optgroup option output p pre progress q rp rt ruby s samp script section\n select small span strong sub summary sup table tbody td textarea tfoot\n th thead time title tr u ul video',
4
+ regular: 'a abbr address article aside audio b bdi bdo blockquote body button\n canvas caption cite code colgroup datalist dd del details dfn div dl dt em\n fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup\n html i iframe ins kbd label legend li main map mark menu meter nav noscript object\n ol optgroup option output p pre progress q rp rt ruby s samp script section\n select small span strong sub summary sup table tbody td textarea tfoot\n th thead time title tr u ul video',
7
5
  'void': 'area base br col command embed hr img input keygen link meta param\n source track wbr',
8
6
  obsolete: 'applet acronym bgsound dir frameset noframes isindex listing\n nextid noembed plaintext rb strike xmp big blink center font marquee multicol\n nobr spacer tt',
9
7
  obsolete_void: 'basefont frame'
@@ -14,8 +12,10 @@ merge_elements = function () {
14
12
  result = [];
15
13
  for (var i$ = 0, length$ = args.length; i$ < length$; ++i$) {
16
14
  a = args[i$];
17
- for (var cache$ = elements[a].split(' '), i$1 = 0, length$1 = cache$.length; i$1 < length$1; ++i$1) {
15
+ for (var cache$ = elements[a].split(/\s+/), i$1 = 0, length$1 = cache$.length; i$1 < length$1; ++i$1) {
18
16
  element = cache$[i$1];
17
+ if (!element)
18
+ continue;
19
19
  if (!in$(element, result))
20
20
  result.push(element);
21
21
  }
@@ -148,7 +148,7 @@ Decision = function () {
148
148
  el = this.Pragma.createElement.apply(this.Pragma, [
149
149
  tagName,
150
150
  attrs
151
- ].concat([].slice.call(children)));
151
+ ].concat(Array.from(children)));
152
152
  } else {
153
153
  el = this.Pragma.createElement(tagName, attrs, children);
154
154
  }
@@ -216,7 +216,7 @@ for (var cache$ = merge_elements('regular', 'obsolete'), i$ = 0, length$ = cache
216
216
  return Decision.prototype[tagName] = function () {
217
217
  var args;
218
218
  args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
219
- return this.$.apply(this, [tagName].concat([].slice.call(args)));
219
+ return this.$.apply(this, [tagName].concat(Array.from(args)));
220
220
  };
221
221
  }(tagName));
222
222
  }
@@ -226,7 +226,7 @@ for (var cache$1 = merge_elements('void', 'obsolete_void'), i$1 = 0, length$1 =
226
226
  return Decision.prototype[tagName] = function () {
227
227
  var args;
228
228
  args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
229
- return this.selfClosingTag.apply(this, [tagName].concat([].slice.call(args)));
229
+ return this.selfClosingTag.apply(this, [tagName].concat(Array.from(args)));
230
230
  };
231
231
  }(tagName));
232
232
  }
@@ -241,4 +241,4 @@ function in$(member, list) {
241
241
  if (i in list && list[i] === member)
242
242
  return true;
243
243
  return false;
244
- }
244
+ }
@@ -0,0 +1,219 @@
1
+ // Generated by MambaScript 2.0.0
2
+ var cache$, carets, cleanMarkers, colourise, frame, indent, render, SITE, spaces;
3
+ cache$ = require('./helpers');
4
+ colourise = cache$.colourise;
5
+ cleanMarkers = cache$.cleanMarkers;
6
+ SITE = 'https://mambascript.org/docs/reference/errors';
7
+ spaces = function (n) {
8
+ if (n > 0) {
9
+ return Array(n + 1).join(' ');
10
+ } else {
11
+ return '';
12
+ }
13
+ };
14
+ carets = function (n) {
15
+ if (n > 0) {
16
+ return Array(n + 1).join('^');
17
+ } else {
18
+ return '^';
19
+ }
20
+ };
21
+ indent = function (text, n) {
22
+ var l;
23
+ return function (accum$) {
24
+ for (var cache$1 = text.split('\n'), i$ = 0, length$ = cache$1.length; i$ < length$; ++i$) {
25
+ l = cache$1[i$];
26
+ accum$.push(spaces(n) + l);
27
+ }
28
+ return accum$;
29
+ }.call(this, []).join('\n');
30
+ };
31
+ this.frame = frame = function (source, line, column, endColumn, before, after) {
32
+ var col, first, last, lines, mark, n, num, out, span, text, width;
33
+ if (null == column)
34
+ column = 1;
35
+ if (null == before)
36
+ before = 3;
37
+ if (null == after)
38
+ after = 1;
39
+ if (!(null != source && null != line))
40
+ return '';
41
+ lines = source.split('\n');
42
+ if (lines.length > 1 && lines[lines.length - 1] === '')
43
+ lines.pop();
44
+ if (!lines.length)
45
+ return '';
46
+ line = Math.min(line, lines.length);
47
+ first = Math.max(1, line - before);
48
+ last = Math.min(lines.length, line + after);
49
+ width = String(last).length;
50
+ out = [];
51
+ n = first;
52
+ while (n <= last) {
53
+ text = cleanMarkers(null != lines[n - 1] ? lines[n - 1] : '');
54
+ num = String(n);
55
+ mark = n === line ? '>' : ' ';
56
+ out.push('' + mark + ' ' + spaces(width - num.length) + num + ' | ' + text);
57
+ if (n === line) {
58
+ col = Math.max(1, column);
59
+ span = null != endColumn && endColumn > col ? endColumn - col : 1;
60
+ out.push(' ' + spaces(width) + ' | ' + spaces(col - 1) + colourise('red', carets(span)));
61
+ }
62
+ n++;
63
+ }
64
+ return out.join('\n');
65
+ };
66
+ this.render = render = function (d) {
67
+ var colour, f, fixLines, parts, r, rf, where;
68
+ where = '' + (null != d.file ? d.file : '<input>') + ':' + (null != d.line ? d.line : '?') + ':' + (null != d.column ? d.column : '?');
69
+ colour = d.kind === 'TypeWarning' ? 'yellow' : 'red';
70
+ parts = ['' + colourise('bold', where) + ' ' + colourise(colour, null != d.kind ? d.kind : 'Error') + ' ' + d.headline];
71
+ f = frame(d.source, d.line, d.column, d.endColumn);
72
+ if (f) {
73
+ parts.push('');
74
+ parts.push(f);
75
+ }
76
+ for (var cache$1 = null != d.related ? d.related : [], i$ = 0, length$ = cache$1.length; i$ < length$; ++i$) {
77
+ r = cache$1[i$];
78
+ rf = frame(null != r.source ? r.source : d.source, r.line, r.column, r.endColumn, 0, 0);
79
+ if (rf) {
80
+ parts.push('');
81
+ parts.push(' ' + r.label);
82
+ parts.push(rf);
83
+ }
84
+ }
85
+ if (d.why) {
86
+ parts.push('');
87
+ parts.push(indent(d.why, 2));
88
+ }
89
+ if (d.fix) {
90
+ parts.push('');
91
+ fixLines = d.fix.split('\n');
92
+ parts.push(' Fix: ' + fixLines[0]);
93
+ if (fixLines.length > 1)
94
+ parts.push(indent(fixLines.slice(1).join('\n'), 7));
95
+ }
96
+ if (d.code) {
97
+ parts.push('');
98
+ parts.push(' See ' + SITE + '#' + d.code.toLowerCase());
99
+ }
100
+ return parts.join('\n');
101
+ };
102
+ this.toJSON = function (d) {
103
+ var key, out, r;
104
+ out = {};
105
+ for (var cache$1 = [
106
+ 'kind',
107
+ 'code',
108
+ 'file',
109
+ 'line',
110
+ 'column',
111
+ 'endColumn',
112
+ 'headline',
113
+ 'why',
114
+ 'fix'
115
+ ], i$ = 0, length$ = cache$1.length; i$ < length$; ++i$) {
116
+ key = cache$1[i$];
117
+ if (null != d[key])
118
+ out[key] = d[key];
119
+ }
120
+ if (d.code)
121
+ out.see = '' + SITE + '#' + d.code.toLowerCase();
122
+ if (null != d.related ? d.related.length : void 0)
123
+ out.related = function (accum$) {
124
+ for (var i$1 = 0, length$1 = d.related.length; i$1 < length$1; ++i$1) {
125
+ r = d.related[i$1];
126
+ accum$.push({
127
+ line: r.line,
128
+ column: r.column,
129
+ endColumn: r.endColumn,
130
+ label: r.label
131
+ });
132
+ }
133
+ return accum$;
134
+ }.call(this, []);
135
+ return out;
136
+ };
137
+ this.attach = function (err, d) {
138
+ err.diagnostic = d;
139
+ if (null != d.code)
140
+ err.code = d.code;
141
+ err.headline = d.headline;
142
+ if (null != d.line)
143
+ err.line = d.line;
144
+ if (null != d.column)
145
+ err.column = d.column;
146
+ if (null != d.endColumn)
147
+ err.endColumn = d.endColumn;
148
+ err.message = render(d);
149
+ return err;
150
+ };
151
+ this.CATALOGUE = {
152
+ MS1001: 'unexpected character',
153
+ MS1002: 'malformed number',
154
+ MS1003: 'a digit separator must sit between two digits',
155
+ MS1010: 'unclosed string',
156
+ MS1011: 'unclosed interpolation',
157
+ MS1012: 'octal escape in a string',
158
+ MS1013: 'a string cannot end with a lone backslash',
159
+ MS1014: 'unclosed block comment',
160
+ MS1015: 'unclosed JavaScript literal',
161
+ MS1016: 'unterminated regular expression',
162
+ MS1017: 'invalid regular expression flags',
163
+ MS1018: 'unclosed heregex',
164
+ MS1019: 'unclosed character class in a heregex',
165
+ MS1020: 'inconsistent base indentation',
166
+ MS1021: 'ambiguous indentation',
167
+ MS1022: 'dedent inside an open bracket',
168
+ MS1023: 'unmatched closing bracket',
169
+ MS1024: 'a backslash is only allowed at the end of a line',
170
+ MS1025: 'empty regular expression',
171
+ MS1101: 'this line is indented but nothing opened a block',
172
+ MS1102: 'the file ended inside an open construct',
173
+ MS1103: 'expected one thing, found another',
174
+ MS1104: 'statement not allowed at the top level',
175
+ MS1105: 'the left side of an assignment is not assignable',
176
+ MS1106: 'a keyword or literal cannot be assigned to',
177
+ MS1107: 'the right side of an operator is missing',
178
+ MS1108: 'unclosed parenthesis',
179
+ MS1109: 'unclosed bracket',
180
+ MS1110: 'unclosed brace',
181
+ MS1111: 'unclosed call',
182
+ MS1112: 'expected a property name',
183
+ MS1113: 'expected an object key',
184
+ MS1114: 'an object key cannot be an interpolated string',
185
+ MS1115: 'unknown macro',
186
+ MS1116: 'expected a function literal',
187
+ MS1117: 'super followed by a property access',
188
+ MS1118: 'expected a class after new',
189
+ MS1119: 'expected an indented block or then',
190
+ MS1120: 'expected when or else inside consider',
191
+ MS1121: 'loop header',
192
+ MS1122: 'grab statement',
193
+ MS1123: 'type annotation',
194
+ MS1124: 'a keyword cannot be used as a value here',
195
+ MS1125: 'unexpected token',
196
+ MS1127: 'range or slice',
197
+ MS1128: 'object spread or rest written the wrong way round',
198
+ MS1129: 'a computed key needs braces around the object',
199
+ MS1131: 'no loop with that label encloses this line',
200
+ MS1132: 'backticks are embedded JavaScript, not a template',
201
+ MS1300: 'the compiler could not lower this construct',
202
+ MS1301: 'a default value only belongs in a destructuring pattern',
203
+ MS1302: 'a pattern can collect the rest only once',
204
+ MS3001: 'grab cannot destructure deeper than one level',
205
+ MS3002: 'grab and share must be at the top level of an ES module',
206
+ MS3003: 'conflicting shares',
207
+ MS3004: 'grab * needs as; share * needs from',
208
+ MS4001: 'yield outside a function, in a constructor or in a blueprint body',
209
+ MS4002: 'yield from needs an iterable',
210
+ MS4003: 'a from loop takes one variable and no own, by or waitForIt without from',
211
+ MS1900: 'the fallback parser could not continue here',
212
+ MS2001: 'value does not match the declared type',
213
+ MS2002: 'double bind: a name was declared twice with different types',
214
+ MS2004: 'unknown type',
215
+ MS2009: 'a member the type does not have',
216
+ MS2008: 'a blueprint does not define a member of the struct it implements',
217
+ MS2007: 'BigInt and Int cannot be mixed',
218
+ MS2010: 'an unknown type name'
219
+ };
@@ -0,0 +1,60 @@
1
+ // Generated by MambaScript 2.0.0
2
+ var EXTENSIONS, fileURLToPath, fs, isMamba, MambaScript, packageType, path;
3
+ fs = require('fs');
4
+ path = require('path');
5
+ fileURLToPath = require('url').fileURLToPath;
6
+ MambaScript = require('./module');
7
+ EXTENSIONS = [
8
+ '.mamba',
9
+ '.kofu'
10
+ ];
11
+ packageType = function (file) {
12
+ var candidate, dir, e, parent;
13
+ dir = path.dirname(file);
14
+ return function (accum$) {
15
+ while (true) {
16
+ candidate = path.join(dir, 'package.json');
17
+ if (fs.existsSync(candidate))
18
+ try {
19
+ return JSON.parse(fs.readFileSync(candidate, 'utf8')).type;
20
+ } catch (e$) {
21
+ e = e$;
22
+ return;
23
+ }
24
+ parent = path.dirname(dir);
25
+ if (parent === dir)
26
+ return;
27
+ accum$.push(dir = parent);
28
+ }
29
+ return accum$;
30
+ }.call(this, []);
31
+ };
32
+ isMamba = function (url) {
33
+ return url.startsWith('file:') && EXTENSIONS.some(function (ext) {
34
+ return url.endsWith(ext);
35
+ });
36
+ };
37
+ exports.resolve = function (specifier, context, nextResolve) {
38
+ return nextResolve(specifier, context);
39
+ };
40
+ exports.load = function (url, context, nextLoad) {
41
+ var esm, file, js, source;
42
+ if (!isMamba(url))
43
+ return nextLoad(url, context);
44
+ file = fileURLToPath(url);
45
+ source = fs.readFileSync(file, 'utf8');
46
+ esm = packageType(file) === 'module';
47
+ js = MambaScript.cs2js(source, {
48
+ bare: true,
49
+ raw: true,
50
+ filename: file,
51
+ inputSource: file,
52
+ typeCheck: process.env.MAMBA_TYPECHECK || 'warn',
53
+ modules: esm ? 'esm' : 'cjs'
54
+ });
55
+ return {
56
+ format: esm ? 'module' : 'commonjs',
57
+ source: js,
58
+ shortCircuit: true
59
+ };
60
+ };