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/cli.js
CHANGED
|
@@ -1,121 +1,178 @@
|
|
|
1
|
-
// Generated by MambaScript 0.
|
|
2
|
-
var
|
|
3
|
-
// Generated by MambaScript 0.5.2
|
|
4
|
-
var $0, $0, additionalArgs, concat, escodegen, esmangle, foldl, fs, humanReadable, input, input, inputName, inputSource, inspect, knownOpts, MambaScript, mscodegen, nopt, numberLines, optAliases, Optimiser, option, options, output, parameter, path, pkg, positionalArgs, Preprocessor, processInput, Repl, runMain;
|
|
1
|
+
// Generated by MambaScript 2.0.0
|
|
2
|
+
var additionalArgs, BANNER, cache$, count, e, fs, humanReadable, input, inputName, inputSource, inspect, MambaScript, numberLines, Optimiser, OptionParser, options, output, parser, path, positionalArgs, Preprocessor, processInput, Repl, runMain, SWITCHES, typeCheckMode;
|
|
5
3
|
fs = require('fs');
|
|
6
4
|
path = require('path');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
humanReadable = cache$1.humanReadable;
|
|
13
|
-
Preprocessor = require('./preprocessor').Preprocessor;
|
|
14
|
-
Optimiser = require('./optimiser').Optimiser;
|
|
15
|
-
runMain = require('./run').runMain;
|
|
5
|
+
inspect = require('util').inspect;
|
|
6
|
+
OptionParser = require('./optparse').OptionParser;
|
|
7
|
+
cache$ = require('./helpers');
|
|
8
|
+
numberLines = cache$.numberLines;
|
|
9
|
+
humanReadable = cache$.humanReadable;
|
|
16
10
|
MambaScript = require('./module');
|
|
11
|
+
Preprocessor = MambaScript.Preprocessor;
|
|
12
|
+
Optimiser = MambaScript.Optimiser;
|
|
17
13
|
Repl = require('./repl');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
14
|
+
runMain = require('./run').runMain;
|
|
15
|
+
SWITCHES = [
|
|
16
|
+
[
|
|
17
|
+
'-b',
|
|
18
|
+
'--bare',
|
|
19
|
+
'omit the top-level function wrapper'
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
'-c',
|
|
23
|
+
'--compile',
|
|
24
|
+
'output the compiled JS AST (JSON)'
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
'-e',
|
|
28
|
+
'--eval',
|
|
29
|
+
'evaluate compiled JavaScript'
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
'-f',
|
|
33
|
+
'--mscodegen',
|
|
34
|
+
'output mscodegen-generated MambaScript code'
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
'-i',
|
|
38
|
+
'--input [FILE]',
|
|
39
|
+
'file to be used as input instead of STDIN'
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'-I',
|
|
43
|
+
'--require [FILE]',
|
|
44
|
+
'require a library before a script is executed'
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
'-j',
|
|
48
|
+
'--js',
|
|
49
|
+
'generate JavaScript output'
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
'-l',
|
|
53
|
+
'--literate',
|
|
54
|
+
'treat the input as literate MambaScript code'
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
'-o',
|
|
58
|
+
'--output [FILE]',
|
|
59
|
+
'file to be used as output instead of STDOUT'
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
'-p',
|
|
63
|
+
'--parse',
|
|
64
|
+
'output a JSON-serialised AST representation of the input'
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
'-v',
|
|
68
|
+
'--version',
|
|
69
|
+
'display the version number'
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
'--cli [INPUT]',
|
|
73
|
+
'pass a string from the command line as input'
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
'--debug',
|
|
77
|
+
'output intermediate representations on stderr for debug'
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
'--help',
|
|
81
|
+
'display this help message'
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
'--optimise',
|
|
85
|
+
'enable optimisations (default: on; --no-optimise to disable)'
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
'--raw',
|
|
89
|
+
'preserve source position and raw parse information'
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
'--repl',
|
|
93
|
+
'run an interactive MambaScript REPL'
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'--source-map',
|
|
97
|
+
'generate source map'
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
'--source-map-file [FILE]',
|
|
101
|
+
'file used as output for source map when using --js'
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
'--typecheck',
|
|
105
|
+
'type check the input (default: on, warnings only; --no-typecheck to disable)'
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
'--strict',
|
|
109
|
+
'fail compilation on type errors'
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'--parser [NAME]',
|
|
113
|
+
'parser to use: fast (hand-written) or peg (the previous PEG.js parser)'
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
'--tokens',
|
|
117
|
+
'output the token stream of the input (fast parser) and exit'
|
|
118
|
+
]
|
|
119
|
+
];
|
|
120
|
+
BANNER = 'Usage: mambascript [OPTIONS] [-- ARGS]\n\n mambascript -j -i input.mamba -o output.js compile a file\n mambascript --js < input.mamba compile stdin to stdout\n mambascript script.mamba arg0 arg1 run a script (implies --eval)\n mambascript start the REPL';
|
|
121
|
+
parser = new OptionParser(SWITCHES, BANNER);
|
|
122
|
+
try {
|
|
123
|
+
options = parser.parse(process.argv.slice(2));
|
|
124
|
+
} catch (e$) {
|
|
125
|
+
e = e$;
|
|
126
|
+
console.error('Error: ' + e.message);
|
|
127
|
+
console.error(parser.help());
|
|
128
|
+
process.exit(1);
|
|
81
129
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
options = nopt(knownOpts, optAliases, process.argv, 2);
|
|
85
|
-
positionalArgs = options.argv.remain;
|
|
86
|
-
delete options.argv;
|
|
130
|
+
positionalArgs = options['arguments'];
|
|
131
|
+
additionalArgs = [];
|
|
87
132
|
if (null != options.optimise)
|
|
88
133
|
options.optimise;
|
|
89
134
|
else
|
|
90
135
|
options.optimise = true;
|
|
136
|
+
if (null != options.typecheck)
|
|
137
|
+
options.typecheck;
|
|
138
|
+
else
|
|
139
|
+
options.typecheck = true;
|
|
91
140
|
options.sourceMap = options['source-map'];
|
|
92
141
|
options.sourceMapFile = options['source-map-file'];
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} else if (positionalArgs.length) {
|
|
142
|
+
typeCheckMode = options.typecheck === false ? 'off' : options.strict ? 'error' : 'warn';
|
|
143
|
+
if (!(options.compile || options.js || options.sourceMap || options.parse || options['eval'] || options.mscodegen || options.tokens || options.help || options.version))
|
|
144
|
+
if (positionalArgs.length) {
|
|
97
145
|
options['eval'] = true;
|
|
98
146
|
options.input = positionalArgs.shift();
|
|
99
147
|
additionalArgs = positionalArgs;
|
|
100
148
|
} else {
|
|
101
149
|
options.repl = true;
|
|
102
150
|
}
|
|
103
|
-
|
|
104
|
-
|
|
151
|
+
count = function () {
|
|
152
|
+
var o, opts;
|
|
153
|
+
opts = arguments.length > 0 ? [].slice.call(arguments, 0) : [];
|
|
154
|
+
return function (accum$) {
|
|
155
|
+
for (var i$ = 0, length$ = opts.length; i$ < length$; ++i$) {
|
|
156
|
+
o = opts[i$];
|
|
157
|
+
if (!o)
|
|
158
|
+
continue;
|
|
159
|
+
accum$.push(1);
|
|
160
|
+
}
|
|
161
|
+
return accum$;
|
|
162
|
+
}.call(this, []).length;
|
|
163
|
+
};
|
|
164
|
+
if (count(options.parse, options.compile, options.js, options.sourceMap, options['eval'], options.mscodegen, options.tokens, options.repl) > 1) {
|
|
165
|
+
console.error('Error: At most one of --parse (-p), --compile (-c), --js (-j), --source-map, --eval (-e), --mscodegen, --tokens, or --repl may be used.');
|
|
105
166
|
process.exit(1);
|
|
106
167
|
}
|
|
107
|
-
if (
|
|
108
|
-
console.error('Error: At most one of --input (-i)
|
|
168
|
+
if (count(null != options.input, null != options.cli) > 1) {
|
|
169
|
+
console.error('Error: At most one of --input (-i) or --cli may be used.');
|
|
109
170
|
process.exit(1);
|
|
110
171
|
}
|
|
111
172
|
if (null != options.require && !options['eval']) {
|
|
112
173
|
console.error('Error: --require (-I) depends on --eval (-e)');
|
|
113
174
|
process.exit(1);
|
|
114
175
|
}
|
|
115
|
-
if (options.minify && !(options.js || options['eval'])) {
|
|
116
|
-
console.error('Error: --minify does not make sense without --js or --eval');
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
176
|
if (options.bare && !(options.compile || options.js || options.sourceMap || options['eval'])) {
|
|
120
177
|
console.error('Error: --bare does not make sense without --compile, --js, --source-map, or --eval');
|
|
121
178
|
process.exit(1);
|
|
@@ -124,12 +181,12 @@ if (options.sourceMapFile && !options.js) {
|
|
|
124
181
|
console.error('Error: --source-map-file depends on --js');
|
|
125
182
|
process.exit(1);
|
|
126
183
|
}
|
|
127
|
-
if (null != options.input && fs.
|
|
128
|
-
console.error('Error:
|
|
184
|
+
if (null != options.input && !fs.existsSync(options.input)) {
|
|
185
|
+
console.error('Error: input file not found: ' + options.input);
|
|
129
186
|
process.exit(1);
|
|
130
187
|
}
|
|
131
|
-
if (options.
|
|
132
|
-
console.error('Error:
|
|
188
|
+
if (null != options.input && fs.statSync(options.input).isDirectory() && (!(null != options.output) || fs.existsSync(options.output) && fs.statSync(options.output).isFile())) {
|
|
189
|
+
console.error('Error: when --input is a directory, --output must be provided, and --output must not reference a file');
|
|
133
190
|
process.exit(1);
|
|
134
191
|
}
|
|
135
192
|
output = function (out) {
|
|
@@ -143,12 +200,10 @@ output = function (out) {
|
|
|
143
200
|
}
|
|
144
201
|
};
|
|
145
202
|
if (options.help) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
console.log('\n Usage: (OPT is interpreted by ' + $0 + ', ARG is passed to FILE)\n\n ' + $0 + ' OPT* -{p,c,j,f} OPT*\n example: ' + $0 + ' --js --no-optimise <input.mamba >output.js\n ' + $0 + ' [-e] FILE {OPT,ARG}* [-- ARG*]\n example: ' + $0 + ' myfile.mamba arg0 arg1\n ' + $0 + ' OPT* [--repl] OPT*\n example: ' + $0 + '\n\n -b, --bare omit the top-level function wrapper\n -c, --compile compile input .mamba file to js\n -z, --svelte compile input .mamba file to js svelte\n -e, --eval evaluate compiled JavaScript\n -f, --mscodegen output mscodegen-generated MambaScript code\n -i, --input FILE file to be used as input instead of STDIN\n -I, --require FILE require a library before a script is executed\n -j, --js generate JavaScript output\n -l, --literate treat the input as literate MambaScript code\n -m, --minify run compiled javascript output through a JS minifier\n -o, --output FILE file to be used as output instead of STDOUT\n -p, --parse output a JSON-serialised AST representation of the input\n -v, --version display the version number\n -w, --watch FILE watch the given file/directory for changes\n --cli INPUT pass a string from the command line as input\n --debug output intermediate representations on stderr for debug\n --help display this help message\n --nodejs OPTS pass options through to the node binary\n --optimise enable optimisations (default: on)\n --raw preserve source position and raw parse information\n --repl run an interactive TypedMambaScript REPL\n --source-map generate source map\n --source-map-file FILE file used as output for source map when using --js\n\n Unless given --input or --cli flags, `' + $0 + '` will operate on stdin/stdout.\n When none of --{parse,compile,js,source-map,eval,mscodegen,repl} are given,\n If positional arguments were given\n * --eval is implied\n * the first positional argument is used as an input filename\n * additional positional arguments are passed as arguments to the script\n Else --repl is implied\n');
|
|
203
|
+
console.log(parser.help());
|
|
204
|
+
console.log('\nUnless given --input or --cli flags, `mambascript` operates on stdin/stdout.\nWhen none of --{parse,compile,js,source-map,eval,mscodegen,repl} are given,\n If positional arguments were given\n * --eval is implied\n * the first positional argument is used as an input filename\n * additional positional arguments are passed as arguments to the script\n Else --repl is implied\n\nType checking: on by default and reports warnings; --strict turns type errors\ninto a failed compile (exit 1); --no-typecheck turns the checker off.\nEnvironment: MAMBA_TYPECHECK=off|warn|error sets the default for `require` hooks.\nParser: --parser peg selects the previous PEG.js parser; MAMBA_PARSER=peg does\nthe same for the `require` hook and jest.');
|
|
149
205
|
} else if (options.version) {
|
|
150
|
-
|
|
151
|
-
console.log('mambascript version ' + pkg.version);
|
|
206
|
+
console.log('mambascript version ' + MambaScript.VERSION);
|
|
152
207
|
} else if (options.repl) {
|
|
153
208
|
MambaScript.register();
|
|
154
209
|
process.argv.shift();
|
|
@@ -158,29 +213,44 @@ if (options.help) {
|
|
|
158
213
|
inputName = null != options.input ? options.input : options.cli && 'cli' || 'stdin';
|
|
159
214
|
inputSource = null != options.input ? fs.realpathSync(options.input) : options.cli && '(cli)' || '(stdin)';
|
|
160
215
|
processInput = function (err) {
|
|
161
|
-
var cache$
|
|
216
|
+
var cache$1, js, jsAST, preprocessed, result, sourceMap, sourceMappingUrl;
|
|
162
217
|
if (null != err)
|
|
163
218
|
throw err;
|
|
164
219
|
result = null;
|
|
165
220
|
input = input.toString();
|
|
166
221
|
if (65279 === input.charCodeAt(0))
|
|
167
222
|
input = input.slice(1);
|
|
223
|
+
if (options.tokens) {
|
|
224
|
+
process.stdout.write(require('./lexer').dumpTokens(input) + '\n');
|
|
225
|
+
process.exit(0);
|
|
226
|
+
}
|
|
168
227
|
if (options.debug)
|
|
169
228
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
229
|
+
if ((null != options.parser ? options.parser : null != process.env.MAMBA_PARSER ? process.env.MAMBA_PARSER : MambaScript.defaultParser) === 'peg') {
|
|
230
|
+
console.error('### PREPROCESSED CS ###');
|
|
231
|
+
preprocessed = Preprocessor.process(input, { literate: options.literate });
|
|
232
|
+
console.error(numberLines(humanReadable(preprocessed)));
|
|
233
|
+
} else {
|
|
234
|
+
console.error('### TOKENS ###');
|
|
235
|
+
console.error(require('./lexer').dumpTokens(input));
|
|
236
|
+
}
|
|
237
|
+
} catch (e$1) {
|
|
174
238
|
}
|
|
175
239
|
try {
|
|
176
240
|
result = MambaScript.parse(input, {
|
|
177
241
|
optimise: false,
|
|
178
242
|
raw: options.raw || options.sourceMap || options.sourceMapFile || options['eval'],
|
|
179
243
|
inputSource: inputSource,
|
|
180
|
-
|
|
244
|
+
filename: inputName,
|
|
245
|
+
literate: options.literate,
|
|
246
|
+
typeCheck: typeCheckMode,
|
|
247
|
+
parser: options.parser,
|
|
248
|
+
warn: function (msg) {
|
|
249
|
+
return console.error(msg);
|
|
250
|
+
}
|
|
181
251
|
});
|
|
182
|
-
} catch (e$
|
|
183
|
-
e = e$
|
|
252
|
+
} catch (e$2) {
|
|
253
|
+
e = e$2;
|
|
184
254
|
console.error(e.message);
|
|
185
255
|
process.exit(1);
|
|
186
256
|
}
|
|
@@ -192,7 +262,7 @@ if (options.help) {
|
|
|
192
262
|
result = Optimiser.optimise(result);
|
|
193
263
|
if (options.parse)
|
|
194
264
|
if (null != result) {
|
|
195
|
-
output(inspect(result.toBasicObject()));
|
|
265
|
+
output(inspect(result.toBasicObject(), false, null));
|
|
196
266
|
return;
|
|
197
267
|
} else {
|
|
198
268
|
process.exit(1);
|
|
@@ -203,9 +273,9 @@ if (options.help) {
|
|
|
203
273
|
}
|
|
204
274
|
if (options.mscodegen) {
|
|
205
275
|
try {
|
|
206
|
-
result =
|
|
207
|
-
} catch (e$
|
|
208
|
-
e = e$
|
|
276
|
+
result = MambaScript.compileTypedToCS(result);
|
|
277
|
+
} catch (e$3) {
|
|
278
|
+
e = e$3;
|
|
209
279
|
console.error(e.stack || e.message);
|
|
210
280
|
process.exit(1);
|
|
211
281
|
}
|
|
@@ -216,10 +286,19 @@ if (options.help) {
|
|
|
216
286
|
process.exit(1);
|
|
217
287
|
}
|
|
218
288
|
}
|
|
219
|
-
|
|
289
|
+
try {
|
|
290
|
+
jsAST = MambaScript.compile(result, {
|
|
291
|
+
bare: options.bare,
|
|
292
|
+
stdlibPath: options['eval'] ? MambaScript.stdlibPath : void 0
|
|
293
|
+
});
|
|
294
|
+
} catch (e$4) {
|
|
295
|
+
e = e$4;
|
|
296
|
+
console.error(e.stack || e.message);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
220
299
|
if (options.compile)
|
|
221
300
|
if (null != jsAST) {
|
|
222
|
-
output(inspect(jsAST));
|
|
301
|
+
output(inspect(jsAST, false, null));
|
|
223
302
|
return;
|
|
224
303
|
} else {
|
|
225
304
|
process.exit(1);
|
|
@@ -228,19 +307,11 @@ if (options.help) {
|
|
|
228
307
|
console.error('### COMPILED JS-AST ###');
|
|
229
308
|
console.error(inspect(jsAST));
|
|
230
309
|
}
|
|
231
|
-
if (options.minify)
|
|
232
|
-
try {
|
|
233
|
-
jsAST = esmangle.mangle(esmangle.optimize(jsAST), { destructive: true });
|
|
234
|
-
} catch (e$6) {
|
|
235
|
-
e = e$6;
|
|
236
|
-
console.error(e.stack || e.message);
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
310
|
if (options.sourceMap) {
|
|
240
311
|
try {
|
|
241
|
-
sourceMap = MambaScript.sourceMap(jsAST, inputName
|
|
242
|
-
} catch (e$
|
|
243
|
-
e = e$
|
|
312
|
+
sourceMap = MambaScript.sourceMap(jsAST, inputName);
|
|
313
|
+
} catch (e$5) {
|
|
314
|
+
e = e$5;
|
|
244
315
|
console.error(e.stack || e.message);
|
|
245
316
|
process.exit(1);
|
|
246
317
|
}
|
|
@@ -252,12 +323,12 @@ if (options.help) {
|
|
|
252
323
|
}
|
|
253
324
|
}
|
|
254
325
|
try {
|
|
255
|
-
cache$
|
|
256
|
-
js = cache$
|
|
257
|
-
sourceMap = cache$
|
|
258
|
-
cache$
|
|
259
|
-
} catch (e$
|
|
260
|
-
e = e$
|
|
326
|
+
cache$1 = MambaScript.jsWithSourceMap(jsAST, inputName);
|
|
327
|
+
js = cache$1.code;
|
|
328
|
+
sourceMap = cache$1.map;
|
|
329
|
+
cache$1;
|
|
330
|
+
} catch (e$6) {
|
|
331
|
+
e = e$6;
|
|
261
332
|
console.error(e.stack || e.message);
|
|
262
333
|
process.exit(1);
|
|
263
334
|
}
|
|
@@ -272,6 +343,8 @@ if (options.help) {
|
|
|
272
343
|
}
|
|
273
344
|
if (options['eval']) {
|
|
274
345
|
MambaScript.register();
|
|
346
|
+
if (null != options.require)
|
|
347
|
+
require(options.require[0] === '.' ? path.resolve(options.require) : options.require);
|
|
275
348
|
process.argv = [
|
|
276
349
|
process.argv[1],
|
|
277
350
|
options.input
|
|
@@ -293,8 +366,6 @@ if (options.help) {
|
|
|
293
366
|
return processInput();
|
|
294
367
|
});
|
|
295
368
|
});
|
|
296
|
-
} else if (null != options.watch) {
|
|
297
|
-
options.watch;
|
|
298
369
|
} else if (null != options.cli) {
|
|
299
370
|
input = options.cli;
|
|
300
371
|
processInput();
|
|
@@ -306,4 +377,4 @@ if (options.help) {
|
|
|
306
377
|
process.stdin.setEncoding('utf8');
|
|
307
378
|
process.stdin.resume();
|
|
308
379
|
}
|
|
309
|
-
}
|
|
380
|
+
}
|