@makano/rew 1.1.73 → 1.2.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.
Files changed (73) 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 +288 -186
  18. package/lib/rew/cli/log.js +31 -32
  19. package/lib/rew/cli/run.js +10 -12
  20. package/lib/rew/cli/utils.js +344 -176
  21. package/lib/rew/const/config_path.js +4 -0
  22. package/lib/rew/const/default.js +38 -35
  23. package/lib/rew/const/files.js +9 -9
  24. package/lib/rew/const/opt.js +8 -8
  25. package/lib/rew/css/theme.css +2 -2
  26. package/lib/rew/functions/core.js +55 -57
  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 -21
  30. package/lib/rew/functions/export.js +18 -20
  31. package/lib/rew/functions/fs.js +55 -54
  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 +107 -93
  35. package/lib/rew/functions/map.js +13 -16
  36. package/lib/rew/functions/match.js +35 -26
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -33
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +20 -20
  41. package/lib/rew/functions/types.js +96 -95
  42. package/lib/rew/html/ui.html +12 -13
  43. package/lib/rew/html/ui.js +205 -168
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +16 -0
  47. package/lib/rew/misc/findAppPath.js +21 -0
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +13 -0
  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 -177
  53. package/lib/rew/modules/context.js +35 -22
  54. package/lib/rew/modules/fs.js +10 -10
  55. package/lib/rew/modules/runtime.js +17 -21
  56. package/lib/rew/modules/yaml.js +27 -30
  57. package/lib/rew/pkgs/conf.js +82 -75
  58. package/lib/rew/pkgs/data.js +12 -7
  59. package/lib/rew/pkgs/date.js +27 -28
  60. package/lib/rew/pkgs/env.js +6 -8
  61. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  62. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  63. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  64. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  65. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  66. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  67. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  68. package/lib/rew/pkgs/pkgs.js +9 -10
  69. package/lib/rew/pkgs/rune.js +400 -0
  70. package/lib/rew/pkgs/threads.js +57 -53
  71. package/lib/rew/pkgs/ui.js +148 -136
  72. package/lib/rew/qrew/compile.js +12 -0
  73. package/package.json +11 -4
