Skip to content

Commit 243a83a

Browse files
committed
Merge branch 'master' into feature/module-resolution
# Conflicts: # package-lock.json
2 parents af82e4e + 2ff677c commit 243a83a

11 files changed

Lines changed: 3894 additions & 3871 deletions

File tree

package-lock.json

Lines changed: 3480 additions & 3568 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-to-lua",
3-
"version": "0.39.2",
3+
"version": "0.39.3",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",

src/LuaLib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
106106
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
107107
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
108108
Spread: [LuaLibFeature.Iterator, LuaLibFeature.Unpack],
109-
StringSplit: [LuaLibFeature.StringSubstring],
109+
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
110110
SymbolRegistry: [LuaLibFeature.Symbol],
111111
};
112112
/* eslint-enable @typescript-eslint/naming-convention */

src/transformation/visitors/namespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const transformModuleDeclaration: FunctionVisitor<ts.ModuleDeclaration> =
7676
const isFirstDeclaration =
7777
symbol === undefined ||
7878
(!symbol.declarations.some(d => ts.isClassLike(d) || ts.isFunctionDeclaration(d)) &&
79-
node === symbol.declarations.find(ts.isModuleDeclaration));
79+
ts.getOriginalNode(node) === symbol.declarations.find(ts.isModuleDeclaration));
8080

8181
if (isNonModuleMergeable) {
8282
// 'local NS = NS or {}' or 'exportTable.NS = exportTable.NS or {}'

src/transformation/visitors/switch.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export const transformSwitchStatement: FunctionVisitor<ts.SwitchStatement> = (st
1818

1919
let statements: lua.Statement[] = [];
2020

21-
const caseClauses = statement.caseBlock.clauses.filter(ts.isCaseClause);
22-
2321
// Starting from the back, concatenating ifs into one big if/elseif statement
24-
const concatenatedIf = caseClauses.reduceRight((previousCondition, clause, index) => {
22+
const concatenatedIf = statement.caseBlock.clauses.reduceRight((previousCondition, clause, index) => {
23+
if (ts.isDefaultClause(clause)) {
24+
// Skip default clause here (needs to be included to ensure index lines up with index later)
25+
return previousCondition;
26+
}
27+
2528
// If the clause condition holds, go to the correct label
2629
const condition = lua.createBinaryExpression(
2730
switchVariable,

test/transpile/plugins/plugins.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,23 @@ test("statement comments", () => {
4040
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "add-comments.ts") }] })
4141
.expectLuaToMatchSnapshot();
4242
});
43+
44+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1013
45+
test.each(["namespace", "module"])("%s with TS transformer plugin", moduleOrNamespace => {
46+
util.testModule`
47+
import { ns } from "module";
48+
export const result = ns.returnsBool();
49+
`
50+
.addExtraFile(
51+
"module.ts",
52+
`
53+
export ${moduleOrNamespace} ns {
54+
export function returnsBool() {
55+
return false;
56+
}
57+
}
58+
`
59+
)
60+
.setOptions({ plugins: [{ transform: path.join(__dirname, "transformer-plugin.ts") }] })
61+
.expectNoExecutionError();
62+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This is a TS tranformer plugin that replaces any return statement to 'return true'.
3+
*/
4+
import * as ts from "typescript";
5+
6+
const replaceNode = (node: ts.Node) => {
7+
if (ts.isReturnStatement(node)) {
8+
return ts.factory.createReturnStatement(ts.factory.createTrue());
9+
}
10+
};
11+
const createTransformer = () => (context: ts.TransformationContext) => {
12+
const visit = (node: ts.Node): ts.Node => replaceNode(node) ?? ts.visitEachChild(node, visit, context);
13+
return (file: ts.SourceFile) => ts.visitNode(file, visit);
14+
};
15+
exports.default = createTransformer;
File renamed without changes.

test/unit/builtins/string.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ test("string.split inline", () => {
200200
.expectToMatchJsResult();
201201
});
202202

203+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1009
204+
test("string.split inline empty separator", () => {
205+
util.testExpression`"a, b, c".split("")`
206+
.setOptions({ luaLibImport: LuaLibImportKind.Inline })
207+
.expectToMatchJsResult();
208+
});
209+
203210
test.each([
204211
{ inp: "hello test", index: 0 },
205212
{ inp: "hello test", index: 1 },

0 commit comments

Comments
 (0)