@makano/rew 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/rew +9 -0
- package/bin/ui +0 -0
- package/bin/webkit_app +0 -0
- package/lib/coffeescript/browser.js +151 -0
- package/lib/coffeescript/cake.js +135 -0
- package/lib/coffeescript/coffeescript.js +409 -0
- package/lib/coffeescript/command.js +750 -0
- package/lib/coffeescript/grammar.js +2496 -0
- package/lib/coffeescript/helpers.js +477 -0
- package/lib/coffeescript/index.js +217 -0
- package/lib/coffeescript/lexer.js +1943 -0
- package/lib/coffeescript/nodes.js +9204 -0
- package/lib/coffeescript/optparse.js +230 -0
- package/lib/coffeescript/parser.js +1344 -0
- package/lib/coffeescript/register.js +100 -0
- package/lib/coffeescript/repl.js +305 -0
- package/lib/coffeescript/rewriter.js +1138 -0
- package/lib/coffeescript/scope.js +187 -0
- package/lib/coffeescript/sourcemap.js +229 -0
- package/lib/rew/cli/cli.js +117 -0
- package/lib/rew/cli/log.js +40 -0
- package/lib/rew/cli/run.js +20 -0
- package/lib/rew/cli/utils.js +122 -0
- package/lib/rew/const/default.js +35 -0
- package/lib/rew/const/files.js +15 -0
- package/lib/rew/css/theme.css +3 -0
- package/lib/rew/functions/core.js +85 -0
- package/lib/rew/functions/emitter.js +57 -0
- package/lib/rew/functions/export.js +9 -0
- package/lib/rew/functions/future.js +22 -0
- package/lib/rew/functions/id.js +13 -0
- package/lib/rew/functions/import.js +57 -0
- package/lib/rew/functions/map.js +17 -0
- package/lib/rew/functions/match.js +34 -0
- package/lib/rew/functions/sleep.js +5 -0
- package/lib/rew/functions/types.js +96 -0
- package/lib/rew/html/ui.html +223 -0
- package/lib/rew/main.js +17 -0
- package/lib/rew/models/enum.js +14 -0
- package/lib/rew/models/struct.js +41 -0
- package/lib/rew/modules/compiler.js +17 -0
- package/lib/rew/modules/context.js +50 -0
- package/lib/rew/modules/fs.js +19 -0
- package/lib/rew/modules/runtime.js +24 -0
- package/lib/rew/modules/utils.js +0 -0
- package/lib/rew/modules/yaml.js +36 -0
- package/lib/rew/pkgs/conf.js +92 -0
- package/lib/rew/pkgs/data.js +8 -0
- package/lib/rew/pkgs/date.js +98 -0
- package/lib/rew/pkgs/modules/data/bintree.js +66 -0
- package/lib/rew/pkgs/modules/data/doublylinked.js +100 -0
- package/lib/rew/pkgs/modules/data/linkedList.js +88 -0
- package/lib/rew/pkgs/modules/data/queue.js +28 -0
- package/lib/rew/pkgs/modules/data/stack.js +27 -0
- package/lib/rew/pkgs/modules/ui/classes.js +171 -0
- package/lib/rew/pkgs/pkgs.js +13 -0
- package/lib/rew/pkgs/ui.js +108 -0
- package/package.json +41 -0
@@ -0,0 +1,477 @@
|
|
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}
|
373
|
+
${codeLine}
|
374
|
+
${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
|
+
|
477
|
+
}).call(this);
|
@@ -0,0 +1,217 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
(function() {
|
3
|
+
// Node.js Implementation
|
4
|
+
var CoffeeScript, ext, fs, helpers, i, len, path, ref, universalCompile, vm,
|
5
|
+
hasProp = {}.hasOwnProperty;
|
6
|
+
|
7
|
+
CoffeeScript = require('./coffeescript');
|
8
|
+
|
9
|
+
fs = require('fs');
|
10
|
+
|
11
|
+
vm = require('vm');
|
12
|
+
|
13
|
+
path = require('path');
|
14
|
+
|
15
|
+
helpers = CoffeeScript.helpers;
|
16
|
+
|
17
|
+
CoffeeScript.transpile = function(js, options) {
|
18
|
+
var babel;
|
19
|
+
try {
|
20
|
+
babel = require('@babel/core');
|
21
|
+
} catch (error) {
|
22
|
+
try {
|
23
|
+
babel = require('babel-core');
|
24
|
+
} catch (error) {
|
25
|
+
// This error is only for Node, as CLI users will see a different error
|
26
|
+
// earlier if they don’t have Babel installed.
|
27
|
+
throw new Error('To use the transpile option, you must have the \'@babel/core\' module installed');
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return babel.transform(js, options);
|
31
|
+
};
|
32
|
+
|
33
|
+
// The `compile` method shared by the CLI, Node and browser APIs.
|
34
|
+
universalCompile = CoffeeScript.compile;
|
35
|
+
|
36
|
+
// The `compile` method particular to the Node API.
|
37
|
+
CoffeeScript.compile = function(code, options) {
|
38
|
+
// Pass a reference to Babel into the compiler, so that the transpile option
|
39
|
+
// is available in the Node API. We need to do this so that tools like Webpack
|
40
|
+
// can `require('coffeescript')` and build correctly, without trying to
|
41
|
+
// require Babel.
|
42
|
+
if (options != null ? options.transpile : void 0) {
|
43
|
+
options.transpile.transpile = CoffeeScript.transpile;
|
44
|
+
}
|
45
|
+
return universalCompile.call(CoffeeScript, code, options);
|
46
|
+
};
|
47
|
+
|
48
|
+
// Compile and execute a string of CoffeeScript (on the server), correctly
|
49
|
+
// setting `__filename`, `__dirname`, and relative `require()`.
|
50
|
+
CoffeeScript.run = function(code, options = {}) {
|
51
|
+
var answer, dir, mainModule, ref;
|
52
|
+
mainModule = require.main;
|
53
|
+
// Set the filename.
|
54
|
+
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : helpers.anonymousFileName();
|
55
|
+
// Clear the module cache.
|
56
|
+
mainModule.moduleCache && (mainModule.moduleCache = {});
|
57
|
+
// Assign paths for node_modules loading
|
58
|
+
dir = options.filename != null ? path.dirname(fs.realpathSync(options.filename)) : fs.realpathSync('.');
|
59
|
+
mainModule.paths = require('module')._nodeModulePaths(dir);
|
60
|
+
// Save the options for compiling child imports.
|
61
|
+
mainModule.options = options;
|
62
|
+
options.filename = mainModule.filename;
|
63
|
+
options.inlineMap = true;
|
64
|
+
// Compile.
|
65
|
+
answer = CoffeeScript.compile(code, options);
|
66
|
+
code = (ref = answer.js) != null ? ref : answer;
|
67
|
+
return mainModule._compile(code, mainModule.filename);
|
68
|
+
};
|
69
|
+
|
70
|
+
// Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
|
71
|
+
// The CoffeeScript REPL uses this to run the input.
|
72
|
+
CoffeeScript.eval = function(code, options = {}) {
|
73
|
+
var Module, _module, _require, createContext, i, isContext, js, k, len, o, r, ref, ref1, ref2, ref3, sandbox, v;
|
74
|
+
if (!(code = code.trim())) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
createContext = (ref = vm.Script.createContext) != null ? ref : vm.createContext;
|
78
|
+
isContext = (ref1 = vm.isContext) != null ? ref1 : function(ctx) {
|
79
|
+
return options.sandbox instanceof createContext().constructor;
|
80
|
+
};
|
81
|
+
if (createContext) {
|
82
|
+
if (options.sandbox != null) {
|
83
|
+
if (isContext(options.sandbox)) {
|
84
|
+
sandbox = options.sandbox;
|
85
|
+
} else {
|
86
|
+
sandbox = createContext();
|
87
|
+
ref2 = options.sandbox;
|
88
|
+
for (k in ref2) {
|
89
|
+
if (!hasProp.call(ref2, k)) continue;
|
90
|
+
v = ref2[k];
|
91
|
+
sandbox[k] = v;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
|
95
|
+
} else {
|
96
|
+
sandbox = global;
|
97
|
+
}
|
98
|
+
sandbox.__filename = options.filename || 'eval';
|
99
|
+
sandbox.__dirname = path.dirname(sandbox.__filename);
|
100
|
+
// define module/require only if they chose not to specify their own
|
101
|
+
if (!(sandbox !== global || sandbox.module || sandbox.require)) {
|
102
|
+
Module = require('module');
|
103
|
+
sandbox.module = _module = new Module(options.modulename || 'eval');
|
104
|
+
sandbox.require = _require = function(path) {
|
105
|
+
return Module._load(path, _module, true);
|
106
|
+
};
|
107
|
+
_module.filename = sandbox.__filename;
|
108
|
+
ref3 = Object.getOwnPropertyNames(require);
|
109
|
+
for (i = 0, len = ref3.length; i < len; i++) {
|
110
|
+
r = ref3[i];
|
111
|
+
if (r !== 'paths' && r !== 'arguments' && r !== 'caller') {
|
112
|
+
_require[r] = require[r];
|
113
|
+
}
|
114
|
+
}
|
115
|
+
// use the same hack node currently uses for their own REPL
|
116
|
+
_require.paths = _module.paths = Module._nodeModulePaths(process.cwd());
|
117
|
+
_require.resolve = function(request) {
|
118
|
+
return Module._resolveFilename(request, _module);
|
119
|
+
};
|
120
|
+
}
|
121
|
+
}
|
122
|
+
o = {};
|
123
|
+
for (k in options) {
|
124
|
+
if (!hasProp.call(options, k)) continue;
|
125
|
+
v = options[k];
|
126
|
+
o[k] = v;
|
127
|
+
}
|
128
|
+
o.bare = true; // ensure return value
|
129
|
+
js = CoffeeScript.compile(code, o);
|
130
|
+
if (sandbox === global) {
|
131
|
+
return vm.runInThisContext(js);
|
132
|
+
} else {
|
133
|
+
return vm.runInContext(js, sandbox);
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
CoffeeScript.register = function() {
|
138
|
+
return require('./register');
|
139
|
+
};
|
140
|
+
|
141
|
+
// Throw error with deprecation warning when depending upon implicit `require.extensions` registration
|
142
|
+
if (require.extensions) {
|
143
|
+
ref = CoffeeScript.FILE_EXTENSIONS;
|
144
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
145
|
+
ext = ref[i];
|
146
|
+
(function(ext) {
|
147
|
+
var base;
|
148
|
+
return (base = require.extensions)[ext] != null ? base[ext] : base[ext] = function() {
|
149
|
+
throw new Error(`Use CoffeeScript.register() or require the coffeescript/register module to require ${ext} files.`);
|
150
|
+
};
|
151
|
+
})(ext);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
CoffeeScript._compileRawFileContent = function(raw, filename, options = {}) {
|
156
|
+
var answer, err, stripped;
|
157
|
+
// Strip the Unicode byte order mark, if this file begins with one.
|
158
|
+
stripped = raw.charCodeAt(0) === 0xFEFF ? raw.substring(1) : raw;
|
159
|
+
options = Object.assign({}, options, {
|
160
|
+
filename: filename,
|
161
|
+
literate: helpers.isLiterate(filename),
|
162
|
+
sourceFiles: [filename]
|
163
|
+
});
|
164
|
+
try {
|
165
|
+
answer = CoffeeScript.compile(stripped, options);
|
166
|
+
} catch (error) {
|
167
|
+
err = error;
|
168
|
+
// As the filename and code of a dynamically loaded file will be different
|
169
|
+
// from the original file compiled with CoffeeScript.run, add that
|
170
|
+
// information to error so it can be pretty-printed later.
|
171
|
+
throw helpers.updateSyntaxError(err, stripped, filename);
|
172
|
+
}
|
173
|
+
return answer;
|
174
|
+
};
|
175
|
+
|
176
|
+
CoffeeScript._compileFile = function(filename, options = {}) {
|
177
|
+
var raw;
|
178
|
+
raw = fs.readFileSync(filename, 'utf8');
|
179
|
+
return CoffeeScript._compileRawFileContent(raw, filename, options);
|
180
|
+
};
|
181
|
+
|
182
|
+
module.exports = CoffeeScript;
|
183
|
+
|
184
|
+
// Explicitly define all named exports so that Node’s automatic detection of
|
185
|
+
// named exports from CommonJS packages finds all of them. This enables consuming
|
186
|
+
// packages to write code like `import { compile } from 'coffeescript'`.
|
187
|
+
// Don’t simplify this into a loop or similar; the `module.exports.name` part is
|
188
|
+
// essential for Node’s algorithm to successfully detect the name.
|
189
|
+
module.exports.VERSION = CoffeeScript.VERSION;
|
190
|
+
|
191
|
+
module.exports.FILE_EXTENSIONS = CoffeeScript.FILE_EXTENSIONS;
|
192
|
+
|
193
|
+
module.exports.helpers = CoffeeScript.helpers;
|
194
|
+
|
195
|
+
module.exports.registerCompiled = CoffeeScript.registerCompiled;
|
196
|
+
|
197
|
+
module.exports.compile = CoffeeScript.compile;
|
198
|
+
|
199
|
+
module.exports.tokens = CoffeeScript.tokens;
|
200
|
+
|
201
|
+
module.exports.nodes = CoffeeScript.nodes;
|
202
|
+
|
203
|
+
module.exports.register = CoffeeScript.register;
|
204
|
+
|
205
|
+
module.exports.eval = CoffeeScript.eval;
|
206
|
+
|
207
|
+
module.exports.run = CoffeeScript.run;
|
208
|
+
|
209
|
+
module.exports.transpile = CoffeeScript.transpile;
|
210
|
+
|
211
|
+
module.exports.patchStackTrace = CoffeeScript.patchStackTrace;
|
212
|
+
|
213
|
+
module.exports._compileRawFileContent = CoffeeScript._compileRawFileContent;
|
214
|
+
|
215
|
+
module.exports._compileFile = CoffeeScript._compileFile;
|
216
|
+
|
217
|
+
}).call(this);
|