@gi-tcg/gts-transpiler 0.3.8 → 0.3.10
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/dist/index.d.ts +501 -1
- package/dist/index.js +5 -4
- package/package.json +1 -1
- package/src/index.ts +14 -2
- package/src/parse/index.ts +7 -2
- package/src/parse/loose_plugin.ts +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
|
+
import { Options, Parser } from "acorn";
|
|
1
2
|
import { SourceMap } from "magic-string";
|
|
2
3
|
|
|
3
4
|
//#region node_modules/@types/estree/index.d.ts
|
|
5
|
+
// This definition file follows a somewhat unusual format. ESTree allows
|
|
6
|
+
// runtime type checks based on the `type` parameter. In order to explain this
|
|
7
|
+
// to typescript we want to use discriminated union types:
|
|
8
|
+
// https://github.com/Microsoft/TypeScript/pull/9163
|
|
9
|
+
//
|
|
10
|
+
// For ESTree this is a bit tricky because the high level interfaces like
|
|
11
|
+
// Node or Function are pulling double duty. We want to pass common fields down
|
|
12
|
+
// to the interfaces that extend them (like Identifier or
|
|
13
|
+
// ArrowFunctionExpression), but you can't extend a type union or enforce
|
|
14
|
+
// common fields on them. So we've split the high level interfaces into two
|
|
15
|
+
// types, a base type which passes down inherited fields, and a type union of
|
|
16
|
+
// all types which extend the base type. Only the type union is exported, and
|
|
17
|
+
// the union is how other types refer to the collection of inheriting types.
|
|
18
|
+
//
|
|
19
|
+
// This makes the definitions file here somewhat more difficult to maintain,
|
|
20
|
+
// but it has the notable advantage of making ESTree much easier to use as
|
|
21
|
+
// an end user.
|
|
22
|
+
interface BaseNodeWithoutComments {
|
|
23
|
+
// Every leaf interface that extends BaseNode must specify a type property.
|
|
24
|
+
// The type property should be a string literal. For example, Identifier
|
|
25
|
+
// has: `type: "Identifier"`
|
|
26
|
+
type: string;
|
|
27
|
+
loc?: SourceLocation | null | undefined;
|
|
28
|
+
range?: [number, number] | undefined;
|
|
29
|
+
}
|
|
30
|
+
interface BaseNode extends BaseNodeWithoutComments {
|
|
31
|
+
leadingComments?: Comment[] | undefined;
|
|
32
|
+
trailingComments?: Comment[] | undefined;
|
|
33
|
+
}
|
|
34
|
+
interface Comment extends BaseNodeWithoutComments {
|
|
35
|
+
type: "Line" | "Block";
|
|
36
|
+
value: string;
|
|
37
|
+
}
|
|
4
38
|
interface SourceLocation {
|
|
5
39
|
source?: string | null | undefined;
|
|
6
40
|
start: Position;
|
|
@@ -12,6 +46,472 @@ interface Position {
|
|
|
12
46
|
/** >= 0 */
|
|
13
47
|
column: number;
|
|
14
48
|
}
|
|
49
|
+
interface Program extends BaseNode {
|
|
50
|
+
type: "Program";
|
|
51
|
+
sourceType: "script" | "module";
|
|
52
|
+
body: Array<Directive | Statement | ModuleDeclaration>;
|
|
53
|
+
comments?: Comment[] | undefined;
|
|
54
|
+
}
|
|
55
|
+
interface Directive extends BaseNode {
|
|
56
|
+
type: "ExpressionStatement";
|
|
57
|
+
expression: Literal;
|
|
58
|
+
directive: string;
|
|
59
|
+
}
|
|
60
|
+
interface BaseFunction extends BaseNode {
|
|
61
|
+
params: Pattern[];
|
|
62
|
+
generator?: boolean | undefined;
|
|
63
|
+
async?: boolean | undefined; // The body is either BlockStatement or Expression because arrow functions
|
|
64
|
+
// can have a body that's either. FunctionDeclarations and
|
|
65
|
+
// FunctionExpressions have only BlockStatement bodies.
|
|
66
|
+
body: BlockStatement | Expression;
|
|
67
|
+
}
|
|
68
|
+
type Statement = ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
|
|
69
|
+
interface BaseStatement extends BaseNode {}
|
|
70
|
+
interface EmptyStatement extends BaseStatement {
|
|
71
|
+
type: "EmptyStatement";
|
|
72
|
+
}
|
|
73
|
+
interface BlockStatement extends BaseStatement {
|
|
74
|
+
type: "BlockStatement";
|
|
75
|
+
body: Statement[];
|
|
76
|
+
innerComments?: Comment[] | undefined;
|
|
77
|
+
}
|
|
78
|
+
interface StaticBlock extends Omit<BlockStatement, "type"> {
|
|
79
|
+
type: "StaticBlock";
|
|
80
|
+
}
|
|
81
|
+
interface ExpressionStatement extends BaseStatement {
|
|
82
|
+
type: "ExpressionStatement";
|
|
83
|
+
expression: Expression;
|
|
84
|
+
}
|
|
85
|
+
interface IfStatement extends BaseStatement {
|
|
86
|
+
type: "IfStatement";
|
|
87
|
+
test: Expression;
|
|
88
|
+
consequent: Statement;
|
|
89
|
+
alternate?: Statement | null | undefined;
|
|
90
|
+
}
|
|
91
|
+
interface LabeledStatement extends BaseStatement {
|
|
92
|
+
type: "LabeledStatement";
|
|
93
|
+
label: Identifier;
|
|
94
|
+
body: Statement;
|
|
95
|
+
}
|
|
96
|
+
interface BreakStatement extends BaseStatement {
|
|
97
|
+
type: "BreakStatement";
|
|
98
|
+
label?: Identifier | null | undefined;
|
|
99
|
+
}
|
|
100
|
+
interface ContinueStatement extends BaseStatement {
|
|
101
|
+
type: "ContinueStatement";
|
|
102
|
+
label?: Identifier | null | undefined;
|
|
103
|
+
}
|
|
104
|
+
interface WithStatement extends BaseStatement {
|
|
105
|
+
type: "WithStatement";
|
|
106
|
+
object: Expression;
|
|
107
|
+
body: Statement;
|
|
108
|
+
}
|
|
109
|
+
interface SwitchStatement extends BaseStatement {
|
|
110
|
+
type: "SwitchStatement";
|
|
111
|
+
discriminant: Expression;
|
|
112
|
+
cases: SwitchCase[];
|
|
113
|
+
}
|
|
114
|
+
interface ReturnStatement extends BaseStatement {
|
|
115
|
+
type: "ReturnStatement";
|
|
116
|
+
argument?: Expression | null | undefined;
|
|
117
|
+
}
|
|
118
|
+
interface ThrowStatement extends BaseStatement {
|
|
119
|
+
type: "ThrowStatement";
|
|
120
|
+
argument: Expression;
|
|
121
|
+
}
|
|
122
|
+
interface TryStatement extends BaseStatement {
|
|
123
|
+
type: "TryStatement";
|
|
124
|
+
block: BlockStatement;
|
|
125
|
+
handler?: CatchClause | null | undefined;
|
|
126
|
+
finalizer?: BlockStatement | null | undefined;
|
|
127
|
+
}
|
|
128
|
+
interface WhileStatement extends BaseStatement {
|
|
129
|
+
type: "WhileStatement";
|
|
130
|
+
test: Expression;
|
|
131
|
+
body: Statement;
|
|
132
|
+
}
|
|
133
|
+
interface DoWhileStatement extends BaseStatement {
|
|
134
|
+
type: "DoWhileStatement";
|
|
135
|
+
body: Statement;
|
|
136
|
+
test: Expression;
|
|
137
|
+
}
|
|
138
|
+
interface ForStatement extends BaseStatement {
|
|
139
|
+
type: "ForStatement";
|
|
140
|
+
init?: VariableDeclaration | Expression | null | undefined;
|
|
141
|
+
test?: Expression | null | undefined;
|
|
142
|
+
update?: Expression | null | undefined;
|
|
143
|
+
body: Statement;
|
|
144
|
+
}
|
|
145
|
+
interface BaseForXStatement extends BaseStatement {
|
|
146
|
+
left: VariableDeclaration | Pattern;
|
|
147
|
+
right: Expression;
|
|
148
|
+
body: Statement;
|
|
149
|
+
}
|
|
150
|
+
interface ForInStatement extends BaseForXStatement {
|
|
151
|
+
type: "ForInStatement";
|
|
152
|
+
}
|
|
153
|
+
interface DebuggerStatement extends BaseStatement {
|
|
154
|
+
type: "DebuggerStatement";
|
|
155
|
+
}
|
|
156
|
+
type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
|
|
157
|
+
interface BaseDeclaration extends BaseStatement {}
|
|
158
|
+
interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration {
|
|
159
|
+
type: "FunctionDeclaration";
|
|
160
|
+
/** It is null when a function declaration is a part of the `export default function` statement */
|
|
161
|
+
id: Identifier | null;
|
|
162
|
+
body: BlockStatement;
|
|
163
|
+
}
|
|
164
|
+
interface FunctionDeclaration extends MaybeNamedFunctionDeclaration {
|
|
165
|
+
id: Identifier;
|
|
166
|
+
}
|
|
167
|
+
interface VariableDeclaration extends BaseDeclaration {
|
|
168
|
+
type: "VariableDeclaration";
|
|
169
|
+
declarations: VariableDeclarator[];
|
|
170
|
+
kind: "var" | "let" | "const" | "using" | "await using";
|
|
171
|
+
}
|
|
172
|
+
interface VariableDeclarator extends BaseNode {
|
|
173
|
+
type: "VariableDeclarator";
|
|
174
|
+
id: Pattern;
|
|
175
|
+
init?: Expression | null | undefined;
|
|
176
|
+
}
|
|
177
|
+
interface ExpressionMap {
|
|
178
|
+
ArrayExpression: ArrayExpression;
|
|
179
|
+
ArrowFunctionExpression: ArrowFunctionExpression;
|
|
180
|
+
AssignmentExpression: AssignmentExpression;
|
|
181
|
+
AwaitExpression: AwaitExpression;
|
|
182
|
+
BinaryExpression: BinaryExpression;
|
|
183
|
+
CallExpression: CallExpression;
|
|
184
|
+
ChainExpression: ChainExpression;
|
|
185
|
+
ClassExpression: ClassExpression;
|
|
186
|
+
ConditionalExpression: ConditionalExpression;
|
|
187
|
+
FunctionExpression: FunctionExpression;
|
|
188
|
+
Identifier: Identifier;
|
|
189
|
+
ImportExpression: ImportExpression;
|
|
190
|
+
Literal: Literal;
|
|
191
|
+
LogicalExpression: LogicalExpression;
|
|
192
|
+
MemberExpression: MemberExpression;
|
|
193
|
+
MetaProperty: MetaProperty;
|
|
194
|
+
NewExpression: NewExpression;
|
|
195
|
+
ObjectExpression: ObjectExpression;
|
|
196
|
+
SequenceExpression: SequenceExpression;
|
|
197
|
+
TaggedTemplateExpression: TaggedTemplateExpression;
|
|
198
|
+
TemplateLiteral: TemplateLiteral;
|
|
199
|
+
ThisExpression: ThisExpression;
|
|
200
|
+
UnaryExpression: UnaryExpression;
|
|
201
|
+
UpdateExpression: UpdateExpression;
|
|
202
|
+
YieldExpression: YieldExpression;
|
|
203
|
+
}
|
|
204
|
+
type Expression = ExpressionMap[keyof ExpressionMap];
|
|
205
|
+
interface BaseExpression extends BaseNode {}
|
|
206
|
+
type ChainElement = SimpleCallExpression | MemberExpression;
|
|
207
|
+
interface ChainExpression extends BaseExpression {
|
|
208
|
+
type: "ChainExpression";
|
|
209
|
+
expression: ChainElement;
|
|
210
|
+
}
|
|
211
|
+
interface ThisExpression extends BaseExpression {
|
|
212
|
+
type: "ThisExpression";
|
|
213
|
+
}
|
|
214
|
+
interface ArrayExpression extends BaseExpression {
|
|
215
|
+
type: "ArrayExpression";
|
|
216
|
+
elements: Array<Expression | SpreadElement | null>;
|
|
217
|
+
}
|
|
218
|
+
interface ObjectExpression extends BaseExpression {
|
|
219
|
+
type: "ObjectExpression";
|
|
220
|
+
properties: Array<Property | SpreadElement>;
|
|
221
|
+
}
|
|
222
|
+
interface PrivateIdentifier extends BaseNode {
|
|
223
|
+
type: "PrivateIdentifier";
|
|
224
|
+
name: string;
|
|
225
|
+
}
|
|
226
|
+
interface Property extends BaseNode {
|
|
227
|
+
type: "Property";
|
|
228
|
+
key: Expression;
|
|
229
|
+
value: Expression | Pattern; // Could be an AssignmentProperty
|
|
230
|
+
kind: "init" | "get" | "set";
|
|
231
|
+
method: boolean;
|
|
232
|
+
shorthand: boolean;
|
|
233
|
+
computed: boolean;
|
|
234
|
+
}
|
|
235
|
+
interface PropertyDefinition extends BaseNode {
|
|
236
|
+
type: "PropertyDefinition";
|
|
237
|
+
key: Expression | PrivateIdentifier;
|
|
238
|
+
value?: Expression | null | undefined;
|
|
239
|
+
computed: boolean;
|
|
240
|
+
static: boolean;
|
|
241
|
+
}
|
|
242
|
+
interface FunctionExpression extends BaseFunction, BaseExpression {
|
|
243
|
+
id?: Identifier | null | undefined;
|
|
244
|
+
type: "FunctionExpression";
|
|
245
|
+
body: BlockStatement;
|
|
246
|
+
}
|
|
247
|
+
interface SequenceExpression extends BaseExpression {
|
|
248
|
+
type: "SequenceExpression";
|
|
249
|
+
expressions: Expression[];
|
|
250
|
+
}
|
|
251
|
+
interface UnaryExpression extends BaseExpression {
|
|
252
|
+
type: "UnaryExpression";
|
|
253
|
+
operator: UnaryOperator;
|
|
254
|
+
prefix: true;
|
|
255
|
+
argument: Expression;
|
|
256
|
+
}
|
|
257
|
+
interface BinaryExpression extends BaseExpression {
|
|
258
|
+
type: "BinaryExpression";
|
|
259
|
+
operator: BinaryOperator;
|
|
260
|
+
left: Expression | PrivateIdentifier;
|
|
261
|
+
right: Expression;
|
|
262
|
+
}
|
|
263
|
+
interface AssignmentExpression extends BaseExpression {
|
|
264
|
+
type: "AssignmentExpression";
|
|
265
|
+
operator: AssignmentOperator;
|
|
266
|
+
left: Pattern | MemberExpression;
|
|
267
|
+
right: Expression;
|
|
268
|
+
}
|
|
269
|
+
interface UpdateExpression extends BaseExpression {
|
|
270
|
+
type: "UpdateExpression";
|
|
271
|
+
operator: UpdateOperator;
|
|
272
|
+
argument: Expression;
|
|
273
|
+
prefix: boolean;
|
|
274
|
+
}
|
|
275
|
+
interface LogicalExpression extends BaseExpression {
|
|
276
|
+
type: "LogicalExpression";
|
|
277
|
+
operator: LogicalOperator;
|
|
278
|
+
left: Expression;
|
|
279
|
+
right: Expression;
|
|
280
|
+
}
|
|
281
|
+
interface ConditionalExpression extends BaseExpression {
|
|
282
|
+
type: "ConditionalExpression";
|
|
283
|
+
test: Expression;
|
|
284
|
+
alternate: Expression;
|
|
285
|
+
consequent: Expression;
|
|
286
|
+
}
|
|
287
|
+
interface BaseCallExpression extends BaseExpression {
|
|
288
|
+
callee: Expression | Super;
|
|
289
|
+
arguments: Array<Expression | SpreadElement>;
|
|
290
|
+
}
|
|
291
|
+
type CallExpression = SimpleCallExpression | NewExpression;
|
|
292
|
+
interface SimpleCallExpression extends BaseCallExpression {
|
|
293
|
+
type: "CallExpression";
|
|
294
|
+
optional: boolean;
|
|
295
|
+
}
|
|
296
|
+
interface NewExpression extends BaseCallExpression {
|
|
297
|
+
type: "NewExpression";
|
|
298
|
+
}
|
|
299
|
+
interface MemberExpression extends BaseExpression, BasePattern {
|
|
300
|
+
type: "MemberExpression";
|
|
301
|
+
object: Expression | Super;
|
|
302
|
+
property: Expression | PrivateIdentifier;
|
|
303
|
+
computed: boolean;
|
|
304
|
+
optional: boolean;
|
|
305
|
+
}
|
|
306
|
+
type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
|
|
307
|
+
interface BasePattern extends BaseNode {}
|
|
308
|
+
interface SwitchCase extends BaseNode {
|
|
309
|
+
type: "SwitchCase";
|
|
310
|
+
test?: Expression | null | undefined;
|
|
311
|
+
consequent: Statement[];
|
|
312
|
+
}
|
|
313
|
+
interface CatchClause extends BaseNode {
|
|
314
|
+
type: "CatchClause";
|
|
315
|
+
param: Pattern | null;
|
|
316
|
+
body: BlockStatement;
|
|
317
|
+
}
|
|
318
|
+
interface Identifier extends BaseNode, BaseExpression, BasePattern {
|
|
319
|
+
type: "Identifier";
|
|
320
|
+
name: string;
|
|
321
|
+
}
|
|
322
|
+
type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
|
|
323
|
+
interface SimpleLiteral extends BaseNode, BaseExpression {
|
|
324
|
+
type: "Literal";
|
|
325
|
+
value: string | boolean | number | null;
|
|
326
|
+
raw?: string | undefined;
|
|
327
|
+
}
|
|
328
|
+
interface RegExpLiteral extends BaseNode, BaseExpression {
|
|
329
|
+
type: "Literal";
|
|
330
|
+
value?: RegExp | null | undefined;
|
|
331
|
+
regex: {
|
|
332
|
+
pattern: string;
|
|
333
|
+
flags: string;
|
|
334
|
+
};
|
|
335
|
+
raw?: string | undefined;
|
|
336
|
+
}
|
|
337
|
+
interface BigIntLiteral extends BaseNode, BaseExpression {
|
|
338
|
+
type: "Literal";
|
|
339
|
+
value?: bigint | null | undefined;
|
|
340
|
+
bigint: string;
|
|
341
|
+
raw?: string | undefined;
|
|
342
|
+
}
|
|
343
|
+
type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
|
|
344
|
+
type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "in" | "instanceof";
|
|
345
|
+
type LogicalOperator = "||" | "&&" | "??";
|
|
346
|
+
type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "||=" | "&&=" | "??=";
|
|
347
|
+
type UpdateOperator = "++" | "--";
|
|
348
|
+
interface ForOfStatement extends BaseForXStatement {
|
|
349
|
+
type: "ForOfStatement";
|
|
350
|
+
await: boolean;
|
|
351
|
+
}
|
|
352
|
+
interface Super extends BaseNode {
|
|
353
|
+
type: "Super";
|
|
354
|
+
}
|
|
355
|
+
interface SpreadElement extends BaseNode {
|
|
356
|
+
type: "SpreadElement";
|
|
357
|
+
argument: Expression;
|
|
358
|
+
}
|
|
359
|
+
interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
|
|
360
|
+
type: "ArrowFunctionExpression";
|
|
361
|
+
expression: boolean;
|
|
362
|
+
body: BlockStatement | Expression;
|
|
363
|
+
}
|
|
364
|
+
interface YieldExpression extends BaseExpression {
|
|
365
|
+
type: "YieldExpression";
|
|
366
|
+
argument?: Expression | null | undefined;
|
|
367
|
+
delegate: boolean;
|
|
368
|
+
}
|
|
369
|
+
interface TemplateLiteral extends BaseExpression {
|
|
370
|
+
type: "TemplateLiteral";
|
|
371
|
+
quasis: TemplateElement[];
|
|
372
|
+
expressions: Expression[];
|
|
373
|
+
}
|
|
374
|
+
interface TaggedTemplateExpression extends BaseExpression {
|
|
375
|
+
type: "TaggedTemplateExpression";
|
|
376
|
+
tag: Expression;
|
|
377
|
+
quasi: TemplateLiteral;
|
|
378
|
+
}
|
|
379
|
+
interface TemplateElement extends BaseNode {
|
|
380
|
+
type: "TemplateElement";
|
|
381
|
+
tail: boolean;
|
|
382
|
+
value: {
|
|
383
|
+
/** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */cooked?: string | null | undefined;
|
|
384
|
+
raw: string;
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
interface AssignmentProperty extends Property {
|
|
388
|
+
value: Pattern;
|
|
389
|
+
kind: "init";
|
|
390
|
+
method: boolean; // false
|
|
391
|
+
}
|
|
392
|
+
interface ObjectPattern extends BasePattern {
|
|
393
|
+
type: "ObjectPattern";
|
|
394
|
+
properties: Array<AssignmentProperty | RestElement>;
|
|
395
|
+
}
|
|
396
|
+
interface ArrayPattern extends BasePattern {
|
|
397
|
+
type: "ArrayPattern";
|
|
398
|
+
elements: Array<Pattern | null>;
|
|
399
|
+
}
|
|
400
|
+
interface RestElement extends BasePattern {
|
|
401
|
+
type: "RestElement";
|
|
402
|
+
argument: Pattern;
|
|
403
|
+
}
|
|
404
|
+
interface AssignmentPattern extends BasePattern {
|
|
405
|
+
type: "AssignmentPattern";
|
|
406
|
+
left: Pattern;
|
|
407
|
+
right: Expression;
|
|
408
|
+
}
|
|
409
|
+
interface BaseClass extends BaseNode {
|
|
410
|
+
superClass?: Expression | null | undefined;
|
|
411
|
+
body: ClassBody;
|
|
412
|
+
}
|
|
413
|
+
interface ClassBody extends BaseNode {
|
|
414
|
+
type: "ClassBody";
|
|
415
|
+
body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
|
|
416
|
+
}
|
|
417
|
+
interface MethodDefinition extends BaseNode {
|
|
418
|
+
type: "MethodDefinition";
|
|
419
|
+
key: Expression | PrivateIdentifier;
|
|
420
|
+
value: FunctionExpression;
|
|
421
|
+
kind: "constructor" | "method" | "get" | "set";
|
|
422
|
+
computed: boolean;
|
|
423
|
+
static: boolean;
|
|
424
|
+
}
|
|
425
|
+
interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration {
|
|
426
|
+
type: "ClassDeclaration";
|
|
427
|
+
/** It is null when a class declaration is a part of the `export default class` statement */
|
|
428
|
+
id: Identifier | null;
|
|
429
|
+
}
|
|
430
|
+
interface ClassDeclaration extends MaybeNamedClassDeclaration {
|
|
431
|
+
id: Identifier;
|
|
432
|
+
}
|
|
433
|
+
interface ClassExpression extends BaseClass, BaseExpression {
|
|
434
|
+
type: "ClassExpression";
|
|
435
|
+
id?: Identifier | null | undefined;
|
|
436
|
+
}
|
|
437
|
+
interface MetaProperty extends BaseExpression {
|
|
438
|
+
type: "MetaProperty";
|
|
439
|
+
meta: Identifier;
|
|
440
|
+
property: Identifier;
|
|
441
|
+
}
|
|
442
|
+
type ModuleDeclaration = ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration;
|
|
443
|
+
interface BaseModuleDeclaration extends BaseNode {}
|
|
444
|
+
interface BaseModuleSpecifier extends BaseNode {
|
|
445
|
+
local: Identifier;
|
|
446
|
+
}
|
|
447
|
+
interface ImportDeclaration extends BaseModuleDeclaration {
|
|
448
|
+
type: "ImportDeclaration";
|
|
449
|
+
specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
|
|
450
|
+
attributes: ImportAttribute[];
|
|
451
|
+
source: Literal;
|
|
452
|
+
}
|
|
453
|
+
interface ImportSpecifier extends BaseModuleSpecifier {
|
|
454
|
+
type: "ImportSpecifier";
|
|
455
|
+
imported: Identifier | Literal;
|
|
456
|
+
}
|
|
457
|
+
interface ImportAttribute extends BaseNode {
|
|
458
|
+
type: "ImportAttribute";
|
|
459
|
+
key: Identifier | Literal;
|
|
460
|
+
value: Literal;
|
|
461
|
+
}
|
|
462
|
+
interface ImportExpression extends BaseExpression {
|
|
463
|
+
type: "ImportExpression";
|
|
464
|
+
source: Expression;
|
|
465
|
+
options?: Expression | null | undefined;
|
|
466
|
+
}
|
|
467
|
+
interface ImportDefaultSpecifier extends BaseModuleSpecifier {
|
|
468
|
+
type: "ImportDefaultSpecifier";
|
|
469
|
+
}
|
|
470
|
+
interface ImportNamespaceSpecifier extends BaseModuleSpecifier {
|
|
471
|
+
type: "ImportNamespaceSpecifier";
|
|
472
|
+
}
|
|
473
|
+
interface ExportNamedDeclaration extends BaseModuleDeclaration {
|
|
474
|
+
type: "ExportNamedDeclaration";
|
|
475
|
+
declaration?: Declaration | null | undefined;
|
|
476
|
+
specifiers: ExportSpecifier[];
|
|
477
|
+
attributes: ImportAttribute[];
|
|
478
|
+
source?: Literal | null | undefined;
|
|
479
|
+
}
|
|
480
|
+
interface ExportSpecifier extends Omit<BaseModuleSpecifier, "local"> {
|
|
481
|
+
type: "ExportSpecifier";
|
|
482
|
+
local: Identifier | Literal;
|
|
483
|
+
exported: Identifier | Literal;
|
|
484
|
+
}
|
|
485
|
+
interface ExportDefaultDeclaration extends BaseModuleDeclaration {
|
|
486
|
+
type: "ExportDefaultDeclaration";
|
|
487
|
+
declaration: MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | Expression;
|
|
488
|
+
}
|
|
489
|
+
interface ExportAllDeclaration extends BaseModuleDeclaration {
|
|
490
|
+
type: "ExportAllDeclaration";
|
|
491
|
+
exported: Identifier | Literal | null;
|
|
492
|
+
attributes: ImportAttribute[];
|
|
493
|
+
source: Literal;
|
|
494
|
+
}
|
|
495
|
+
interface AwaitExpression extends BaseExpression {
|
|
496
|
+
type: "AwaitExpression";
|
|
497
|
+
argument: Expression;
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/parse/gts_plugin.d.ts
|
|
501
|
+
interface GtsPluginOption {
|
|
502
|
+
allowEmptyShortcutMember?: boolean;
|
|
503
|
+
allowEmptyPositionalAttribute?: boolean;
|
|
504
|
+
}
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/parse/index.d.ts
|
|
507
|
+
interface ParseOptions extends GtsPluginOption {
|
|
508
|
+
onComment: Options["onComment"];
|
|
509
|
+
}
|
|
510
|
+
declare function parse(input: string, options?: ParseOptions): Program;
|
|
511
|
+
interface ParseLooseOptions extends GtsPluginOption {
|
|
512
|
+
recordCallLParens?: boolean;
|
|
513
|
+
}
|
|
514
|
+
declare function parseLoose(input: string, options?: ParseLooseOptions): Program;
|
|
15
515
|
//#endregion
|
|
16
516
|
//#region src/transform/gts.d.ts
|
|
17
517
|
interface TranspileOption {
|
|
@@ -132,4 +632,4 @@ declare function resolveGtsConfigSync(filePath: string, inlineConfig: GtsConfig,
|
|
|
132
632
|
declare function transpile(source: string, filename: string, option: TranspileOption): TranspileResult;
|
|
133
633
|
declare function transpileForVolar(source: string, filename: string, option: TranspileOption): VolarMappingResult;
|
|
134
634
|
//#endregion
|
|
135
|
-
export { type GtsConfig, GtsTranspilerError, type TranspileOption, type TranspileResult, type VolarMappingResult, resolveGtsConfig, resolveGtsConfigSync, transpile, transpileForVolar };
|
|
635
|
+
export { type GtsConfig, type ParseLooseOptions as GtsParseLooseOptions, type ParseOptions as GtsParseOptions, GtsTranspilerError, type TranspileOption, type TranspileResult, type VolarMappingResult, parse, parseLoose, resolveGtsConfig, resolveGtsConfigSync, transpile, transpileForVolar };
|
package/dist/index.js
CHANGED
|
@@ -68,8 +68,8 @@ function loosePlugin() {
|
|
|
68
68
|
return function loosePluginTransformer(parser) {
|
|
69
69
|
return class LooseParser extends parser {
|
|
70
70
|
_patchedParseIdent = (liberal) => {
|
|
71
|
-
if (this.type
|
|
72
|
-
else return
|
|
71
|
+
if (this.type === tokTypes.name || this.type.keyword) return super.parseIdent(liberal);
|
|
72
|
+
else return this.createDummyIdentifier();
|
|
73
73
|
};
|
|
74
74
|
#proxiedThis = new Proxy(this, { get: (target, prop) => {
|
|
75
75
|
if (prop === "parseIdent") return this._patchedParseIdent;
|
|
@@ -527,7 +527,8 @@ function parse(input, options) {
|
|
|
527
527
|
ecmaVersion: "latest",
|
|
528
528
|
sourceType: "module",
|
|
529
529
|
locations: true,
|
|
530
|
-
ranges: true
|
|
530
|
+
ranges: true,
|
|
531
|
+
onComment: options?.onComment
|
|
531
532
|
});
|
|
532
533
|
} catch (e) {
|
|
533
534
|
if (e instanceof SyntaxError && "loc" in e) {
|
|
@@ -2044,4 +2045,4 @@ function transpileForVolar(source, filename, option) {
|
|
|
2044
2045
|
});
|
|
2045
2046
|
}
|
|
2046
2047
|
//#endregion
|
|
2047
|
-
export { GtsTranspilerError, resolveGtsConfig, resolveGtsConfigSync, transpile, transpileForVolar };
|
|
2048
|
+
export { GtsTranspilerError, parse, parseLoose, resolveGtsConfig, resolveGtsConfigSync, transpile, transpileForVolar };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
parse,
|
|
3
|
+
parseLoose,
|
|
4
|
+
type ParseLooseOptions,
|
|
5
|
+
type ParseOptions,
|
|
6
|
+
} from "./parse/index.ts";
|
|
2
7
|
import {
|
|
3
8
|
transform,
|
|
4
9
|
transformForVolar,
|
|
@@ -34,7 +39,14 @@ export function transpileForVolar(
|
|
|
34
39
|
});
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
export
|
|
42
|
+
export { parse, parseLoose };
|
|
43
|
+
export type {
|
|
44
|
+
ParseOptions as GtsParseOptions,
|
|
45
|
+
ParseLooseOptions as GtsParseLooseOptions,
|
|
46
|
+
TranspileOption,
|
|
47
|
+
TranspileResult,
|
|
48
|
+
VolarMappingResult,
|
|
49
|
+
};
|
|
38
50
|
export {
|
|
39
51
|
resolveGtsConfig,
|
|
40
52
|
resolveGtsConfigSync,
|
package/src/parse/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Parser } from "acorn";
|
|
1
|
+
import { Parser, type Options } from "acorn";
|
|
2
2
|
import type { Position, Program } from "estree";
|
|
3
3
|
import { tsPlugin } from "@sveltejs/acorn-typescript";
|
|
4
4
|
import { gtsPlugin, type GtsPluginOption } from "./gts_plugin.ts";
|
|
@@ -9,7 +9,11 @@ import { recordCallLParenPlugin } from "./record_call_lparen_plugin.ts";
|
|
|
9
9
|
|
|
10
10
|
const TsParser = Parser.extend(tsPlugin());
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface ParseOptions extends GtsPluginOption {
|
|
13
|
+
onComment: Options["onComment"];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parse(input: string, options?: ParseOptions): Program {
|
|
13
17
|
try {
|
|
14
18
|
const GtsParser = TsParser.extend(gtsPlugin(options));
|
|
15
19
|
return GtsParser.parse(input, {
|
|
@@ -17,6 +21,7 @@ export function parse(input: string, options?: GtsPluginOption): Program {
|
|
|
17
21
|
sourceType: "module",
|
|
18
22
|
locations: true,
|
|
19
23
|
ranges: true,
|
|
24
|
+
onComment: options?.onComment,
|
|
20
25
|
}) as Program;
|
|
21
26
|
} catch (e) {
|
|
22
27
|
if (e instanceof SyntaxError && "loc" in e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { tokTypes, type Parser } from "acorn";
|
|
2
2
|
import type { AST, Parse } from "../types.js";
|
|
3
3
|
|
|
4
|
-
export const DUMMY_PLACEHOLDER =
|
|
4
|
+
export const DUMMY_PLACEHOLDER = "✖";
|
|
5
5
|
|
|
6
6
|
export function loosePlugin() {
|
|
7
7
|
return function loosePluginTransformer(parser: typeof Parser): typeof Parser {
|
|
@@ -9,10 +9,10 @@ export function loosePlugin() {
|
|
|
9
9
|
private readonly _patchedParseIdent = (
|
|
10
10
|
liberal?: boolean,
|
|
11
11
|
): AST.Identifier => {
|
|
12
|
-
if (this.type
|
|
13
|
-
return this.createDummyIdentifier();
|
|
14
|
-
} else {
|
|
12
|
+
if (this.type === tokTypes.name || this.type.keyword) {
|
|
15
13
|
return super.parseIdent(liberal);
|
|
14
|
+
} else {
|
|
15
|
+
return this.createDummyIdentifier();
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
readonly #proxiedThis = new Proxy(this, {
|
|
@@ -29,7 +29,10 @@ export function loosePlugin() {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
createDummyIdentifier() {
|
|
32
|
-
const dummy = this.startNodeAt(
|
|
32
|
+
const dummy = this.startNodeAt(
|
|
33
|
+
this.lastTokEnd,
|
|
34
|
+
this.lastTokEndLoc,
|
|
35
|
+
) as AST.Identifier;
|
|
33
36
|
dummy.name = DUMMY_PLACEHOLDER;
|
|
34
37
|
dummy.isDummy = true;
|
|
35
38
|
return this.finishNode(dummy, "Identifier");
|