@@ -36,6 +36,7 @@ export function getTransformers(
36
36
37
37
...( transformersFromOptions . after ?? [ ] ) ,
38
38
...( customTransformers . after ?? [ ] ) ,
39
+ stripParenthesisExpressionsTransformer ,
39
40
luaTransformer ,
40
41
] ,
41
42
} ;
@@ -53,6 +54,30 @@ export const noImplicitSelfTransformer: ts.TransformerFactory<ts.SourceFile | ts
53
54
: transformSourceFile ( node ) ;
54
55
} ;
55
56
57
+ export const stripParenthesisExpressionsTransformer : ts . TransformerFactory < ts . SourceFile > = context => sourceFile => {
58
+ // Remove parenthesis expressions before transforming to Lua, so transpiler is not hindered by extra ParenthesizedExpression nodes
59
+ function unwrapParentheses ( node : ts . Expression ) {
60
+ while ( ts . isParenthesizedExpression ( node ) ) {
61
+ node = node . expression ;
62
+ }
63
+ return node ;
64
+ }
65
+ function visit ( node : ts . Node ) : ts . Node {
66
+ // For now only call expressions strip their expressions of parentheses, there could be more cases where this is required
67
+ if ( ts . isCallExpression ( node ) ) {
68
+ return ts . factory . updateCallExpression (
69
+ node ,
70
+ unwrapParentheses ( node . expression ) ,
71
+ node . typeArguments ,
72
+ node . arguments
73
+ ) ;
74
+ }
75
+
76
+ return ts . visitEachChild ( node , visit , context ) ;
77
+ }
78
+ return ts . visitNode ( sourceFile , visit ) ;
79
+ } ;
80
+
56
81
function loadTransformersFromOptions ( program : ts . Program , diagnostics : ts . Diagnostic [ ] ) : ts . CustomTransformers {
57
82
const customTransformers : Required < ts . CustomTransformers > = {
58
83
before : [ ] ,
0 commit comments