@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,100 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
(function() {
|
3
|
+
var CoffeeScript, Module, binary, cacheSourceMaps, child_process, ext, findExtension, fork, getRootModule, helpers, i, len, loadFile, nodeSourceMapsSupportEnabled, patchStackTrace, path, ref, ref1;
|
4
|
+
|
5
|
+
CoffeeScript = require('./');
|
6
|
+
|
7
|
+
child_process = require('child_process');
|
8
|
+
|
9
|
+
helpers = require('./helpers');
|
10
|
+
|
11
|
+
path = require('path');
|
12
|
+
|
13
|
+
({patchStackTrace} = CoffeeScript);
|
14
|
+
|
15
|
+
// Check if Node's built-in source map stack trace transformations are enabled.
|
16
|
+
nodeSourceMapsSupportEnabled = (typeof process !== "undefined" && process !== null) && (process.execArgv.includes('--enable-source-maps') || ((ref = process.env.NODE_OPTIONS) != null ? ref.includes('--enable-source-maps') : void 0));
|
17
|
+
|
18
|
+
if (!(Error.prepareStackTrace || nodeSourceMapsSupportEnabled)) {
|
19
|
+
cacheSourceMaps = true;
|
20
|
+
patchStackTrace();
|
21
|
+
}
|
22
|
+
|
23
|
+
// Load and run a CoffeeScript file for Node, stripping any `BOM`s.
|
24
|
+
loadFile = function(module, filename) {
|
25
|
+
var js, options;
|
26
|
+
options = module.options || getRootModule(module).options || {};
|
27
|
+
// Currently `CoffeeScript.compile` caches all source maps if present. They
|
28
|
+
// are available in `getSourceMap` retrieved by `filename`.
|
29
|
+
if (cacheSourceMaps || nodeSourceMapsSupportEnabled) {
|
30
|
+
options.inlineMap = true;
|
31
|
+
}
|
32
|
+
js = CoffeeScript._compileFile(filename, options);
|
33
|
+
return module._compile(js, filename);
|
34
|
+
};
|
35
|
+
|
36
|
+
// If the installed version of Node supports `require.extensions`, register
|
37
|
+
// CoffeeScript as an extension.
|
38
|
+
if (require.extensions) {
|
39
|
+
ref1 = CoffeeScript.FILE_EXTENSIONS;
|
40
|
+
for (i = 0, len = ref1.length; i < len; i++) {
|
41
|
+
ext = ref1[i];
|
42
|
+
require.extensions[ext] = loadFile;
|
43
|
+
}
|
44
|
+
// Patch Node's module loader to be able to handle multi-dot extensions.
|
45
|
+
// This is a horrible thing that should not be required.
|
46
|
+
Module = require('module');
|
47
|
+
findExtension = function(filename) {
|
48
|
+
var curExtension, extensions;
|
49
|
+
extensions = path.basename(filename).split('.');
|
50
|
+
if (extensions[0] === '') {
|
51
|
+
// Remove the initial dot from dotfiles.
|
52
|
+
extensions.shift();
|
53
|
+
}
|
54
|
+
// Start with the longest possible extension and work our way shortwards.
|
55
|
+
while (extensions.shift()) {
|
56
|
+
curExtension = '.' + extensions.join('.');
|
57
|
+
if (Module._extensions[curExtension]) {
|
58
|
+
return curExtension;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return '.js';
|
62
|
+
};
|
63
|
+
Module.prototype.load = function(filename) {
|
64
|
+
var extension;
|
65
|
+
this.filename = filename;
|
66
|
+
this.paths = Module._nodeModulePaths(path.dirname(filename));
|
67
|
+
extension = findExtension(filename);
|
68
|
+
Module._extensions[extension](this, filename);
|
69
|
+
return this.loaded = true;
|
70
|
+
};
|
71
|
+
}
|
72
|
+
|
73
|
+
// If we're on Node, patch `child_process.fork` so that Coffee scripts are able
|
74
|
+
// to fork both CoffeeScript files, and JavaScript files, directly.
|
75
|
+
if (child_process) {
|
76
|
+
({fork} = child_process);
|
77
|
+
binary = require.resolve('../../bin/coffee');
|
78
|
+
child_process.fork = function(path, args, options) {
|
79
|
+
if (helpers.isCoffee(path)) {
|
80
|
+
if (!Array.isArray(args)) {
|
81
|
+
options = args || {};
|
82
|
+
args = [];
|
83
|
+
}
|
84
|
+
args = [path].concat(args);
|
85
|
+
path = binary;
|
86
|
+
}
|
87
|
+
return fork(path, args, options);
|
88
|
+
};
|
89
|
+
}
|
90
|
+
|
91
|
+
// Utility function to find the `options` object attached to the topmost module.
|
92
|
+
getRootModule = function(module) {
|
93
|
+
if (module.parent) {
|
94
|
+
return getRootModule(module.parent);
|
95
|
+
} else {
|
96
|
+
return module;
|
97
|
+
}
|
98
|
+
};
|
99
|
+
|
100
|
+
}).call(this);
|
@@ -0,0 +1,305 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
(function() {
|
3
|
+
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, runInContext, sawSIGINT, transpile, updateSyntaxError, vm;
|
4
|
+
|
5
|
+
fs = require('fs');
|
6
|
+
|
7
|
+
path = require('path');
|
8
|
+
|
9
|
+
vm = require('vm');
|
10
|
+
|
11
|
+
nodeREPL = require('repl');
|
12
|
+
|
13
|
+
CoffeeScript = require('./');
|
14
|
+
|
15
|
+
({merge, updateSyntaxError} = require('./helpers'));
|
16
|
+
|
17
|
+
sawSIGINT = false;
|
18
|
+
|
19
|
+
transpile = false;
|
20
|
+
|
21
|
+
replDefaults = {
|
22
|
+
prompt: 'coffee> ',
|
23
|
+
historyFile: (function() {
|
24
|
+
var historyPath;
|
25
|
+
historyPath = process.env.XDG_CACHE_HOME || process.env.HOME;
|
26
|
+
if (historyPath) {
|
27
|
+
return path.join(historyPath, '.coffee_history');
|
28
|
+
}
|
29
|
+
})(),
|
30
|
+
historyMaxInputSize: 10240,
|
31
|
+
eval: function(input, context, filename, cb) {
|
32
|
+
var Assign, Block, Call, Code, Literal, Root, Value, ast, err, isAsync, js, ref, ref1, referencedVars, result, token, tokens;
|
33
|
+
// XXX: multiline hack.
|
34
|
+
input = input.replace(/\uFF00/g, '\n');
|
35
|
+
// Node's REPL sends the input ending with a newline and then wrapped in
|
36
|
+
// parens. Unwrap all that.
|
37
|
+
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
|
38
|
+
// Node's REPL v6.9.1+ sends the input wrapped in a try/catch statement.
|
39
|
+
// Unwrap that too.
|
40
|
+
input = input.replace(/^\s*try\s*{([\s\S]*)}\s*catch.*$/m, '$1');
|
41
|
+
// Require AST nodes to do some AST manipulation.
|
42
|
+
({Block, Assign, Value, Literal, Call, Code, Root} = require('./nodes'));
|
43
|
+
try {
|
44
|
+
// Tokenize the clean input.
|
45
|
+
tokens = CoffeeScript.tokens(input);
|
46
|
+
// Filter out tokens generated just to hold comments.
|
47
|
+
if (tokens.length >= 2 && tokens[0].generated && ((ref = tokens[0].comments) != null ? ref.length : void 0) !== 0 && `${tokens[0][1]}` === '' && tokens[1][0] === 'TERMINATOR') {
|
48
|
+
tokens = tokens.slice(2);
|
49
|
+
}
|
50
|
+
if (tokens.length >= 1 && tokens[tokens.length - 1].generated && ((ref1 = tokens[tokens.length - 1].comments) != null ? ref1.length : void 0) !== 0 && `${tokens[tokens.length - 1][1]}` === '') {
|
51
|
+
tokens.pop();
|
52
|
+
}
|
53
|
+
// Collect referenced variable names just like in `CoffeeScript.compile`.
|
54
|
+
referencedVars = (function() {
|
55
|
+
var i, len, results;
|
56
|
+
results = [];
|
57
|
+
for (i = 0, len = tokens.length; i < len; i++) {
|
58
|
+
token = tokens[i];
|
59
|
+
if (token[0] === 'IDENTIFIER') {
|
60
|
+
results.push(token[1]);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return results;
|
64
|
+
})();
|
65
|
+
// Generate the AST of the tokens.
|
66
|
+
ast = CoffeeScript.nodes(tokens).body;
|
67
|
+
// Add assignment to `__` variable to force the input to be an expression.
|
68
|
+
ast = new Block([new Assign(new Value(new Literal('__')), ast, '=')]);
|
69
|
+
// Wrap the expression in a closure to support top-level `await`.
|
70
|
+
ast = new Code([], ast);
|
71
|
+
isAsync = ast.isAsync;
|
72
|
+
// Invoke the wrapping closure.
|
73
|
+
ast = new Root(new Block([new Call(ast)]));
|
74
|
+
js = ast.compile({
|
75
|
+
bare: true,
|
76
|
+
locals: Object.keys(context),
|
77
|
+
referencedVars,
|
78
|
+
sharedScope: true
|
79
|
+
});
|
80
|
+
if (transpile) {
|
81
|
+
js = transpile.transpile(js, transpile.options).code;
|
82
|
+
// Strip `"use strict"`, to avoid an exception on assigning to
|
83
|
+
// undeclared variable `__`.
|
84
|
+
js = js.replace(/^"use strict"|^'use strict'/, '');
|
85
|
+
}
|
86
|
+
result = runInContext(js, context, filename);
|
87
|
+
// Await an async result, if necessary.
|
88
|
+
if (isAsync) {
|
89
|
+
result.then(function(resolvedResult) {
|
90
|
+
if (!sawSIGINT) {
|
91
|
+
return cb(null, resolvedResult);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
return sawSIGINT = false;
|
95
|
+
} else {
|
96
|
+
return cb(null, result);
|
97
|
+
}
|
98
|
+
} catch (error) {
|
99
|
+
err = error;
|
100
|
+
// AST's `compile` does not add source code information to syntax errors.
|
101
|
+
updateSyntaxError(err, input);
|
102
|
+
return cb(err);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
runInContext = function(js, context, filename) {
|
108
|
+
if (context === global) {
|
109
|
+
return vm.runInThisContext(js, filename);
|
110
|
+
} else {
|
111
|
+
return vm.runInContext(js, context, filename);
|
112
|
+
}
|
113
|
+
};
|
114
|
+
|
115
|
+
addMultilineHandler = function(repl) {
|
116
|
+
var inputStream, multiline, nodeLineListener, origPrompt, outputStream, ref;
|
117
|
+
({inputStream, outputStream} = repl);
|
118
|
+
// Node 0.11.12 changed API, prompt is now _prompt.
|
119
|
+
origPrompt = (ref = repl._prompt) != null ? ref : repl.prompt;
|
120
|
+
multiline = {
|
121
|
+
enabled: false,
|
122
|
+
initialPrompt: origPrompt.replace(/^[^> ]*/, function(x) {
|
123
|
+
return x.replace(/./g, '-');
|
124
|
+
}),
|
125
|
+
prompt: origPrompt.replace(/^[^> ]*>?/, function(x) {
|
126
|
+
return x.replace(/./g, '.');
|
127
|
+
}),
|
128
|
+
buffer: ''
|
129
|
+
};
|
130
|
+
// Proxy node's line listener
|
131
|
+
nodeLineListener = repl.listeners('line')[0];
|
132
|
+
repl.removeListener('line', nodeLineListener);
|
133
|
+
repl.on('line', function(cmd) {
|
134
|
+
if (multiline.enabled) {
|
135
|
+
multiline.buffer += `${cmd}\n`;
|
136
|
+
repl.setPrompt(multiline.prompt);
|
137
|
+
repl.prompt(true);
|
138
|
+
} else {
|
139
|
+
repl.setPrompt(origPrompt);
|
140
|
+
nodeLineListener(cmd);
|
141
|
+
}
|
142
|
+
});
|
143
|
+
// Handle Ctrl-v
|
144
|
+
return inputStream.on('keypress', function(char, key) {
|
145
|
+
if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'v')) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
if (multiline.enabled) {
|
149
|
+
// allow arbitrarily switching between modes any time before multiple lines are entered
|
150
|
+
if (!multiline.buffer.match(/\n/)) {
|
151
|
+
multiline.enabled = !multiline.enabled;
|
152
|
+
repl.setPrompt(origPrompt);
|
153
|
+
repl.prompt(true);
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
// no-op unless the current line is empty
|
157
|
+
if ((repl.line != null) && !repl.line.match(/^\s*$/)) {
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
// eval, print, loop
|
161
|
+
multiline.enabled = !multiline.enabled;
|
162
|
+
repl.line = '';
|
163
|
+
repl.cursor = 0;
|
164
|
+
repl.output.cursorTo(0);
|
165
|
+
repl.output.clearLine(1);
|
166
|
+
// XXX: multiline hack
|
167
|
+
multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00');
|
168
|
+
repl.emit('line', multiline.buffer);
|
169
|
+
multiline.buffer = '';
|
170
|
+
} else {
|
171
|
+
multiline.enabled = !multiline.enabled;
|
172
|
+
repl.setPrompt(multiline.initialPrompt);
|
173
|
+
repl.prompt(true);
|
174
|
+
}
|
175
|
+
});
|
176
|
+
};
|
177
|
+
|
178
|
+
// Store and load command history from a file
|
179
|
+
addHistory = function(repl, filename, maxSize) {
|
180
|
+
var buffer, fd, lastLine, readFd, size, stat;
|
181
|
+
lastLine = null;
|
182
|
+
try {
|
183
|
+
// Get file info and at most maxSize of command history
|
184
|
+
stat = fs.statSync(filename);
|
185
|
+
size = Math.min(maxSize, stat.size);
|
186
|
+
// Read last `size` bytes from the file
|
187
|
+
readFd = fs.openSync(filename, 'r');
|
188
|
+
buffer = Buffer.alloc(size);
|
189
|
+
fs.readSync(readFd, buffer, 0, size, stat.size - size);
|
190
|
+
fs.closeSync(readFd);
|
191
|
+
// Set the history on the interpreter
|
192
|
+
repl.history = buffer.toString().split('\n').reverse();
|
193
|
+
if (stat.size > maxSize) {
|
194
|
+
// If the history file was truncated we should pop off a potential partial line
|
195
|
+
repl.history.pop();
|
196
|
+
}
|
197
|
+
if (repl.history[0] === '') {
|
198
|
+
// Shift off the final blank newline
|
199
|
+
repl.history.shift();
|
200
|
+
}
|
201
|
+
repl.historyIndex = -1;
|
202
|
+
lastLine = repl.history[0];
|
203
|
+
} catch (error) {}
|
204
|
+
fd = fs.openSync(filename, 'a');
|
205
|
+
repl.addListener('line', function(code) {
|
206
|
+
if (code && code.length && code !== '.history' && code !== '.exit' && lastLine !== code) {
|
207
|
+
// Save the latest command in the file
|
208
|
+
fs.writeSync(fd, `${code}\n`);
|
209
|
+
return lastLine = code;
|
210
|
+
}
|
211
|
+
});
|
212
|
+
// XXX: The SIGINT event from REPLServer is undocumented, so this is a bit fragile
|
213
|
+
repl.on('SIGINT', function() {
|
214
|
+
return sawSIGINT = true;
|
215
|
+
});
|
216
|
+
repl.on('exit', function() {
|
217
|
+
return fs.closeSync(fd);
|
218
|
+
});
|
219
|
+
// Add a command to show the history stack
|
220
|
+
return repl.commands[getCommandId(repl, 'history')] = {
|
221
|
+
help: 'Show command history',
|
222
|
+
action: function() {
|
223
|
+
repl.outputStream.write(`${repl.history.slice(0).reverse().join('\n')}\n`);
|
224
|
+
return repl.displayPrompt();
|
225
|
+
}
|
226
|
+
};
|
227
|
+
};
|
228
|
+
|
229
|
+
getCommandId = function(repl, commandName) {
|
230
|
+
var commandsHaveLeadingDot;
|
231
|
+
// Node 0.11 changed API, a command such as '.help' is now stored as 'help'
|
232
|
+
commandsHaveLeadingDot = repl.commands['.help'] != null;
|
233
|
+
if (commandsHaveLeadingDot) {
|
234
|
+
return `.${commandName}`;
|
235
|
+
} else {
|
236
|
+
return commandName;
|
237
|
+
}
|
238
|
+
};
|
239
|
+
|
240
|
+
module.exports = {
|
241
|
+
start: function(opts = {}) {
|
242
|
+
var Module, build, major, minor, originalModuleLoad, repl;
|
243
|
+
[major, minor, build] = process.versions.node.split('.').map(function(n) {
|
244
|
+
return parseInt(n, 10);
|
245
|
+
});
|
246
|
+
if (major < 6) {
|
247
|
+
console.warn("Node 6+ required for CoffeeScript REPL");
|
248
|
+
process.exit(1);
|
249
|
+
}
|
250
|
+
CoffeeScript.register();
|
251
|
+
process.argv = ['coffee'].concat(process.argv.slice(2));
|
252
|
+
if (opts.transpile) {
|
253
|
+
transpile = {};
|
254
|
+
try {
|
255
|
+
transpile.transpile = require('@babel/core').transform;
|
256
|
+
} catch (error) {
|
257
|
+
try {
|
258
|
+
transpile.transpile = require('babel-core').transform;
|
259
|
+
} catch (error) {
|
260
|
+
console.error(`To use --transpile with an interactive REPL, @babel/core must be installed either in the current folder or globally:
|
261
|
+
npm install --save-dev @babel/core
|
262
|
+
or
|
263
|
+
npm install --global @babel/core
|
264
|
+
And you must save options to configure Babel in one of the places it looks to find its options.
|
265
|
+
See https://coffeescript.org/#transpilation`);
|
266
|
+
process.exit(1);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
transpile.options = {
|
270
|
+
filename: path.resolve(process.cwd(), '<repl>')
|
271
|
+
};
|
272
|
+
// Since the REPL compilation path is unique (in `eval` above), we need
|
273
|
+
// another way to get the `options` object attached to a module so that
|
274
|
+
// it knows later on whether it needs to be transpiled. In the case of
|
275
|
+
// the REPL, the only applicable option is `transpile`.
|
276
|
+
Module = require('module');
|
277
|
+
originalModuleLoad = Module.prototype.load;
|
278
|
+
Module.prototype.load = function(filename) {
|
279
|
+
this.options = {
|
280
|
+
transpile: transpile.options
|
281
|
+
};
|
282
|
+
return originalModuleLoad.call(this, filename);
|
283
|
+
};
|
284
|
+
}
|
285
|
+
opts = merge(replDefaults, opts);
|
286
|
+
repl = nodeREPL.start(opts);
|
287
|
+
if (opts.prelude) {
|
288
|
+
runInContext(opts.prelude, repl.context, 'prelude');
|
289
|
+
}
|
290
|
+
repl.on('exit', function() {
|
291
|
+
if (!repl.closed) {
|
292
|
+
return repl.outputStream.write('\n');
|
293
|
+
}
|
294
|
+
});
|
295
|
+
addMultilineHandler(repl);
|
296
|
+
if (opts.historyFile) {
|
297
|
+
addHistory(repl, opts.historyFile, opts.historyMaxInputSize);
|
298
|
+
}
|
299
|
+
// Adapt help inherited from the node REPL
|
300
|
+
repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session';
|
301
|
+
return repl;
|
302
|
+
}
|
303
|
+
};
|
304
|
+
|
305
|
+
}).call(this);
|