{"name":"yuku-codegen","version":"0.7.0","keywords":["ast","codegen","estree","javascript","minifier","napi","printer","typescript"],"license":"MIT","_id":"yuku-codegen@0.7.0","maintainers":[{"name":"arshadyaseen","email":"arshadpyaseen@gmail.com"}],"homepage":"https://github.com/yuku-toolchain/yuku#readme","bugs":{"url":"https://github.com/yuku-toolchain/yuku/issues"},"dist":{"shasum":"7cb823d525ec1f832fdcd61ed3030718beead0b1","tarball":"http://registry-npm.ywwl.com/yuku-codegen/download/yuku-codegen-0.7.0.tgz","fileCount":6,"integrity":"sha512-RJgoLaIU2AGKRkUHqMtw6gQhYm+NXZm/AFnfn+5YAHgRfApIc/PNJABJHihHoxWltayjbwEOCa68zqxdJafgfA==","signatures":[{"sig":"MEQCIDmd1CHelkd2NCBz/BnFQCD+neFx/p0/+0BG3rnZJrFcAiAU8qSG9S0f1HfbYcrfdwjLm5Rda4hJLT0DqE7Jye/bgQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/yuku-codegen@0.7.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":102235,"size":16889,"noattachment":false,"key":"/yuku-codegen/-/yuku-codegen-0.7.0.tgz"},"main":"index.js","type":"module","_from":"file:yuku-codegen-0.7.0.tgz","types":"index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:67f850d7-01e6-435f-a035-3f1dd5de71c2"}},"_resolved":"/home/runner/work/yuku/yuku/npm/yuku-codegen/yuku-codegen-0.7.0.tgz","_integrity":"sha512-RJgoLaIU2AGKRkUHqMtw6gQhYm+NXZm/AFnfn+5YAHgRfApIc/PNJABJHihHoxWltayjbwEOCa68zqxdJafgfA==","repository":{"url":"git+https://github.com/yuku-toolchain/yuku.git","type":"git"},"_npmVersion":"11.18.0","description":"High-performance JavaScript/TypeScript code generator written in Zig","directories":{},"_nodeVersion":"24.18.0","dependencies":{"@yuku-toolchain/types":"0.7.0"},"_hasShrinkwrap":false,"optionalDependencies":{"@yuku-codegen/binding-win32-x64":"0.7.0","@yuku-codegen/binding-darwin-x64":"0.7.0","@yuku-codegen/binding-freebsd-x64":"0.7.0","@yuku-codegen/binding-win32-arm64":"0.7.0","@yuku-codegen/binding-darwin-arm64":"0.7.0","@yuku-codegen/binding-linux-arm-gnu":"0.7.0","@yuku-codegen/binding-linux-x64-gnu":"0.7.0","@yuku-codegen/binding-linux-arm-musl":"0.7.0","@yuku-codegen/binding-linux-x64-musl":"0.7.0","@yuku-codegen/binding-linux-arm64-gnu":"0.7.0","@yuku-codegen/binding-linux-arm64-musl":"0.7.0"},"_npmOperationalInternal":{"tmp":"tmp/yuku-codegen_0.7.0_1784442078580_0.30136998489584665","host":"s3://npm-registry-packages-npm-production"},"readme":"# yuku-codegen\n\nA fast code generator for any ESTree / TypeScript-ESTree AST, with type stripping, minification, and Source Map V3 output, part of [Yuku](https://yuku.fyi).\n\nIt is plain JavaScript with no native binary, and prints any ESTree AST, whichever parser produced it. Its output is byte-identical to Yuku's Zig printer, source maps included, and it runs 2.6x faster than `@babel/generator`, or 3x with source maps on.\n\n- [Install](#install)\n- [Usage](#usage)\n- [Result](#result)\n- [Options](#options)\n- [Type stripping](#type-stripping)\n- [Minification](#minification)\n- [Quotes](#quotes)\n- [Comments](#comments)\n- [Source maps](#source-maps)\n\n## Install\n\n```bash\nnpm install yuku-codegen\n```\n\n## Usage\n\n```js\nimport { generate } from \"yuku-codegen\";\nimport { parse } from \"yuku-parser\";\n\nconst { code } = generate(parse(\"const x = 1 + 2;\").program);\n// \"const x = 1 + 2;\"\n```\n\n## Result\n\n`generate` takes a `Program` or any single node, such as an object property, and returns a `GenerateResult`.\n\n```ts\ninterface GenerateResult {\n  code: string;\n  diagnostics: Diagnostic[]; // empty on a clean run\n  map: SourceMap | null;     // with sourceMap\n}\n```\n\n`diagnostics` has the same shape as [`yuku-parser`'s](https://www.npmjs.com/package/yuku-parser#diagnostics).\n\n## Options\n\nEvery transformation is an independent flag, so they compose freely.\n\n```js\ngenerate(program, { strip: true, minify: true, sourceMap: { source } });\n```\n\n| Option      | Type                                                        | Default      | Description                                                                 |\n| ----------- | ----------------------------------------------------------- | ------------ | --------------------------------------------------------------------------- |\n| `strip`     | `boolean`                                                   | `false`      | Drop TypeScript-only syntax. See [Type stripping](#type-stripping).         |\n| `minify`    | `boolean \\| MinifyOptions`                                  | `false`      | Minify the output. See [Minification](#minification).                       |\n| `format`    | `\"pretty\" \\| \"compact\"`                                     | `\"pretty\"`   | `\"compact\"` emits only the separators the grammar requires.                 |\n| `indent`    | `number`                                                    | `2`          | Spaces per level in pretty format, from 0 to 255.                           |\n| `quotes`    | `\"preserve\" \\| \"double\" \\| \"single\" \\| \"shortest\"`          | `\"preserve\"` | Quote style for string literals. See [Quotes](#quotes).                     |\n| `comments`  | `boolean \\| \"all\" \\| \"some\" \\| \"none\" \\| \"line\" \\| \"block\"` | `\"some\"`     | Which attached comments to emit. See [Comments](#comments).                 |\n| `sourceMap` | `SourceMapOptions`                                          | none         | Emit a Source Map V3. See [Source maps](#source-maps).                      |\n\n## Type stripping\n\n`strip: true` prints a TypeScript AST as plain JavaScript.\n\n```js\ngenerate(parse(`const x: number = 1;`, { lang: \"ts\" }).program, { strip: true }).code;\n// \"const x = 1;\"\n```\n\nTypes, interfaces, type aliases, generics, type assertions, `satisfies`, non-null `!`, `declare`, and `abstract` strip cleanly. A few TypeScript features emit runtime values: `enum`, `namespace`, `module`, `export =`, `import = require()`, and parameter properties. Converting them is transpilation, not stripping, so each one is reported in `diagnostics` and left out, a parameter property keeps its plain parameter, and the rest of the file is still emitted. Their ambient forms (`declare enum`, `declare namespace`, `declare module`, `import type X = require(...)`) carry no runtime and strip silently.\n\n## Minification\n\n`minify: true` enables every switch. An object picks them, and enabled switches override `format` and `quotes`.\n\n| Switch       | Behavior                                                    |\n| ------------ | ----------------------------------------------------------- |\n| `whitespace` | Emit compact whitespace.                                    |\n| `syntax`     | Apply the size-reducing syntax rewrites below.              |\n| `quotes`     | Use whichever quote needs fewer escapes per literal.        |\n\n```js\ngenerate(program, { minify: { syntax: true } }); // rewrites only, readable output\n```\n\nThe syntax rewrites:\n\n- `true` and `false` become `!0` and `!1`.\n- Numeric literals take their shortest form (`1000000` becomes `1e6`, `0.5` becomes `.5`).\n- `obj[\"foo\"]` becomes `obj.foo` when the key is a valid identifier.\n- `{ \"foo\": x }` becomes `{ foo: x }` when safe.\n- `</script`, `<!--`, and `-->` are escaped in strings and untagged template literals, so the output is safe to inline in a `<script>` tag. Tagged templates keep their raw text, since the tag reads it.\n\n## Quotes\n\n| Value        | Behavior                                                               |\n| ------------ | ---------------------------------------------------------------------- |\n| `\"preserve\"` | Keep each literal's source quote style, re-escaping the content.       |\n| `\"double\"`   | Force double quotes.                                                   |\n| `\"single\"`   | Force single quotes.                                                   |\n| `\"shortest\"` | Pick whichever quote needs fewer escapes per literal, double on a tie. |\n\n## Comments\n\nComments print from the nodes they are attached to, so parse with [`attachComments: true`](https://www.npmjs.com/package/yuku-parser#comments) to keep them. Because they live on nodes, they move with their node through transforms.\n\n| Value                | Behavior                                                                            |\n| -------------------- | ----------------------------------------------------------------------------------- |\n| `\"some\"`             | Legal headers, JSDoc, and `@`/`#` annotations, the bundler convention. The default. |\n| `\"all\"` or `true`    | Every comment.                                                                      |\n| `\"none\"` or `false`  | No comments.                                                                        |\n| `\"line\"`             | `// ...` only.                                                                      |\n| `\"block\"`            | `/* ... */` only.                                                                   |\n\n```js\nconst { program } = parse(`// hello\\nconst x = 1;`, { attachComments: true });\ngenerate(program, { comments: true }).code;\n// \"// hello\\nconst x = 1;\"\n```\n\n## Source maps\n\nPass the original source to emit a Source Map V3 alongside the code.\n\n```js\nconst { code, map } = generate(program, {\n  sourceMap: { source, file: \"out.js\", sourceFileName: \"in.js\", sourcesContent: source },\n});\n\nconst output = `${code}\\n//# sourceMappingURL=out.js.map`;\nconst mapJson = JSON.stringify(map);\n```\n\n| Field            | Description                                                 |\n| ---------------- | ----------------------------------------------------------- |\n| `source`         | **Required.** The original source text, positions map to it. |\n| `file`           | Output filename, embedded as `file`.                        |\n| `sourceFileName` | Source filename, the single entry of `sources`.             |\n| `sourceRoot`     | Embedded as `sourceRoot`.                                   |\n| `sourcesContent` | The single entry of `sourcesContent`.                       |\n\n`map` is a Source Map V3 object, ready for `JSON.stringify`. Columns are 0-indexed UTF-16 code units, the convention of browser devtools and source map libraries.\n\n```ts\ninterface SourceMap {\n  version: 3;\n  file: string | null;\n  sourceRoot: string | null;\n  sources: string[];\n  sourcesContent: (string | null)[] | null;\n  names: string[];\n  mappings: string;\n}\n```\n\n## License\n\nMIT\n","publish_time":1784442078742,"_cnpm_publish_time":1784442078742,"dist-tags":{"latest":"0.19.0"}}