File tree Expand file tree Collapse file tree 3 files changed +60
-3
lines changed Expand file tree Collapse file tree 3 files changed +60
-3
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,9 @@ export function popScope(context: TransformationContext): Scope {
92
92
return scope ;
93
93
}
94
94
95
- function isDeclaredInScope ( symbol : ts . Symbol , scopeNode : ts . Node ) {
95
+ function isHoistableFunctionDeclaredInScope ( symbol : ts . Symbol , scopeNode : ts . Node ) {
96
96
return symbol ?. declarations ?. some (
97
- d => findFirstNodeAbove ( d , ( n ) : n is ts . Node => n === scopeNode ) && ! ts . isParameter ( d . parent )
97
+ d => ts . isFunctionDeclaration ( d ) && findFirstNodeAbove ( d , ( n ) : n is ts . Node => n === scopeNode )
98
98
) ;
99
99
}
100
100
@@ -109,7 +109,7 @@ export function hasReferencedUndefinedLocalFunction(context: TransformationConte
109
109
if (
110
110
! scope . functionDefinitions ?. has ( symbolId ) &&
111
111
type . getCallSignatures ( ) . length > 0 &&
112
- isDeclaredInScope ( type . symbol , scope . node )
112
+ isHoistableFunctionDeclaredInScope ( type . symbol , scope . node )
113
113
) {
114
114
return true ;
115
115
}
Original file line number Diff line number Diff line change 81
81
return ____exports"
82
82
` ;
83
83
84
+ exports [` vararg spread optimization curry with indirect type 1` ] = `
85
+ "local ____exports = { }
86
+ function ____exports.__main(self)
87
+ local function test(self, obj, ...)
88
+ local fn = obj.fn
89
+ return fn(nil, ...)
90
+ end
91
+ return test(
92
+ nil,
93
+ {
94
+ fn = function (____ , arg ) return arg end
95
+ } ,
96
+ \\ "foobar\\ "
97
+ )
98
+ end
99
+ return ____exports"
100
+ ` ;
101
+
84
102
exports [` vararg spread optimization finally clause 1` ] = `
85
103
"local ____exports = { }
86
104
function ____exports.__main(self)
105
123
return ____exports"
106
124
` ;
107
125
126
+ exports [` vararg spread optimization function type declared inside scope 1` ] = `
127
+ "local ____exports = { }
128
+ function ____exports.__main(self)
129
+ local function test(self, ...)
130
+ local function fn(____, ...)
131
+ local args = { ... }
132
+ return args[1]
133
+ end
134
+ return fn(nil, ...)
135
+ end
136
+ test(nil, \\ "foobar\\ ")
137
+ end
138
+ return ____exports"
139
+ ` ;
140
+
108
141
exports [` vararg spread optimization if statement 1` ] = `
109
142
"local ____exports = { }
110
143
function ____exports.__main(self)
Original file line number Diff line number Diff line change @@ -241,6 +241,30 @@ describe("vararg spread optimization", () => {
241
241
. expectLuaToMatchSnapshot ( )
242
242
. expectToMatchJsResult ( ) ;
243
243
} ) ;
244
+
245
+ test ( "curry with indirect type" , ( ) => {
246
+ util . testFunction `
247
+ function test<A extends any[]>(obj: {fn: (...args: A) => void}, ...args: A) {
248
+ const fn = obj.fn;
249
+ return fn(...args);
250
+ }
251
+ return test({fn: (arg: string) => arg}, "foobar");
252
+ `
253
+ . expectLuaToMatchSnapshot ( )
254
+ . expectToMatchJsResult ( ) ;
255
+ } ) ;
256
+
257
+ test ( "function type declared inside scope" , ( ) => {
258
+ util . testFunction `
259
+ function test<A extends any[]>(...args: A) {
260
+ const fn: (...args: A) => A[0] = (...args) => args[0];
261
+ return fn(...args);
262
+ }
263
+ test("foobar");
264
+ `
265
+ . expectLuaToMatchSnapshot ( )
266
+ . expectToMatchJsResult ( ) ;
267
+ } ) ;
244
268
} ) ;
245
269
246
270
describe ( "vararg spread de-optimization" , ( ) => {
You can’t perform that action at this time.
0 commit comments