@makano/rew 1.1.7 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/bin/ui +0 -0
- package/build.sh +3 -1
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +245 -186
- package/lib/rew/cli/log.js +31 -32
- package/lib/rew/cli/run.js +10 -12
- package/lib/rew/cli/utils.js +248 -175
- package/lib/rew/const/config_path.js +4 -0
- package/lib/rew/const/default.js +38 -35
- package/lib/rew/const/files.js +9 -9
- package/lib/rew/const/opt.js +8 -8
- package/lib/rew/css/theme.css +2 -2
- package/lib/rew/functions/core.js +55 -57
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -21
- package/lib/rew/functions/export.js +18 -20
- package/lib/rew/functions/fs.js +55 -54
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +104 -93
- package/lib/rew/functions/map.js +13 -16
- package/lib/rew/functions/match.js +35 -26
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -33
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +20 -20
- package/lib/rew/functions/types.js +96 -95
- package/lib/rew/html/ui.html +12 -13
- package/lib/rew/html/ui.js +205 -168
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/findAppInfo.js +16 -0
- package/lib/rew/misc/findAppPath.js +21 -0
- package/lib/rew/misc/seededid.js +13 -0
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +228 -177
- package/lib/rew/modules/context.js +35 -22
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +82 -75
- package/lib/rew/pkgs/data.js +12 -7
- package/lib/rew/pkgs/date.js +27 -28
- package/lib/rew/pkgs/env.js +6 -8
- package/lib/rew/pkgs/modules/data/bintree.js +52 -52
- package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
- package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
- package/lib/rew/pkgs/modules/data/queue.js +19 -20
- package/lib/rew/pkgs/modules/data/stack.js +19 -19
- package/lib/rew/pkgs/modules/threads/worker.js +36 -26
- package/lib/rew/pkgs/modules/ui/classes.js +182 -178
- package/lib/rew/pkgs/pkgs.js +9 -10
- package/lib/rew/pkgs/rune.js +422 -0
- package/lib/rew/pkgs/threads.js +57 -53
- package/lib/rew/pkgs/ui.js +148 -136
- package/meson.build +13 -0
- package/package.json +9 -2
@@ -1,477 +1,513 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
(function() {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
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
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
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);
|