File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,7 +176,9 @@ export function createLocalOrExportedOrGlobalDeclaration(
176176 if ( scope . type === ScopeType . Switch || ( ! isFunctionDeclaration && hasMultipleReferences ( scope , lhs ) ) ) {
177177 // Split declaration and assignment of identifiers that reference themselves in their declaration
178178 declaration = lua . createVariableDeclarationStatement ( lhs , undefined , tsOriginal ) ;
179- assignment = lua . createAssignmentStatement ( lhs , rhs , tsOriginal ) ;
179+ if ( rhs ) {
180+ assignment = lua . createAssignmentStatement ( lhs , rhs , tsOriginal ) ;
181+ }
180182 } else {
181183 declaration = lua . createVariableDeclarationStatement ( lhs , rhs , tsOriginal ) ;
182184 }
Original file line number Diff line number Diff line change @@ -254,3 +254,14 @@ test("Hoisting Shorthand Property", () => {
254254 return foo();` ;
255255 expect ( util . transpileAndExecute ( code ) ) . toBe ( "foobar" ) ;
256256} ) ;
257+
258+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/944
259+ test ( "Hoisting variable without initializer" , ( ) => {
260+ util . testFunction `
261+ function foo() {
262+ return x;
263+ }
264+ let x: number;
265+ return foo();
266+ ` . expectToMatchJsResult ( ) ;
267+ } ) ;
You can’t perform that action at this time.
0 commit comments