@makano/rew 1.2.55 → 1.2.57

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,513 +0,0 @@
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,
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}
410
- ${codeLine}
411
- ${marker}`;
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.
513
- }).call(this);