yuku-codegen 0.5.9 → 0.5.10
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 -44
- package/encode.js +60 -10
- package/index.d.ts +25 -11
- package/index.js +18 -6
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# yuku-codegen
|
|
2
2
|
|
|
3
|
-
A high-performance JavaScript
|
|
3
|
+
A high-performance JavaScript and TypeScript code generator written in Zig, powered by [Yuku](https://github.com/yuku-toolchain/yuku).
|
|
4
4
|
|
|
5
|
-
Renders an ESTree / TypeScript-ESTree AST back to source code, with optional Source Map V3 output. The input
|
|
5
|
+
Renders an ESTree / TypeScript-ESTree AST back to source code, with optional Source Map V3 output. The input is exactly the `ParseResult` produced by [`yuku-parser`](https://www.npmjs.com/package/yuku-parser).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -16,21 +16,23 @@ npm install yuku-codegen
|
|
|
16
16
|
import { parse } from "yuku-parser";
|
|
17
17
|
import { print } from "yuku-codegen";
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const { code } = print(
|
|
19
|
+
const ast = parse("const x = 1 + 2;");
|
|
20
|
+
const { code } = print(ast);
|
|
21
21
|
|
|
22
22
|
console.log(code); // "const x = 1 + 2;"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## API
|
|
26
26
|
|
|
27
|
-
Three entry points share the same options shape
|
|
27
|
+
Three entry points share the same options and result shape. Each accepts the full `ParseResult` from `yuku-parser`.
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
| Function | Behavior |
|
|
30
|
+
| -------- | ----------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `print` | Renders verbatim, preserving TypeScript syntax. |
|
|
32
|
+
| `strip` | Drops type-only syntax and emits plain JavaScript. See [TypeScript stripping](#typescript-stripping). |
|
|
33
|
+
| `minify` | Applies size-reducing rewrites at print time. See [Minification](#minification). |
|
|
32
34
|
|
|
33
|
-
All return
|
|
35
|
+
All return a `CodegenResult`:
|
|
34
36
|
|
|
35
37
|
```ts
|
|
36
38
|
interface CodegenResult {
|
|
@@ -40,7 +42,7 @@ interface CodegenResult {
|
|
|
40
42
|
}
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
`errors` is empty
|
|
45
|
+
`errors` is empty on a clean run. `map` is non-null only when `sourceMaps` is set.
|
|
44
46
|
|
|
45
47
|
## Options
|
|
46
48
|
|
|
@@ -49,54 +51,54 @@ const result = print(ast, {
|
|
|
49
51
|
format: "pretty",
|
|
50
52
|
indent: 2,
|
|
51
53
|
quotes: "double",
|
|
52
|
-
|
|
54
|
+
comments: "some",
|
|
55
|
+
sourceMaps: { sourceFileName: "in.js" },
|
|
53
56
|
});
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
| Option |
|
|
57
|
-
| ------------ |
|
|
58
|
-
| `format` | `"pretty"
|
|
59
|
-
| `indent` | `number`
|
|
60
|
-
| `quotes` | `"double"
|
|
61
|
-
| `
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
| ------------ | ---------------------------------------- | ---------- | ---------------------------------------------------------------------------- |
|
|
61
|
+
| `format` | `"pretty" \| "compact"` | `"pretty"` | Whitespace mode. `"compact"` emits only the separators the grammar requires. |
|
|
62
|
+
| `indent` | `number` | `2` | Spaces per indentation level. Applies in pretty mode only. |
|
|
63
|
+
| `quotes` | `"double" \| "single"` | `"double"` | Quote style for emitted string literals. |
|
|
64
|
+
| `comments` | `boolean \| "some" \| "line" \| "block"` | `"some"` | Comment passthrough filter. See [Comments](#comments). |
|
|
65
|
+
| `sourceMaps` | `SourceMapOptions` | _disabled_ | Pass an object to emit a Source Map V3 alongside the code. Omit to skip. |
|
|
62
66
|
|
|
63
67
|
## Source maps
|
|
64
68
|
|
|
65
|
-
Pass `sourceMaps` to emit a Source Map V3 alongside the code.
|
|
69
|
+
Pass `sourceMaps` to emit a Source Map V3 alongside the generated code.
|
|
66
70
|
|
|
67
71
|
```js
|
|
68
72
|
import { parse } from "yuku-parser";
|
|
69
73
|
import { print } from "yuku-codegen";
|
|
70
74
|
|
|
71
75
|
const source = `const greet = (name) => "Hello, " + name;`;
|
|
72
|
-
const
|
|
76
|
+
const ast = parse(source);
|
|
73
77
|
|
|
74
|
-
const { code, map } = print(
|
|
78
|
+
const { code, map } = print(ast, {
|
|
75
79
|
sourceMaps: {
|
|
76
|
-
source,
|
|
77
80
|
file: "out.js",
|
|
78
81
|
sourceFileName: "in.js",
|
|
79
|
-
sourcesContent:
|
|
82
|
+
sourcesContent: source,
|
|
80
83
|
},
|
|
81
84
|
});
|
|
82
85
|
|
|
83
|
-
await Bun.write("out.js", code
|
|
86
|
+
await Bun.write("out.js", `${code}\n//# sourceMappingURL=out.js.map`);
|
|
84
87
|
await Bun.write("out.js.map", JSON.stringify(map));
|
|
85
88
|
```
|
|
86
89
|
|
|
87
90
|
### `SourceMapOptions`
|
|
88
91
|
|
|
89
|
-
| Field
|
|
90
|
-
|
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `sourcesContent` | `boolean` | no | When `true`, embeds `source` into the map's `sourcesContent`. |
|
|
92
|
+
| Field | Type | Description |
|
|
93
|
+
| ---------------- | -------- | ----------------------------------------------------------------------------------- |
|
|
94
|
+
| `file` | `string` | Output filename, embedded as the map's `file`. |
|
|
95
|
+
| `sourceFileName` | `string` | Source filename, embedded as the single entry of `sources`. |
|
|
96
|
+
| `sourceRoot` | `string` | Prefix embedded as `sourceRoot`. |
|
|
97
|
+
| `sourcesContent` | `string` | When set, embedded as the single entry of the map's `sourcesContent`. Omit to skip. |
|
|
96
98
|
|
|
97
|
-
###
|
|
99
|
+
### Output shape
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
`map` is a Source Map V3 object, ready to serialize with `JSON.stringify`:
|
|
100
102
|
|
|
101
103
|
```ts
|
|
102
104
|
interface SourceMap {
|
|
@@ -110,39 +112,57 @@ interface SourceMap {
|
|
|
110
112
|
}
|
|
111
113
|
```
|
|
112
114
|
|
|
113
|
-
Columns are 0-indexed UTF-16 code units, matching
|
|
115
|
+
Columns are 0-indexed UTF-16 code units, matching Chrome DevTools and consumer-side libraries like `@jridgewell/trace-mapping` and `source-map`.
|
|
114
116
|
|
|
115
117
|
## TypeScript stripping
|
|
116
118
|
|
|
117
|
-
`strip` rewrites the AST as plain JavaScript
|
|
119
|
+
`strip` rewrites the AST as plain JavaScript.
|
|
118
120
|
|
|
119
121
|
```js
|
|
120
122
|
import { parse } from "yuku-parser";
|
|
121
123
|
import { strip } from "yuku-codegen";
|
|
122
124
|
|
|
123
|
-
const
|
|
124
|
-
console.log(strip(
|
|
125
|
+
const ast = parse(`const x: number = 1;`, { lang: "ts" });
|
|
126
|
+
console.log(strip(ast).code); // "const x = 1;"
|
|
125
127
|
```
|
|
126
128
|
|
|
127
|
-
Type annotations, type aliases, interfaces, and other type-only constructs are dropped. Constructs that
|
|
129
|
+
Type annotations, type aliases, interfaces, and other type-only constructs are dropped. Constructs that have no clean JavaScript equivalent (`enum`, `namespace`, `import = require()`, `export =`) are reported in `errors` and elided. The output is always syntactically valid JavaScript.
|
|
130
|
+
|
|
131
|
+
## Comments
|
|
132
|
+
|
|
133
|
+
The `comments` option selects which entries from `ast.comments` are emitted. The default is `"some"`, which matches the bundler convention of keeping legal banners, JSDoc, and tree-shaking annotations while dropping plain noise.
|
|
134
|
+
|
|
135
|
+
| Value | Behavior |
|
|
136
|
+
| --------- | --------------------------------------------------------------- |
|
|
137
|
+
| `"some"` | Emit legal headers, JSDoc, and `@`/`#` annotations. _(default)_ |
|
|
138
|
+
| `true` | Emit every comment. |
|
|
139
|
+
| `false` | Drop every comment. |
|
|
140
|
+
| `"line"` | Emit `// ...` only. |
|
|
141
|
+
| `"block"` | Emit `/* ... */` only. |
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const ast = parse(`// hello\nconst x = 1;`);
|
|
145
|
+
print(ast, { comments: true }).code;
|
|
146
|
+
// "// hello\nconst x = 1;"
|
|
147
|
+
```
|
|
128
148
|
|
|
129
149
|
## Minification
|
|
130
150
|
|
|
131
151
|
`minify` applies size-reducing rewrites at print time:
|
|
132
152
|
|
|
133
|
-
- `true`
|
|
134
|
-
- `undefined`
|
|
135
|
-
- `Infinity`
|
|
136
|
-
-
|
|
137
|
-
- `obj["foo"]`
|
|
138
|
-
- `{ "foo": x }`
|
|
153
|
+
- `true` and `false` rewrite to `!0` and `!1`.
|
|
154
|
+
- `undefined` rewrites to `void 0` (in expression position).
|
|
155
|
+
- `Infinity` rewrites to `1/0`.
|
|
156
|
+
- Numeric literals shorten to their shortest form (`1000000` becomes `1e6`, `0.5` becomes `.5`).
|
|
157
|
+
- `obj["foo"]` rewrites to `obj.foo` when the key is a valid identifier.
|
|
158
|
+
- `{ "foo": x }` rewrites to `{ foo: x }` when safe.
|
|
139
159
|
|
|
140
160
|
Combine with `format: "compact"` for full minification:
|
|
141
161
|
|
|
142
162
|
```js
|
|
143
163
|
import { minify } from "yuku-codegen";
|
|
144
164
|
|
|
145
|
-
const { code } = minify(
|
|
165
|
+
const { code } = minify(ast, { format: "compact" });
|
|
146
166
|
```
|
|
147
167
|
|
|
148
168
|
## License
|
package/encode.js
CHANGED
|
@@ -4,12 +4,21 @@
|
|
|
4
4
|
const NULL = 0xFFFFFFFF;
|
|
5
5
|
const _enc = new TextEncoder();
|
|
6
6
|
const NODE_SIZE = 48;
|
|
7
|
-
const HEADER_SIZE =
|
|
7
|
+
const HEADER_SIZE = 40;
|
|
8
8
|
const NODE_FLAGS_OFFSET = 2;
|
|
9
9
|
const NODE_FIELD0_OFFSET = 4;
|
|
10
10
|
const NODE_HEADER_U32S = 2;
|
|
11
11
|
const NODE_SPAN_START_U32 = 10;
|
|
12
12
|
const NODE_SPAN_END_U32 = 11;
|
|
13
|
+
const COMMENT_SIZE = 20;
|
|
14
|
+
const COMMENT_TYPE_OFFSET = 0;
|
|
15
|
+
const COMMENT_KIND_OFFSET = 1;
|
|
16
|
+
const COMMENT_FLAGS_OFFSET = 2;
|
|
17
|
+
const COMMENT_START_OFFSET = 4;
|
|
18
|
+
const COMMENT_END_OFFSET = 8;
|
|
19
|
+
const COMMENT_VALUE_START_OFFSET = 12;
|
|
20
|
+
const COMMENT_VALUE_END_OFFSET = 16;
|
|
21
|
+
const COMMENT_KINDS_INV = {"normal": 0, "legal": 1, "jsdoc": 2, "annotation": 3, "pure": 4, "no_side_effects": 5};
|
|
13
22
|
const BINARY_OPS_INV = {"==": 0, "!=": 1, "===": 2, "!==": 3, "<": 4, "<=": 5, ">": 6, ">=": 7, "+": 8, "-": 9, "*": 10, "/": 11, "%": 12, "**": 13, "|": 14, "^": 15, "&": 16, "<<": 17, ">>": 18, ">>>": 19, "in": 20, "instanceof": 21};
|
|
14
23
|
const LOGICAL_OPS_INV = {"&&": 0, "||": 1, "??": 2};
|
|
15
24
|
const UNARY_OPS_INV = {"-": 0, "+": 1, "!": 2, "~": 3, "typeof": 4, "void": 5, "delete": 6};
|
|
@@ -26,7 +35,7 @@ const IMPORT_PHASE_INV = {"source": 0, "defer": 1};
|
|
|
26
35
|
const ACCESSIBILITY_INV = (v) => v == null ? 0 : v === "public" ? 1 : v === "private" ? 2 : 3;
|
|
27
36
|
const TS_MAPPED_OPTIONAL_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
|
|
28
37
|
const TS_MAPPED_READONLY_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
|
|
29
|
-
function encode(estree) {
|
|
38
|
+
function encode(estree, comments, lineStarts) {
|
|
30
39
|
let nodeCap = 512;
|
|
31
40
|
let nodeAB = new ArrayBuffer(nodeCap * NODE_SIZE);
|
|
32
41
|
let nU8 = new Uint8Array(nodeAB);
|
|
@@ -2046,9 +2055,42 @@ function encode(estree) {
|
|
|
2046
2055
|
}
|
|
2047
2056
|
}
|
|
2048
2057
|
const progIdx = encNode(estree);
|
|
2058
|
+
// Comments are encoded after the node walk so string interning lands in the pool first.
|
|
2059
|
+
const commentCount = Array.isArray(comments) ? comments.length : 0;
|
|
2060
|
+
let commentBytes = null;
|
|
2061
|
+
if (commentCount > 0) {
|
|
2062
|
+
commentBytes = new ArrayBuffer(commentCount * COMMENT_SIZE);
|
|
2063
|
+
const cU8 = new Uint8Array(commentBytes);
|
|
2064
|
+
const cDV = new DataView(commentBytes);
|
|
2065
|
+
for (let i = 0; i < commentCount; i++) {
|
|
2066
|
+
const c = comments[i];
|
|
2067
|
+
const v = encStr(typeof c.value === "string" ? c.value : "");
|
|
2068
|
+
const kind = typeof c.kind === "string" ? (COMMENT_KINDS_INV[c.kind] ?? 0) : 0;
|
|
2069
|
+
let flags = 0;
|
|
2070
|
+
if (c.precededByNewline) flags |= 1;
|
|
2071
|
+
if (c.followedByNewline) flags |= 2;
|
|
2072
|
+
const o = i * COMMENT_SIZE;
|
|
2073
|
+
cU8[o + COMMENT_TYPE_OFFSET] = c.type === "Block" ? 1 : 0;
|
|
2074
|
+
cU8[o + COMMENT_KIND_OFFSET] = kind;
|
|
2075
|
+
cU8[o + COMMENT_FLAGS_OFFSET] = flags;
|
|
2076
|
+
cDV.setUint32(o + COMMENT_START_OFFSET, (c.start >>> 0), true);
|
|
2077
|
+
cDV.setUint32(o + COMMENT_END_OFFSET, (c.end >>> 0), true);
|
|
2078
|
+
cDV.setUint32(o + COMMENT_VALUE_START_OFFSET, v.start, true);
|
|
2079
|
+
cDV.setUint32(o + COMMENT_VALUE_END_OFFSET, v.end, true);
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
const lineStartsCount = Array.isArray(lineStarts) ? lineStarts.length : 0;
|
|
2083
|
+
let lineStartsBytes = null;
|
|
2084
|
+
if (lineStartsCount > 0) {
|
|
2085
|
+
lineStartsBytes = new ArrayBuffer(lineStartsCount * 4);
|
|
2086
|
+
const lsDV = new DataView(lineStartsBytes);
|
|
2087
|
+
for (let i = 0; i < lineStartsCount; i++) lsDV.setUint32(i * 4, lineStarts[i] >>> 0, true);
|
|
2088
|
+
}
|
|
2049
2089
|
const totalNodeBytes = nodeCount * NODE_SIZE;
|
|
2050
2090
|
const totalExtraBytes = extraCount * 4;
|
|
2051
|
-
const
|
|
2091
|
+
const totalCommentBytes = commentCount * COMMENT_SIZE;
|
|
2092
|
+
const totalLineStartsBytes = lineStartsCount * 4;
|
|
2093
|
+
const finalSize = HEADER_SIZE + totalNodeBytes + totalExtraBytes + poolLen + totalCommentBytes + totalLineStartsBytes;
|
|
2052
2094
|
const out = new ArrayBuffer(finalSize);
|
|
2053
2095
|
const outU8 = new Uint8Array(out);
|
|
2054
2096
|
const outU32 = new Uint32Array(out, 0, (finalSize >>> 2));
|
|
@@ -2056,14 +2098,22 @@ function encode(estree) {
|
|
|
2056
2098
|
outU32[1] = extraCount;
|
|
2057
2099
|
outU32[2] = poolLen;
|
|
2058
2100
|
outU32[3] = 0;
|
|
2059
|
-
outU32[4] =
|
|
2060
|
-
outU32[5] =
|
|
2061
|
-
outU32[6] =
|
|
2062
|
-
outU32[7] =
|
|
2101
|
+
outU32[4] = commentCount;
|
|
2102
|
+
outU32[5] = lineStartsCount;
|
|
2103
|
+
outU32[6] = 0;
|
|
2104
|
+
outU32[7] = progIdx;
|
|
2063
2105
|
outU32[8] = 0;
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2106
|
+
outU32[9] = 0;
|
|
2107
|
+
const nodesOff = HEADER_SIZE;
|
|
2108
|
+
const extrasOff = nodesOff + totalNodeBytes;
|
|
2109
|
+
const poolOff = extrasOff + totalExtraBytes;
|
|
2110
|
+
const commentsOff = poolOff + poolLen;
|
|
2111
|
+
const lineStartsOff = commentsOff + totalCommentBytes;
|
|
2112
|
+
outU8.set(new Uint8Array(nodeAB, 0, totalNodeBytes), nodesOff);
|
|
2113
|
+
outU8.set(new Uint8Array(extras.buffer, 0, totalExtraBytes), extrasOff);
|
|
2114
|
+
outU8.set(pool.subarray(0, poolLen), poolOff);
|
|
2115
|
+
if (commentBytes !== null) outU8.set(new Uint8Array(commentBytes), commentsOff);
|
|
2116
|
+
if (lineStartsBytes !== null) outU8.set(new Uint8Array(lineStartsBytes), lineStartsOff);
|
|
2067
2117
|
return out;
|
|
2068
2118
|
}
|
|
2069
2119
|
export { encode };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Comment, ParseResult } from "yuku-parser";
|
|
2
2
|
|
|
3
3
|
/** Whitespace mode for the generated output. */
|
|
4
4
|
export type Format = "pretty" | "compact";
|
|
@@ -6,21 +6,29 @@ export type Format = "pretty" | "compact";
|
|
|
6
6
|
/** Quote style for emitted string literals. */
|
|
7
7
|
export type Quotes = "double" | "single";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Comment passthrough filter.
|
|
11
|
+
*
|
|
12
|
+
* - `false`: drop all comments.
|
|
13
|
+
* - `true` or `"all"`: emit every comment.
|
|
14
|
+
* - `"some"`: emit legal headers, JSDoc, and `@__*__` annotations.
|
|
15
|
+
* - `"line"`: emit `// ...` only.
|
|
16
|
+
* - `"block"`: emit block comments only.
|
|
17
|
+
*/
|
|
18
|
+
export type Comments = boolean | "all" | "some" | "line" | "block";
|
|
19
|
+
|
|
20
|
+
export type { Comment };
|
|
21
|
+
|
|
9
22
|
/** Source-map configuration. Pass to `CodegenOptions.sourceMaps` to enable. */
|
|
10
23
|
export interface SourceMapOptions {
|
|
11
|
-
/** Original source the AST was parsed from. Required. */
|
|
12
|
-
source: string;
|
|
13
24
|
/** Output filename, embedded as the map's `file`. */
|
|
14
25
|
file?: string;
|
|
15
26
|
/** Source filename, embedded as the single entry of `sources`. */
|
|
16
27
|
sourceFileName?: string;
|
|
17
28
|
/** Prefix embedded as `sourceRoot`. */
|
|
18
29
|
sourceRoot?: string;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
* @default false
|
|
22
|
-
*/
|
|
23
|
-
sourcesContent?: boolean;
|
|
30
|
+
/** When set, embedded as the single entry of the map's `sourcesContent`. */
|
|
31
|
+
sourcesContent?: string;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/** Codegen options shared by `print`, `strip`, and `minify`. */
|
|
@@ -36,6 +44,12 @@ export interface CodegenOptions {
|
|
|
36
44
|
quotes?: Quotes;
|
|
37
45
|
/** Pass to enable source maps. Omit to disable. */
|
|
38
46
|
sourceMaps?: SourceMapOptions;
|
|
47
|
+
/**
|
|
48
|
+
* Comment passthrough filter. Defaults to `"some"`, which preserves
|
|
49
|
+
* legal headers, JSDoc, and tree-shaking annotations.
|
|
50
|
+
* @default "some"
|
|
51
|
+
*/
|
|
52
|
+
comments?: Comments;
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
/** A codegen-detected problem in the input AST. */
|
|
@@ -69,13 +83,13 @@ export interface CodegenResult {
|
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
/** Renders the AST verbatim, preserving TypeScript syntax. */
|
|
72
|
-
export function print(
|
|
86
|
+
export function print(ast: ParseResult, options?: CodegenOptions): CodegenResult;
|
|
73
87
|
|
|
74
88
|
/** Renders the AST as JavaScript, dropping TypeScript-specific syntax. */
|
|
75
|
-
export function strip(
|
|
89
|
+
export function strip(ast: ParseResult, options?: CodegenOptions): CodegenResult;
|
|
76
90
|
|
|
77
91
|
/**
|
|
78
92
|
* Renders the AST with size-reducing rewrites. Combine with
|
|
79
93
|
* `format: "compact"` for full minification.
|
|
80
94
|
*/
|
|
81
|
-
export function minify(
|
|
95
|
+
export function minify(ast: ParseResult, options?: CodegenOptions): CodegenResult;
|
package/index.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import binding from "./binding.js";
|
|
2
2
|
import { encode } from "./encode.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
function normalizeOptions(options) {
|
|
5
|
+
if (options == null) return {};
|
|
6
|
+
const c = options.comments;
|
|
7
|
+
if (c === true) return { ...options, comments: "all" };
|
|
8
|
+
if (c === false) return { ...options, comments: "none" };
|
|
9
|
+
return options;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
return
|
|
12
|
+
function encodeAst(ast) {
|
|
13
|
+
return encode(ast.program, ast.comments, ast.lineStarts);
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export function
|
|
13
|
-
return binding.
|
|
16
|
+
export function print(ast, options) {
|
|
17
|
+
return binding.print(encodeAst(ast), normalizeOptions(options));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function strip(ast, options) {
|
|
21
|
+
return binding.strip(encodeAst(ast), normalizeOptions(options));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function minify(ast, options) {
|
|
25
|
+
return binding.minify(encodeAst(ast), normalizeOptions(options));
|
|
14
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuku-codegen",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "High-performance JavaScript/TypeScript code generator written in Zig",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,29 +17,29 @@
|
|
|
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.
|
|
31
|
-
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"yuku-parser": "workspace:*"
|
|
20
|
+
"@yuku-codegen/binding-linux-x64-gnu": "0.5.10",
|
|
21
|
+
"@yuku-codegen/binding-linux-arm64-gnu": "0.5.10",
|
|
22
|
+
"@yuku-codegen/binding-linux-arm-gnu": "0.5.10",
|
|
23
|
+
"@yuku-codegen/binding-linux-x64-musl": "0.5.10",
|
|
24
|
+
"@yuku-codegen/binding-linux-arm64-musl": "0.5.10",
|
|
25
|
+
"@yuku-codegen/binding-linux-arm-musl": "0.5.10",
|
|
26
|
+
"@yuku-codegen/binding-darwin-x64": "0.5.10",
|
|
27
|
+
"@yuku-codegen/binding-darwin-arm64": "0.5.10",
|
|
28
|
+
"@yuku-codegen/binding-win32-x64": "0.5.10",
|
|
29
|
+
"@yuku-codegen/binding-win32-arm64": "0.5.10",
|
|
30
|
+
"@yuku-codegen/binding-freebsd-x64": "0.5.10"
|
|
34
31
|
},
|
|
35
32
|
"keywords": [
|
|
36
|
-
"codegen",
|
|
37
|
-
"javascript",
|
|
38
|
-
"typescript",
|
|
39
33
|
"ast",
|
|
34
|
+
"codegen",
|
|
40
35
|
"estree",
|
|
41
|
-
"
|
|
36
|
+
"javascript",
|
|
42
37
|
"minifier",
|
|
43
|
-
"napi"
|
|
44
|
-
|
|
38
|
+
"napi",
|
|
39
|
+
"printer",
|
|
40
|
+
"typescript"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"yuku-parser": "workspace:*"
|
|
44
|
+
}
|
|
45
45
|
}
|