@makano/rew 1.1.81 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +312 -239
- package/lib/rew/cli/log.js +27 -27
- package/lib/rew/cli/run.js +8 -8
- package/lib/rew/cli/utils.js +368 -199
- package/lib/rew/const/config_path.js +2 -2
- package/lib/rew/const/default.js +38 -53
- package/lib/rew/const/files.js +11 -14
- package/lib/rew/const/opt.js +6 -6
- package/lib/rew/css/theme.css +1 -1
- package/lib/rew/functions/core.js +55 -55
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -25
- package/lib/rew/functions/export.js +17 -17
- package/lib/rew/functions/fs.js +57 -59
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +106 -122
- package/lib/rew/functions/map.js +10 -10
- package/lib/rew/functions/match.js +35 -42
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -36
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +18 -18
- package/lib/rew/functions/types.js +82 -106
- package/lib/rew/html/ui.html +12 -12
- package/lib/rew/html/ui.js +196 -201
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/bin.js +37 -0
- package/lib/rew/misc/findAppInfo.js +13 -13
- package/lib/rew/misc/findAppPath.js +15 -15
- package/lib/rew/misc/req.js +7 -0
- package/lib/rew/misc/seededid.js +8 -8
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +237 -209
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +82 -92
- package/lib/rew/pkgs/data.js +10 -10
- package/lib/rew/pkgs/date.js +27 -27
- package/lib/rew/pkgs/env.js +5 -5
- package/lib/rew/pkgs/modules/data/bintree.js +51 -51
- package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
- package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
- package/lib/rew/pkgs/modules/data/queue.js +18 -18
- package/lib/rew/pkgs/modules/data/stack.js +18 -18
- package/lib/rew/pkgs/modules/threads/worker.js +36 -36
- package/lib/rew/pkgs/modules/ui/classes.js +181 -184
- package/lib/rew/pkgs/pkgs.js +9 -9
- package/lib/rew/pkgs/rune.js +373 -410
- package/lib/rew/pkgs/threads.js +62 -66
- package/lib/rew/pkgs/ui.js +148 -160
- package/lib/rew/qrew/compile.js +12 -0
- package/package.json +4 -3
@@ -1,409 +1,465 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
(function() {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
(function () {
|
3
|
+
// CoffeeScript can be used both on the server, as a command-line compiler based
|
4
|
+
// on Node.js/V8, or to run CoffeeScript directly in the browser. This module
|
5
|
+
// contains the main entry functions for tokenizing, parsing, and compiling
|
6
|
+
// source CoffeeScript into JavaScript.
|
7
|
+
var FILE_EXTENSIONS,
|
8
|
+
Lexer,
|
9
|
+
SourceMap,
|
10
|
+
base64encode,
|
11
|
+
checkShebangLine,
|
12
|
+
compile,
|
13
|
+
getSourceMap,
|
14
|
+
helpers,
|
15
|
+
lexer,
|
16
|
+
packageJson,
|
17
|
+
parser,
|
18
|
+
registerCompiled,
|
19
|
+
withPrettyErrors;
|
8
20
|
|
9
|
-
|
21
|
+
({ Lexer } = require('./lexer'));
|
10
22
|
|
11
|
-
|
23
|
+
({ parser } = require('./parser'));
|
12
24
|
|
13
|
-
|
25
|
+
helpers = require('./helpers');
|
14
26
|
|
15
|
-
|
27
|
+
SourceMap = require('./sourcemap');
|
16
28
|
|
17
|
-
|
18
|
-
|
19
|
-
|
29
|
+
// Require `package.json`, which is two levels above this file, as this file is
|
30
|
+
// evaluated from `lib/coffeescript`.
|
31
|
+
packageJson = require('../../package.json');
|
20
32
|
|
21
|
-
|
22
|
-
|
33
|
+
// The current CoffeeScript version number.
|
34
|
+
exports.VERSION = packageJson.version;
|
23
35
|
|
24
|
-
|
36
|
+
exports.FILE_EXTENSIONS = FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
25
37
|
|
26
|
-
|
27
|
-
|
38
|
+
// Expose helpers for testing.
|
39
|
+
exports.helpers = helpers;
|
28
40
|
|
29
|
-
|
41
|
+
({ getSourceMap, registerCompiled } = SourceMap);
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
43
|
+
// This is exported to enable an external module to implement caching of
|
44
|
+
// sourcemaps. This is used only when `patchStackTrace` has been called to adjust
|
45
|
+
// stack traces for files with cached source maps.
|
46
|
+
exports.registerCompiled = registerCompiled;
|
35
47
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
// Function that allows for btoa in both nodejs and the browser.
|
49
|
+
base64encode = function (src) {
|
50
|
+
switch (false) {
|
51
|
+
case typeof Buffer !== 'function':
|
52
|
+
return Buffer.from(src).toString('base64');
|
53
|
+
case typeof btoa !== 'function':
|
54
|
+
// The contents of a `<script>` block are encoded via UTF-16, so if any extended
|
55
|
+
// characters are used in the block, btoa will fail as it maxes out at UTF-8.
|
56
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
57
|
+
// for the gory details, and for the solution implemented here.
|
58
|
+
return btoa(
|
59
|
+
encodeURIComponent(src).replace(/%([0-9A-F]{2})/g, function (match, p1) {
|
60
|
+
return String.fromCharCode('0x' + p1);
|
61
|
+
}),
|
62
|
+
);
|
63
|
+
default:
|
64
|
+
throw new Error('Unable to base64 encode inline sourcemap.');
|
65
|
+
}
|
66
|
+
};
|
53
67
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
// Function wrapper to add source file information to SyntaxErrors thrown by the
|
69
|
+
// lexer/parser/compiler.
|
70
|
+
withPrettyErrors = function (fn) {
|
71
|
+
return function (code, options = {}) {
|
72
|
+
var err;
|
73
|
+
try {
|
74
|
+
return fn.call(this, code, options);
|
75
|
+
} catch (error) {
|
76
|
+
err = error;
|
77
|
+
if (typeof code !== 'string') {
|
78
|
+
// Support `CoffeeScript.nodes(tokens)`.
|
79
|
+
throw err;
|
80
|
+
}
|
81
|
+
throw helpers.updateSyntaxError(err, code, options.filename);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
};
|
70
85
|
|
71
|
-
|
86
|
+
// Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
|
72
87
|
|
73
|
-
|
74
|
-
|
75
|
-
|
88
|
+
// If `options.sourceMap` is specified, then `options.filename` must also be
|
89
|
+
// specified. All options that can be passed to `SourceMap#generate` may also
|
90
|
+
// be passed here.
|
76
91
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
92
|
+
// This returns a javascript string, unless `options.sourceMap` is passed,
|
93
|
+
// in which case this returns a `{js, v3SourceMap, sourceMap}`
|
94
|
+
// object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for
|
95
|
+
// doing programmatic lookups.
|
96
|
+
exports.compile = compile = withPrettyErrors(function (code, options = {}) {
|
97
|
+
var ast,
|
98
|
+
currentColumn,
|
99
|
+
currentLine,
|
100
|
+
encoded,
|
101
|
+
filename,
|
102
|
+
fragment,
|
103
|
+
fragments,
|
104
|
+
generateSourceMap,
|
105
|
+
header,
|
106
|
+
i,
|
107
|
+
j,
|
108
|
+
js,
|
109
|
+
len,
|
110
|
+
len1,
|
111
|
+
map,
|
112
|
+
newLines,
|
113
|
+
nodes,
|
114
|
+
range,
|
115
|
+
ref,
|
116
|
+
sourceCodeLastLine,
|
117
|
+
sourceCodeNumberOfLines,
|
118
|
+
sourceMapDataURI,
|
119
|
+
sourceURL,
|
120
|
+
token,
|
121
|
+
tokens,
|
122
|
+
transpiler,
|
123
|
+
transpilerOptions,
|
124
|
+
transpilerOutput,
|
125
|
+
v3SourceMap;
|
126
|
+
// Clone `options`, to avoid mutating the `options` object passed in.
|
127
|
+
options = Object.assign({}, options);
|
128
|
+
generateSourceMap = options.sourceMap || options.inlineMap || options.filename == null;
|
129
|
+
filename = options.filename || helpers.anonymousFileName();
|
130
|
+
checkShebangLine(filename, code);
|
131
|
+
if (generateSourceMap) {
|
132
|
+
map = new SourceMap();
|
133
|
+
}
|
134
|
+
tokens = lexer.tokenize(code, options);
|
135
|
+
// Pass a list of referenced variables, so that generated variables won’t get
|
136
|
+
// the same name.
|
137
|
+
options.referencedVars = (function () {
|
138
|
+
var i, len, results;
|
139
|
+
results = [];
|
140
|
+
for (i = 0, len = tokens.length; i < len; i++) {
|
141
|
+
token = tokens[i];
|
142
|
+
if (token[0] === 'IDENTIFIER') {
|
143
|
+
results.push(token[1]);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
return results;
|
147
|
+
})();
|
148
|
+
// Check for import or export; if found, force bare mode.
|
149
|
+
if (!(options.bare != null && options.bare === true)) {
|
150
|
+
for (i = 0, len = tokens.length; i < len; i++) {
|
151
|
+
token = tokens[i];
|
152
|
+
if ((ref = token[0]) === 'IMPORT' || ref === 'EXPORT') {
|
153
|
+
options.bare = true;
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
nodes = parser.parse(tokens);
|
159
|
+
// If all that was requested was a POJO representation of the nodes, e.g.
|
160
|
+
// the abstract syntax tree (AST), we can stop now and just return that
|
161
|
+
// (after fixing the location data for the root/`File`»`Program` node,
|
162
|
+
// which might’ve gotten misaligned from the original source due to the
|
163
|
+
// `clean` function in the lexer).
|
164
|
+
if (options.ast) {
|
165
|
+
nodes.allCommentTokens = helpers.extractAllCommentTokens(tokens);
|
166
|
+
sourceCodeNumberOfLines = (code.match(/\r?\n/g) || '').length + 1;
|
167
|
+
sourceCodeLastLine = /.*$/.exec(code)[0];
|
168
|
+
ast = nodes.ast(options);
|
169
|
+
range = [0, code.length];
|
170
|
+
ast.start = ast.program.start = range[0];
|
171
|
+
ast.end = ast.program.end = range[1];
|
172
|
+
ast.range = ast.program.range = range;
|
173
|
+
ast.loc.start = ast.program.loc.start = {
|
174
|
+
line: 1,
|
175
|
+
column: 0,
|
176
|
+
};
|
177
|
+
ast.loc.end.line = ast.program.loc.end.line = sourceCodeNumberOfLines;
|
178
|
+
ast.loc.end.column = ast.program.loc.end.column = sourceCodeLastLine.length;
|
179
|
+
ast.tokens = tokens;
|
180
|
+
return ast;
|
181
|
+
}
|
182
|
+
fragments = nodes.compileToFragments(options);
|
183
|
+
currentLine = 0;
|
184
|
+
if (options.header) {
|
185
|
+
currentLine += 1;
|
186
|
+
}
|
187
|
+
if (options.shiftLine) {
|
188
|
+
currentLine += 1;
|
189
|
+
}
|
190
|
+
currentColumn = 0;
|
191
|
+
js = '';
|
192
|
+
for (j = 0, len1 = fragments.length; j < len1; j++) {
|
193
|
+
fragment = fragments[j];
|
194
|
+
// Update the sourcemap with data from each fragment.
|
195
|
+
if (generateSourceMap) {
|
196
|
+
// Do not include empty, whitespace, or semicolon-only fragments.
|
197
|
+
if (fragment.locationData && !/^[;\s]*$/.test(fragment.code)) {
|
198
|
+
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
|
199
|
+
noReplace: true,
|
200
|
+
});
|
201
|
+
}
|
202
|
+
newLines = helpers.count(fragment.code, '\n');
|
203
|
+
currentLine += newLines;
|
204
|
+
if (newLines) {
|
205
|
+
currentColumn = fragment.code.length - (fragment.code.lastIndexOf('\n') + 1);
|
206
|
+
} else {
|
207
|
+
currentColumn += fragment.code.length;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
// Copy the code from each fragment into the final JavaScript.
|
211
|
+
js += fragment.code;
|
212
|
+
}
|
213
|
+
if (options.header) {
|
214
|
+
header = `Generated by CoffeeScript ${this.VERSION}`;
|
215
|
+
js = `// ${header}\n${js}`;
|
216
|
+
}
|
217
|
+
if (generateSourceMap) {
|
218
|
+
v3SourceMap = map.generate(options, code);
|
219
|
+
}
|
220
|
+
if (options.transpile) {
|
221
|
+
if (typeof options.transpile !== 'object') {
|
222
|
+
// This only happens if run via the Node API and `transpile` is set to
|
223
|
+
// something other than an object.
|
224
|
+
throw new Error('The transpile option must be given an object with options to pass to Babel');
|
225
|
+
}
|
226
|
+
// Get the reference to Babel that we have been passed if this compiler
|
227
|
+
// is run via the CLI or Node API.
|
228
|
+
transpiler = options.transpile.transpile;
|
229
|
+
delete options.transpile.transpile;
|
230
|
+
transpilerOptions = Object.assign({}, options.transpile);
|
231
|
+
// See https://github.com/babel/babel/issues/827#issuecomment-77573107:
|
232
|
+
// Babel can take a v3 source map object as input in `inputSourceMap`
|
233
|
+
// and it will return an *updated* v3 source map object in its output.
|
234
|
+
if (v3SourceMap && transpilerOptions.inputSourceMap == null) {
|
235
|
+
transpilerOptions.inputSourceMap = v3SourceMap;
|
236
|
+
}
|
237
|
+
transpilerOutput = transpiler(js, transpilerOptions);
|
238
|
+
js = transpilerOutput.code;
|
239
|
+
if (v3SourceMap && transpilerOutput.map) {
|
240
|
+
v3SourceMap = transpilerOutput.map;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
if (options.inlineMap) {
|
244
|
+
encoded = base64encode(JSON.stringify(v3SourceMap));
|
245
|
+
sourceMapDataURI = `//# sourceMappingURL=data:application/json;base64,${encoded}`;
|
246
|
+
sourceURL = `//# sourceURL=${filename}`;
|
247
|
+
js = `${js}\n${sourceMapDataURI}\n${sourceURL}`;
|
248
|
+
}
|
249
|
+
registerCompiled(filename, code, map);
|
250
|
+
if (options.sourceMap) {
|
251
|
+
return {
|
252
|
+
js,
|
253
|
+
sourceMap: map,
|
254
|
+
v3SourceMap: JSON.stringify(v3SourceMap, null, 2),
|
255
|
+
};
|
256
|
+
} else {
|
257
|
+
return js;
|
258
|
+
}
|
259
|
+
});
|
217
260
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
261
|
+
// Tokenize a string of CoffeeScript code, and return the array of tokens.
|
262
|
+
exports.tokens = withPrettyErrors(function (code, options) {
|
263
|
+
return lexer.tokenize(code, options);
|
264
|
+
});
|
222
265
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
266
|
+
// Parse a string of CoffeeScript code or an array of lexed tokens, and
|
267
|
+
// return the AST. You can then compile it by calling `.compile()` on the root,
|
268
|
+
// or traverse it by using `.traverseChildren()` with a callback.
|
269
|
+
exports.nodes = withPrettyErrors(function (source, options) {
|
270
|
+
if (typeof source === 'string') {
|
271
|
+
source = lexer.tokenize(source, options);
|
272
|
+
}
|
273
|
+
return parser.parse(source);
|
274
|
+
});
|
232
275
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
276
|
+
// This file used to export these methods; leave stubs that throw warnings
|
277
|
+
// instead. These methods have been moved into `index.coffee` to provide
|
278
|
+
// separate entrypoints for Node and non-Node environments, so that static
|
279
|
+
// analysis tools don’t choke on Node packages when compiling for a non-Node
|
280
|
+
// environment.
|
281
|
+
exports.run =
|
282
|
+
exports.eval =
|
283
|
+
exports.register =
|
284
|
+
function () {
|
285
|
+
throw new Error('require index.coffee, not this file');
|
286
|
+
};
|
241
287
|
|
242
|
-
|
243
|
-
|
288
|
+
// Instantiate a Lexer for our use here.
|
289
|
+
lexer = new Lexer();
|
244
290
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
291
|
+
// The real Lexer produces a generic stream of tokens. This object provides a
|
292
|
+
// thin wrapper around it, compatible with the Jison API. We can then pass it
|
293
|
+
// directly as a “Jison lexer.”
|
294
|
+
parser.lexer = {
|
295
|
+
yylloc: {
|
296
|
+
range: [],
|
297
|
+
},
|
298
|
+
options: {
|
299
|
+
ranges: true,
|
300
|
+
},
|
301
|
+
lex: function () {
|
302
|
+
var tag, token;
|
303
|
+
token = parser.tokens[this.pos++];
|
304
|
+
if (token) {
|
305
|
+
[tag, this.yytext, this.yylloc] = token;
|
306
|
+
parser.errorToken = token.origin || token;
|
307
|
+
this.yylineno = this.yylloc.first_line;
|
308
|
+
} else {
|
309
|
+
tag = '';
|
310
|
+
}
|
311
|
+
return tag;
|
312
|
+
},
|
313
|
+
setInput: function (tokens) {
|
314
|
+
parser.tokens = tokens;
|
315
|
+
return (this.pos = 0);
|
316
|
+
},
|
317
|
+
upcomingInput: function () {
|
318
|
+
return '';
|
319
|
+
},
|
320
|
+
};
|
275
321
|
|
276
|
-
|
277
|
-
|
322
|
+
// Make all the AST nodes visible to the parser.
|
323
|
+
parser.yy = require('./nodes');
|
278
324
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
325
|
+
// Override Jison's default error handling function.
|
326
|
+
parser.yy.parseError = function (message, { token }) {
|
327
|
+
var errorLoc, errorTag, errorText, errorToken, tokens;
|
328
|
+
// Disregard Jison's message, it contains redundant line number information.
|
329
|
+
// Disregard the token, we take its value directly from the lexer in case
|
330
|
+
// the error is caused by a generated token which might refer to its origin.
|
331
|
+
({ errorToken, tokens } = parser);
|
332
|
+
[errorTag, errorText, errorLoc] = errorToken;
|
333
|
+
errorText = (function () {
|
334
|
+
switch (false) {
|
335
|
+
case errorToken !== tokens[tokens.length - 1]:
|
336
|
+
return 'end of input';
|
337
|
+
case errorTag !== 'INDENT' && errorTag !== 'OUTDENT':
|
338
|
+
return 'indentation';
|
339
|
+
case errorTag !== 'IDENTIFIER' &&
|
340
|
+
errorTag !== 'NUMBER' &&
|
341
|
+
errorTag !== 'INFINITY' &&
|
342
|
+
errorTag !== 'STRING' &&
|
343
|
+
errorTag !== 'STRING_START' &&
|
344
|
+
errorTag !== 'REGEX' &&
|
345
|
+
errorTag !== 'REGEX_START':
|
346
|
+
return errorTag.replace(/_START$/, '').toLowerCase();
|
347
|
+
default:
|
348
|
+
return helpers.nameWhitespaceCharacter(errorText);
|
349
|
+
}
|
350
|
+
})();
|
351
|
+
// The second argument has a `loc` property, which should have the location
|
352
|
+
// data for this token. Unfortunately, Jison seems to send an outdated `loc`
|
353
|
+
// (from the previous token), so we take the location information directly
|
354
|
+
// from the lexer.
|
355
|
+
return helpers.throwSyntaxError(`unexpected ${errorText}`, errorLoc);
|
356
|
+
};
|
305
357
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
358
|
+
exports.patchStackTrace = function () {
|
359
|
+
var formatSourcePosition, getSourceMapping;
|
360
|
+
// Based on http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js
|
361
|
+
// Modified to handle sourceMap
|
362
|
+
formatSourcePosition = function (frame, getSourceMapping) {
|
363
|
+
var as, column, fileLocation, filename, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
|
364
|
+
filename = void 0;
|
365
|
+
fileLocation = '';
|
366
|
+
if (frame.isNative()) {
|
367
|
+
fileLocation = 'native';
|
368
|
+
} else {
|
369
|
+
if (frame.isEval()) {
|
370
|
+
filename = frame.getScriptNameOrSourceURL();
|
371
|
+
if (!filename) {
|
372
|
+
fileLocation = `${frame.getEvalOrigin()}, `;
|
373
|
+
}
|
374
|
+
} else {
|
375
|
+
filename = frame.getFileName();
|
376
|
+
}
|
377
|
+
filename || (filename = '<anonymous>');
|
378
|
+
line = frame.getLineNumber();
|
379
|
+
column = frame.getColumnNumber();
|
380
|
+
// Check for a sourceMap position
|
381
|
+
source = getSourceMapping(filename, line, column);
|
382
|
+
fileLocation = source ? `${filename}:${source[0]}:${source[1]}` : `${filename}:${line}:${column}`;
|
383
|
+
}
|
384
|
+
functionName = frame.getFunctionName();
|
385
|
+
isConstructor = frame.isConstructor();
|
386
|
+
isMethodCall = !(frame.isToplevel() || isConstructor);
|
387
|
+
if (isMethodCall) {
|
388
|
+
methodName = frame.getMethodName();
|
389
|
+
typeName = frame.getTypeName();
|
390
|
+
if (functionName) {
|
391
|
+
tp = as = '';
|
392
|
+
if (typeName && functionName.indexOf(typeName)) {
|
393
|
+
tp = `${typeName}.`;
|
394
|
+
}
|
395
|
+
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) {
|
396
|
+
as = ` [as ${methodName}]`;
|
397
|
+
}
|
398
|
+
return `${tp}${functionName}${as} (${fileLocation})`;
|
399
|
+
} else {
|
400
|
+
return `${typeName}.${methodName || '<anonymous>'} (${fileLocation})`;
|
401
|
+
}
|
402
|
+
} else if (isConstructor) {
|
403
|
+
return `new ${functionName || '<anonymous>'} (${fileLocation})`;
|
404
|
+
} else if (functionName) {
|
405
|
+
return `${functionName} (${fileLocation})`;
|
406
|
+
} else {
|
407
|
+
return fileLocation;
|
408
|
+
}
|
409
|
+
};
|
410
|
+
getSourceMapping = function (filename, line, column) {
|
411
|
+
var answer, sourceMap;
|
412
|
+
sourceMap = getSourceMap(filename, line, column);
|
413
|
+
if (sourceMap != null) {
|
414
|
+
answer = sourceMap.sourceLocation([line - 1, column - 1]);
|
415
|
+
}
|
416
|
+
if (answer != null) {
|
417
|
+
return [answer[0] + 1, answer[1] + 1];
|
418
|
+
} else {
|
419
|
+
return null;
|
420
|
+
}
|
421
|
+
};
|
422
|
+
// Based on [michaelficarra/CoffeeScriptRedux](http://goo.gl/ZTx1p)
|
423
|
+
// NodeJS / V8 have no support for transforming positions in stack traces using
|
424
|
+
// sourceMap, so we must monkey-patch Error to display CoffeeScript source
|
425
|
+
// positions.
|
426
|
+
return (Error.prepareStackTrace = function (err, stack) {
|
427
|
+
var frame, frames;
|
428
|
+
frames = (function () {
|
429
|
+
var i, len, results;
|
430
|
+
results = [];
|
431
|
+
for (i = 0, len = stack.length; i < len; i++) {
|
432
|
+
frame = stack[i];
|
433
|
+
if (frame.getFunction() === exports.run) {
|
434
|
+
// Don’t display stack frames deeper than `CoffeeScript.run`.
|
435
|
+
break;
|
436
|
+
}
|
437
|
+
results.push(` at ${formatSourcePosition(frame, getSourceMapping)}`);
|
438
|
+
}
|
439
|
+
return results;
|
440
|
+
})();
|
441
|
+
return `${err.toString()}\n${frames.join('\n')}\n`;
|
442
|
+
});
|
443
|
+
};
|
392
444
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
445
|
+
checkShebangLine = function (file, input) {
|
446
|
+
var args, firstLine, ref, rest;
|
447
|
+
firstLine = input.split(/$/m, 1)[0];
|
448
|
+
rest = firstLine != null ? firstLine.match(/^#!\s*([^\s]+\s*)(.*)/) : void 0;
|
449
|
+
args =
|
450
|
+
rest != null
|
451
|
+
? (ref = rest[2]) != null
|
452
|
+
? ref.split(/\s/).filter(function (s) {
|
453
|
+
return s !== '';
|
454
|
+
})
|
455
|
+
: void 0
|
456
|
+
: void 0;
|
457
|
+
if ((args != null ? args.length : void 0) > 1) {
|
458
|
+
console.error(`The script to be run begins with a shebang line with more than one
|
402
459
|
argument. This script will fail on platforms such as Linux which only
|
403
460
|
allow a single argument.`);
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
461
|
+
console.error(`The shebang line was: '${firstLine}' in file '${file}'`);
|
462
|
+
return console.error(`The arguments were: ${JSON.stringify(args)}`);
|
463
|
+
}
|
464
|
+
};
|
409
465
|
}).call(this);
|