yuku-codegen 0.5.14 → 0.5.15

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 (5) hide show
  1. package/README.md +23 -24
  2. package/encode.js +294 -46
  3. package/index.d.ts +10 -5
  4. package/index.js +21 -8
  5. package/package.json +13 -13
package/index.d.ts CHANGED
@@ -42,8 +42,13 @@ export interface CodegenOptions {
42
42
  indent?: number;
43
43
  /** @default "double" */
44
44
  quotes?: Quotes;
45
- /** Pass to enable source maps. Omit to disable. */
46
- sourceMaps?: SourceMapOptions;
45
+ /**
46
+ * Enable Source Map V3 output. `true` uses default metadata; pass a
47
+ * {@link SourceMapOptions} object to fill in `file`, `sources`,
48
+ * `sourcesContent`, and `sourceRoot`.
49
+ * @default false
50
+ */
51
+ sourceMaps?: boolean | SourceMapOptions;
47
52
  /**
48
53
  * Comment passthrough filter. Defaults to `"some"`, which preserves
49
54
  * legal headers, JSDoc, and tree-shaking annotations.
@@ -83,13 +88,13 @@ export interface CodegenResult {
83
88
  }
84
89
 
85
90
  /** Renders the AST verbatim, preserving TypeScript syntax. */
86
- export function print(ast: ParseResult, options?: CodegenOptions): CodegenResult;
91
+ export function print(result: ParseResult, options?: CodegenOptions): CodegenResult;
87
92
 
88
93
  /** Renders the AST as JavaScript, dropping TypeScript-specific syntax. */
89
- export function strip(ast: ParseResult, options?: CodegenOptions): CodegenResult;
94
+ export function strip(result: ParseResult, options?: CodegenOptions): CodegenResult;
90
95
 
91
96
  /**
92
97
  * Renders the AST with size-reducing rewrites. Combine with
93
98
  * `format: "compact"` for full minification.
94
99
  */
95
- export function minify(ast: ParseResult, options?: CodegenOptions): CodegenResult;
100
+ export function minify(result: ParseResult, options?: CodegenOptions): CodegenResult;
package/index.js CHANGED
@@ -13,18 +13,31 @@ function normalizeOptions(options) {
13
13
  return next;
14
14
  }
15
15
 
16
- function encodeAst(ast) {
17
- return encode(ast.program, ast.comments, ast.lineStarts);
16
+ function prepare(result, options) {
17
+ if (!result || !result.program || !result.program.type) {
18
+ throw new TypeError(
19
+ "Expected a `ParseResult` from yuku-parser, got " +
20
+ (result === null ? "null" : typeof result),
21
+ );
22
+ }
23
+ if (options?.sourceMaps && !result.lineStarts) {
24
+ throw new Error(
25
+ "Source maps require a `ParseResult` with `lineStarts`. " +
26
+ "If you built or transformed this result outside of yuku-parser, " +
27
+ "either drop `sourceMaps` or attach a `lineStarts` array.",
28
+ );
29
+ }
30
+ return encode(result);
18
31
  }
19
32
 
20
- export function print(ast, options) {
21
- return binding.print(encodeAst(ast), normalizeOptions(options));
33
+ export function print(result, options) {
34
+ return binding.print(prepare(result, options), normalizeOptions(options));
22
35
  }
23
36
 
24
- export function strip(ast, options) {
25
- return binding.strip(encodeAst(ast), normalizeOptions(options));
37
+ export function strip(result, options) {
38
+ return binding.strip(prepare(result, options), normalizeOptions(options));
26
39
  }
27
40
 
28
- export function minify(ast, options) {
29
- return binding.minify(encodeAst(ast), normalizeOptions(options));
41
+ export function minify(result, options) {
42
+ return binding.minify(prepare(result, options), normalizeOptions(options));
30
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuku-codegen",
3
- "version": "0.5.14",
3
+ "version": "0.5.15",
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.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"
20
+ "@yuku-codegen/binding-linux-x64-gnu": "0.5.15",
21
+ "@yuku-codegen/binding-linux-arm64-gnu": "0.5.15",
22
+ "@yuku-codegen/binding-linux-arm-gnu": "0.5.15",
23
+ "@yuku-codegen/binding-linux-x64-musl": "0.5.15",
24
+ "@yuku-codegen/binding-linux-arm64-musl": "0.5.15",
25
+ "@yuku-codegen/binding-linux-arm-musl": "0.5.15",
26
+ "@yuku-codegen/binding-darwin-x64": "0.5.15",
27
+ "@yuku-codegen/binding-darwin-arm64": "0.5.15",
28
+ "@yuku-codegen/binding-win32-x64": "0.5.15",
29
+ "@yuku-codegen/binding-win32-arm64": "0.5.15",
30
+ "@yuku-codegen/binding-freebsd-x64": "0.5.15"
31
31
  },
32
32
  "keywords": [
33
33
  "ast",
@@ -40,6 +40,6 @@
40
40
  "typescript"
41
41
  ],
42
42
  "dependencies": {
43
- "yuku-parser": "0.5.10"
43
+ "yuku-parser": "0.5.14"
44
44
  }
45
45
  }