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/bin/mamba
CHANGED
|
@@ -1,259 +1,2 @@
|
|
|
1
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, mscodegen, 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
|
-
mscodegen = require('mambacodegen');
|
|
14
|
-
escodegen = require('escodegen');
|
|
15
|
-
repl = require('../lib/repl');
|
|
16
|
-
reporter = require('../lib/reporter');
|
|
17
|
-
debug = require('../lib/helpers').debug;
|
|
18
|
-
argv = require('kofu-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.mscodegen) {
|
|
164
|
-
console.log(mscodegen.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.mscodegen) {
|
|
222
|
-
console.log(mscodegen.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
|
-
}
|
|
2
|
+
require('../lib/mamba');
|
package/decision.js
CHANGED
|
@@ -1,246 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var present = console.log;
|
|
3
|
-
// Generated by MambaScript 0.3.5
|
|
4
|
-
void function () {
|
|
5
|
-
var elements, merge_elements, tagName;
|
|
6
|
-
elements = {
|
|
7
|
-
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',
|
|
8
|
-
'void': 'area base br col command embed hr img input keygen link meta param\n source track wbr',
|
|
9
|
-
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',
|
|
10
|
-
obsolete_void: 'basefont frame'
|
|
11
|
-
};
|
|
12
|
-
merge_elements = function () {
|
|
13
|
-
var a, args, element, result;
|
|
14
|
-
args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
|
|
15
|
-
result = [];
|
|
16
|
-
for (var i$ = 0, length$ = args.length; i$ < length$; ++i$) {
|
|
17
|
-
a = args[i$];
|
|
18
|
-
for (var cache$ = elements[a].split(' '), i$1 = 0, length$1 = cache$.length; i$1 < length$1; ++i$1) {
|
|
19
|
-
element = cache$[i$1];
|
|
20
|
-
if (!in$(element, result))
|
|
21
|
-
result.push(element);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Decision = function () {
|
|
27
|
-
function Decision(Pragma) {
|
|
28
|
-
this.stack = null;
|
|
29
|
-
this.Pragma = Pragma;
|
|
30
|
-
}
|
|
31
|
-
Decision.prototype.resetStack = function (stack) {
|
|
32
|
-
var previous;
|
|
33
|
-
if (null == stack)
|
|
34
|
-
stack = null;
|
|
35
|
-
previous = this.stack;
|
|
36
|
-
this.stack = stack;
|
|
37
|
-
return previous;
|
|
38
|
-
};
|
|
39
|
-
Decision.prototype.isSelector = function (string) {
|
|
40
|
-
return string.length > 1 && in$(string.charAt(0), [
|
|
41
|
-
'#',
|
|
42
|
-
'.'
|
|
43
|
-
]);
|
|
44
|
-
};
|
|
45
|
-
Decision.prototype.parseSelector = function (selector) {
|
|
46
|
-
var cache$1, classes, id, klass, token;
|
|
47
|
-
id = null;
|
|
48
|
-
classes = [];
|
|
49
|
-
for (var cache$ = selector.split('.'), i$ = 0, length$ = cache$.length; i$ < length$; ++i$) {
|
|
50
|
-
token = cache$[i$];
|
|
51
|
-
token = token.trim();
|
|
52
|
-
if (id) {
|
|
53
|
-
classes.push(token);
|
|
54
|
-
} else {
|
|
55
|
-
cache$1 = token.split('#');
|
|
56
|
-
klass = cache$1[0];
|
|
57
|
-
id = cache$1[1];
|
|
58
|
-
if (!(klass === ''))
|
|
59
|
-
classes.push(token);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
id: id,
|
|
64
|
-
classes: classes
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
Decision.prototype.normalizeArgs = function (args) {
|
|
68
|
-
var arg, attrs, cache$, classes, contents, dataAttrs, id, index, k, parsedSelector, selector, v;
|
|
69
|
-
attrs = {};
|
|
70
|
-
selector = null;
|
|
71
|
-
contents = null;
|
|
72
|
-
for (var i$ = 0, length$ = args.length; i$ < length$; ++i$) {
|
|
73
|
-
arg = args[i$];
|
|
74
|
-
index = i$;
|
|
75
|
-
if (!('undefined' !== typeof arg && null != arg))
|
|
76
|
-
continue;
|
|
77
|
-
switch (typeof arg) {
|
|
78
|
-
case 'string':
|
|
79
|
-
if (index === 0 && this.isSelector(arg)) {
|
|
80
|
-
selector = arg;
|
|
81
|
-
parsedSelector = this.parseSelector(arg);
|
|
82
|
-
} else {
|
|
83
|
-
contents = arg;
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
case 'function':
|
|
87
|
-
case 'number':
|
|
88
|
-
case 'boolean':
|
|
89
|
-
contents = arg;
|
|
90
|
-
break;
|
|
91
|
-
case 'object':
|
|
92
|
-
if (arg.constructor === Object && !this.Pragma.isValidElement(arg)) {
|
|
93
|
-
attrs = Object.keys(arg).reduce(function (clone, key) {
|
|
94
|
-
clone[key] = arg[key];
|
|
95
|
-
return clone;
|
|
96
|
-
}, {});
|
|
97
|
-
} else {
|
|
98
|
-
contents = arg;
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
contents = arg;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (null != parsedSelector) {
|
|
106
|
-
cache$ = parsedSelector;
|
|
107
|
-
id = cache$.id;
|
|
108
|
-
classes = cache$.classes;
|
|
109
|
-
if (null != id)
|
|
110
|
-
attrs.id = id;
|
|
111
|
-
if (null != classes ? classes.length : void 0) {
|
|
112
|
-
if (attrs.className)
|
|
113
|
-
classes.push(attrs.className);
|
|
114
|
-
attrs.className = classes.join(' ');
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
dataAttrs = attrs.data;
|
|
118
|
-
if (typeof dataAttrs === 'object') {
|
|
119
|
-
delete attrs.data;
|
|
120
|
-
for (k in dataAttrs) {
|
|
121
|
-
v = dataAttrs[k];
|
|
122
|
-
attrs['data-' + k] = v;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
attrs: attrs,
|
|
127
|
-
contents: contents,
|
|
128
|
-
selector: selector
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
Decision.prototype.$ = function (tagName) {
|
|
132
|
-
var args, attrs, cache$, children, contents, el, previous;
|
|
133
|
-
args = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
|
|
134
|
-
if (!(null != tagName))
|
|
135
|
-
throw new Error('Element type is invalid big dog:\nCheck this out I expected a string from you or a class/function because thats how I know its a component\nbut instead I got: ' + tagName + ' lets figure this out together? Is ' + tagname + ' as string or class/function\nIf you are certain it is, if its a string then its not one of the built in tags i.e div or section, so it wont work,\nif its a class or function did you forget to require it? Or maybe did you forget export it from the file you came from?\nDid you save the file? Just a few suggestions to get the wheels turning. This error shall pass');
|
|
136
|
-
cache$ = this.normalizeArgs(args);
|
|
137
|
-
attrs = cache$.attrs;
|
|
138
|
-
contents = cache$.contents;
|
|
139
|
-
switch (typeof contents) {
|
|
140
|
-
case 'function':
|
|
141
|
-
previous = this.resetStack([]);
|
|
142
|
-
contents();
|
|
143
|
-
children = this.resetStack(previous);
|
|
144
|
-
break;
|
|
145
|
-
default:
|
|
146
|
-
children = contents;
|
|
147
|
-
}
|
|
148
|
-
if (null != children ? children.splice : void 0) {
|
|
149
|
-
el = this.Pragma.createElement.apply(this.Pragma, [
|
|
150
|
-
tagName,
|
|
151
|
-
attrs
|
|
152
|
-
].concat([].slice.call(children)));
|
|
153
|
-
} else {
|
|
154
|
-
el = this.Pragma.createElement(tagName, attrs, children);
|
|
155
|
-
}
|
|
156
|
-
if (null != this.stack)
|
|
157
|
-
this.stack.push(el);
|
|
158
|
-
return el;
|
|
159
|
-
};
|
|
160
|
-
Decision.prototype.pureComponent = function (contents) {
|
|
161
|
-
var decision;
|
|
162
|
-
decision = this;
|
|
163
|
-
return function () {
|
|
164
|
-
var children, previous;
|
|
165
|
-
previous = decision.resetStack(null);
|
|
166
|
-
children = contents.apply(decision, arguments);
|
|
167
|
-
decision.resetStack(previous);
|
|
168
|
-
return children;
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
Decision.prototype.selfClosingTag = function (tagName) {
|
|
172
|
-
var args, attrs, cache$, contents;
|
|
173
|
-
args = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
|
|
174
|
-
cache$ = this.normalizeArgs(args);
|
|
175
|
-
attrs = cache$.attrs;
|
|
176
|
-
contents = cache$.contents;
|
|
177
|
-
if (contents)
|
|
178
|
-
throw new Error('Decision.Mamba: <' + tagName + '/> must not have content big dog because its a self closing tag.\nIt looks like you tried to nest ' + contents + " no big deal though everyone has errors,\nif this isn't even what you meant to do look around at your surrounding items and see where you have a curly brace,\ncomma, semicolon, or indent in the wrong spot. You got this, this error shall fade away.");
|
|
179
|
-
return this.$(tagName, attrs);
|
|
180
|
-
};
|
|
181
|
-
Decision.prototype.text = function (s) {
|
|
182
|
-
if (!(null != s ? s.toString : void 0))
|
|
183
|
-
return s;
|
|
184
|
-
if (null != this.stack)
|
|
185
|
-
this.stack.push(s.toString());
|
|
186
|
-
return s.toString();
|
|
187
|
-
};
|
|
188
|
-
Decision.prototype.use = function (plugin) {
|
|
189
|
-
return plugin(this);
|
|
190
|
-
};
|
|
191
|
-
Decision.prototype.tags = function () {
|
|
192
|
-
var bound, boundMethodNames, method;
|
|
193
|
-
bound = {};
|
|
194
|
-
boundMethodNames = [].concat('ie normalizeArgs script $ pureComponent text use'.split(' '), merge_elements('regular', 'obsolete', 'void', 'obsolete_void'));
|
|
195
|
-
for (var i$ = 0, length$ = boundMethodNames.length; i$ < length$; ++i$) {
|
|
196
|
-
method = boundMethodNames[i$];
|
|
197
|
-
(function (this$) {
|
|
198
|
-
return function (method) {
|
|
199
|
-
return bound[method] = function (this$1) {
|
|
200
|
-
return function () {
|
|
201
|
-
var args;
|
|
202
|
-
args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
|
|
203
|
-
return this$1[method].apply(this$1, args);
|
|
204
|
-
};
|
|
205
|
-
}(this$);
|
|
206
|
-
};
|
|
207
|
-
}(this)(method));
|
|
208
|
-
}
|
|
209
|
-
bound.$.text = bound.text;
|
|
210
|
-
return bound;
|
|
211
|
-
};
|
|
212
|
-
return Decision;
|
|
213
|
-
}();
|
|
214
|
-
for (var cache$ = merge_elements('regular', 'obsolete'), i$ = 0, length$ = cache$.length; i$ < length$; ++i$) {
|
|
215
|
-
tagName = cache$[i$];
|
|
216
|
-
(function (tagName) {
|
|
217
|
-
return Decision.prototype[tagName] = function () {
|
|
218
|
-
var args;
|
|
219
|
-
args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
|
|
220
|
-
return this.$.apply(this, [tagName].concat([].slice.call(args)));
|
|
221
|
-
};
|
|
222
|
-
}(tagName));
|
|
223
|
-
}
|
|
224
|
-
for (var cache$1 = merge_elements('void', 'obsolete_void'), i$1 = 0, length$1 = cache$1.length; i$1 < length$1; ++i$1) {
|
|
225
|
-
tagName = cache$1[i$1];
|
|
226
|
-
(function (tagName) {
|
|
227
|
-
return Decision.prototype[tagName] = function () {
|
|
228
|
-
var args;
|
|
229
|
-
args = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
|
|
230
|
-
return this.selfClosingTag.apply(this, [tagName].concat([].slice.call(args)));
|
|
231
|
-
};
|
|
232
|
-
}(tagName));
|
|
233
|
-
}
|
|
234
|
-
if ('undefined' !== typeof module && null != module ? module.exports : void 0) {
|
|
235
|
-
module.exports = function (Pragma) {
|
|
236
|
-
return new Decision(Pragma).tags();
|
|
237
|
-
};
|
|
238
|
-
module.exports.Decision = Decision;
|
|
239
|
-
}
|
|
240
|
-
function in$(member, list) {
|
|
241
|
-
for (var i = 0, length = list.length; i < length; ++i)
|
|
242
|
-
if (i in list && list[i] === member)
|
|
243
|
-
return true;
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}.call(this);
|
|
1
|
+
module.exports = require('./lib/decision');
|
package/docs/coverage.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Coverage matrix
|
|
2
|
+
|
|
3
|
+
One row per language feature: where it is documented (a heading of `docs/reference.md`), which spec
|
|
4
|
+
files prove it (both parsers), and the example program. `node scripts/coverage-matrix.js` (part of
|
|
5
|
+
`npm run build`) fails when a row names a missing heading, spec or example, when a `tdd/lang` suite
|
|
6
|
+
is in no row, or when a reference heading is in no row: a feature cannot land without its test and its
|
|
7
|
+
page. The Course / Book / YDKJS column names the corpora under `tdd/course`, `tdd/book`, `tdd/ydkjs`
|
|
8
|
+
that exercise the feature; the site (mambascript.org) extends this table with its pages and sessions.
|
|
9
|
+
|
|
10
|
+
Tiers: **Basics** (super readable, learn first), **Hard Parts** (what a sentence has to slow down
|
|
11
|
+
for), **Fancy** (powerful, harder to read: comment it), **Reference** (tooling and tables).
|
|
12
|
+
|
|
13
|
+
| Feature | Tier | Reference | Specs | Example | Course / Book / YDKJS |
|
|
14
|
+
|---|---|---|---|---|---|
|
|
15
|
+
| Program shape: indentation, lines, chains, `;` | Basics | Indentation and lines | tdd/lang/indentation.spec.mamba, tdd/parser/lexer.spec.mamba | examples/basics.mamba | book 02-BasicCoffeeScript |
|
|
16
|
+
| Comments, backtick JavaScript, macros | Fancy | Comments, embedded JavaScript and macros | tdd/lang/comments-embedded-js-macros.spec.mamba | examples/basics.mamba | book 02-BasicCoffeeScript |
|
|
17
|
+
| `blueprint` | Basics | `blueprint` → `class` | tdd/lang/classes.spec.mamba, tdd/classes/test.spec.mamba | examples/classes.mamba | course javascript-classes-this, algorithms-trees-bst; book 08-ObjectOrientation; ydkjs this-objects |
|
|
18
|
+
| `inheritsFrom`, `super` | Basics | `inheritsFrom` → `extends`, `super` | tdd/lang/classes.spec.mamba | examples/classes.mamba | course javascript-classes-this; book 08-ObjectOrientation |
|
|
19
|
+
| `make` | Basics | `make` → `new` | tdd/lang/classes.spec.mamba, tdd/lang/operators.spec.mamba | examples/classes.mamba | course javascript-classes-this |
|
|
20
|
+
| `@` and `this` | Hard Parts | `@` → `this` | tdd/lang/classes.spec.mamba, tdd/lang/scope.spec.mamba, tdd/lang/functions.spec.mamba | examples/classes.mamba | ydkjs this-objects; course javascript-classes-this |
|
|
21
|
+
| `struct`, `implements` | Basics | `implements`, `struct` | tdd/lang/types.spec.mamba, tdd/typecheck/test.spec.mamba | examples/struct.mamba | |
|
|
22
|
+
| `module` namespaces | Fancy | `module` → namespace | tdd/legacy/module.spec.mamba | examples/ks.mamba | |
|
|
23
|
+
| `forEvery … in` | Basics | `forEvery … in` → `for` over an array | tdd/lang/comprehensions-ranges-slices.spec.mamba, tdd/lang/control-flow.spec.mamba | examples/basics.mamba | course javascript-arrays, algorithms-arrays; book 02-BasicCoffeeScript |
|
|
24
|
+
| `forEvery … of`, `own` | Basics | `forEvery … of` → `for … in` over keys | tdd/lang/comprehensions-ranges-slices.spec.mamba | examples/basics.mamba | course javascript-objects-destructuring |
|
|
25
|
+
| `by` steps, descending ranges | Basics | `by` → step | tdd/lang/comprehensions-ranges-slices.spec.mamba, tdd/legacy/comprehensions.spec.mamba | examples/basics.mamba | course javascript-arrays, algorithms-sorting, algorithms-dynamic-programming |
|
|
26
|
+
| `when` loop filter | Basics | `when` as a loop filter | tdd/lang/comprehensions-ranges-slices.spec.mamba | examples/basics.mamba | |
|
|
27
|
+
| `while`, `until`, `loop` | Basics | `until` → `while (!…)`, `loop` → `while (true)` | tdd/lang/control-flow.spec.mamba | examples/basics.mamba | course algorithms-linked-lists, algorithms-two-pointers |
|
|
28
|
+
| `keepGoing`, `bail` | Basics | `keepGoing` → `continue`, `bail` → `break` | tdd/lang/control-flow.spec.mamba | examples/basics.mamba | course javascript-arrays |
|
|
29
|
+
| Labeled loops | Fancy | Labeled loops | tdd/lang/labeled-loops.spec.mamba, tdd/lang/control-flow.spec.mamba | examples/labeled-loops.mamba | course algorithms-matrices, algorithms-graphs, algorithms-backtracking |
|
|
30
|
+
| `do` | Fancy | `do` → call immediately | tdd/lang/functions.spec.mamba, tdd/lang/scope.spec.mamba | examples/function.mamba | ydkjs scope-closures |
|
|
31
|
+
| Comprehensions | Fancy | Comprehensions | tdd/lang/comprehensions-ranges-slices.spec.mamba | examples/basics.mamba | course javascript-arrays; book 06-FunctionalProgramming |
|
|
32
|
+
| `if` / `then` / `otherwise`, postfix forms | Basics | `if` / `then` / `otherwise` (`else`) | tdd/lang/control-flow.spec.mamba | examples/keywords.mamba | book 02-BasicCoffeeScript |
|
|
33
|
+
| `unless` | Basics | `unless` → `if (!…)` | tdd/lang/control-flow.spec.mamba | examples/keywords.mamba | |
|
|
34
|
+
| `consider` / `when` / `otherwise` | Basics | `consider` → `switch`, `when` → `case`, `otherwise` → `default` | tdd/lang/control-flow.spec.mamba | examples/keywords.mamba | |
|
|
35
|
+
| Operators and word aliases, chained comparisons, `in`/`of`/`has` | Basics | Operators | tdd/lang/operators.spec.mamba, tdd/parser/tables.spec.mamba | examples/keywords.mamba | ydkjs types-grammar; course javascript-equality-coercion-gotchas |
|
|
36
|
+
| Values: `yes`/`no`/`on`/`off`, `nothing`/`missing` | Basics | Values | tdd/lang/numbers-and-booleans.spec.mamba, tdd/booleans/test.spec.mamba | examples/keywords.mamba | ydkjs types-grammar |
|
|
37
|
+
| Numbers, BigInt, separators | Basics | Numbers | tdd/lang/numbers.spec.mamba, tdd/lang/numbers-and-booleans.spec.mamba | examples/numbers.mamba | course javascript-numbers-math |
|
|
38
|
+
| Strings, heredocs, regexes, ranges, slices | Basics | Strings, ranges and regular expressions | tdd/lang/strings.spec.mamba, tdd/lang/comprehensions-ranges-slices.spec.mamba, tdd/legacy/regexps.spec.mamba | examples/basics.mamba | course javascript-strings, javascript-regex, algorithms-strings; book 09-RegularExpressions |
|
|
39
|
+
| Destructuring defaults | Basics | Destructuring defaults | tdd/lang/destructuring-defaults.spec.mamba, tdd/lang/assignment.spec.mamba | examples/destructuring-defaults.mamba | course javascript-objects-destructuring; ydkjs es6-beyond |
|
|
40
|
+
| Object rest and spread | Basics | Object rest and spread | tdd/lang/object-rest-spread.spec.mamba, tdd/lang/assignment.spec.mamba, tdd/lang/objects-and-arrays.spec.mamba | examples/object-rest-spread.mamba | course javascript-objects-destructuring |
|
|
41
|
+
| Tagged templates | Fancy | Tagged templates | tdd/lang/tagged-templates.spec.mamba | examples/tagged-templates.mamba | ydkjs es6-beyond |
|
|
42
|
+
| Computed keys | Fancy | Computed keys | tdd/lang/computed-keys.spec.mamba, tdd/lang/objects-and-arrays.spec.mamba | examples/basics.mamba | course algorithms-hash-maps, algorithms-tries |
|
|
43
|
+
| Assignment and destructuring | Basics | Values | tdd/lang/assignment.spec.mamba, tdd/assignments/test.spec.mamba | examples/basics.mamba | course javascript-objects-destructuring |
|
|
44
|
+
| Objects and arrays | Basics | Values | tdd/lang/objects-and-arrays.spec.mamba, tdd/arrays/test.spec.mamba | examples/basics.mamba | course javascript-arrays, javascript-map-set, algorithms-stacks-queues, algorithms-heaps |
|
|
45
|
+
| Functions: literals, implicit calls, splats, defaults, `=>` | Basics | Program structure | tdd/lang/functions.spec.mamba, tdd/legacy/functions.spec.mamba | examples/function.mamba | book 03-Functions; ydkjs scope-closures; course javascript-closures-scope-hoisting |
|
|
46
|
+
| Scope and closures | Hard Parts | Program structure | tdd/lang/scope.spec.mamba, tdd/legacy/scope.spec.mamba | examples/function.mamba | ydkjs scope-closures; course javascript-closures-scope-hoisting |
|
|
47
|
+
| `x?`, `exists` | Basics | `x?`, `x exists` | tdd/lang/existence-and-soaks.spec.mamba | examples/existential.mamba | |
|
|
48
|
+
| `a ? b`, `orElse` | Basics | `a ? b`, `a orElse b` → existential default | tdd/lang/existence-and-soaks.spec.mamba, tdd/lang/operators.spec.mamba | examples/existential.mamba | |
|
|
49
|
+
| Soaks `?.` `?[]` `?()` | Fancy | `a?.b`, `a?[i]`, `a?()` → soak | tdd/lang/existence-and-soaks.spec.mamba | examples/existential.mamba | |
|
|
50
|
+
| `?=` | Basics | `a ?= b` → assign when null | tdd/lang/existence-and-soaks.spec.mamba, tdd/lang/assignment.spec.mamba | examples/existential.mamba | |
|
|
51
|
+
| Generators, `yield`, `for … from` | Hard Parts | Generators | tdd/lang/generators.spec.mamba | examples/generators.mamba | course javascript-errors-generators-misc; ydkjs async |
|
|
52
|
+
| `waitForIt` | Basics | `waitForIt` → `await` | tdd/lang/async.spec.mamba, tdd/waitForIt/test.spec.mamba | examples/async.mamba | course javascript-async-promises; ydkjs async |
|
|
53
|
+
| `waitForAll` | Basics | `waitForAll` → `await Promise.all` | tdd/lang/async.spec.mamba | examples/async.mamba | course javascript-async-promises |
|
|
54
|
+
| `attempt` / `onFail` / `regardless` | Basics | `attempt` / `onFail` / `regardless` → `try` / `catch` / `finally` | tdd/lang/exceptions.spec.mamba | examples/errors.mamba | book 05-ErrorHandling; course javascript-errors-generators-misc |
|
|
55
|
+
| `panic` | Basics | `panic` → `throw` | tdd/lang/exceptions.spec.mamba | examples/errors.mamba | book 05-ErrorHandling; course javascript-errors-generators-misc |
|
|
56
|
+
| `present`, `complain` | Basics | `present` → `console.log`, `complain` → `console.warn` | tdd/keywords/test.spec.mamba, tdd/lang/cli.spec.mamba | examples/basics.mamba | book 01-Introduction |
|
|
57
|
+
| Error messages and codes | Reference | Error messages | tdd/lang/error-messages.spec.mamba, tdd/errors/errors.spec.mamba | examples/basics.mamba | |
|
|
58
|
+
| Modules: `grab`, `share`, ESM and CommonJS, `import()` | Basics | Modules | tdd/lang/modules.spec.mamba | examples/modules.mamba | book 10-Modularity; ydkjs es6-beyond |
|
|
59
|
+
| Type annotations, structs, generics | Hard Parts | Grammar | tdd/lang/types.spec.mamba, tdd/typecheck/test.spec.mamba, tdd/legacy/type-checker.spec.mamba | examples/generics.mamba | |
|
|
60
|
+
| Type-check modes | Reference | Modes | tdd/lang/types.spec.mamba, tdd/lang/cli.spec.mamba | examples/nullable.mamba | |
|
|
61
|
+
| Standard library `_` | Reference | Standard library | tdd/stdlib/test.spec.mamba | examples/stdlib.mamba | |
|
|
62
|
+
| MambaView | Reference | MambaView | tdd/mambaview/test.spec.mamba | examples/mambaview.mamba | |
|
|
63
|
+
| Decision | Reference | Decision | tdd/decision/test.spec.mamba | examples/decision.mamba | |
|
|
64
|
+
| Compiler API | Reference | API | tdd/compiler/regressions.spec.mamba, tdd/parser/parse.spec.mamba | examples/basics.mamba | |
|
|
65
|
+
| Two parsers, parity | Reference | Parsers | tdd/parser/parity.spec.mamba, tdd/parser/positions.spec.mamba | examples/basics.mamba | |
|
|
66
|
+
| `mamba` command | Reference | `mamba` | tdd/lang/cli.spec.mamba | examples/basics.mamba | |
|
|
67
|
+
| `mambascript` command | Reference | `mambascript` | tdd/lang/cli.spec.mamba | examples/basics.mamba | |
|
|
68
|
+
| Environment variables | Reference | Environment variables | tdd/lang/cli.spec.mamba, tdd/lang/types.spec.mamba | examples/basics.mamba | |
|
|
69
|
+
| Reserved words | Reference | Reserved words | tdd/parser/tables.spec.mamba, tdd/lang/assignment.spec.mamba | examples/keywords.mamba | |
|
|
70
|
+
| Golden JavaScript baselines | Reference | Program structure | tdd/golden/golden.spec.mamba | examples/basics.mamba | |
|