oxc-codegen 0.0.0 → 0.144.0
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/LICENSE +22 -0
- package/README.md +75 -0
- package/dist/index.d.ts +1367 -0
- package/dist/index.js +1 -0
- package/dist/print_js.js +54 -0
- package/dist/print_js_maps.js +56 -0
- package/dist/print_ts.js +80 -0
- package/dist/print_ts_maps.js +82 -0
- package/package.json +53 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present VoidZero Inc. & Contributors
|
|
4
|
+
Copyright (c) 2023 Boshen
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# oxc-codegen
|
|
2
|
+
|
|
3
|
+
A fast JavaScript code generator from an [ESTree](https://github.com/estree/estree)-compliant AST,
|
|
4
|
+
written in TypeScript.
|
|
5
|
+
|
|
6
|
+
It is a faithful port of Oxc's Rust [`oxc_codegen`](https://github.com/oxc-project/oxc/tree/main/crates/oxc_codegen)
|
|
7
|
+
crate (pretty-printing mode). Output is byte-identical to `oxc_codegen` with default options
|
|
8
|
+
(tab indentation, double quotes, comments off).
|
|
9
|
+
|
|
10
|
+
Unlike the rest of Oxc's JS packages, this package contains no Rust and no native bindings.
|
|
11
|
+
It is pure JavaScript, and consumes an AST which already lives on the JS side, so doesn't need
|
|
12
|
+
to serialize it across a JS/native boundary. This is the key to `oxc-codegen`'s speed -
|
|
13
|
+
along with many optimizations to hit JS engines' fast paths.
|
|
14
|
+
|
|
15
|
+
See [DESIGN.md](https://github.com/oxc-project/oxc/blob/main/packages/codegen/DESIGN.md) for more details
|
|
16
|
+
on the implementation, and what makes it fast.
|
|
17
|
+
|
|
18
|
+
100% tests passing against Test262, Acorn-JSX, and TypeScript conformance suites (62,000 tests in total).
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { parseSync } from "oxc-parser";
|
|
24
|
+
import { printSync } from "oxc-codegen";
|
|
25
|
+
|
|
26
|
+
const { program } = parseSync("foo.js", "let x = 1");
|
|
27
|
+
console.log(printSync(program));
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Supported language variants
|
|
31
|
+
|
|
32
|
+
- JS
|
|
33
|
+
- JSX
|
|
34
|
+
- TS
|
|
35
|
+
- TSX
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### `printSync(node, options?)`
|
|
40
|
+
|
|
41
|
+
Returns a string containing the code for the AST `node`.
|
|
42
|
+
|
|
43
|
+
`node` must be a whole AST (`Program` node) or a statement node.
|
|
44
|
+
|
|
45
|
+
### Options
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| :-------------------- | :------------------- | :------ | :---------------------------------------------- |
|
|
49
|
+
| `indent` | `string` | `"\t"` | Indentation - spaces and/or tabs only |
|
|
50
|
+
| `startingIndentLevel` | `number` | `0` | Indent level to start from |
|
|
51
|
+
| `jsx` | `boolean` | `false` | `.tsx` mode - lone type parameters print `<T,>` |
|
|
52
|
+
| `ts` | `boolean` | `false` | AST may contain TypeScript syntax |
|
|
53
|
+
| `sourceMap` | `SourceMapGenerator` | - | If present, source mappings are emitted into it |
|
|
54
|
+
|
|
55
|
+
## Missing features
|
|
56
|
+
|
|
57
|
+
- There is currently no support for printing comments.
|
|
58
|
+
- Pretty-printing only, no compact/minified output.
|
|
59
|
+
- Source map support is only lightly tested, and API is likely to change.
|
|
60
|
+
|
|
61
|
+
## Benchmarks
|
|
62
|
+
|
|
63
|
+
| fixture | bytes | Oxc |
|
|
64
|
+
| :------------------------- | ------: | --------: |
|
|
65
|
+
| tiny.js | 26 | 0.0001ms |
|
|
66
|
+
| RadixUIAdoptionSection.jsx | 2518 | 0.0033ms |
|
|
67
|
+
| react.development.js | 72141 | 0.1138ms |
|
|
68
|
+
| binder.ts | 193077 | 0.2472ms |
|
|
69
|
+
| App.tsx | 415340 | 0.7490ms |
|
|
70
|
+
| lodash.js | 544096 | 0.4995ms |
|
|
71
|
+
| kitchen-sink.tsx | 732222 | 2.5682ms |
|
|
72
|
+
| antd.js | 6683633 | 11.3914ms |
|
|
73
|
+
|
|
74
|
+
Numbers above are from one machine and are not a regression baseline - the `antd.js` figures in
|
|
75
|
+
particular move by over 10% run to run.
|