@makano/rew 1.2.5 → 1.2.6

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