esrap 1.0.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 +7 -0
- package/README.md +57 -0
- package/package.json +30 -0
- package/src/handlers.js +1373 -0
- package/src/index.js +123 -0
- package/src/types.d.ts +23 -0
- package/types/index.d.ts +16 -0
- package/types/index.d.ts.map +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2023 [these people](https://github.com/Rich-Harris/esrap/graphs/contributors)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# esrap
|
|
2
|
+
|
|
3
|
+
Parse in reverse. AST goes in, code comes out.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { print } from 'esrap';
|
|
9
|
+
|
|
10
|
+
const { code, map } = print({
|
|
11
|
+
type: 'Program',
|
|
12
|
+
body: [
|
|
13
|
+
{
|
|
14
|
+
type: 'ExpressionStatement',
|
|
15
|
+
expression: {
|
|
16
|
+
callee: {
|
|
17
|
+
type: 'Identifier',
|
|
18
|
+
name: 'alert'
|
|
19
|
+
},
|
|
20
|
+
arguments: [
|
|
21
|
+
{
|
|
22
|
+
type: 'Literal',
|
|
23
|
+
value: 'hello world!'
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(code); // alert('hello world!');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If the nodes of the input AST have `loc` properties (e.g. the AST was generated with [`acorn`](https://github.com/acornjs/acorn/tree/master/acorn/#interface) with the `locations` option set), sourcemap mappings will be created.
|
|
35
|
+
|
|
36
|
+
## Options
|
|
37
|
+
|
|
38
|
+
You can pass information that will be added to the resulting sourcemap (note that the AST is assumed to come from a single file):
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const { code, map } = parse(ast, {
|
|
42
|
+
sourceMapSource: 'input.js',
|
|
43
|
+
sourceMapContent: fs.readFileSync('input.js', 'utf-8')
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Why not just use Prettier?
|
|
48
|
+
|
|
49
|
+
Because it's ginormous.
|
|
50
|
+
|
|
51
|
+
## Developing
|
|
52
|
+
|
|
53
|
+
This repo uses [Bun](https://bun.sh/). Once it's installed, do `bun install` to install dependencies, and `bun test` to run the tests.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](LICENSE)
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "esrap",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"src",
|
|
7
|
+
"types"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"acorn": "^8.10.0",
|
|
18
|
+
"dts-buddy": "^0.2.4",
|
|
19
|
+
"prettier": "^3.0.3",
|
|
20
|
+
"zimmerframe": "^1.0.0"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepublishOnly": "bun test && dts-buddy"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
28
|
+
"@types/estree": "^1.0.1"
|
|
29
|
+
}
|
|
30
|
+
}
|