Skip to content

Commit 8b13adb

Browse files
committed
Merge remote-tracking branch 'upstream/master' into helpers
2 parents 0464ca6 + 8dd12a9 commit 8b13adb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+667
-520
lines changed

CHANGELOG.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Changelog
22

3-
## Unreleased
4-
5-
- `Function.length` is supported now
6-
3+
## 0.35.0
4+
5+
- In preparation for some new features, some public APIs have been changed:
6+
- High-level APIs that read input files from the file system (`transpileFiles` and `transpileProject`) now write transpiled files by default. This behavior can be changed by providing a `writeFile` callback, similarly to TypeScript's `program.emit`.
7+
- `transpile` and `emitTranspiledFiles` functions have been replaced with the `Transpiler` class. See [documentation](https://typescripttolua.github.io/docs/api/overview#low-level-api) for usage examples.
8+
- Fixed `declarationDir` option not being respected.
9+
- `Function.length` is supported now.
10+
- String iteration is now supported.
11+
- Exposed `parseConfigFileWithSystem` to parse _tsconfig.json_ files as part of the tstl API.
712
- Fixed `string.replace` incorrectly escaping some `replaceValue` characters (`().+-*?[^$`)
13+
- Fixed several other string operations behaving differently from JS (mostly regarding indices out of bounds and NaN arguments).
14+
- Fixed a bug where the length argument of `String.prototype.substr` was evaluated twice.
15+
- Fixed some missing dependencies in LuaLib classes (Map, Set, WeakMap, WeakSet)
816

917
## 0.34.0
1018

build-lualib.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ const tstl = require("./src");
66
const { loadLuaLibFeatures } = require("./src/LuaLib");
77

88
const configFileName = path.resolve(__dirname, "src/lualib/tsconfig.json");
9-
const { emitResult, diagnostics } = tstl.transpileProject(configFileName);
10-
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
11-
12-
const reportDiagnostic = tstl.createDiagnosticReporter(true);
13-
diagnostics.forEach(reportDiagnostic);
9+
const { diagnostics } = tstl.transpileProject(configFileName);
10+
diagnostics.forEach(tstl.createDiagnosticReporter(true));
1411

1512
const bundlePath = path.join(__dirname, "dist/lualib/lualib_bundle.lua");
1613
if (fs.existsSync(bundlePath)) {

package-lock.json

Lines changed: 1 addition & 1 deletion
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.34.0",
3+
"version": "0.35.0",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"license": "MIT",

src/CompilerOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export enum LuaTarget {
5151
LuaJIT = "JIT",
5252
}
5353

54+
export const isBundleEnabled = (options: CompilerOptions) =>
55+
options.luaBundle !== undefined && options.luaBundleEntry !== undefined;
56+
5457
export function validateOptions(options: CompilerOptions): ts.Diagnostic[] {
5558
const diagnostics: ts.Diagnostic[] = [];
5659

src/LuaLib.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ export enum LuaLibFeature {
5454
WeakSet = "WeakSet",
5555
SourceMapTraceBack = "SourceMapTraceBack",
5656
Spread = "Spread",
57+
StringAccess = "StringAccess",
58+
StringCharAt = "StringCharAt",
59+
StringCharCodeAt = "StringCharCodeAt",
5760
StringConcat = "StringConcat",
5861
StringEndsWith = "StringEndsWith",
5962
StringPadEnd = "StringPadEnd",
6063
StringPadStart = "StringPadStart",
6164
StringReplace = "StringReplace",
65+
StringSlice = "StringSlice",
6266
StringSplit = "StringSplit",
6367
StringStartsWith = "StringStartsWith",
68+
StringSubstr = "StringSubstr",
69+
StringSubstring = "StringSubstring",
6470
StringTrim = "StringTrim",
6571
StringTrimEnd = "StringTrimEnd",
6672
StringTrimStart = "StringTrimStart",
@@ -79,10 +85,10 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
7985
InstanceOf: [LuaLibFeature.Symbol],
8086
Iterator: [LuaLibFeature.Symbol],
8187
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
82-
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
83-
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
84-
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
85-
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol],
88+
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
89+
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
90+
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
91+
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
8692
Spread: [LuaLibFeature.Iterator, LuaLibFeature.Unpack],
8793
SymbolRegistry: [LuaLibFeature.Symbol],
8894
};

src/lualib/StringAccess.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function __TS__StringAccess(this: string, index: number) {
2+
if (index >= 0 && index < this.length) {
3+
return string.sub(this, index + 1, index + 1);
4+
}
5+
}

src/lualib/StringCharAt.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function __TS__StringCharAt(this: string, pos: number): string {
2+
if (pos !== pos) pos = 0;
3+
if (pos < 0) return "";
4+
return string.sub(this, pos + 1, pos + 1);
5+
}

src/lualib/StringCharCodeAt.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function __TS__StringCharCodeAt(this: string, index: number): number {
2+
if (index !== index) index = 0;
3+
if (index < 0) return NaN;
4+
return string.byte(this, index + 1) ?? NaN;
5+
}

src/lualib/StringPadEnd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ function __TS__StringPadEnd(this: string, maxLength: number, fillString = " "):
1313
fillString += fillString.repeat(maxLength / fillString.length);
1414
}
1515

16-
return this + fillString.slice(0, Math.floor(maxLength));
16+
return this + string.sub(fillString, 1, Math.floor(maxLength));
1717
}

0 commit comments

Comments
 (0)