@makano/rew 1.1.81 → 1.2.0

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