@@ -1,477 +1,513 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- (function() {
3
- // This file contains the common helper functions that we'd like to share among
4
- // the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
5
- // arrays, count characters, that sort of thing.
6
-
7
- // Peek at the beginning of a given string to see if it matches a sequence.
8
- var UNICODE_CODE_POINT_ESCAPE, attachCommentsToNode, buildLocationData, buildLocationHash, buildTokenDataDictionary, extend, flatten, isBoolean, isNumber, isString, ref, repeat, syntaxErrorToString, unicodeCodePointToUnicodeEscapes,
9
- indexOf = [].indexOf;
10
-
11
- exports.starts = function(string, literal, start) {
12
- return literal === string.substr(start, literal.length);
13
- };
14
-
15
- // Peek at the end of a given string to see if it matches a sequence.
16
- exports.ends = function(string, literal, back) {
17
- var len;
18
- len = literal.length;
19
- return literal === string.substr(string.length - len - (back || 0), len);
20
- };
21
-
22
- // Repeat a string `n` times.
23
- exports.repeat = repeat = function(str, n) {
24
- var res;
25
- // Use clever algorithm to have O(log(n)) string concatenation operations.
26
- res = '';
27
- while (n > 0) {
28
- if (n & 1) {
29
- res += str;
30
- }
31
- n >>>= 1;
32
- str += str;
33
- }
34
- return res;
35
- };
36
-
37
- // Trim out all falsy values from an array.
38
- exports.compact = function(array) {
39
- var i, item, len1, results;
40
- results = [];
41
- for (i = 0, len1 = array.length; i < len1; i++) {
42
- item = array[i];
43
- if (item) {
44
- results.push(item);
45
- }
46
- }
47
- return results;
48
- };
49
-
50
- // Count the number of occurrences of a string in a string.
51
- exports.count = function(string, substr) {
52
- var num, pos;
53
- num = pos = 0;
54
- if (!substr.length) {
55
- return 1 / 0;
56
- }
57
- while (pos = 1 + string.indexOf(substr, pos)) {
58
- num++;
59
- }
60
- return num;
61
- };
62
-
63
- // Merge objects, returning a fresh copy with attributes from both sides.
64
- // Used every time `Base#compile` is called, to allow properties in the
65
- // options hash to propagate down the tree without polluting other branches.
66
- exports.merge = function(options, overrides) {
67
- return extend(extend({}, options), overrides);
68
- };
69
-
70
- // Extend a source object with the properties of another object (shallow copy).
71
- extend = exports.extend = function(object, properties) {
72
- var key, val;
73
- for (key in properties) {
74
- val = properties[key];
75
- object[key] = val;
76
- }
77
- return object;
78
- };
79
-
80
- // Return a flattened version of an array.
81
- // Handy for getting a list of `children` from the nodes.
82
- exports.flatten = flatten = function(array) {
83
- return array.flat(2e308);
84
- };
85
-
86
- // Delete a key from an object, returning the value. Useful when a node is
87
- // looking for a particular method in an options hash.
88
- exports.del = function(obj, key) {
89
- var val;
90
- val = obj[key];
91
- delete obj[key];
92
- return val;
93
- };
94
-
95
- // Typical Array::some
96
- exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
97
- var e, i, len1, ref1;
98
- ref1 = this;
99
- for (i = 0, len1 = ref1.length; i < len1; i++) {
100
- e = ref1[i];
101
- if (fn(e)) {
102
- return true;
103
- }
104
- }
105
- return false;
106
- };
107
-
108
- // Helper function for extracting code from Literate CoffeeScript by stripping
109
- // out all non-code blocks, producing a string of CoffeeScript code that can
110
- // be compiled “normally.”
111
- exports.invertLiterate = function(code) {
112
- var blankLine, i, indented, insideComment, len1, line, listItemStart, out, ref1;
113
- out = [];
114
- blankLine = /^\s*$/;
115
- indented = /^[\t ]/;
116
- listItemStart = /^(?:\t?| {0,3})(?:[\*\-\+]|[0-9]{1,9}\.)[ \t]/; // Up to one tab, or up to three spaces, or neither;
117
- // followed by `*`, `-` or `+`;
118
- // or by an integer up to 9 digits long, followed by a period;
119
- // followed by a space or a tab.
120
- insideComment = false;
121
- ref1 = code.split('\n');
122
- for (i = 0, len1 = ref1.length; i < len1; i++) {
123
- line = ref1[i];
124
- if (blankLine.test(line)) {
125
- insideComment = false;
126
- out.push(line);
127
- } else if (insideComment || listItemStart.test(line)) {
128
- insideComment = true;
129
- out.push(`# ${line}`);
130
- } else if (!insideComment && indented.test(line)) {
131
- out.push(line);
132
- } else {
133
- insideComment = true;
134
- out.push(`# ${line}`);
135
- }
136
- }
137
- return out.join('\n');
138
- };
139
-
140
- // Merge two jison-style location data objects together.
141
- // If `last` is not provided, this will simply return `first`.
142
- buildLocationData = function(first, last) {
143
- if (!last) {
144
- return first;
145
- } else {
146
- return {
147
- first_line: first.first_line,
148
- first_column: first.first_column,
149
- last_line: last.last_line,
150
- last_column: last.last_column,
151
- last_line_exclusive: last.last_line_exclusive,
152
- last_column_exclusive: last.last_column_exclusive,
153
- range: [first.range[0], last.range[1]]
154
- };
155
- }
156
- };
157
-
158
- // Build a list of all comments attached to tokens.
159
- exports.extractAllCommentTokens = function(tokens) {
160
- var allCommentsObj, comment, commentKey, i, j, k, key, len1, len2, len3, ref1, results, sortedKeys, token;
161
- allCommentsObj = {};
162
- for (i = 0, len1 = tokens.length; i < len1; i++) {
163
- token = tokens[i];
164
- if (token.comments) {
165
- ref1 = token.comments;
166
- for (j = 0, len2 = ref1.length; j < len2; j++) {
167
- comment = ref1[j];
168
- commentKey = comment.locationData.range[0];
169
- allCommentsObj[commentKey] = comment;
170
- }
171
- }
172
- }
173
- sortedKeys = Object.keys(allCommentsObj).sort(function(a, b) {
174
- return a - b;
175
- });
176
- results = [];
177
- for (k = 0, len3 = sortedKeys.length; k < len3; k++) {
178
- key = sortedKeys[k];
179
- results.push(allCommentsObj[key]);
180
- }
181
- return results;
182
- };
183
-
184
- // Get a lookup hash for a token based on its location data.
185
- // Multiple tokens might have the same location hash, but using exclusive
186
- // location data distinguishes e.g. zero-length generated tokens from
187
- // actual source tokens.
188
- buildLocationHash = function(loc) {
189
- return `${loc.range[0]}-${loc.range[1]}`;
190
- };
191
-
192
- // Build a dictionary of extra token properties organized by tokens’ locations
193
- // used as lookup hashes.
194
- exports.buildTokenDataDictionary = buildTokenDataDictionary = function(tokens) {
195
- var base1, i, len1, token, tokenData, tokenHash;
196
- tokenData = {};
197
- for (i = 0, len1 = tokens.length; i < len1; i++) {
198
- token = tokens[i];
199
- if (!token.comments) {
200
- continue;
201
- }
202
- tokenHash = buildLocationHash(token[2]);
203
- // Multiple tokens might have the same location hash, such as the generated
204
- // `JS` tokens added at the start or end of the token stream to hold
205
- // comments that start or end a file.
206
- if (tokenData[tokenHash] == null) {
207
- tokenData[tokenHash] = {};
208
- }
209
- if (token.comments) { // `comments` is always an array.
210
- // For “overlapping” tokens, that is tokens with the same location data
211
- // and therefore matching `tokenHash`es, merge the comments from both/all
212
- // tokens together into one array, even if there are duplicate comments;
213
- // they will get sorted out later.
214
- ((base1 = tokenData[tokenHash]).comments != null ? base1.comments : base1.comments = []).push(...token.comments);
215
- }
216
- }
217
- return tokenData;
218
- };
219
-
220
- // This returns a function which takes an object as a parameter, and if that
221
- // object is an AST node, updates that object's locationData.
222
- // The object is returned either way.
223
- exports.addDataToNode = function(parserState, firstLocationData, firstValue, lastLocationData, lastValue, forceUpdateLocation = true) {
224
- return function(obj) {
225
- var locationData, objHash, ref1, ref2, ref3;
226
- // Add location data.
227
- locationData = buildLocationData((ref1 = firstValue != null ? firstValue.locationData : void 0) != null ? ref1 : firstLocationData, (ref2 = lastValue != null ? lastValue.locationData : void 0) != null ? ref2 : lastLocationData);
228
- if (((obj != null ? obj.updateLocationDataIfMissing : void 0) != null) && (firstLocationData != null)) {
229
- obj.updateLocationDataIfMissing(locationData, forceUpdateLocation);
230
- } else {
231
- obj.locationData = locationData;
232
- }
233
- // Add comments, building the dictionary of token data if it hasn’t been
234
- // built yet.
235
- if (parserState.tokenData == null) {
236
- parserState.tokenData = buildTokenDataDictionary(parserState.parser.tokens);
237
- }
238
- if (obj.locationData != null) {
239
- objHash = buildLocationHash(obj.locationData);
240
- if (((ref3 = parserState.tokenData[objHash]) != null ? ref3.comments : void 0) != null) {
241
- attachCommentsToNode(parserState.tokenData[objHash].comments, obj);
242
- }
243
- }
244
- return obj;
245
- };
246
- };
247
-
248
- exports.attachCommentsToNode = attachCommentsToNode = function(comments, node) {
249
- if ((comments == null) || comments.length === 0) {
250
- return;
251
- }
252
- if (node.comments == null) {
253
- node.comments = [];
254
- }
255
- return node.comments.push(...comments);
256
- };
257
-
258
- // Convert jison location data to a string.
259
- // `obj` can be a token, or a locationData.
260
- exports.locationDataToString = function(obj) {
261
- var locationData;
262
- if (("2" in obj) && ("first_line" in obj[2])) {
263
- locationData = obj[2];
264
- } else if ("first_line" in obj) {
265
- locationData = obj;
266
- }
267
- if (locationData) {
268
- return `${locationData.first_line + 1}:${locationData.first_column + 1}-` + `${locationData.last_line + 1}:${locationData.last_column + 1}`;
269
- } else {
270
- return "No location data";
271
- }
272
- };
273
-
274
- // Generate a unique anonymous file name so we can distinguish source map cache
275
- // entries for any number of anonymous scripts.
276
- exports.anonymousFileName = (function() {
277
- var n;
278
- n = 0;
279
- return function() {
280
- return `<anonymous-${n++}>`;
281
- };
282
- })();
283
-
284
- // A `.coffee.md` compatible version of `basename`, that returns the file sans-extension.
285
- exports.baseFileName = function(file, stripExt = false, useWinPathSep = false) {
286
- var parts, pathSep;
287
- pathSep = useWinPathSep ? /\\|\// : /\//;
288
- parts = file.split(pathSep);
289
- file = parts[parts.length - 1];
290
- if (!(stripExt && file.indexOf('.') >= 0)) {
291
- return file;
292
- }
293
- parts = file.split('.');
294
- parts.pop();
295
- if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
296
- parts.pop();
297
- }
298
- return parts.join('.');
299
- };
300
-
301
- // Determine if a filename represents a CoffeeScript file.
302
- exports.isCoffee = function(file) {
303
- return /\.((lit)?coffee|coffee\.md)$/.test(file);
304
- };
305
-
306
- // Determine if a filename represents a Literate CoffeeScript file.
307
- exports.isLiterate = function(file) {
308
- return /\.(litcoffee|coffee\.md)$/.test(file);
309
- };
310
-
311
- // Throws a SyntaxError from a given location.
312
- // The error's `toString` will return an error message following the "standard"
313
- // format `<filename>:<line>:<col>: <message>` plus the line with the error and a
314
- // marker showing where the error is.
315
- exports.throwSyntaxError = function(message, location) {
316
- var error;
317
- error = new SyntaxError(message);
318
- error.location = location;
319
- error.toString = syntaxErrorToString;
320
- // Instead of showing the compiler's stacktrace, show our custom error message
321
- // (this is useful when the error bubbles up in Node.js applications that
322
- // compile CoffeeScript for example).
323
- error.stack = error.toString();
324
- throw error;
325
- };
326
-
327
- // Update a compiler SyntaxError with source code information if it didn't have
328
- // it already.
329
- exports.updateSyntaxError = function(error, code, filename) {
330
- // Avoid screwing up the `stack` property of other errors (i.e. possible bugs).
331
- if (error.toString === syntaxErrorToString) {
332
- error.code || (error.code = code);
333
- error.filename || (error.filename = filename);
334
- error.stack = error.toString();
335
- }
336
- return error;
337
- };
338
-
339
- syntaxErrorToString = function() {
340
- var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref1, ref2, ref3, ref4, start;
341
- if (!(this.code && this.location)) {
342
- return Error.prototype.toString.call(this);
343
- }
344
- ({first_line, first_column, last_line, last_column} = this.location);
345
- if (last_line == null) {
346
- last_line = first_line;
347
- }
348
- if (last_column == null) {
349
- last_column = first_column;
350
- }
351
- if ((ref1 = this.filename) != null ? ref1.startsWith('<anonymous') : void 0) {
352
- filename = '[stdin]';
353
- } else {
354
- filename = this.filename || '[stdin]';
355
- }
356
- codeLine = this.code.split('\n')[first_line];
357
- start = first_column;
358
- // Show only the first line on multi-line errors.
359
- end = first_line === last_line ? last_column + 1 : codeLine.length;
360
- marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
361
- // Check to see if we're running on a color-enabled TTY.
362
- if (typeof process !== "undefined" && process !== null) {
363
- colorsEnabled = ((ref2 = process.stdout) != null ? ref2.isTTY : void 0) && !((ref3 = process.env) != null ? ref3.NODE_DISABLE_COLORS : void 0);
364
- }
365
- if ((ref4 = this.colorful) != null ? ref4 : colorsEnabled) {
366
- colorize = function(str) {
367
- return `\x1B[1;31m${str}\x1B[0m`;
368
- };
369
- codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
370
- marker = colorize(marker);
371
- }
372
- return `${filename}:${first_line + 1}:${first_column + 1}: error: ${this.message}
2
+ (function () {
3
+ // This file contains the common helper functions that we'd like to share among
4
+ // the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
5
+ // arrays, count characters, that sort of thing.
6
+
7
+ // Peek at the beginning of a given string to see if it matches a sequence.
8
+ var UNICODE_CODE_POINT_ESCAPE,
9
+ attachCommentsToNode,
10
+ buildLocationData,
11
+ buildLocationHash,
12
+ buildTokenDataDictionary,
13
+ extend,
14
+ flatten,
15
+ isBoolean,
16
+ isNumber,
17
+ isString,
18
+ ref,
19
+ repeat,
20
+ syntaxErrorToString,
21
+ unicodeCodePointToUnicodeEscapes,
22
+ indexOf = [].indexOf;
23
+
24
+ exports.starts = function (string, literal, start) {
25
+ return literal === string.substr(start, literal.length);
26
+ };
27
+
28
+ // Peek at the end of a given string to see if it matches a sequence.
29
+ exports.ends = function (string, literal, back) {
30
+ var len;
31
+ len = literal.length;
32
+ return literal === string.substr(string.length - len - (back || 0), len);
33
+ };
34
+
35
+ // Repeat a string `n` times.
36
+ exports.repeat = repeat = function (str, n) {
37
+ var res;
38
+ // Use clever algorithm to have O(log(n)) string concatenation operations.
39
+ res = '';
40
+ while (n > 0) {
41
+ if (n & 1) {
42
+ res += str;
43
+ }
44
+ n >>>= 1;
45
+ str += str;
46
+ }
47
+ return res;
48
+ };
49
+
50
+ // Trim out all falsy values from an array.
51
+ exports.compact = function (array) {
52
+ var i, item, len1, results;
53
+ results = [];
54
+ for (i = 0, len1 = array.length; i < len1; i++) {
55
+ item = array[i];
56
+ if (item) {
57
+ results.push(item);
58
+ }
59
+ }
60
+ return results;
61
+ };
62
+
63
+ // Count the number of occurrences of a string in a string.
64
+ exports.count = function (string, substr) {
65
+ var num, pos;
66
+ num = pos = 0;
67
+ if (!substr.length) {
68
+ return 1 / 0;
69
+ }
70
+ while ((pos = 1 + string.indexOf(substr, pos))) {
71
+ num++;
72
+ }
73
+ return num;
74
+ };
75
+
76
+ // Merge objects, returning a fresh copy with attributes from both sides.
77
+ // Used every time `Base#compile` is called, to allow properties in the
78
+ // options hash to propagate down the tree without polluting other branches.
79
+ exports.merge = function (options, overrides) {
80
+ return extend(extend({}, options), overrides);
81
+ };
82
+
83
+ // Extend a source object with the properties of another object (shallow copy).
84
+ extend = exports.extend = function (object, properties) {
85
+ var key, val;
86
+ for (key in properties) {
87
+ val = properties[key];
88
+ object[key] = val;
89
+ }
90
+ return object;
91
+ };
92
+
93
+ // Return a flattened version of an array.
94
+ // Handy for getting a list of `children` from the nodes.
95
+ exports.flatten = flatten = function (array) {
96
+ return array.flat(2e308);
97
+ };
98
+
99
+ // Delete a key from an object, returning the value. Useful when a node is
100
+ // looking for a particular method in an options hash.
101
+ exports.del = function (obj, key) {
102
+ var val;
103
+ val = obj[key];
104
+ delete obj[key];
105
+ return val;
106
+ };
107
+
108
+ // Typical Array::some
109
+ exports.some =
110
+ (ref = Array.prototype.some) != null
111
+ ? ref
112
+ : function (fn) {
113
+ var e, i, len1, ref1;
114
+ ref1 = this;
115
+ for (i = 0, len1 = ref1.length; i < len1; i++) {
116
+ e = ref1[i];
117
+ if (fn(e)) {
118
+ return true;
119
+ }
120
+ }
121
+ return false;
122
+ };
123
+
124
+ // Helper function for extracting code from Literate CoffeeScript by stripping
125
+ // out all non-code blocks, producing a string of CoffeeScript code that can
126
+ // be compiled “normally.”
127
+ exports.invertLiterate = function (code) {
128
+ var blankLine, i, indented, insideComment, len1, line, listItemStart, out, ref1;
129
+ out = [];
130
+ blankLine = /^\s*$/;
131
+ indented = /^[\t ]/;
132
+ listItemStart = /^(?:\t?| {0,3})(?:[\*\-\+]|[0-9]{1,9}\.)[ \t]/; // Up to one tab, or up to three spaces, or neither;
133
+ // followed by `*`, `-` or `+`;
134
+ // or by an integer up to 9 digits long, followed by a period;
135
+ // followed by a space or a tab.
136
+ insideComment = false;
137
+ ref1 = code.split('\n');
138
+ for (i = 0, len1 = ref1.length; i < len1; i++) {
139
+ line = ref1[i];
140
+ if (blankLine.test(line)) {
141
+ insideComment = false;
142
+ out.push(line);
143
+ } else if (insideComment || listItemStart.test(line)) {
144
+ insideComment = true;
145
+ out.push(`# ${line}`);
146
+ } else if (!insideComment && indented.test(line)) {
147
+ out.push(line);
148
+ } else {
149
+ insideComment = true;
150
+ out.push(`# ${line}`);
151
+ }
152
+ }
153
+ return out.join('\n');
154
+ };
155
+
156
+ // Merge two jison-style location data objects together.
157
+ // If `last` is not provided, this will simply return `first`.
158
+ buildLocationData = function (first, last) {
159
+ if (!last) {
160
+ return first;
161
+ } else {
162
+ return {
163
+ first_line: first.first_line,
164
+ first_column: first.first_column,
165
+ last_line: last.last_line,
166
+ last_column: last.last_column,
167
+ last_line_exclusive: last.last_line_exclusive,
168
+ last_column_exclusive: last.last_column_exclusive,
169
+ range: [first.range[0], last.range[1]],
170
+ };
171
+ }
172
+ };
173
+
174
+ // Build a list of all comments attached to tokens.
175
+ exports.extractAllCommentTokens = function (tokens) {
176
+ var allCommentsObj, comment, commentKey, i, j, k, key, len1, len2, len3, ref1, results, sortedKeys, token;
177
+ allCommentsObj = {};
178
+ for (i = 0, len1 = tokens.length; i < len1; i++) {
179
+ token = tokens[i];
180
+ if (token.comments) {
181
+ ref1 = token.comments;
182
+ for (j = 0, len2 = ref1.length; j < len2; j++) {
183
+ comment = ref1[j];
184
+ commentKey = comment.locationData.range[0];
185
+ allCommentsObj[commentKey] = comment;
186
+ }
187
+ }
188
+ }
189
+ sortedKeys = Object.keys(allCommentsObj).sort(function (a, b) {
190
+ return a - b;
191
+ });
192
+ results = [];
193
+ for (k = 0, len3 = sortedKeys.length; k < len3; k++) {
194
+ key = sortedKeys[k];
195
+ results.push(allCommentsObj[key]);
196
+ }
197
+ return results;
198
+ };
199
+
200
+ // Get a lookup hash for a token based on its location data.
201
+ // Multiple tokens might have the same location hash, but using exclusive
202
+ // location data distinguishes e.g. zero-length generated tokens from
203
+ // actual source tokens.
204
+ buildLocationHash = function (loc) {
205
+ return `${loc.range[0]}-${loc.range[1]}`;
206
+ };
207
+
208
+ // Build a dictionary of extra token properties organized by tokens’ locations
209
+ // used as lookup hashes.
210
+ exports.buildTokenDataDictionary = buildTokenDataDictionary = function (tokens) {
211
+ var base1, i, len1, token, tokenData, tokenHash;
212
+ tokenData = {};
213
+ for (i = 0, len1 = tokens.length; i < len1; i++) {
214
+ token = tokens[i];
215
+ if (!token.comments) {
216
+ continue;
217
+ }
218
+ tokenHash = buildLocationHash(token[2]);
219
+ // Multiple tokens might have the same location hash, such as the generated
220
+ // `JS` tokens added at the start or end of the token stream to hold
221
+ // comments that start or end a file.
222
+ if (tokenData[tokenHash] == null) {
223
+ tokenData[tokenHash] = {};
224
+ }
225
+ if (token.comments) {
226
+ // `comments` is always an array.
227
+ // For “overlapping” tokens, that is tokens with the same location data
228
+ // and therefore matching `tokenHash`es, merge the comments from both/all
229
+ // tokens together into one array, even if there are duplicate comments;
230
+ // they will get sorted out later.
231
+ ((base1 = tokenData[tokenHash]).comments != null ? base1.comments : (base1.comments = [])).push(...token.comments);
232
+ }
233
+ }
234
+ return tokenData;
235
+ };
236
+
237
+ // This returns a function which takes an object as a parameter, and if that
238
+ // object is an AST node, updates that object's locationData.
239
+ // The object is returned either way.
240
+ exports.addDataToNode = function (parserState, firstLocationData, firstValue, lastLocationData, lastValue, forceUpdateLocation = true) {
241
+ return function (obj) {
242
+ var locationData, objHash, ref1, ref2, ref3;
243
+ // Add location data.
244
+ locationData = buildLocationData(
245
+ (ref1 = firstValue != null ? firstValue.locationData : void 0) != null ? ref1 : firstLocationData,
246
+ (ref2 = lastValue != null ? lastValue.locationData : void 0) != null ? ref2 : lastLocationData,
247
+ );
248
+ if ((obj != null ? obj.updateLocationDataIfMissing : void 0) != null && firstLocationData != null) {
249
+ obj.updateLocationDataIfMissing(locationData, forceUpdateLocation);
250
+ } else {
251
+ obj.locationData = locationData;
252
+ }
253
+ // Add comments, building the dictionary of token data if it hasn’t been
254
+ // built yet.
255
+ if (parserState.tokenData == null) {
256
+ parserState.tokenData = buildTokenDataDictionary(parserState.parser.tokens);
257
+ }
258
+ if (obj.locationData != null) {
259
+ objHash = buildLocationHash(obj.locationData);
260
+ if (((ref3 = parserState.tokenData[objHash]) != null ? ref3.comments : void 0) != null) {
261
+ attachCommentsToNode(parserState.tokenData[objHash].comments, obj);
262
+ }
263
+ }
264
+ return obj;
265
+ };
266
+ };
267
+
268
+ exports.attachCommentsToNode = attachCommentsToNode = function (comments, node) {
269
+ if (comments == null || comments.length === 0) {
270
+ return;
271
+ }
272
+ if (node.comments == null) {
273
+ node.comments = [];
274
+ }
275
+ return node.comments.push(...comments);
276
+ };
277
+
278
+ // Convert jison location data to a string.
279
+ // `obj` can be a token, or a locationData.
280
+ exports.locationDataToString = function (obj) {
281
+ var locationData;
282
+ if ('2' in obj && 'first_line' in obj[2]) {
283
+ locationData = obj[2];
284
+ } else if ('first_line' in obj) {
285
+ locationData = obj;
286
+ }
287
+ if (locationData) {
288
+ return (
289
+ `${locationData.first_line + 1}:${locationData.first_column + 1}-` + `${locationData.last_line + 1}:${locationData.last_column + 1}`
290
+ );
291
+ } else {
292
+ return 'No location data';
293
+ }
294
+ };
295
+
296
+ // Generate a unique anonymous file name so we can distinguish source map cache
297
+ // entries for any number of anonymous scripts.
298
+ exports.anonymousFileName = (function () {
299
+ var n;
300
+ n = 0;
301
+ return function () {
302
+ return `<anonymous-${n++}>`;
303
+ };
304
+ })();
305
+
306
+ // A `.coffee.md` compatible version of `basename`, that returns the file sans-extension.
307
+ exports.baseFileName = function (file, stripExt = false, useWinPathSep = false) {
308
+ var parts, pathSep;
309
+ pathSep = useWinPathSep ? /\\|\// : /\//;
310
+ parts = file.split(pathSep);
311
+ file = parts[parts.length - 1];
312
+ if (!(stripExt && file.indexOf('.') >= 0)) {
313
+ return file;
314
+ }
315
+ parts = file.split('.');
316
+ parts.pop();
317
+ if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
318
+ parts.pop();
319
+ }
320
+ return parts.join('.');
321
+ };
322
+
323
+ // Determine if a filename represents a CoffeeScript file.
324
+ exports.isCoffee = function (file) {
325
+ return /\.((lit)?coffee|coffee\.md)$/.test(file);
326
+ };
327
+
328
+ // Determine if a filename represents a Literate CoffeeScript file.
329
+ exports.isLiterate = function (file) {
330
+ return /\.(litcoffee|coffee\.md)$/.test(file);
331
+ };
332
+
333
+ // Throws a SyntaxError from a given location.
334
+ // The error's `toString` will return an error message following the "standard"
335
+ // format `<filename>:<line>:<col>: <message>` plus the line with the error and a
336
+ // marker showing where the error is.
337
+ exports.throwSyntaxError = function (message, location) {
338
+ var error;
339
+ error = new SyntaxError(message);
340
+ error.location = location;
341
+ error.toString = syntaxErrorToString;
342
+ // Instead of showing the compiler's stacktrace, show our custom error message
343
+ // (this is useful when the error bubbles up in Node.js applications that
344
+ // compile CoffeeScript for example).
345
+ error.stack = error.toString();
346
+ throw error;
347
+ };
348
+
349
+ // Update a compiler SyntaxError with source code information if it didn't have
350
+ // it already.
351
+ exports.updateSyntaxError = function (error, code, filename) {
352
+ // Avoid screwing up the `stack` property of other errors (i.e. possible bugs).
353
+ if (error.toString === syntaxErrorToString) {
354
+ error.code || (error.code = code);
355
+ error.filename || (error.filename = filename);
356
+ error.stack = error.toString();
357
+ }
358
+ return error;
359
+ };
360
+
361
+ syntaxErrorToString = function () {
362
+ var codeLine,
363
+ colorize,
364
+ colorsEnabled,
365
+ end,
366
+ filename,
367
+ first_column,
368
+ first_line,
369
+ last_column,
370
+ last_line,
371
+ marker,
372
+ ref1,
373
+ ref2,
374
+ ref3,
375
+ ref4,
376
+ start;
377
+ if (!(this.code && this.location)) {
378
+ return Error.prototype.toString.call(this);
379
+ }
380
+ ({ first_line, first_column, last_line, last_column } = this.location);
381
+ if (last_line == null) {
382
+ last_line = first_line;
383
+ }
384
+ if (last_column == null) {
385
+ last_column = first_column;
386
+ }
387
+ if ((ref1 = this.filename) != null ? ref1.startsWith('<anonymous') : void 0) {
388
+ filename = '[stdin]';
389
+ } else {
390
+ filename = this.filename || '[stdin]';
391
+ }
392
+ codeLine = this.code.split('\n')[first_line];
393
+ start = first_column;
394
+ // Show only the first line on multi-line errors.
395
+ end = first_line === last_line ? last_column + 1 : codeLine.length;
396
+ marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
397
+ // Check to see if we're running on a color-enabled TTY.
398
+ if (typeof process !== 'undefined' && process !== null) {
399
+ colorsEnabled =
400
+ ((ref2 = process.stdout) != null ? ref2.isTTY : void 0) && !((ref3 = process.env) != null ? ref3.NODE_DISABLE_COLORS : void 0);
401
+ }
402
+ if ((ref4 = this.colorful) != null ? ref4 : colorsEnabled) {
403
+ colorize = function (str) {
404
+ return `\x1B[1;31m${str}\x1B[0m`;
405
+ };
406
+ codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
407
+ marker = colorize(marker);
408
+ }
409
+ return `${filename}:${first_line + 1}:${first_column + 1}: error: ${this.message}
373
410
  ${codeLine}
374
411
  ${marker}`;
375
- };
376
-
377
- exports.nameWhitespaceCharacter = function(string) {
378
- switch (string) {
379
- case ' ':
380
- return 'space';
381
- case '\n':
382
- return 'newline';
383
- case '\r':
384
- return 'carriage return';
385
- case '\t':
386
- return 'tab';
387
- default:
388
- return string;
389
- }
390
- };
391
-
392
- exports.parseNumber = function(string) {
393
- var base;
394
- if (string == null) {
395
- return 0/0;
396
- }
397
- base = (function() {
398
- switch (string.charAt(1)) {
399
- case 'b':
400
- return 2;
401
- case 'o':
402
- return 8;
403
- case 'x':
404
- return 16;
405
- default:
406
- return null;
407
- }
408
- })();
409
- if (base != null) {
410
- return parseInt(string.slice(2).replace(/_/g, ''), base);
411
- } else {
412
- return parseFloat(string.replace(/_/g, ''));
413
- }
414
- };
415
-
416
- exports.isFunction = function(obj) {
417
- return Object.prototype.toString.call(obj) === '[object Function]';
418
- };
419
-
420
- exports.isNumber = isNumber = function(obj) {
421
- return Object.prototype.toString.call(obj) === '[object Number]';
422
- };
423
-
424
- exports.isString = isString = function(obj) {
425
- return Object.prototype.toString.call(obj) === '[object String]';
426
- };
427
-
428
- exports.isBoolean = isBoolean = function(obj) {
429
- return obj === true || obj === false || Object.prototype.toString.call(obj) === '[object Boolean]';
430
- };
431
-
432
- exports.isPlainObject = function(obj) {
433
- return typeof obj === 'object' && !!obj && !Array.isArray(obj) && !isNumber(obj) && !isString(obj) && !isBoolean(obj);
434
- };
435
-
436
- unicodeCodePointToUnicodeEscapes = function(codePoint) {
437
- var high, low, toUnicodeEscape;
438
- toUnicodeEscape = function(val) {
439
- var str;
440
- str = val.toString(16);
441
- return `\\u${repeat('0', 4 - str.length)}${str}`;
442
- };
443
- if (codePoint < 0x10000) {
444
- return toUnicodeEscape(codePoint);
445
- }
446
- // surrogate pair
447
- high = Math.floor((codePoint - 0x10000) / 0x400) + 0xD800;
448
- low = (codePoint - 0x10000) % 0x400 + 0xDC00;
449
- return `${toUnicodeEscape(high)}${toUnicodeEscape(low)}`;
450
- };
451
-
452
- // Replace `\u{...}` with `\uxxxx[\uxxxx]` in regexes without `u` flag
453
- exports.replaceUnicodeCodePointEscapes = function(str, {flags, error, delimiter = ''} = {}) {
454
- var shouldReplace;
455
- shouldReplace = (flags != null) && indexOf.call(flags, 'u') < 0;
456
- return str.replace(UNICODE_CODE_POINT_ESCAPE, function(match, escapedBackslash, codePointHex, offset) {
457
- var codePointDecimal;
458
- if (escapedBackslash) {
459
- return escapedBackslash;
460
- }
461
- codePointDecimal = parseInt(codePointHex, 16);
462
- if (codePointDecimal > 0x10ffff) {
463
- error("unicode code point escapes greater than \\u{10ffff} are not allowed", {
464
- offset: offset + delimiter.length,
465
- length: codePointHex.length + 4
466
- });
467
- }
468
- if (!shouldReplace) {
469
- return match;
470
- }
471
- return unicodeCodePointToUnicodeEscapes(codePointDecimal);
472
- });
473
- };
474
-
475
- UNICODE_CODE_POINT_ESCAPE = /(\\\\)|\\u\{([\da-fA-F]+)\}/g; // Make sure the escape isn’t escaped.
476
-
412
+ };
413
+
414
+ exports.nameWhitespaceCharacter = function (string) {
415
+ switch (string) {
416
+ case ' ':
417
+ return 'space';
418
+ case '\n':
419
+ return 'newline';
420
+ case '\r':
421
+ return 'carriage return';
422
+ case '\t':
423
+ return 'tab';
424
+ default:
425
+ return string;
426
+ }
427
+ };
428
+
429
+ exports.parseNumber = function (string) {
430
+ var base;
431
+ if (string == null) {
432
+ return 0 / 0;
433
+ }
434
+ base = (function () {
435
+ switch (string.charAt(1)) {
436
+ case 'b':
437
+ return 2;
438
+ case 'o':
439
+ return 8;
440
+ case 'x':
441
+ return 16;
442
+ default:
443
+ return null;
444
+ }
445
+ })();
446
+ if (base != null) {
447
+ return parseInt(string.slice(2).replace(/_/g, ''), base);
448
+ } else {
449
+ return parseFloat(string.replace(/_/g, ''));
450
+ }
451
+ };
452
+
453
+ exports.isFunction = function (obj) {
454
+ return Object.prototype.toString.call(obj) === '[object Function]';
455
+ };
456
+
457
+ exports.isNumber = isNumber = function (obj) {
458
+ return Object.prototype.toString.call(obj) === '[object Number]';
459
+ };
460
+
461
+ exports.isString = isString = function (obj) {
462
+ return Object.prototype.toString.call(obj) === '[object String]';
463
+ };
464
+
465
+ exports.isBoolean = isBoolean = function (obj) {
466
+ return obj === true || obj === false || Object.prototype.toString.call(obj) === '[object Boolean]';
467
+ };
468
+
469
+ exports.isPlainObject = function (obj) {
470
+ return typeof obj === 'object' && !!obj && !Array.isArray(obj) && !isNumber(obj) && !isString(obj) && !isBoolean(obj);
471
+ };
472
+
473
+ unicodeCodePointToUnicodeEscapes = function (codePoint) {
474
+ var high, low, toUnicodeEscape;
475
+ toUnicodeEscape = function (val) {
476
+ var str;
477
+ str = val.toString(16);
478
+ return `\\u${repeat('0', 4 - str.length)}${str}`;
479
+ };
480
+ if (codePoint < 0x10000) {
481
+ return toUnicodeEscape(codePoint);
482
+ }
483
+ // surrogate pair
484
+ high = Math.floor((codePoint - 0x10000) / 0x400) + 0xd800;
485
+ low = ((codePoint - 0x10000) % 0x400) + 0xdc00;
486
+ return `${toUnicodeEscape(high)}${toUnicodeEscape(low)}`;
487
+ };
488
+
489
+ // Replace `\u{...}` with `\uxxxx[\uxxxx]` in regexes without `u` flag
490
+ exports.replaceUnicodeCodePointEscapes = function (str, { flags, error, delimiter = '' } = {}) {
491
+ var shouldReplace;
492
+ shouldReplace = flags != null && indexOf.call(flags, 'u') < 0;
493
+ return str.replace(UNICODE_CODE_POINT_ESCAPE, function (match, escapedBackslash, codePointHex, offset) {
494
+ var codePointDecimal;
495
+ if (escapedBackslash) {
496
+ return escapedBackslash;
497
+ }
498
+ codePointDecimal = parseInt(codePointHex, 16);
499
+ if (codePointDecimal > 0x10ffff) {
500
+ error('unicode code point escapes greater than \\u{10ffff} are not allowed', {
501
+ offset: offset + delimiter.length,
502
+ length: codePointHex.length + 4,
503
+ });
504
+ }
505
+ if (!shouldReplace) {
506
+ return match;
507
+ }
508
+ return unicodeCodePointToUnicodeEscapes(codePointDecimal);
509
+ });
510
+ };
511
+
512
+ UNICODE_CODE_POINT_ESCAPE = /(\\\\)|\\u\{([\da-fA-F]+)\}/g; // Make sure the escape isn’t escaped.
477
513
  }).call(this);