yuku-codegen 0.5.8
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 +150 -0
- package/binding.js +63 -0
- package/encode.js +2069 -0
- package/index.d.ts +81 -0
- package/index.js +14 -0
- package/package.json +45 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Program } from "yuku-parser";
|
|
2
|
+
|
|
3
|
+
/** Whitespace mode for the generated output. */
|
|
4
|
+
export type Format = "pretty" | "compact";
|
|
5
|
+
|
|
6
|
+
/** Quote style for emitted string literals. */
|
|
7
|
+
export type Quotes = "double" | "single";
|
|
8
|
+
|
|
9
|
+
/** Source-map configuration. Pass to `CodegenOptions.sourceMaps` to enable. */
|
|
10
|
+
export interface SourceMapOptions {
|
|
11
|
+
/** Original source the AST was parsed from. Required. */
|
|
12
|
+
source: string;
|
|
13
|
+
/** Output filename, embedded as the map's `file`. */
|
|
14
|
+
file?: string;
|
|
15
|
+
/** Source filename, embedded as the single entry of `sources`. */
|
|
16
|
+
sourceFileName?: string;
|
|
17
|
+
/** Prefix embedded as `sourceRoot`. */
|
|
18
|
+
sourceRoot?: string;
|
|
19
|
+
/**
|
|
20
|
+
* When true, embeds `source` into `sourcesContent`.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
sourcesContent?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Codegen options shared by `print`, `strip`, and `minify`. */
|
|
27
|
+
export interface CodegenOptions {
|
|
28
|
+
/** @default "pretty" */
|
|
29
|
+
format?: Format;
|
|
30
|
+
/**
|
|
31
|
+
* Spaces per indentation level. Used only when `format = "pretty"`.
|
|
32
|
+
* @default 2
|
|
33
|
+
*/
|
|
34
|
+
indent?: number;
|
|
35
|
+
/** @default "double" */
|
|
36
|
+
quotes?: Quotes;
|
|
37
|
+
/** Pass to enable source maps. Omit to disable. */
|
|
38
|
+
sourceMaps?: SourceMapOptions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A codegen-detected problem in the input AST. */
|
|
42
|
+
export interface Diagnostic {
|
|
43
|
+
message: string;
|
|
44
|
+
/** Byte offset where the problem starts. */
|
|
45
|
+
start: number;
|
|
46
|
+
/** Byte offset where the problem ends. */
|
|
47
|
+
end: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Source Map V3. */
|
|
51
|
+
export interface SourceMap {
|
|
52
|
+
version: 3;
|
|
53
|
+
file: string | null;
|
|
54
|
+
sourceRoot: string | null;
|
|
55
|
+
sources: string[];
|
|
56
|
+
sourcesContent: (string | null)[] | null;
|
|
57
|
+
names: string[];
|
|
58
|
+
/** VLQ-encoded mappings string. */
|
|
59
|
+
mappings: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Result of a codegen run. */
|
|
63
|
+
export interface CodegenResult {
|
|
64
|
+
code: string;
|
|
65
|
+
/** Empty when codegen succeeded cleanly. */
|
|
66
|
+
errors: Diagnostic[];
|
|
67
|
+
/** `null` unless `sourceMaps` was enabled. */
|
|
68
|
+
map: SourceMap | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Renders the AST verbatim, preserving TypeScript syntax. */
|
|
72
|
+
export function print(estree: Program, options?: CodegenOptions): CodegenResult;
|
|
73
|
+
|
|
74
|
+
/** Renders the AST as JavaScript, dropping TypeScript-specific syntax. */
|
|
75
|
+
export function strip(estree: Program, options?: CodegenOptions): CodegenResult;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Renders the AST with size-reducing rewrites. Combine with
|
|
79
|
+
* `format: "compact"` for full minification.
|
|
80
|
+
*/
|
|
81
|
+
export function minify(estree: Program, options?: CodegenOptions): CodegenResult;
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import binding from "./binding.js";
|
|
2
|
+
import { encode } from "./encode.js";
|
|
3
|
+
|
|
4
|
+
export function print(estree, options) {
|
|
5
|
+
return binding.print(encode(estree), options ?? {});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function strip(estree, options) {
|
|
9
|
+
return binding.strip(encode(estree), options ?? {});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function minify(estree, options) {
|
|
13
|
+
return binding.minify(encode(estree), options ?? {});
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "yuku-codegen",
|
|
3
|
+
"version": "0.5.8",
|
|
4
|
+
"description": "High-performance JavaScript/TypeScript code generator written in Zig",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/yuku-toolchain/yuku"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "index.js",
|
|
12
|
+
"types": "index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"binding.js",
|
|
17
|
+
"encode.js"
|
|
18
|
+
],
|
|
19
|
+
"optionalDependencies": {
|
|
20
|
+
"@yuku-codegen/binding-linux-x64-gnu": "0.5.8",
|
|
21
|
+
"@yuku-codegen/binding-linux-arm64-gnu": "0.5.8",
|
|
22
|
+
"@yuku-codegen/binding-linux-arm-gnu": "0.5.8",
|
|
23
|
+
"@yuku-codegen/binding-linux-x64-musl": "0.5.8",
|
|
24
|
+
"@yuku-codegen/binding-linux-arm64-musl": "0.5.8",
|
|
25
|
+
"@yuku-codegen/binding-linux-arm-musl": "0.5.8",
|
|
26
|
+
"@yuku-codegen/binding-darwin-x64": "0.5.8",
|
|
27
|
+
"@yuku-codegen/binding-darwin-arm64": "0.5.8",
|
|
28
|
+
"@yuku-codegen/binding-win32-x64": "0.5.8",
|
|
29
|
+
"@yuku-codegen/binding-win32-arm64": "0.5.8",
|
|
30
|
+
"@yuku-codegen/binding-freebsd-x64": "0.5.8"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"yuku-parser": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"codegen",
|
|
37
|
+
"javascript",
|
|
38
|
+
"typescript",
|
|
39
|
+
"ast",
|
|
40
|
+
"estree",
|
|
41
|
+
"printer",
|
|
42
|
+
"minifier",
|
|
43
|
+
"napi"
|
|
44
|
+
]
|
|
45
|
+
}
|