@makano/rew 1.2.56 → 1.2.58
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/civet/main.js +17239 -0
- package/lib/rew/cli/cli.js +3 -2
- package/lib/rew/cli/utils.js +20 -9
- package/lib/rew/const/default.js +2 -1
- package/lib/rew/const/ext.js +5 -0
- package/lib/rew/const/opt.js +7 -3
- package/lib/rew/const/usage.js +15 -0
- package/lib/rew/functions/fs.js +6 -1
- package/lib/rew/functions/import.js +12 -7
- package/lib/rew/functions/require.js +1 -1
- package/lib/rew/functions/stdout.js +4 -0
- package/lib/rew/main.js +1 -13
- package/lib/rew/modules/compiler.js +92 -28
- package/lib/rew/modules/context.js +12 -0
- package/lib/rew/modules/runtime.js +31 -13
- package/lib/rew/pkgs/serve.js +7 -4
- package/lib/rew/pkgs/web.js +5 -4
- package/package.json +5 -3
- package/runtime.d.ts +103 -62
- package/jsconfig.json +0 -13
- package/lib/coffeescript/browser.js +0 -156
- package/lib/coffeescript/cake.js +0 -134
- package/lib/coffeescript/coffeescript.js +0 -465
- package/lib/coffeescript/command.js +0 -832
- package/lib/coffeescript/grammar.js +0 -1930
- package/lib/coffeescript/helpers.js +0 -513
- package/lib/coffeescript/index.js +0 -230
- package/lib/coffeescript/lexer.js +0 -2316
- package/lib/coffeescript/nodes.js +0 -9784
- package/lib/coffeescript/optparse.js +0 -258
- package/lib/coffeescript/parser.js +0 -20384
- package/lib/coffeescript/register.js +0 -120
- package/lib/coffeescript/repl.js +0 -328
- package/lib/coffeescript/rewriter.js +0 -1448
- package/lib/coffeescript/scope.js +0 -191
- package/lib/coffeescript/sourcemap.js +0 -244
package/lib/coffeescript/cake.js
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 2.7.0
|
2
|
-
(function () {
|
3
|
-
// `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
|
4
|
-
// ([Rake](http://rake.rubyforge.org/), [Jake](https://github.com/280north/jake))
|
5
|
-
// for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
|
6
|
-
// and can call them from the command line, or invoke them from other tasks.
|
7
|
-
|
8
|
-
// Running `cake` with no arguments will print out a list of all the tasks in the
|
9
|
-
// current directory's Cakefile.
|
10
|
-
|
11
|
-
// External dependencies.
|
12
|
-
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
13
|
-
|
14
|
-
fs = require('fs');
|
15
|
-
|
16
|
-
path = require('path');
|
17
|
-
|
18
|
-
helpers = require('./helpers');
|
19
|
-
|
20
|
-
optparse = require('./optparse');
|
21
|
-
|
22
|
-
CoffeeScript = require('./');
|
23
|
-
|
24
|
-
// Register .coffee extension
|
25
|
-
CoffeeScript.register();
|
26
|
-
|
27
|
-
// Keep track of the list of defined tasks, the accepted options, and so on.
|
28
|
-
tasks = {};
|
29
|
-
|
30
|
-
options = {};
|
31
|
-
|
32
|
-
switches = [];
|
33
|
-
|
34
|
-
oparse = null;
|
35
|
-
|
36
|
-
// Mixin the top-level Cake functions for Cakefiles to use directly.
|
37
|
-
helpers.extend(global, {
|
38
|
-
// Define a Cake task with a short name, an optional sentence description,
|
39
|
-
// and the function to run as the action itself.
|
40
|
-
task: function (name, description, action) {
|
41
|
-
if (!action) {
|
42
|
-
[action, description] = [description, action];
|
43
|
-
}
|
44
|
-
return (tasks[name] = { name, description, action });
|
45
|
-
},
|
46
|
-
// Define an option that the Cakefile accepts. The parsed options hash,
|
47
|
-
// containing all of the command-line options passed, will be made available
|
48
|
-
// as the first argument to the action.
|
49
|
-
option: function (letter, flag, description) {
|
50
|
-
return switches.push([letter, flag, description]);
|
51
|
-
},
|
52
|
-
// Invoke another task in the current Cakefile.
|
53
|
-
invoke: function (name) {
|
54
|
-
if (!tasks[name]) {
|
55
|
-
missingTask(name);
|
56
|
-
}
|
57
|
-
return tasks[name].action(options);
|
58
|
-
},
|
59
|
-
});
|
60
|
-
|
61
|
-
// Run `cake`. Executes all of the tasks you pass, in order. Note that Node's
|
62
|
-
// asynchrony may cause tasks to execute in a different order than you'd expect.
|
63
|
-
// If no tasks are passed, print the help screen. Keep a reference to the
|
64
|
-
// original directory name, when running Cake tasks from subdirectories.
|
65
|
-
exports.run = function () {
|
66
|
-
var arg, args, e, i, len, ref, results;
|
67
|
-
global.__originalDirname = fs.realpathSync('.');
|
68
|
-
process.chdir(cakefileDirectory(__originalDirname));
|
69
|
-
args = process.argv.slice(2);
|
70
|
-
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
|
71
|
-
filename: 'Cakefile',
|
72
|
-
});
|
73
|
-
oparse = new optparse.OptionParser(switches);
|
74
|
-
if (!args.length) {
|
75
|
-
return printTasks();
|
76
|
-
}
|
77
|
-
try {
|
78
|
-
options = oparse.parse(args);
|
79
|
-
} catch (error) {
|
80
|
-
e = error;
|
81
|
-
return fatalError(`${e}`);
|
82
|
-
}
|
83
|
-
ref = options.arguments;
|
84
|
-
results = [];
|
85
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
86
|
-
arg = ref[i];
|
87
|
-
results.push(invoke(arg));
|
88
|
-
}
|
89
|
-
return results;
|
90
|
-
};
|
91
|
-
|
92
|
-
// Display the list of Cake tasks in a format similar to `rake -T`
|
93
|
-
printTasks = function () {
|
94
|
-
var cakefilePath, desc, name, relative, spaces, task;
|
95
|
-
relative = path.relative || path.resolve;
|
96
|
-
cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
|
97
|
-
console.log(`${cakefilePath} defines the following tasks:\n`);
|
98
|
-
for (name in tasks) {
|
99
|
-
task = tasks[name];
|
100
|
-
spaces = 20 - name.length;
|
101
|
-
spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
|
102
|
-
desc = task.description ? `# ${task.description}` : '';
|
103
|
-
console.log(`cake ${name}${spaces} ${desc}`);
|
104
|
-
}
|
105
|
-
if (switches.length) {
|
106
|
-
return console.log(oparse.help());
|
107
|
-
}
|
108
|
-
};
|
109
|
-
|
110
|
-
// Print an error and exit when attempting to use an invalid task/option.
|
111
|
-
fatalError = function (message) {
|
112
|
-
console.error(message + '\n');
|
113
|
-
console.log('To see a list of all tasks/options, run "cake"');
|
114
|
-
return process.exit(1);
|
115
|
-
};
|
116
|
-
|
117
|
-
missingTask = function (task) {
|
118
|
-
return fatalError(`No such task: ${task}`);
|
119
|
-
};
|
120
|
-
|
121
|
-
// When `cake` is invoked, search in the current and all parent directories
|
122
|
-
// to find the relevant Cakefile.
|
123
|
-
cakefileDirectory = function (dir) {
|
124
|
-
var parent;
|
125
|
-
if (fs.existsSync(path.join(dir, 'Cakefile'))) {
|
126
|
-
return dir;
|
127
|
-
}
|
128
|
-
parent = path.normalize(path.join(dir, '..'));
|
129
|
-
if (parent !== dir) {
|
130
|
-
return cakefileDirectory(parent);
|
131
|
-
}
|
132
|
-
throw new Error(`Cakefile not found in ${process.cwd()}`);
|
133
|
-
};
|
134
|
-
}).call(this);
|
@@ -1,465 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 2.7.0
|
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;
|
20
|
-
|
21
|
-
({ Lexer } = require('./lexer'));
|
22
|
-
|
23
|
-
({ parser } = require('./parser'));
|
24
|
-
|
25
|
-
helpers = require('./helpers');
|
26
|
-
|
27
|
-
SourceMap = require('./sourcemap');
|
28
|
-
|
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');
|
32
|
-
|
33
|
-
// The current CoffeeScript version number.
|
34
|
-
exports.VERSION = packageJson.version;
|
35
|
-
|
36
|
-
exports.FILE_EXTENSIONS = FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
37
|
-
|
38
|
-
// Expose helpers for testing.
|
39
|
-
exports.helpers = helpers;
|
40
|
-
|
41
|
-
({ getSourceMap, registerCompiled } = SourceMap);
|
42
|
-
|
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;
|
47
|
-
|
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
|
-
};
|
67
|
-
|
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
|
-
};
|
85
|
-
|
86
|
-
// Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
|
87
|
-
|
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.
|
91
|
-
|
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
|
-
});
|
260
|
-
|
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
|
-
});
|
265
|
-
|
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
|
-
});
|
275
|
-
|
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
|
-
};
|
287
|
-
|
288
|
-
// Instantiate a Lexer for our use here.
|
289
|
-
lexer = new Lexer();
|
290
|
-
|
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
|
-
};
|
321
|
-
|
322
|
-
// Make all the AST nodes visible to the parser.
|
323
|
-
parser.yy = require('./nodes');
|
324
|
-
|
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
|
-
};
|
357
|
-
|
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
|
-
};
|
444
|
-
|
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
|
459
|
-
argument. This script will fail on platforms such as Linux which only
|
460
|
-
allow a single argument.`);
|
461
|
-
console.error(`The shebang line was: '${firstLine}' in file '${file}'`);
|
462
|
-
return console.error(`The arguments were: ${JSON.stringify(args)}`);
|
463
|
-
}
|
464
|
-
};
|
465
|
-
}).call(this);
|