jz 0.1.0 → 0.1.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.
- package/README.md +64 -72
- package/index.js +38 -8
- package/module/array.js +7 -2
- package/module/collection.js +3 -1
- package/module/console.js +3 -1
- package/module/core.js +3 -1
- package/module/function.js +4 -3
- package/module/json.js +3 -1
- package/module/math.js +2 -1
- package/module/number.js +3 -7
- package/module/object.js +3 -1
- package/module/regex.js +2 -1
- package/module/schema.js +3 -1
- package/module/string.js +63 -6
- package/module/symbol.js +2 -1
- package/module/timer.js +2 -2
- package/module/typedarray.js +3 -1
- package/package.json +4 -2
- package/src/analyze.js +28 -7
- package/src/autoload.js +175 -0
- package/src/compile.js +58 -1022
- package/src/ctx.js +1 -0
- package/src/emit.js +16 -6
- package/src/host.js +38 -26
- package/src/jzify.js +45 -18
- package/src/key.js +73 -0
- package/src/narrow.js +928 -0
- package/src/plan.js +105 -0
- package/src/prepare.js +151 -215
- package/src/source.js +76 -0
- package/wasi.js +10 -4
package/src/source.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function normalizeSource(code) {
|
|
2
|
+
let source = code.startsWith('#!') ? `//${code.slice(2)}` : code
|
|
3
|
+
// Optional catch binding: `catch {` → `catch(_e) {` (parser gap workaround)
|
|
4
|
+
source = source.replace(/\bcatch\s*\{/g, 'catch(_e){')
|
|
5
|
+
let out = ''
|
|
6
|
+
let parenDepth = 0
|
|
7
|
+
let bracketDepth = 0
|
|
8
|
+
let quote = ''
|
|
9
|
+
let lineComment = false
|
|
10
|
+
let blockComment = false
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < source.length; i++) {
|
|
13
|
+
const ch = source[i]
|
|
14
|
+
const next = source[i + 1]
|
|
15
|
+
|
|
16
|
+
if (lineComment) {
|
|
17
|
+
out += ch
|
|
18
|
+
if (ch === '\n') lineComment = false
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (blockComment) {
|
|
23
|
+
out += ch
|
|
24
|
+
if (ch === '*' && next === '/') { out += next; i++; blockComment = false }
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (quote) {
|
|
29
|
+
out += ch
|
|
30
|
+
if (ch === '\\') { if (next != null) { out += next; i++ } }
|
|
31
|
+
else if (ch === quote) quote = ''
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (ch === '/' && next === '/') { out += ch + next; i++; lineComment = true; continue }
|
|
36
|
+
if (ch === '/' && next === '*') { out += ch + next; i++; blockComment = true; continue }
|
|
37
|
+
if (ch === '"' || ch === "'" || ch === '`') { out += ch; quote = ch; continue }
|
|
38
|
+
if (ch === '(') parenDepth++
|
|
39
|
+
else if (ch === ')' && parenDepth > 0) parenDepth--
|
|
40
|
+
else if (ch === '[') bracketDepth++
|
|
41
|
+
else if (ch === ']' && bracketDepth > 0) bracketDepth--
|
|
42
|
+
|
|
43
|
+
out += ch
|
|
44
|
+
if (ch === ';' && parenDepth === 0 && bracketDepth === 0) {
|
|
45
|
+
let j = i + 1
|
|
46
|
+
let sawNewline = false
|
|
47
|
+
while (j < source.length) {
|
|
48
|
+
const c = source[j]
|
|
49
|
+
const n = source[j + 1]
|
|
50
|
+
if (c === ' ' || c === '\t' || c === '\r' || c === '\n') {
|
|
51
|
+
if (c === '\n') sawNewline = true
|
|
52
|
+
j++
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
if (c === '/' && n === '/') {
|
|
56
|
+
j += 2
|
|
57
|
+
while (j < source.length && source[j] !== '\n') j++
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
if (c === '/' && n === '*') {
|
|
61
|
+
j += 2
|
|
62
|
+
while (j < source.length && !(source[j] === '*' && source[j + 1] === '/')) {
|
|
63
|
+
if (source[j] === '\n') sawNewline = true
|
|
64
|
+
j++
|
|
65
|
+
}
|
|
66
|
+
if (j < source.length) j += 2
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
if (sawNewline && source[j] === '(') out += ';'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return out
|
|
76
|
+
}
|
package/wasi.js
CHANGED
|
@@ -20,10 +20,16 @@
|
|
|
20
20
|
*/
|
|
21
21
|
export function wasi(opts = {}) {
|
|
22
22
|
let mem = null
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const fallbackWrite = (fd, text) => {
|
|
24
|
+
const stream = fd === 1 ? globalThis.process?.stdout : globalThis.process?.stderr
|
|
25
|
+
if (stream && typeof stream.write === 'function') {
|
|
26
|
+
try { stream.write(text); return }
|
|
27
|
+
catch {}
|
|
28
|
+
}
|
|
29
|
+
const msg = text.replace(/\n$/, '')
|
|
30
|
+
;(fd === 1 ? console.log : console.warn)(msg)
|
|
31
|
+
}
|
|
32
|
+
const write = opts.write || fallbackWrite
|
|
27
33
|
|
|
28
34
|
return {
|
|
29
35
|
wasi_snapshot_preview1: {
|