@danielx/civet 0.5.17 → 0.5.18
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.
- package/dist/browser.js +25 -16
- package/dist/civet +234 -47
- package/dist/main.js +25 -16
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -11113,8 +11113,10 @@ ${input.slice(result.pos)}
|
|
|
11113
11113
|
return true;
|
|
11114
11114
|
});
|
|
11115
11115
|
if (classes.length) {
|
|
11116
|
-
let
|
|
11116
|
+
let isBraced = function(c) {
|
|
11117
11117
|
return c[0] === "{" || c[0]?.token === "{";
|
|
11118
|
+
}, unbrace = function(c) {
|
|
11119
|
+
return c.slice(1, -1);
|
|
11118
11120
|
}, parseClass = function(c) {
|
|
11119
11121
|
c = c.token || c;
|
|
11120
11122
|
if (c.startsWith("'")) {
|
|
@@ -11132,21 +11134,25 @@ ${input.slice(result.pos)}
|
|
|
11132
11134
|
}
|
|
11133
11135
|
return true;
|
|
11134
11136
|
});
|
|
11137
|
+
const strings = [], exprs = [];
|
|
11138
|
+
classes.forEach((c) => {
|
|
11139
|
+
if (isBraced(c)) {
|
|
11140
|
+
exprs.push(unbrace(c));
|
|
11141
|
+
exprs.push(", ");
|
|
11142
|
+
} else {
|
|
11143
|
+
strings.push(parseClass(c));
|
|
11144
|
+
}
|
|
11145
|
+
});
|
|
11146
|
+
const stringPart = strings.filter(Boolean).join(" ");
|
|
11135
11147
|
let classValue;
|
|
11136
|
-
if (
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
classValue.push("$", c);
|
|
11143
|
-
} else {
|
|
11144
|
-
classValue.push(parseClass(c));
|
|
11145
|
-
}
|
|
11146
|
-
});
|
|
11147
|
-
classValue.push("`}");
|
|
11148
|
+
if (exprs.length) {
|
|
11149
|
+
exprs.pop();
|
|
11150
|
+
if (stringPart) {
|
|
11151
|
+
exprs.unshift(JSON.stringify(stringPart), ", ");
|
|
11152
|
+
}
|
|
11153
|
+
classValue = ["{[", ...exprs, '].filter(Boolean).join(" ")}'];
|
|
11148
11154
|
} else {
|
|
11149
|
-
classValue = JSON.stringify(
|
|
11155
|
+
classValue = JSON.stringify(stringPart);
|
|
11150
11156
|
}
|
|
11151
11157
|
attrs.splice(0, 0, [" ", [className, ["=", classValue]]]);
|
|
11152
11158
|
}
|
|
@@ -12690,11 +12696,11 @@ ${input.slice(result.pos)}
|
|
|
12690
12696
|
return result;
|
|
12691
12697
|
}
|
|
12692
12698
|
}
|
|
12693
|
-
var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
|
|
12699
|
+
var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
|
|
12694
12700
|
var content = value[2];
|
|
12695
12701
|
return content;
|
|
12696
12702
|
});
|
|
12697
|
-
var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
|
|
12703
|
+
var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
|
|
12698
12704
|
var content = value[2];
|
|
12699
12705
|
return content;
|
|
12700
12706
|
});
|
|
@@ -15246,6 +15252,9 @@ ${input.slice(result.pos)}
|
|
|
15246
15252
|
compile: function(src, options = defaultOptions) {
|
|
15247
15253
|
var ast, code, events, filename, sm, srcMapJSON;
|
|
15248
15254
|
filename = options.filename || "unknown";
|
|
15255
|
+
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
15256
|
+
src = `"civet coffeeCompat"; ${src}`;
|
|
15257
|
+
}
|
|
15249
15258
|
if (!options.noCache) {
|
|
15250
15259
|
events = makeCache();
|
|
15251
15260
|
}
|
package/dist/civet
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var compile, encoding, fs, generate, parse, prune,
|
|
3
|
+
var cli, compile, encoding, fs, generate, parse, parseArgs, path, prune, readFiles, repl, version, splice = [].splice;
|
|
4
|
+
version = function() {
|
|
5
|
+
return require("../package.json").version;
|
|
6
|
+
};
|
|
4
7
|
if (process.argv.includes("--version")) {
|
|
5
|
-
|
|
8
|
+
console.log(version());
|
|
6
9
|
process.exit(0);
|
|
7
10
|
}
|
|
8
11
|
if (process.argv.includes("--help")) {
|
|
@@ -15,14 +18,24 @@ if (process.argv.includes("--help")) {
|
|
|
15
18
|
|
|
16
19
|
Usage:
|
|
17
20
|
|
|
18
|
-
civet [options]
|
|
21
|
+
civet [options] # REPL
|
|
22
|
+
civet [options] -c input.civet # -> input.civet.tsx
|
|
23
|
+
civet [options] -c input.civet -o .ts # -> input.ts
|
|
24
|
+
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
25
|
+
civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
|
|
26
|
+
civet [options] -c input.civet -o output.ts # -> output.ts
|
|
27
|
+
civet [options] < input.civet > output.ts # pipe form
|
|
19
28
|
|
|
20
29
|
Options:
|
|
21
|
-
--help
|
|
22
|
-
--version
|
|
23
|
-
--
|
|
24
|
-
|
|
25
|
-
--js
|
|
30
|
+
--help Show this help message
|
|
31
|
+
--version Show the version number
|
|
32
|
+
-o / --output XX Specify output directory and/or extension, or filename
|
|
33
|
+
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
34
|
+
--js Strip out all type annotations; default to .jsx extension
|
|
35
|
+
--ast Print the AST instead of the compiled code
|
|
36
|
+
--inline-map Generate a sourcemap
|
|
37
|
+
|
|
38
|
+
You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
26
39
|
|
|
27
40
|
`);
|
|
28
41
|
process.exit(0);
|
|
@@ -30,47 +43,221 @@ Options:
|
|
|
30
43
|
({ parse, compile, generate } = require("./main"));
|
|
31
44
|
({ prune } = generate);
|
|
32
45
|
encoding = "utf8";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
fs = require("fs/promises");
|
|
47
|
+
path = require("path");
|
|
48
|
+
parseArgs = function(args = process.argv.slice(2)) {
|
|
49
|
+
var arg, char, filenames, i, options, ref;
|
|
50
|
+
options = {};
|
|
51
|
+
filenames = [];
|
|
52
|
+
i = 0;
|
|
53
|
+
while (i < args.length) {
|
|
54
|
+
arg = args[i];
|
|
55
|
+
if (/^-\w{2,}$/.test(arg)) {
|
|
56
|
+
splice.apply(args, [i, i - i + 1].concat(ref = function() {
|
|
57
|
+
var j, len, ref1, results;
|
|
58
|
+
ref1 = arg.slice(1);
|
|
59
|
+
results = [];
|
|
60
|
+
for (j = 0, len = ref1.length; j < len; j++) {
|
|
61
|
+
char = ref1[j];
|
|
62
|
+
results.push(`-${char}`);
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}())), ref;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
switch (arg) {
|
|
69
|
+
case "-c":
|
|
70
|
+
case "--compile":
|
|
71
|
+
options.compile = true;
|
|
72
|
+
break;
|
|
73
|
+
case "-o":
|
|
74
|
+
case "--output":
|
|
75
|
+
options.output = args[++i];
|
|
76
|
+
break;
|
|
77
|
+
case "--ast":
|
|
78
|
+
options.ast = true;
|
|
79
|
+
break;
|
|
80
|
+
case "--no-cache":
|
|
81
|
+
options.noCache = true;
|
|
82
|
+
break;
|
|
83
|
+
case "--inline-map":
|
|
84
|
+
options.inlineMap = true;
|
|
85
|
+
break;
|
|
86
|
+
case "--js":
|
|
87
|
+
options.js = true;
|
|
88
|
+
break;
|
|
89
|
+
case "--":
|
|
90
|
+
filenames.push(...args.slice(++i));
|
|
91
|
+
i = args.length;
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
filenames.push(arg);
|
|
95
|
+
}
|
|
96
|
+
i++;
|
|
40
97
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
98
|
+
return { filenames, options };
|
|
99
|
+
};
|
|
100
|
+
readFiles = async function* (filenames, options) {
|
|
101
|
+
var content, error, filename, j, len, lines, results, rl, stdin;
|
|
102
|
+
results = [];
|
|
103
|
+
for (j = 0, len = filenames.length; j < len; j++) {
|
|
104
|
+
filename = filenames[j];
|
|
105
|
+
stdin = filename === "-";
|
|
106
|
+
try {
|
|
107
|
+
if (stdin) {
|
|
108
|
+
process.stdin.setEncoding(encoding);
|
|
109
|
+
filename = "<stdin>";
|
|
110
|
+
try {
|
|
111
|
+
filename = await fs.realpath("/dev/stdin");
|
|
112
|
+
} catch (error1) {
|
|
113
|
+
}
|
|
114
|
+
lines = [];
|
|
115
|
+
rl = require("readline").createInterface(process.stdin, process.stdout);
|
|
116
|
+
rl.on("line", function(buffer) {
|
|
117
|
+
return lines.push(buffer + "\n");
|
|
118
|
+
});
|
|
119
|
+
content = await new Promise(function(resolve, reject) {
|
|
120
|
+
rl.on("SIGINT", function() {
|
|
121
|
+
return reject("^C");
|
|
122
|
+
});
|
|
123
|
+
return rl.on("close", function() {
|
|
124
|
+
return resolve(lines.join(""));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
content = await fs.readFile(filename, { encoding });
|
|
129
|
+
}
|
|
130
|
+
results.push(yield { filename, content, stdin });
|
|
131
|
+
} catch (error1) {
|
|
132
|
+
error = error1;
|
|
133
|
+
results.push(yield { filename, error, stdin });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return results;
|
|
137
|
+
};
|
|
138
|
+
repl = function(options) {
|
|
139
|
+
var nodeRepl, r, vm;
|
|
140
|
+
console.log(`Civet ${version()} REPL. Enter a blank line to execute code.`);
|
|
141
|
+
global.quit = global.exit = function() {
|
|
142
|
+
return process.exit(0);
|
|
143
|
+
};
|
|
144
|
+
nodeRepl = require("repl");
|
|
145
|
+
vm = require("vm");
|
|
146
|
+
return r = nodeRepl.start({
|
|
147
|
+
prompt: "\u{1F431}> ",
|
|
148
|
+
eval: function(input, context, filename, callback) {
|
|
149
|
+
var error, output, result;
|
|
150
|
+
if (input === "\n") {
|
|
151
|
+
return callback(null);
|
|
152
|
+
} else if (input === "quit\n" || input === "exit\n" || input === "quit()\n" || input === "exit()\n") {
|
|
153
|
+
return process.exit(0);
|
|
154
|
+
} else if (input.endsWith("\n\n")) {
|
|
155
|
+
try {
|
|
156
|
+
output = compile(input, { ...options, filename });
|
|
157
|
+
} catch (error1) {
|
|
158
|
+
error = error1;
|
|
159
|
+
return callback(error);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
result = vm.runInContext(output, context, { filename });
|
|
163
|
+
} catch (error1) {
|
|
164
|
+
error = error1;
|
|
165
|
+
return callback(error);
|
|
166
|
+
}
|
|
167
|
+
return callback(null, result);
|
|
168
|
+
} else {
|
|
169
|
+
return callback(new nodeRepl.Recoverable("Enter a blank line to execute code."));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
55
172
|
});
|
|
56
173
|
};
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
174
|
+
cli = async function() {
|
|
175
|
+
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, stat, stdin, x;
|
|
176
|
+
({ filenames, options } = parseArgs());
|
|
177
|
+
if (!filenames.length) {
|
|
178
|
+
options.compile = true;
|
|
179
|
+
if (process.stdin.isTTY) {
|
|
180
|
+
options.repl = true;
|
|
181
|
+
} else {
|
|
182
|
+
filenames = ["-"];
|
|
183
|
+
}
|
|
67
184
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
185
|
+
options.run = !(options.ast || options.compile);
|
|
186
|
+
if (options.run) {
|
|
187
|
+
options.js = true;
|
|
188
|
+
options.inlineMap = true;
|
|
71
189
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
190
|
+
if (options.repl) {
|
|
191
|
+
return repl(options);
|
|
192
|
+
}
|
|
193
|
+
ref = readFiles(filenames, options);
|
|
194
|
+
results = [];
|
|
195
|
+
for await (x of ref) {
|
|
196
|
+
({ filename, error, content, stdin } = x);
|
|
197
|
+
if (error) {
|
|
198
|
+
console.error(`${filename} failed to load:`);
|
|
199
|
+
console.error(error);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
output = compile(content, { ...options, filename });
|
|
204
|
+
} catch (error1) {
|
|
205
|
+
error = error1;
|
|
206
|
+
console.error(error);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (options.ast) {
|
|
210
|
+
results.push(process.stdout.write(JSON.stringify(output, null, 2)));
|
|
211
|
+
} else if (options.compile) {
|
|
212
|
+
if (stdin && !options.output || options.output === "-") {
|
|
213
|
+
results.push(process.stdout.write(output));
|
|
214
|
+
} else {
|
|
215
|
+
outputPath = path.parse(filename);
|
|
216
|
+
delete outputPath.base;
|
|
217
|
+
if (options.js) {
|
|
218
|
+
outputPath.ext += ".jsx";
|
|
219
|
+
} else {
|
|
220
|
+
outputPath.ext += ".tsx";
|
|
221
|
+
}
|
|
222
|
+
if (options.output) {
|
|
223
|
+
optionsPath = path.parse(options.output);
|
|
224
|
+
try {
|
|
225
|
+
stat = await fs.stat(options.output);
|
|
226
|
+
} catch (error1) {
|
|
227
|
+
stat = null;
|
|
228
|
+
}
|
|
229
|
+
if (stat != null ? stat.isDirectory() : void 0) {
|
|
230
|
+
outputPath.dir = options.output;
|
|
231
|
+
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
232
|
+
outputPath.ext = optionsPath.base;
|
|
233
|
+
if (optionsPath.dir) {
|
|
234
|
+
outputPath.dir = optionsPath.dir;
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
outputPath = optionsPath;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
outputFilename = path.format(outputPath);
|
|
241
|
+
try {
|
|
242
|
+
results.push(await fs.writeFile(outputFilename, output));
|
|
243
|
+
} catch (error1) {
|
|
244
|
+
error = error1;
|
|
245
|
+
console.error(`${outputFilename} failed to write:`);
|
|
246
|
+
results.push(console.error(error));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
try {
|
|
251
|
+
results.push(require.main._compile(output, filename));
|
|
252
|
+
} catch (error1) {
|
|
253
|
+
error = error1;
|
|
254
|
+
console.error(`${filename} crashed while running:`);
|
|
255
|
+
results.push(console.error(error));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return results;
|
|
260
|
+
};
|
|
261
|
+
if (require.main === module) {
|
|
262
|
+
cli();
|
|
263
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -11112,8 +11112,10 @@ ${input.slice(result.pos)}
|
|
|
11112
11112
|
return true;
|
|
11113
11113
|
});
|
|
11114
11114
|
if (classes.length) {
|
|
11115
|
-
let
|
|
11115
|
+
let isBraced = function(c) {
|
|
11116
11116
|
return c[0] === "{" || c[0]?.token === "{";
|
|
11117
|
+
}, unbrace = function(c) {
|
|
11118
|
+
return c.slice(1, -1);
|
|
11117
11119
|
}, parseClass = function(c) {
|
|
11118
11120
|
c = c.token || c;
|
|
11119
11121
|
if (c.startsWith("'")) {
|
|
@@ -11131,21 +11133,25 @@ ${input.slice(result.pos)}
|
|
|
11131
11133
|
}
|
|
11132
11134
|
return true;
|
|
11133
11135
|
});
|
|
11136
|
+
const strings = [], exprs = [];
|
|
11137
|
+
classes.forEach((c) => {
|
|
11138
|
+
if (isBraced(c)) {
|
|
11139
|
+
exprs.push(unbrace(c));
|
|
11140
|
+
exprs.push(", ");
|
|
11141
|
+
} else {
|
|
11142
|
+
strings.push(parseClass(c));
|
|
11143
|
+
}
|
|
11144
|
+
});
|
|
11145
|
+
const stringPart = strings.filter(Boolean).join(" ");
|
|
11134
11146
|
let classValue;
|
|
11135
|
-
if (
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
classValue.push("$", c);
|
|
11142
|
-
} else {
|
|
11143
|
-
classValue.push(parseClass(c));
|
|
11144
|
-
}
|
|
11145
|
-
});
|
|
11146
|
-
classValue.push("`}");
|
|
11147
|
+
if (exprs.length) {
|
|
11148
|
+
exprs.pop();
|
|
11149
|
+
if (stringPart) {
|
|
11150
|
+
exprs.unshift(JSON.stringify(stringPart), ", ");
|
|
11151
|
+
}
|
|
11152
|
+
classValue = ["{[", ...exprs, '].filter(Boolean).join(" ")}'];
|
|
11147
11153
|
} else {
|
|
11148
|
-
classValue = JSON.stringify(
|
|
11154
|
+
classValue = JSON.stringify(stringPart);
|
|
11149
11155
|
}
|
|
11150
11156
|
attrs.splice(0, 0, [" ", [className, ["=", classValue]]]);
|
|
11151
11157
|
}
|
|
@@ -12689,11 +12695,11 @@ ${input.slice(result.pos)}
|
|
|
12689
12695
|
return result;
|
|
12690
12696
|
}
|
|
12691
12697
|
}
|
|
12692
|
-
var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
|
|
12698
|
+
var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
|
|
12693
12699
|
var content = value[2];
|
|
12694
12700
|
return content;
|
|
12695
12701
|
});
|
|
12696
|
-
var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
|
|
12702
|
+
var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
|
|
12697
12703
|
var content = value[2];
|
|
12698
12704
|
return content;
|
|
12699
12705
|
});
|
|
@@ -15243,6 +15249,9 @@ module.exports = {
|
|
|
15243
15249
|
compile: function(src, options = defaultOptions) {
|
|
15244
15250
|
var ast, code, events, filename, sm, srcMapJSON;
|
|
15245
15251
|
filename = options.filename || "unknown";
|
|
15252
|
+
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
15253
|
+
src = `"civet coffeeCompat"; ${src}`;
|
|
15254
|
+
}
|
|
15246
15255
|
if (!options.noCache) {
|
|
15247
15256
|
events = makeCache();
|
|
15248
15257
|
}
|