yuku-codegen 0.5.41 → 0.5.43
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 +6 -6
- package/encode.js +7 -20
- package/index.d.ts +4 -5
- package/index.js +2 -16
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const out = print(program, {
|
|
|
52
52
|
indent: 2,
|
|
53
53
|
quotes: "preserve",
|
|
54
54
|
comments: "some",
|
|
55
|
-
sourceMaps: {
|
|
55
|
+
sourceMaps: { source },
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -62,22 +62,22 @@ const out = print(program, {
|
|
|
62
62
|
| `indent` | `number` | `2` | Spaces per indentation level. Applies in pretty mode only. |
|
|
63
63
|
| `quotes` | `"preserve" \| "double" \| "single"` | `"preserve"` | Quote style for string literals. `"preserve"` keeps each literal's source quote style (re-escaping the content); `"double"` / `"single"` force one. |
|
|
64
64
|
| `comments` | `boolean \| "some" \| "line" \| "block"` | `"some"` | Comment passthrough filter. See [Comments](#comments). |
|
|
65
|
-
| `sourceMaps` | `SourceMapOptions` | `undefined` | Pass an object to emit a Source Map V3. Its `
|
|
65
|
+
| `sourceMaps` | `SourceMapOptions` | `undefined` | Pass an object to emit a Source Map V3. Its `source` is required, the rest of the metadata is optional. See [Source maps](#source-maps). |
|
|
66
66
|
|
|
67
67
|
## Source maps
|
|
68
68
|
|
|
69
|
-
Pass a `SourceMapOptions` object to emit a Source Map V3. Its `
|
|
69
|
+
Pass a `SourceMapOptions` object to emit a Source Map V3. Its `source` field is required: feed it the original source text (this is what maps generated positions back to the source). Without it, no map is produced and `map` is `null`. The remaining fields (`file`, `sources`, `sourcesContent`, `sourceRoot`) are optional metadata.
|
|
70
70
|
|
|
71
71
|
```js
|
|
72
72
|
import { parse } from "yuku-parser";
|
|
73
73
|
import { print } from "yuku-codegen";
|
|
74
74
|
|
|
75
75
|
const source = `const greet = (name) => "Hello, " + name;`;
|
|
76
|
-
const { program
|
|
76
|
+
const { program } = parse(source);
|
|
77
77
|
|
|
78
78
|
const { code, map } = print(program, {
|
|
79
79
|
sourceMaps: {
|
|
80
|
-
|
|
80
|
+
source,
|
|
81
81
|
file: "out.js",
|
|
82
82
|
sourceFileName: "in.js",
|
|
83
83
|
sourcesContent: source,
|
|
@@ -92,7 +92,7 @@ await Bun.write("out.js.map", JSON.stringify(map));
|
|
|
92
92
|
|
|
93
93
|
| Field | Type | Description |
|
|
94
94
|
| ---------------- | ---------- | --------------------------------------------------------------------------------- |
|
|
95
|
-
| `
|
|
95
|
+
| `source` | `string` | **Required.** The original source text, used to map positions to the source. |
|
|
96
96
|
| `file` | `string` | Output filename, embedded as the map's `file`. |
|
|
97
97
|
| `sourceFileName` | `string` | Source filename, embedded as the single entry of `sources`. |
|
|
98
98
|
| `sourceRoot` | `string` | Prefix embedded as `sourceRoot`. |
|
package/encode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// generated by tools/estree/encoder.zig, do not edit
|
|
2
2
|
const NULL = 0xFFFFFFFF;
|
|
3
3
|
const NODE_SIZE = 48;
|
|
4
|
-
const HEADER_SIZE =
|
|
4
|
+
const HEADER_SIZE = 40;
|
|
5
5
|
const NODE_FLAGS_OFFSET = 2;
|
|
6
6
|
const NODE_FIELD0_OFFSET = 4;
|
|
7
7
|
const NODE_HEADER_U32S = 2;
|
|
@@ -32,7 +32,7 @@ const ACCESSIBILITY_INV = (v) =>
|
|
|
32
32
|
: 3;
|
|
33
33
|
const TS_MAPPED_OPTIONAL_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
|
|
34
34
|
const TS_MAPPED_READONLY_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
|
|
35
|
-
function encode(program
|
|
35
|
+
function encode(program) {
|
|
36
36
|
const root = program;
|
|
37
37
|
const sizeHint = root.end || 0;
|
|
38
38
|
let nodeCap = Math.max(512, (sizeHint / 7) | 0);
|
|
@@ -2333,23 +2333,13 @@ function encode(program, lineStarts) {
|
|
|
2333
2333
|
}
|
|
2334
2334
|
}
|
|
2335
2335
|
}
|
|
2336
|
-
const lineStartsCount = Array.isArray(lineStarts) ? lineStarts.length : 0;
|
|
2337
|
-
let lineStartsBytes = null;
|
|
2338
|
-
if (lineStartsCount > 0) {
|
|
2339
|
-
lineStartsBytes = new ArrayBuffer(lineStartsCount * 4);
|
|
2340
|
-
const lsDV = new DataView(lineStartsBytes);
|
|
2341
|
-
for (let i = 0; i < lineStartsCount; i++) {
|
|
2342
|
-
lsDV.setUint32(i * 4, lineStarts[i] >>> 0, true);
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
2336
|
const totalNodeBytes = nodeCount * NODE_SIZE;
|
|
2346
2337
|
const totalExtraBytes = extraCount * 4;
|
|
2347
2338
|
const totalOffsetsBytes = attached ? (nodeCount + 1) * 4 : 0;
|
|
2348
2339
|
const totalAttachedBytes = attachedCount * ATTACHED_COMMENT_SIZE;
|
|
2349
|
-
const totalLineStartsBytes = lineStartsCount * 4;
|
|
2350
2340
|
const finalSize =
|
|
2351
2341
|
HEADER_SIZE + totalNodeBytes + totalExtraBytes + poolLen +
|
|
2352
|
-
totalOffsetsBytes + totalAttachedBytes
|
|
2342
|
+
totalOffsetsBytes + totalAttachedBytes;
|
|
2353
2343
|
const out = new ArrayBuffer(finalSize);
|
|
2354
2344
|
const outU8 = new Uint8Array(out);
|
|
2355
2345
|
const outU32 = new Uint32Array(out, 0, (finalSize >>> 2));
|
|
@@ -2359,23 +2349,20 @@ function encode(program, lineStarts) {
|
|
|
2359
2349
|
outU32[3] = 0;
|
|
2360
2350
|
outU32[4] = 0;
|
|
2361
2351
|
outU32[5] = attachedCount;
|
|
2362
|
-
outU32[6] =
|
|
2363
|
-
outU32[7] =
|
|
2364
|
-
outU32[8] =
|
|
2365
|
-
outU32[9] =
|
|
2366
|
-
outU32[10] = 0;
|
|
2352
|
+
outU32[6] = 0;
|
|
2353
|
+
outU32[7] = progIdx;
|
|
2354
|
+
outU32[8] = attached ? FLAG_ATTACHED_COMMENTS : 0;
|
|
2355
|
+
outU32[9] = 0;
|
|
2367
2356
|
const nodesOff = HEADER_SIZE;
|
|
2368
2357
|
const extrasOff = nodesOff + totalNodeBytes;
|
|
2369
2358
|
const poolOff = extrasOff + totalExtraBytes;
|
|
2370
2359
|
const offsetsOff = poolOff + poolLen;
|
|
2371
2360
|
const attachedOff = offsetsOff + totalOffsetsBytes;
|
|
2372
|
-
const lineStartsOff = attachedOff + totalAttachedBytes;
|
|
2373
2361
|
outU8.set(new Uint8Array(nodeAB, 0, totalNodeBytes), nodesOff);
|
|
2374
2362
|
outU8.set(new Uint8Array(extras.buffer, 0, totalExtraBytes), extrasOff);
|
|
2375
2363
|
outU8.set(pool.subarray(0, poolLen), poolOff);
|
|
2376
2364
|
if (offsetsBytes !== null) outU8.set(new Uint8Array(offsetsBytes), offsetsOff);
|
|
2377
2365
|
if (attachedBytes !== null) outU8.set(new Uint8Array(attachedBytes), attachedOff);
|
|
2378
|
-
if (lineStartsBytes !== null) outU8.set(new Uint8Array(lineStartsBytes), lineStartsOff);
|
|
2379
2366
|
return out;
|
|
2380
2367
|
}
|
|
2381
2368
|
export { encode };
|
package/index.d.ts
CHANGED
|
@@ -28,11 +28,10 @@ export type { Comment };
|
|
|
28
28
|
/** Source-map configuration. Pass to `CodegenOptions.sourceMaps` to enable. */
|
|
29
29
|
export interface SourceMapOptions {
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* `
|
|
33
|
-
* back to the original source.
|
|
31
|
+
* The original source text. Required to emit a map; without it, `map` is
|
|
32
|
+
* `null`.
|
|
34
33
|
*/
|
|
35
|
-
|
|
34
|
+
source: string;
|
|
36
35
|
/** Output filename, embedded as the map's `file`. */
|
|
37
36
|
file?: string;
|
|
38
37
|
/** Source filename, embedded as the single entry of `sources`. */
|
|
@@ -56,7 +55,7 @@ export interface CodegenOptions {
|
|
|
56
55
|
quotes?: Quotes;
|
|
57
56
|
/**
|
|
58
57
|
* Enable Source Map V3 output. Pass a {@link SourceMapOptions} object. Its
|
|
59
|
-
* `
|
|
58
|
+
* `source` (the original source text) is required. The rest of the metadata
|
|
60
59
|
* (`file`, `sources`, `sourcesContent`, `sourceRoot`) is optional. Omit to
|
|
61
60
|
* disable.
|
|
62
61
|
* @default undefined
|
package/index.js
CHANGED
|
@@ -7,13 +7,7 @@ function normalizeOptions(options) {
|
|
|
7
7
|
const c = next.comments;
|
|
8
8
|
if (c === true) next.comments = "all";
|
|
9
9
|
else if (c === false) next.comments = "none";
|
|
10
|
-
|
|
11
|
-
if (s) {
|
|
12
|
-
const { lineStarts: _, ...meta } = s;
|
|
13
|
-
next.sourceMaps = meta;
|
|
14
|
-
} else {
|
|
15
|
-
next.sourceMaps = undefined;
|
|
16
|
-
}
|
|
10
|
+
if (next.sourceMaps == null) next.sourceMaps = undefined;
|
|
17
11
|
return next;
|
|
18
12
|
}
|
|
19
13
|
|
|
@@ -24,15 +18,7 @@ function run(method, program, options) {
|
|
|
24
18
|
(program === null ? "null" : typeof program),
|
|
25
19
|
);
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
const lineStarts = sourceMaps ? sourceMaps.lineStarts : null;
|
|
29
|
-
if (sourceMaps && !Array.isArray(lineStarts)) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
"`sourceMaps` requires a `lineStarts` array. Pass the parser's " +
|
|
32
|
-
"`ParseResult.lineStarts`, e.g. `{ sourceMaps: { lineStarts } }`.",
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
return binding[method](encode(program, lineStarts), normalizeOptions(options));
|
|
21
|
+
return binding[method](encode(program), normalizeOptions(options));
|
|
36
22
|
}
|
|
37
23
|
|
|
38
24
|
export function print(program, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuku-codegen",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.43",
|
|
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.
|
|
21
|
-
"@yuku-codegen/binding-linux-arm64-gnu": "0.5.
|
|
22
|
-
"@yuku-codegen/binding-linux-arm-gnu": "0.5.
|
|
23
|
-
"@yuku-codegen/binding-linux-x64-musl": "0.5.
|
|
24
|
-
"@yuku-codegen/binding-linux-arm64-musl": "0.5.
|
|
25
|
-
"@yuku-codegen/binding-linux-arm-musl": "0.5.
|
|
26
|
-
"@yuku-codegen/binding-darwin-x64": "0.5.
|
|
27
|
-
"@yuku-codegen/binding-darwin-arm64": "0.5.
|
|
28
|
-
"@yuku-codegen/binding-win32-x64": "0.5.
|
|
29
|
-
"@yuku-codegen/binding-win32-arm64": "0.5.
|
|
30
|
-
"@yuku-codegen/binding-freebsd-x64": "0.5.
|
|
20
|
+
"@yuku-codegen/binding-linux-x64-gnu": "0.5.43",
|
|
21
|
+
"@yuku-codegen/binding-linux-arm64-gnu": "0.5.43",
|
|
22
|
+
"@yuku-codegen/binding-linux-arm-gnu": "0.5.43",
|
|
23
|
+
"@yuku-codegen/binding-linux-x64-musl": "0.5.43",
|
|
24
|
+
"@yuku-codegen/binding-linux-arm64-musl": "0.5.43",
|
|
25
|
+
"@yuku-codegen/binding-linux-arm-musl": "0.5.43",
|
|
26
|
+
"@yuku-codegen/binding-darwin-x64": "0.5.43",
|
|
27
|
+
"@yuku-codegen/binding-darwin-arm64": "0.5.43",
|
|
28
|
+
"@yuku-codegen/binding-win32-x64": "0.5.43",
|
|
29
|
+
"@yuku-codegen/binding-win32-arm64": "0.5.43",
|
|
30
|
+
"@yuku-codegen/binding-freebsd-x64": "0.5.43"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
33
|
"ast",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"typescript"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@yuku-toolchain/types": "0.5.
|
|
43
|
+
"@yuku-toolchain/types": "0.5.42"
|
|
44
44
|
}
|
|
45
45
|
}
|