yuku-codegen 0.5.28 → 0.5.31

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 (2) hide show
  1. package/encode.js +28 -14
  2. package/package.json +13 -13
package/encode.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // generated by tools/gen_estree_encoder.zig, do not edit
2
2
  const NULL = 0xFFFFFFFF;
3
- const _enc = new TextEncoder();
4
3
  const NODE_SIZE = 48;
5
4
  const HEADER_SIZE = 44;
6
5
  const NODE_FLAGS_OFFSET = 2;
@@ -125,21 +124,35 @@ function encode(program, lineStarts) {
125
124
  }
126
125
  const start = poolLen;
127
126
  let p = start;
128
- let ascii = true;
129
- for (let i = 0; i < n; i++) {
127
+ let i = 0;
128
+ for (; i < n; i++) {
130
129
  const c = s.charCodeAt(i);
131
- if (c < 0x80) { pool[p++] = c; } else { ascii = false; break; }
130
+ if (c >= 0x80) break;
131
+ pool[p++] = c;
132
132
  }
133
- let r;
134
- if (ascii) {
135
- r = { start, end: p };
136
- poolLen = p;
137
- } else {
138
- const bytes = _enc.encode(s);
139
- pool.set(bytes, start);
140
- r = { start, end: start + bytes.length };
141
- poolLen = start + bytes.length;
133
+ // wtf-8 tail: keep lone surrogates as ED A0..BF rather than U+FFFD
134
+ for (; i < n; i++) {
135
+ let c = s.charCodeAt(i);
136
+ if (c < 0x80) {
137
+ pool[p++] = c;
138
+ } else if (c < 0x800) {
139
+ pool[p++] = 0xC0 | (c >> 6);
140
+ pool[p++] = 0x80 | (c & 0x3F);
141
+ } else if (c >= 0xD800 && c <= 0xDBFF && i + 1 < n &&
142
+ s.charCodeAt(i + 1) >= 0xDC00 && s.charCodeAt(i + 1) <= 0xDFFF) {
143
+ c = 0x10000 + ((c - 0xD800) << 10) + (s.charCodeAt(++i) - 0xDC00);
144
+ pool[p++] = 0xF0 | (c >> 18);
145
+ pool[p++] = 0x80 | ((c >> 12) & 0x3F);
146
+ pool[p++] = 0x80 | ((c >> 6) & 0x3F);
147
+ pool[p++] = 0x80 | (c & 0x3F);
148
+ } else {
149
+ pool[p++] = 0xE0 | (c >> 12);
150
+ pool[p++] = 0x80 | ((c >> 6) & 0x3F);
151
+ pool[p++] = 0x80 | (c & 0x3F);
152
+ }
142
153
  }
154
+ const r = { start, end: p };
155
+ poolLen = p;
143
156
  strMap.set(s, r);
144
157
  return r;
145
158
  }
@@ -265,7 +278,6 @@ function encode(program, lineStarts) {
265
278
  tagAt(idx, 7);
266
279
  slotAt(idx, 0, pat);
267
280
  spanAt(idx, asStart(p), asEnd(p));
268
- recordComments(p, idx);
269
281
  return idx;
270
282
  }
271
283
  function enc_binary_expression(n) {
@@ -675,10 +687,12 @@ function encode(program, lineStarts) {
675
687
  const v = (n.value || {});
676
688
  const undef = v.cooked == null;
677
689
  const c = encStr(undef ? "" : v.cooked);
690
+ const r = encStr(v.raw);
678
691
  const idx = alloc();
679
692
  tagAt(idx, 41);
680
693
  flagsAt(idx, (n.tail ? 1 : 0) | (undef ? 2 : 0));
681
694
  slotAt(idx, 0, c.start); slotAt(idx, 1, c.end);
695
+ slotAt(idx, 2, r.start); slotAt(idx, 3, r.end);
682
696
  spanAt(idx, asStart(n), asEnd(n));
683
697
  recordComments(n, idx);
684
698
  return idx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuku-codegen",
3
- "version": "0.5.28",
3
+ "version": "0.5.31",
4
4
  "description": "High-performance JavaScript/TypeScript code generator written in Zig",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,17 +17,17 @@
17
17
  "encode.js"
18
18
  ],
19
19
  "optionalDependencies": {
20
- "@yuku-codegen/binding-linux-x64-gnu": "0.5.28",
21
- "@yuku-codegen/binding-linux-arm64-gnu": "0.5.28",
22
- "@yuku-codegen/binding-linux-arm-gnu": "0.5.28",
23
- "@yuku-codegen/binding-linux-x64-musl": "0.5.28",
24
- "@yuku-codegen/binding-linux-arm64-musl": "0.5.28",
25
- "@yuku-codegen/binding-linux-arm-musl": "0.5.28",
26
- "@yuku-codegen/binding-darwin-x64": "0.5.28",
27
- "@yuku-codegen/binding-darwin-arm64": "0.5.28",
28
- "@yuku-codegen/binding-win32-x64": "0.5.28",
29
- "@yuku-codegen/binding-win32-arm64": "0.5.28",
30
- "@yuku-codegen/binding-freebsd-x64": "0.5.28"
20
+ "@yuku-codegen/binding-linux-x64-gnu": "0.5.31",
21
+ "@yuku-codegen/binding-linux-arm64-gnu": "0.5.31",
22
+ "@yuku-codegen/binding-linux-arm-gnu": "0.5.31",
23
+ "@yuku-codegen/binding-linux-x64-musl": "0.5.31",
24
+ "@yuku-codegen/binding-linux-arm64-musl": "0.5.31",
25
+ "@yuku-codegen/binding-linux-arm-musl": "0.5.31",
26
+ "@yuku-codegen/binding-darwin-x64": "0.5.31",
27
+ "@yuku-codegen/binding-darwin-arm64": "0.5.31",
28
+ "@yuku-codegen/binding-win32-x64": "0.5.31",
29
+ "@yuku-codegen/binding-win32-arm64": "0.5.31",
30
+ "@yuku-codegen/binding-freebsd-x64": "0.5.31"
31
31
  },
32
32
  "keywords": [
33
33
  "ast",
@@ -40,6 +40,6 @@
40
40
  "typescript"
41
41
  ],
42
42
  "peerDependencies": {
43
- "yuku-parser": "0.5.22"
43
+ "yuku-parser": "0.5.28"
44
44
  }
45
45
  }