@makano/rew 1.0.1

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