Skip to content

Commit 4c10c28

Browse files
committed
Improved target error messages.
1 parent 1c6d52a commit 4c10c28

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/Transpiler.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export abstract class LuaTranspiler {
419419
public transpileContinue(node: ts.ContinueStatement): string {
420420
throw new TranspileError(
421421
`Unsupported continue statement, ` +
422-
`continue is not supported in Lua ${this.options.luaTarget}.`,
422+
`continue is not supported for target Lua ${this.options.luaTarget}.`,
423423
node
424424
);
425425
}
@@ -881,11 +881,11 @@ export abstract class LuaTranspiler {
881881
}
882882

883883
public transpileUnaryBitOperation(node: ts.PrefixUnaryExpression, operand: string): string {
884-
throw new TranspileError(`Bit operations are not supported in Lua ${this.options.target}`, node);
884+
throw new TranspileError(`Bit operations are not supported for target Lua ${this.options.target}`, node);
885885
}
886886

887887
public transpileBitOperation(node: ts.BinaryExpression, lhs: string, rhs: string): string {
888-
throw new TranspileError(`Bit operations are not supported in Lua ${this.options.target}`, node);
888+
throw new TranspileError(`Bit operations are not supported for target Lua ${this.options.target}`, node);
889889
}
890890

891891
public transpileTemplateExpression(node: ts.TemplateExpression): string {
@@ -1088,7 +1088,7 @@ export abstract class LuaTranspiler {
10881088
return `${translation[identifierString]}`;
10891089
} else {
10901090
throw new TranspileError(`Unsupported string property ${identifierString}, ` +
1091-
`is not supported in Lua ${this.options.luaTarget}.`,
1091+
`is not supported for target Lua ${this.options.luaTarget}.`,
10921092
identifier);
10931093
}
10941094
}
@@ -1303,11 +1303,11 @@ export abstract class LuaTranspiler {
13031303
return result;
13041304
}
13051305

1306-
// Implemented in 5.1 and overridden in 5.2 (and onwards)
1307-
public transpileVariableDestructuring(value: string): string {
1306+
public transpileDestructingAssignmentValue(node: ts.Expression): string {
13081307
throw new TranspileError(
1309-
`transpileVariableDestructuring must be implemented!`,
1310-
null
1308+
`Unsupported destructing statement, ` +
1309+
`destructing statements are not supported for target Lua ${this.options.luaTarget}.`,
1310+
node
13111311
);
13121312
}
13131313

@@ -1330,13 +1330,12 @@ export abstract class LuaTranspiler {
13301330
}
13311331

13321332
const vars = node.name.elements.map(e => this.transpileArrayBindingElement(e)).join(",");
1333-
const value = this.transpileExpression(node.initializer);
13341333

13351334
// Don't unpack TupleReturn decorated functions
13361335
if (tsHelper.isTupleReturnCall(node.initializer, this.checker)) {
1337-
return `local ${vars}=${value}\n`;
1336+
return `local ${vars}=${this.transpileExpression(node.initializer)}\n`;
13381337
} else {
1339-
return `local ${vars}=${this.transpileVariableDestructuring(value)}\n`;
1338+
return `local ${vars}=${this.transpileDestructingAssignmentValue(node.initializer)}\n`;
13401339
}
13411340
} else {
13421341
throw new TranspileError(

src/targets/Transpiler.51.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ts from "typescript";
55

66
export class LuaTranspiler51 extends LuaTranspiler {
77
/** @override */
8-
public transpileVariableDestructuring(value: string): string {
9-
return `unpack(${value})`;
8+
public transpileDestructingAssignmentValue(node: ts.Expression): string {
9+
return `unpack(${this.transpileExpression(node)})`;
1010
}
1111
}

src/targets/Transpiler.52.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class LuaTranspiler52 extends LuaTranspiler51 {
5555
}
5656

5757
/** @override */
58-
public transpileVariableDestructuring(value: string): string {
59-
return `table.unpack(${value})`;
58+
public transpileDestructingAssignmentValue(node: ts.Expression): string {
59+
return `table.unpack(${this.transpileExpression(node)})`;
6060
}
6161
}

test/unit/expressions.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class ExpressionTests {
289289

290290
const identifier = ts.createIdentifier("fromCodePoint");
291291
Expect(() => transpiler.transpileStringExpression(identifier))
292-
.toThrowError(Error, "Unsupported string property fromCodePoint, is not supported in Lua JIT.");
292+
.toThrowError(Error, "Unsupported string property fromCodePoint, is not supported for target Lua JIT.");
293293
}
294294

295295
@Test("Unknown string expression error")
@@ -298,7 +298,7 @@ export class ExpressionTests {
298298

299299
const identifier = ts.createIdentifier("abcd");
300300
Expect(() => transpiler.transpileStringExpression(identifier))
301-
.toThrowError(Error, "Unsupported string property abcd, is not supported in Lua JIT.");
301+
.toThrowError(Error, "Unsupported string property abcd, is not supported for target Lua JIT.");
302302
}
303303

304304
@Test("Unsupported array function error")

0 commit comments

Comments
 (0)