Skip to content

Commit dadb9d1

Browse files
authored
fix: TSNonNullExpression node support (#2264)
1 parent cab0ad7 commit dadb9d1

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

packages/tinyest-for-wgsl/src/parsers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function isDeclared(ctx: Context, name: string) {
2424
return ctx.stack.some((scope) => scope.declaredNames.includes(name));
2525
}
2626

27+
const tsFallthrough = (ctx: Context, node: { expression: babel.Expression }): tinyest.AnyNode => {
28+
return transpile(ctx, node.expression);
29+
};
30+
2731
const Transpilers: Partial<{
2832
[Type in JsNode['type']]: (
2933
ctx: Context,
@@ -292,13 +296,9 @@ const Transpilers: Partial<{
292296
return [NODE.break];
293297
},
294298

295-
TSAsExpression(ctx, node) {
296-
return transpile(ctx, node.expression);
297-
},
298-
299-
TSSatisfiesExpression(ctx, node) {
300-
return transpile(ctx, node.expression);
301-
},
299+
TSAsExpression: tsFallthrough,
300+
TSSatisfiesExpression: tsFallthrough,
301+
TSNonNullExpression: tsFallthrough,
302302
};
303303

304304
function transpile(ctx: Context, node: JsNode): tinyest.AnyNode {

packages/tinyest-for-wgsl/tests/parsers.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { transpileFn } from '../src/parsers.ts';
66

77
const parseRollup = (code: string) => acorn.parse(code, { ecmaVersion: 'latest' });
88
const parseBabel = (code: string) =>
9-
babel.parse(code, { sourceType: 'module' }).program.body[0] as Node;
9+
babel.parse(code, { sourceType: 'module', plugins: ['typescript'] }).program.body[0] as Node;
1010

1111
function dualTest(test: (p: (code: string) => Node | acorn.AnyNode) => void) {
1212
return () => {
@@ -189,4 +189,10 @@ describe('transpileFn', () => {
189189
expect(externalNames).toStrictEqual([]);
190190
}),
191191
);
192+
193+
it('handles TSNonNullExpression', () => {
194+
const { body } = transpileFn(parseBabel('() => x!.y'));
195+
196+
expect(JSON.stringify(body)).toMatchInlineSnapshot(`"[0,[[10,[7,"x","y"]]]]"`);
197+
});
192198
});

0 commit comments

Comments
 (0)