|
1 | 1 | import * as ts from "typescript"; |
2 | 2 | import * as lua from "../../LuaAST"; |
3 | | -import { getOrUpdate, isNonNull } from "../../utils"; |
| 3 | +import { assert, getOrUpdate, isNonNull } from "../../utils"; |
4 | 4 | import { TransformationContext } from "../context"; |
5 | | -import { UndefinedFunctionDefinition, UndefinedScope } from "./errors"; |
| 5 | +import { UndefinedScope } from "./errors"; |
6 | 6 | import { replaceStatementInParent } from "./lua-ast"; |
7 | 7 | import { getSymbolInfo } from "./symbols"; |
8 | 8 | import { getFirstDeclarationInFile } from "./typescript"; |
@@ -125,9 +125,7 @@ function shouldHoistSymbol(context: TransformationContext, symbolId: lua.SymbolI |
125 | 125 |
|
126 | 126 | if (scope.functionDefinitions) { |
127 | 127 | for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) { |
128 | | - if (functionDefinition.definition === undefined) { |
129 | | - throw UndefinedFunctionDefinition(functionSymbolId); |
130 | | - } |
| 128 | + assert(functionDefinition.definition); |
131 | 129 |
|
132 | 130 | const { line, column } = lua.getOriginalPos(functionDefinition.definition); |
133 | 131 | if (line !== undefined && column !== undefined) { |
@@ -202,9 +200,7 @@ function hoistFunctionDefinitions( |
202 | 200 | const result = [...statements]; |
203 | 201 | const hoistedFunctions: Array<lua.VariableDeclarationStatement | lua.AssignmentStatement> = []; |
204 | 202 | for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) { |
205 | | - if (functionDefinition.definition === undefined) { |
206 | | - throw UndefinedFunctionDefinition(functionSymbolId); |
207 | | - } |
| 203 | + assert(functionDefinition.definition); |
208 | 204 |
|
209 | 205 | if (shouldHoistSymbol(context, functionSymbolId, scope)) { |
210 | 206 | const index = result.indexOf(functionDefinition.definition); |
|
0 commit comments