yuku-codegen 0.5.10 → 0.5.14

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 (4) hide show
  1. package/README.md +14 -4
  2. package/encode.js +1 -5
  3. package/index.js +8 -4
  4. package/package.json +13 -13
package/README.md CHANGED
@@ -42,7 +42,7 @@ interface CodegenResult {
42
42
  }
43
43
  ```
44
44
 
45
- `errors` is empty on a clean run. `map` is non-null only when `sourceMaps` is set.
45
+ `errors` is empty on a clean run. `map` is non-null only when `sourceMaps` is enabled.
46
46
 
47
47
  ## Options
48
48
 
@@ -52,7 +52,7 @@ const result = print(ast, {
52
52
  indent: 2,
53
53
  quotes: "double",
54
54
  comments: "some",
55
- sourceMaps: { sourceFileName: "in.js" },
55
+ sourceMaps: true,
56
56
  });
57
57
  ```
58
58
 
@@ -62,11 +62,21 @@ const result = print(ast, {
62
62
  | `indent` | `number` | `2` | Spaces per indentation level. Applies in pretty mode only. |
63
63
  | `quotes` | `"double" \| "single"` | `"double"` | Quote style for emitted string literals. |
64
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. |
65
+ | `sourceMaps` | `boolean \| SourceMapOptions` | `false` | `true` emits a Source Map V3 with default metadata; pass an object for fine-grained control. See [Source maps](#source-maps). |
66
66
 
67
67
  ## Source maps
68
68
 
69
- Pass `sourceMaps` to emit a Source Map V3 alongside the generated code.
69
+ Set `sourceMaps: true` for a Source Map V3 with default metadata, or pass a `SourceMapOptions` object to fill in `file`, `sources`, `sourcesContent`, and `sourceRoot`. `false` (or omitting the field) disables map output.
70
+
71
+ ```js
72
+ import { parse } from "yuku-parser";
73
+ import { print } from "yuku-codegen";
74
+
75
+ const ast = parse(`const x = 1;`);
76
+ const { map } = print(ast, { sourceMaps: true });
77
+ ```
78
+
79
+ For a map with embedded source information:
70
80
 
71
81
  ```js
72
82
  import { parse } from "yuku-parser";
package/encode.js CHANGED
@@ -12,13 +12,11 @@ const NODE_SPAN_START_U32 = 10;
12
12
  const NODE_SPAN_END_U32 = 11;
13
13
  const COMMENT_SIZE = 20;
14
14
  const COMMENT_TYPE_OFFSET = 0;
15
- const COMMENT_KIND_OFFSET = 1;
16
- const COMMENT_FLAGS_OFFSET = 2;
15
+ const COMMENT_FLAGS_OFFSET = 1;
17
16
  const COMMENT_START_OFFSET = 4;
18
17
  const COMMENT_END_OFFSET = 8;
19
18
  const COMMENT_VALUE_START_OFFSET = 12;
20
19
  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};
22
20
  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};
23
21
  const LOGICAL_OPS_INV = {"&&": 0, "||": 1, "??": 2};
24
22
  const UNARY_OPS_INV = {"-": 0, "+": 1, "!": 2, "~": 3, "typeof": 4, "void": 5, "delete": 6};
@@ -2065,13 +2063,11 @@ function encode(estree, comments, lineStarts) {
2065
2063
  for (let i = 0; i < commentCount; i++) {
2066
2064
  const c = comments[i];
2067
2065
  const v = encStr(typeof c.value === "string" ? c.value : "");
2068
- const kind = typeof c.kind === "string" ? (COMMENT_KINDS_INV[c.kind] ?? 0) : 0;
2069
2066
  let flags = 0;
2070
2067
  if (c.precededByNewline) flags |= 1;
2071
2068
  if (c.followedByNewline) flags |= 2;
2072
2069
  const o = i * COMMENT_SIZE;
2073
2070
  cU8[o + COMMENT_TYPE_OFFSET] = c.type === "Block" ? 1 : 0;
2074
- cU8[o + COMMENT_KIND_OFFSET] = kind;
2075
2071
  cU8[o + COMMENT_FLAGS_OFFSET] = flags;
2076
2072
  cDV.setUint32(o + COMMENT_START_OFFSET, (c.start >>> 0), true);
2077
2073
  cDV.setUint32(o + COMMENT_END_OFFSET, (c.end >>> 0), true);
package/index.js CHANGED
@@ -3,10 +3,14 @@ import { encode } from "./encode.js";
3
3
 
4
4
  function normalizeOptions(options) {
5
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
+ const next = { ...options };
7
+ const c = next.comments;
8
+ if (c === true) next.comments = "all";
9
+ else if (c === false) next.comments = "none";
10
+ const s = next.sourceMaps;
11
+ if (s === true) next.sourceMaps = {};
12
+ else if (s === false) next.sourceMaps = undefined;
13
+ return next;
10
14
  }
11
15
 
12
16
  function encodeAst(ast) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuku-codegen",
3
- "version": "0.5.10",
3
+ "version": "0.5.14",
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.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"
20
+ "@yuku-codegen/binding-linux-x64-gnu": "0.5.14",
21
+ "@yuku-codegen/binding-linux-arm64-gnu": "0.5.14",
22
+ "@yuku-codegen/binding-linux-arm-gnu": "0.5.14",
23
+ "@yuku-codegen/binding-linux-x64-musl": "0.5.14",
24
+ "@yuku-codegen/binding-linux-arm64-musl": "0.5.14",
25
+ "@yuku-codegen/binding-linux-arm-musl": "0.5.14",
26
+ "@yuku-codegen/binding-darwin-x64": "0.5.14",
27
+ "@yuku-codegen/binding-darwin-arm64": "0.5.14",
28
+ "@yuku-codegen/binding-win32-x64": "0.5.14",
29
+ "@yuku-codegen/binding-win32-arm64": "0.5.14",
30
+ "@yuku-codegen/binding-freebsd-x64": "0.5.14"
31
31
  },
32
32
  "keywords": [
33
33
  "ast",
@@ -40,6 +40,6 @@
40
40
  "typescript"
41
41
  ],
42
42
  "dependencies": {
43
- "yuku-parser": "workspace:*"
43
+ "yuku-parser": "0.5.10"
44
44
  }
45
45
  }