@gi-tcg/gts-transpiler 0.6.4 → 0.6.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/dist/index.d.ts +15 -0
- package/dist/index.js +11 -1
- package/package.json +1 -1
- package/src/error.ts +3 -0
- package/src/parse/gts_plugin.ts +5 -1
- package/src/transform/gts.ts +6 -0
- package/src/types.ts +17 -0
package/dist/index.d.ts
CHANGED
|
@@ -140,6 +140,13 @@ declare module "estree" {
|
|
|
140
140
|
interface NewExpression {
|
|
141
141
|
lParenRange?: [number, number];
|
|
142
142
|
}
|
|
143
|
+
interface ArrowFunctionExpression {
|
|
144
|
+
returnType?: TSTypeAnnotation;
|
|
145
|
+
}
|
|
146
|
+
interface TSTypeAnnotation extends BaseNode {
|
|
147
|
+
type: "TSTypeAnnotation";
|
|
148
|
+
typeAnnotation: any;
|
|
149
|
+
}
|
|
143
150
|
interface GTSDefineStatement extends BaseStatement {
|
|
144
151
|
type: "GTSDefineStatement";
|
|
145
152
|
body: GTSNamedAttributeDefinition;
|
|
@@ -177,6 +184,7 @@ declare module "estree" {
|
|
|
177
184
|
type: "GTSShortcutFunctionExpression";
|
|
178
185
|
body: BlockStatement | Expression;
|
|
179
186
|
expression: boolean;
|
|
187
|
+
returnType?: TSTypeAnnotation;
|
|
180
188
|
}
|
|
181
189
|
}
|
|
182
190
|
declare module "acorn" {
|
|
@@ -1476,6 +1484,13 @@ declare namespace Parse {
|
|
|
1476
1484
|
aborted: boolean;
|
|
1477
1485
|
failState: any;
|
|
1478
1486
|
};
|
|
1487
|
+
/**
|
|
1488
|
+
* Runs `cb` in a type context.
|
|
1489
|
+
* This should be called one token *before* the first type token,
|
|
1490
|
+
* so that the call to `next()` is run in type context.
|
|
1491
|
+
*/
|
|
1492
|
+
tsInType<T>(cb: () => T): T;
|
|
1493
|
+
tsParseType(): any;
|
|
1479
1494
|
getElementName(node?: AST.Node): string | null;
|
|
1480
1495
|
/**
|
|
1481
1496
|
* The constructor/class type for the extended Ripple parser.
|
package/dist/index.js
CHANGED
|
@@ -240,6 +240,11 @@ function gtsPlugin(options = {}) {
|
|
|
240
240
|
this.enterScope(acornScope.SCOPE_FUNCTION | acornScope.SCOPE_ARROW);
|
|
241
241
|
const oldShortcutContext = this.isShortcutContext;
|
|
242
242
|
this.isShortcutContext = true;
|
|
243
|
+
if (this.type === tokTypes.relational && this.value === "<") {
|
|
244
|
+
this.next();
|
|
245
|
+
node.returnType = this.tsInType(this.tsParseType.bind(this));
|
|
246
|
+
this.expect(tokTypes.relational);
|
|
247
|
+
}
|
|
243
248
|
if (this.type === tokTypes.parenL) {
|
|
244
249
|
this.next();
|
|
245
250
|
node.expression = true;
|
|
@@ -480,12 +485,13 @@ function getCommentHandlers(source, comments, index = 0) {
|
|
|
480
485
|
}
|
|
481
486
|
//#endregion
|
|
482
487
|
//#region src/error.ts
|
|
483
|
-
var GtsTranspilerError = class extends Error {
|
|
488
|
+
var GtsTranspilerError = class GtsTranspilerError extends Error {
|
|
484
489
|
position;
|
|
485
490
|
constructor(message, position) {
|
|
486
491
|
super(message);
|
|
487
492
|
this.name = "GtsTranspilerError";
|
|
488
493
|
this.position = position;
|
|
494
|
+
if ("captureStackTrace" in Error) Error.captureStackTrace(this, GtsTranspilerError);
|
|
489
495
|
}
|
|
490
496
|
};
|
|
491
497
|
//#endregion
|
|
@@ -806,6 +812,10 @@ const commonGtsVisitor = {
|
|
|
806
812
|
params: [state.fnArgId],
|
|
807
813
|
body: visit(node.body),
|
|
808
814
|
expression: node.expression,
|
|
815
|
+
...node.returnType && { returnType: {
|
|
816
|
+
type: "TSTypeAnnotation",
|
|
817
|
+
typeAnnotation: node.returnType
|
|
818
|
+
} },
|
|
809
819
|
loc: node.loc,
|
|
810
820
|
range: node.range
|
|
811
821
|
};
|
package/package.json
CHANGED
package/src/error.ts
CHANGED
package/src/parse/gts_plugin.ts
CHANGED
|
@@ -267,6 +267,11 @@ export function gtsPlugin(options: GtsPluginOption = {}) {
|
|
|
267
267
|
this.enterScope(acornScope.SCOPE_FUNCTION | acornScope.SCOPE_ARROW);
|
|
268
268
|
const oldShortcutContext = this.isShortcutContext;
|
|
269
269
|
this.isShortcutContext = true;
|
|
270
|
+
if (this.type === tokTypes.relational && this.value === "<") {
|
|
271
|
+
this.next(); // consume '<'
|
|
272
|
+
node.returnType = this.tsInType(this.tsParseType.bind(this));
|
|
273
|
+
this.expect(tokTypes.relational);
|
|
274
|
+
}
|
|
270
275
|
if (this.type === tokTypes.parenL) {
|
|
271
276
|
this.next(); // consume '('
|
|
272
277
|
node.expression = true;
|
|
@@ -315,7 +320,6 @@ export function gtsPlugin(options: GtsPluginOption = {}) {
|
|
|
315
320
|
}
|
|
316
321
|
return super.parseExprAtom(refDestructuringErrors, forInit, forNew);
|
|
317
322
|
}
|
|
318
|
-
|
|
319
323
|
};
|
|
320
324
|
};
|
|
321
325
|
}
|
package/src/transform/gts.ts
CHANGED
|
@@ -108,6 +108,12 @@ export const commonGtsVisitor: Visitors<Node, TranspileState> = {
|
|
|
108
108
|
params: [state.fnArgId],
|
|
109
109
|
body: visit(node.body) as Expression | BlockStatement,
|
|
110
110
|
expression: node.expression,
|
|
111
|
+
...(node.returnType && {
|
|
112
|
+
returnType: {
|
|
113
|
+
type: "TSTypeAnnotation",
|
|
114
|
+
typeAnnotation: node.returnType,
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
111
117
|
loc: node.loc,
|
|
112
118
|
range: node.range,
|
|
113
119
|
};
|
package/src/types.ts
CHANGED
|
@@ -29,6 +29,14 @@ declare module "estree" {
|
|
|
29
29
|
interface NewExpression {
|
|
30
30
|
lParenRange?: [number, number];
|
|
31
31
|
}
|
|
32
|
+
interface ArrowFunctionExpression {
|
|
33
|
+
returnType?: TSTypeAnnotation;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TSTypeAnnotation extends BaseNode {
|
|
37
|
+
type: "TSTypeAnnotation";
|
|
38
|
+
typeAnnotation: any;
|
|
39
|
+
}
|
|
32
40
|
|
|
33
41
|
export interface GTSDefineStatement extends BaseStatement {
|
|
34
42
|
type: "GTSDefineStatement";
|
|
@@ -74,6 +82,7 @@ declare module "estree" {
|
|
|
74
82
|
type: "GTSShortcutFunctionExpression";
|
|
75
83
|
body: BlockStatement | Expression;
|
|
76
84
|
expression: boolean;
|
|
85
|
+
returnType?: TSTypeAnnotation;
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
}
|
|
@@ -1500,6 +1509,14 @@ export declare namespace Parse {
|
|
|
1500
1509
|
};
|
|
1501
1510
|
// parse(input: string, options: Options): AST.Program;
|
|
1502
1511
|
|
|
1512
|
+
/**
|
|
1513
|
+
* Runs `cb` in a type context.
|
|
1514
|
+
* This should be called one token *before* the first type token,
|
|
1515
|
+
* so that the call to `next()` is run in type context.
|
|
1516
|
+
*/
|
|
1517
|
+
tsInType<T>(cb: () => T): T
|
|
1518
|
+
tsParseType(): any;
|
|
1519
|
+
|
|
1503
1520
|
getElementName(node?: AST.Node): string | null;
|
|
1504
1521
|
|
|
1505
1522
|
/**
|