Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,10 @@ export class LuaTransformer {
}

public transformImportDeclaration(statement: ts.ImportDeclaration): StatementVisitResult {
if (!statement.importClause || !statement.importClause.namedBindings) {
if (statement.importClause && !statement.importClause.namedBindings) {
throw TSTLErrors.DefaultImportsNotSupported(statement);
}

const imports = statement.importClause.namedBindings;

const result: tstl.Statement[] = [];

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

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

if (!statement.importClause) {
result.push(tstl.createExpressionStatement(requireCall));
return result;
}

const imports = statement.importClause.namedBindings;
if (ts.isNamedImports(imports)) {
const filteredElements = imports.elements.filter(e => {
const decorators = tsHelper.getCustomDecorators(this.checker.getTypeAtLocation(e), this.checker);
Expand Down
1 change: 1 addition & 0 deletions test/translation/lua/modulesImportWithoutFromClause.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("test");
1 change: 1 addition & 0 deletions test/translation/ts/modulesImportWithoutFromClause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "test";