esrap 2.2.4 → 2.2.6
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/package.json +13 -3
- package/src/languages/ts/index.js +21 -6
- package/src/languages/ts/public.d.ts +7 -2
- package/src/languages/tsx/public.d.ts +5 -2
- package/types/index.d.ts +31 -31
- package/types/index.d.ts.map +9 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esrap",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"description": "Parse in reverse",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@changesets/cli": "^2.27.11",
|
|
31
31
|
"@sveltejs/acorn-typescript": "^1.0.5",
|
|
32
|
+
"@types/estree": "^1.0.8",
|
|
33
|
+
"@typescript-eslint/types": "^8.2.0",
|
|
32
34
|
"@vitest/ui": "^2.1.1",
|
|
33
35
|
"acorn": "^8.15.0",
|
|
34
36
|
"dts-buddy": "^0.6.2",
|
|
@@ -40,16 +42,24 @@
|
|
|
40
42
|
},
|
|
41
43
|
"license": "MIT",
|
|
42
44
|
"dependencies": {
|
|
43
|
-
"@jridgewell/sourcemap-codec": "^1.4.15"
|
|
45
|
+
"@jridgewell/sourcemap-codec": "^1.4.15"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
44
48
|
"@typescript-eslint/types": "^8.2.0"
|
|
45
49
|
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@typescript-eslint/types": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
46
55
|
"publishConfig": {
|
|
47
56
|
"access": "public"
|
|
48
57
|
},
|
|
49
58
|
"scripts": {
|
|
50
59
|
"changeset:version": "changeset version",
|
|
51
60
|
"changeset:publish": "changeset publish",
|
|
52
|
-
"
|
|
61
|
+
"gen": "dts-buddy -m esrap:./src/public.d.ts -m esrap/languages/ts:./src/languages/ts/public.d.ts -m esrap/languages/tsx:./src/languages/tsx/public.d.ts",
|
|
62
|
+
"check": "pnpm gen && tsc",
|
|
53
63
|
"sandbox": "node test/sandbox/index.js",
|
|
54
64
|
"test": "vitest --run",
|
|
55
65
|
"test:ui": "vitest --ui",
|
|
@@ -1848,19 +1848,28 @@ export default (options = {}) => {
|
|
|
1848
1848
|
TSMappedType(node, context) {
|
|
1849
1849
|
context.write('{[');
|
|
1850
1850
|
|
|
1851
|
-
|
|
1852
|
-
|
|
1851
|
+
const legacy_type_parameter = node.typeParameter;
|
|
1852
|
+
const key = node.key ?? legacy_type_parameter?.name;
|
|
1853
|
+
const constraint = node.constraint ?? legacy_type_parameter?.constraint;
|
|
1854
|
+
|
|
1855
|
+
if (key && typeof key === 'object') {
|
|
1856
|
+
context.visit(key);
|
|
1853
1857
|
} else {
|
|
1854
|
-
context.
|
|
1858
|
+
context.write(key, node);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
if (constraint) {
|
|
1855
1862
|
context.write(' in ');
|
|
1856
|
-
context.visit(
|
|
1863
|
+
context.visit(constraint);
|
|
1857
1864
|
}
|
|
1858
1865
|
|
|
1859
1866
|
context.write(']');
|
|
1867
|
+
|
|
1860
1868
|
if (node.typeAnnotation) {
|
|
1861
1869
|
context.write(': ');
|
|
1862
1870
|
context.visit(node.typeAnnotation);
|
|
1863
1871
|
}
|
|
1872
|
+
|
|
1864
1873
|
context.write('}');
|
|
1865
1874
|
},
|
|
1866
1875
|
|
|
@@ -2019,9 +2028,15 @@ export default (options = {}) => {
|
|
|
2019
2028
|
|
|
2020
2029
|
TSModuleDeclaration(node, context) {
|
|
2021
2030
|
if (node.declare) context.write('declare ');
|
|
2022
|
-
else context.write('namespace ');
|
|
2023
2031
|
|
|
2024
|
-
|
|
2032
|
+
if (node.global) {
|
|
2033
|
+
context.write('global', node.id);
|
|
2034
|
+
} else {
|
|
2035
|
+
// @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
|
|
2036
|
+
const kind = node.kind ?? (node.id.type === 'Literal' ? 'module' : 'namespace');
|
|
2037
|
+
context.write(kind + ' ');
|
|
2038
|
+
context.visit(node.id);
|
|
2039
|
+
}
|
|
2025
2040
|
|
|
2026
2041
|
if (!node.body) return;
|
|
2027
2042
|
context.visit(node.body);
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Visitors, BaseNode } from '../../types';
|
|
2
|
+
import type { TSOptions, BaseComment, Comment } from '../types';
|
|
3
|
+
export type { BaseComment, Comment };
|
|
4
|
+
export type Node = BaseNode;
|
|
5
|
+
export default function ts(options?: TSOptions): Visitors<BaseNode>;
|
|
6
|
+
// was Record<TSESTree.Expression['type'] | 'Super' | 'RestElement', number>
|
|
7
|
+
export declare const EXPRESSIONS_PRECEDENCE: Record<string, number>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Visitors, BaseNode } from '../../types';
|
|
2
|
+
import type { TSOptions, BaseComment, Comment } from '../types';
|
|
3
|
+
export type { BaseComment, Comment };
|
|
4
|
+
export type Node = BaseNode;
|
|
5
|
+
export default function tsx(options?: TSOptions): Visitors<BaseNode>;
|
package/types/index.d.ts
CHANGED
|
@@ -69,11 +69,30 @@ declare module 'esrap' {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
declare module 'esrap/languages/ts' {
|
|
72
|
-
import type { TSESTree } from '@typescript-eslint/types';
|
|
73
72
|
import type { Context } from 'esrap';
|
|
74
|
-
export
|
|
75
|
-
export default function
|
|
76
|
-
|
|
73
|
+
export type Node = BaseNode;
|
|
74
|
+
export default function ts(options?: TSOptions): Visitors<BaseNode>;
|
|
75
|
+
// was Record<TSESTree.Expression['type'] | 'Super' | 'RestElement', number>
|
|
76
|
+
export const EXPRESSIONS_PRECEDENCE: Record<string, number>;
|
|
77
|
+
type BaseNode = {
|
|
78
|
+
type: string;
|
|
79
|
+
loc?: null | {
|
|
80
|
+
start: { line: number; column: number };
|
|
81
|
+
end: { line: number; column: number };
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
|
86
|
+
|
|
87
|
+
type SpecialisedVisitors<T extends BaseNode> = {
|
|
88
|
+
[K in T['type']]?: Visitor<NodeOf<K, T>>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type Visitor<T> = (node: T, context: Context) => void;
|
|
92
|
+
|
|
93
|
+
type Visitors<T extends BaseNode = BaseNode> = T['type'] extends '_'
|
|
94
|
+
? never
|
|
95
|
+
: SpecialisedVisitors<T> & { _?: (node: T, context: Context, visit: (node: T) => void) => void };
|
|
77
96
|
type TSOptions = {
|
|
78
97
|
quotes?: 'double' | 'single';
|
|
79
98
|
comments?: Comment[];
|
|
@@ -101,6 +120,14 @@ declare module 'esrap/languages/ts' {
|
|
|
101
120
|
end: Position;
|
|
102
121
|
};
|
|
103
122
|
}
|
|
123
|
+
|
|
124
|
+
export {};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare module 'esrap/languages/tsx' {
|
|
128
|
+
import type { Context } from 'esrap';
|
|
129
|
+
export type Node = BaseNode;
|
|
130
|
+
export default function tsx(options?: TSOptions): Visitors<BaseNode>;
|
|
104
131
|
type BaseNode = {
|
|
105
132
|
type: string;
|
|
106
133
|
loc?: null | {
|
|
@@ -120,14 +147,6 @@ declare module 'esrap/languages/ts' {
|
|
|
120
147
|
type Visitors<T extends BaseNode = BaseNode> = T['type'] extends '_'
|
|
121
148
|
? never
|
|
122
149
|
: SpecialisedVisitors<T> & { _?: (node: T, context: Context, visit: (node: T) => void) => void };
|
|
123
|
-
|
|
124
|
-
export {};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
declare module 'esrap/languages/tsx' {
|
|
128
|
-
import type { TSESTree } from '@typescript-eslint/types';
|
|
129
|
-
import type { Context } from 'esrap';
|
|
130
|
-
export default function _default(options?: TSOptions): Visitors<TSESTree.Node>;
|
|
131
150
|
type TSOptions = {
|
|
132
151
|
quotes?: 'double' | 'single';
|
|
133
152
|
comments?: Comment[];
|
|
@@ -155,25 +174,6 @@ declare module 'esrap/languages/tsx' {
|
|
|
155
174
|
end: Position;
|
|
156
175
|
};
|
|
157
176
|
}
|
|
158
|
-
type BaseNode = {
|
|
159
|
-
type: string;
|
|
160
|
-
loc?: null | {
|
|
161
|
-
start: { line: number; column: number };
|
|
162
|
-
end: { line: number; column: number };
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
|
167
|
-
|
|
168
|
-
type SpecialisedVisitors<T extends BaseNode> = {
|
|
169
|
-
[K in T['type']]?: Visitor<NodeOf<K, T>>;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
type Visitor<T> = (node: T, context: Context) => void;
|
|
173
|
-
|
|
174
|
-
type Visitors<T extends BaseNode = BaseNode> = T['type'] extends '_'
|
|
175
|
-
? never
|
|
176
|
-
: SpecialisedVisitors<T> & { _?: (node: T, context: Context, visit: (node: T) => void) => void };
|
|
177
177
|
|
|
178
178
|
export {};
|
|
179
179
|
}
|
package/types/index.d.ts.map
CHANGED
|
@@ -12,27 +12,31 @@
|
|
|
12
12
|
"PrintOptions",
|
|
13
13
|
"print",
|
|
14
14
|
"Context",
|
|
15
|
-
"EXPRESSIONS_PRECEDENCE",
|
|
16
15
|
"Node",
|
|
16
|
+
"ts",
|
|
17
|
+
"EXPRESSIONS_PRECEDENCE",
|
|
17
18
|
"TSOptions",
|
|
18
19
|
"Position",
|
|
19
20
|
"BaseComment",
|
|
20
|
-
"Comment"
|
|
21
|
+
"Comment",
|
|
22
|
+
"tsx"
|
|
21
23
|
],
|
|
22
24
|
"sources": [
|
|
23
25
|
"../src/types.d.ts",
|
|
24
26
|
"../src/index.js",
|
|
25
27
|
"../src/context.js",
|
|
26
|
-
"../src/languages/ts/
|
|
27
|
-
"../src/languages/types.d.ts"
|
|
28
|
+
"../src/languages/ts/public.d.ts",
|
|
29
|
+
"../src/languages/types.d.ts",
|
|
30
|
+
"../src/languages/tsx/public.d.ts"
|
|
28
31
|
],
|
|
29
32
|
"sourcesContent": [
|
|
30
33
|
null,
|
|
31
34
|
null,
|
|
32
35
|
null,
|
|
33
36
|
null,
|
|
37
|
+
null,
|
|
34
38
|
null
|
|
35
39
|
],
|
|
36
|
-
"mappings": ";MAEYA,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA;;;;MAIZC,OAAOA;;aAEPC,QAAQA;;;;WAWHC,QAAQA;;;;;;MAWbC,OAAOA;;kBAEFC,YAAYA;;;;;;;;;iBCWbC,KAAKA;;;;cC7CRC,OAAOA
|
|
40
|
+
"mappings": ";MAEYA,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA;;;;MAIZC,OAAOA;;aAEPC,QAAQA;;;;WAWHC,QAAQA;;;;;;MAWbC,OAAOA;;kBAEFC,YAAYA;;;;;;;;;iBCWbC,KAAKA;;;;cC7CRC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aCLRC,IAAIA;yBACQC,EAAEA;;cAELC,sBAAsBA;MHJ/BZ,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA;;;;MAIZC,OAAOA;;MAEPC,QAAQA;;;MIhBRS,SAASA;;;;;;;WAOXC,QAAQA;;;;;;;kBAODC,WAAWA;;;;;;;kBAOXC,OAAOA;;;;;;;;;;;;aCpBZN,IAAIA;yBACQO,GAAGA;MLFfjB,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA;;;;MAIZC,OAAOA;;MAEPC,QAAQA;;;MIhBRS,SAASA;;;;;;;WAOXC,QAAQA;;;;;;;kBAODC,WAAWA;;;;;;;kBAOXC,OAAOA",
|
|
37
41
|
"ignoreList": []
|
|
38
42
|
}
|