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.
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/mamba DELETED
@@ -1,259 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Generated by MambaScript 0.2.1
4
- var present = console.log;
5
- // Generated by MambaScript 0.2.1
6
- var argv, Code, code, code, code, code, codes, codes, compileFromSourceToJS, cs_ast, cs_ast, cscodegen, debug, e, e, escodegen, exec, extReplacer, extReplacer, filepaths, filepaths, fpath, fpath, fpath, fs, joined, joined, js_ast, js_ast, literate, literate, MambaScript, mode, moduleCode, name, name, outpath, outpath, outpath, outpath, path, Preprocessor, Preprocessor, repl, reporter, result, result, run, runMain, source, source, source, spawn;
7
- fs = require('fs');
8
- path = require('path');
9
- MambaScript = require('../lib/module');
10
- cache$ = require('child_process');
11
- exec = cache$.exec;
12
- spawn = cache$.spawn;
13
- cscodegen = require('cscodegen');
14
- escodegen = require('escodegen');
15
- repl = require('../lib/repl');
16
- reporter = require('../lib/reporter');
17
- debug = require('../lib/helpers').debug;
18
- argv = require('optimist').boolean('compile').boolean('bare').boolean('scope').boolean('self').boolean('print').boolean('svelte').alias('c', 'compile').alias('e', 'execute').alias('b', 'bare').alias('o', 'out').alias('j', 'join').alias('d', 'debug').alias('z', 'svelte').argv;
19
- runMain = require('../lib/run').runMain;
20
- compileFromSourceToJS = function (source, param$) {
21
- var cache$1, compileOption, compileOptions, cs_ast, js_ast, parseOption;
22
- if (null == param$)
23
- param$ = {};
24
- {
25
- cache$1 = param$;
26
- parseOption = cache$1.parseOption;
27
- compileOption = cache$1.compileOption;
28
- }
29
- cs_ast = MambaScript.parse(source, null != parseOption ? parseOption : {
30
- optimise: true,
31
- raw: true,
32
- inputSource: source,
33
- sourceMap: true,
34
- literate: literate
35
- });
36
- compileOptions = {
37
- bare: true,
38
- header: true
39
- };
40
- js_ast = MambaScript.compileTypedToCS(cs_ast, null != compileOptions ? compileOptions : { bare: !!argv.bare });
41
- return MambaScript.js(js_ast, compileOptions);
42
- };
43
- run = function (fname, source, param$) {
44
- var cache$1, compileOption, compileOptions, cs_ast, js, js_ast, parseOption;
45
- if (null == param$)
46
- param$ = {};
47
- {
48
- cache$1 = param$;
49
- parseOption = cache$1.parseOption;
50
- compileOption = cache$1.compileOption;
51
- }
52
- cs_ast = MambaScript.parse(source, null != parseOption ? parseOption : {
53
- optimise: true,
54
- raw: true,
55
- inputSource: source,
56
- sourceMap: true,
57
- literate: literate
58
- });
59
- compileOptions = {
60
- bare: true,
61
- header: true
62
- };
63
- js_ast = MambaScript.compile(cs_ast, null != compileOptions ? compileOptions : { bare: !!argv.bare });
64
- js = escodegen.generate(js_ast);
65
- return runMain(source, js, js_ast, fname);
66
- };
67
- mode = function () {
68
- switch (false) {
69
- case !(argv.z || argv.svelte):
70
- return 'svelte';
71
- case !(argv.c || argv.compile):
72
- return 'compile';
73
- case !(argv.e || argv.execute):
74
- return 'execute';
75
- case !(argv._.length > 0):
76
- return 'execute';
77
- default:
78
- return 'repl';
79
- }
80
- }.call(this);
81
- moduleCode = 'var _include_,_module_;_module_=function(e){return function(t,n,r){var i,s,o,u,a,f,l;r==null&&(r=o),o=(f=typeof window!=="undefined"&&window!==null?window:global)!=null?f:e,r==null&&(r=o),i=[],l=t.split(".");for(u=0,a=l.length;u<a;u++)s=l[u],r[s]==null&&(r[s]={}),r=r[s],i.push(r);return n.apply(r,i)}}(this),_include_=function(e,t){var n,r;for(n in t)r=t[n],e[n]=r;return t}; var present=console.log;';
82
- Code = function () {
83
- Code.join = function (codes, to) {
84
- var c;
85
- c = new Code({
86
- from: function (accum$) {
87
- for (var i$ = 0, length$ = codes.length; i$ < length$; ++i$) {
88
- c = codes[i$];
89
- accum$.push(c.from);
90
- }
91
- return accum$;
92
- }.call(this, []),
93
- to: to,
94
- code: function (accum$1) {
95
- for (var i$1 = 0, length$1 = codes.length; i$1 < length$1; ++i$1) {
96
- c = codes[i$1];
97
- accum$1.push(c.code);
98
- }
99
- return accum$1;
100
- }.call(this, []).join('\n')
101
- });
102
- return c;
103
- };
104
- function Code(param$) {
105
- var cache$1;
106
- {
107
- cache$1 = param$;
108
- this.from = cache$1.from;
109
- this.to = cache$1.to;
110
- this.code = cache$1.code;
111
- }
112
- }
113
- Code.prototype.writeSync = function () {
114
- var err;
115
- err = fs.writeFileSync(this.to, this.code);
116
- if (err)
117
- throw err;
118
- return console.log('compile:', this.from, '->', this.to);
119
- };
120
- Code.prototype.write = function (callback) {
121
- if (global._root_.hasModule)
122
- this.code = moduleCode + '\n' + this.code;
123
- return fs.writeFile(this.to, this.code, function (this$) {
124
- return function (err) {
125
- if (err)
126
- throw err;
127
- console.log('compile:', this$.from, '->', this$.to);
128
- if ('function' === typeof callback)
129
- return callback();
130
- };
131
- }(this));
132
- };
133
- return Code;
134
- }();
135
- switch (mode) {
136
- case 'svelte':
137
- Preprocessor = require('../lib/preprocessor').Preprocessor;
138
- literate = argv.literate;
139
- filepaths = argv._;
140
- result = '';
141
- codes = [];
142
- for (var i$ = 0, length$ = filepaths.length; i$ < length$; ++i$) {
143
- fpath = filepaths[i$];
144
- source = fs.readFileSync(fpath).toString();
145
- try {
146
- cs_ast = MambaScript.parse(source, {
147
- optimise: false,
148
- raw: true,
149
- sourceMap: true,
150
- inputSource: source,
151
- literate: literate
152
- });
153
- } catch (e$) {
154
- e = e$;
155
- console.error('Greetings from the svelteCompile Function in the mamba executable My dude no big deal but you have an Error at', fpath);
156
- throw e;
157
- process.exit(1);
158
- }
159
- if (argv.csast) {
160
- console.log(cs_ast);
161
- return;
162
- }
163
- if (argv.cscodegen) {
164
- console.log(cscodegen.generate(cs_ast));
165
- return;
166
- }
167
- js_ast = MambaScript.compile(cs_ast, { bare: true });
168
- code = MambaScript.jsEsm(js_ast);
169
- extReplacer = function (name) {
170
- return name.replace('.typed.coffee', '.js').replace('.tcoffee', '.js').replace('.coffee', '.js').replace('.mamba', '.js');
171
- };
172
- outpath = argv.out ? (name = extReplacer(path.basename(fpath)), path.join(argv.out || '', name)) : extReplacer(path.basename(fpath));
173
- codes.push(new Code({
174
- from: fpath,
175
- to: outpath,
176
- code: code
177
- }));
178
- }
179
- if (argv.join) {
180
- outpath = path.join(argv.out || '', argv.join);
181
- joined = Code.join(codes, outpath);
182
- joined.write();
183
- } else {
184
- for (var i$1 = 0, length$1 = codes.length; i$1 < length$1; ++i$1) {
185
- code = codes[i$1];
186
- if (argv.print) {
187
- console.log(code.code);
188
- } else {
189
- code.write();
190
- }
191
- }
192
- }
193
- break;
194
- case 'compile':
195
- Preprocessor = require('../lib/preprocessor').Preprocessor;
196
- literate = argv.literate;
197
- filepaths = argv._;
198
- result = '';
199
- codes = [];
200
- for (var i$2 = 0, length$2 = filepaths.length; i$2 < length$2; ++i$2) {
201
- fpath = filepaths[i$2];
202
- source = fs.readFileSync(fpath).toString();
203
- try {
204
- cs_ast = MambaScript.parse(source, {
205
- optimise: false,
206
- raw: true,
207
- sourceMap: true,
208
- inputSource: source,
209
- literate: literate
210
- });
211
- } catch (e$1) {
212
- e = e$1;
213
- console.error('Error at', fpath);
214
- throw e;
215
- process.exit(1);
216
- }
217
- if (argv.csast) {
218
- console.log(cs_ast);
219
- return;
220
- }
221
- if (argv.cscodegen) {
222
- console.log(cscodegen.generate(cs_ast));
223
- return;
224
- }
225
- js_ast = MambaScript.compile(cs_ast, { bare: !!argv.bare });
226
- code = MambaScript.js(js_ast);
227
- extReplacer = function (name) {
228
- return name.replace('.kofu', '.js').replace('.mamba', '.js');
229
- };
230
- outpath = argv.out ? (name = extReplacer(path.basename(fpath)), path.join(argv.out || '', name)) : extReplacer(path.basename(fpath));
231
- codes.push(new Code({
232
- from: fpath,
233
- to: outpath,
234
- code: code
235
- }));
236
- }
237
- if (argv.join) {
238
- outpath = path.join(argv.out || '', argv.join);
239
- joined = Code.join(codes, outpath);
240
- joined.write();
241
- } else {
242
- for (var i$3 = 0, length$3 = codes.length; i$3 < length$3; ++i$3) {
243
- code = codes[i$3];
244
- if (argv.print) {
245
- console.log(code.code);
246
- } else {
247
- code.write();
248
- }
249
- }
250
- }
251
- break;
252
- case 'execute':
253
- fpath = null != argv.execute ? argv.execute : argv._[0];
254
- source = fs.readFileSync(fpath).toString();
255
- run(fpath, '`' + moduleCode + '`\n' + source);
256
- break;
257
- case 'repl':
258
- repl.start();
259
- }
package/msast.js DELETED
@@ -1 +0,0 @@
1
- {"body":{"statements":[{"assignee":{"data":"voltron","typeAnnotation":{"nodeType":"functionType","returnType":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}},"arguments":[null]}},"expression":{"parameters":[{"expression":{"data":"args","typeAnnotation":null}}],"body":{"statements":[{"function":{"expression":{"data":"Object","typeArguments":null,"typeAnnotation":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}}},"memberName":"assign","raw":null,"typeAnnotation":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}}},"arguments":[{"members":[],"typeArguments":null,"typeAnnotation":{"properties":[],"nodeType":"members","implicit":true,"identifier":{"typeRef":"[object]"}}},{"expression":{"data":"args","typeArguments":null}}],"raw":null,"typeAnnotation":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}}}],"typeAnnotation":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}}},"typeAnnotation":{"nodeType":"functionType","returnType":{"implicit":true,"isPrimitive":true,"nodeType":"primitiveIdentifier","identifier":{"typeRef":"Any"}},"arguments":[null]}}}]},"typeAnnotation":{"identifier":{"typeRef":"Program"}}}
@@ -1,29 +0,0 @@
1
- // Generated by MambaScript
2
- var present = console.log;
3
- // Generated by MambaScript
4
- var KofuScript, PLUGIN_NAME, PluginError, replaceExtension, through;
5
- through = require('through2');
6
- cache$ = require('gulp-util');
7
- PluginError = cache$.PluginError;
8
- replaceExtension = cache$.replaceExtension;
9
- KofuScript = require('./lib/module');
10
- PLUGIN_NAME = 'gulp-kofu';
11
- module.exports = function (opts) {
12
- return through.obj(function (file, enc, callback) {
13
- var csAst, input, js, jsAst;
14
- if (file.isNull())
15
- return callback();
16
- if (file.isStream())
17
- throw new PluginError(PLUGIN_NAME, 'Not supports Stream');
18
- if (!file.isBuffer())
19
- throw new PluginError(PLUGIN_NAME, 'Supports Buffer only');
20
- input = file.contents.toString('utf8');
21
- csAst = KofuScript.parse(input, opts.csAst);
22
- jsAst = KofuScript.compile(csAst, opts.jsAst);
23
- js = KofuScript.js(jsAst, opts.js);
24
- file.contents = Buffer.from(js, 'utf8');
25
- file.path = replaceExtension(file.path, '.js');
26
- this.push(file);
27
- return callback();
28
- });
29
- };