Skip to content

Commit afb65e2

Browse files
ark120202Perryvw
authored andcommitted
Support import without from clause (#405)
1 parent 573b762 commit afb65e2

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/LuaTransformer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,10 @@ export class LuaTransformer {
206206
}
207207

208208
public transformImportDeclaration(statement: ts.ImportDeclaration): StatementVisitResult {
209-
if (!statement.importClause || !statement.importClause.namedBindings) {
209+
if (statement.importClause && !statement.importClause.namedBindings) {
210210
throw TSTLErrors.DefaultImportsNotSupported(statement);
211211
}
212212

213-
const imports = statement.importClause.namedBindings;
214-
215213
const result: tstl.Statement[] = [];
216214

217215
const moduleSpecifier = statement.moduleSpecifier as ts.StringLiteral;
@@ -220,6 +218,12 @@ export class LuaTransformer {
220218

221219
const requireCall = tstl.createCallExpression(tstl.createIdentifier("require"), [resolvedModuleSpecifier]);
222220

221+
if (!statement.importClause) {
222+
result.push(tstl.createExpressionStatement(requireCall));
223+
return result;
224+
}
225+
226+
const imports = statement.importClause.namedBindings;
223227
if (ts.isNamedImports(imports)) {
224228
const filteredElements = imports.elements.filter(e => {
225229
const decorators = tsHelper.getCustomDecorators(this.checker.getTypeAtLocation(e), this.checker);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("test");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "test";

0 commit comments

Comments
 (0)