Skip to content

Commit 0464ca6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into helpers
2 parents 823ee93 + f0410e0 commit 0464ca6

179 files changed

Lines changed: 8363 additions & 2194 deletions

File tree

Some content is hidden

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

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/dist
2+
/test/translation/transformation
3+
/test/cli/errors
4+
/test/cli/watch
5+
/test/transpile/directories
6+
/test/transpile/outFile

.eslintrc.js

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
2+
const typescriptBase = {
3+
"@typescript-eslint/adjacent-overload-signatures": "error",
4+
"@typescript-eslint/array-type": "error",
5+
"@typescript-eslint/await-thenable": "error",
6+
"@typescript-eslint/ban-types": [
7+
"error",
8+
{
9+
types: {
10+
Function: null,
11+
CallableFunction: { fixWith: "(...args: any[]) => any" },
12+
NewableFunction: { fixWith: "new (...args: any[]) => any" },
13+
},
14+
},
15+
],
16+
camelcase: "off",
17+
"@typescript-eslint/camelcase": ["error", { properties: "never", ignoreDestructuring: true }],
18+
"@typescript-eslint/class-name-casing": "error",
19+
"@typescript-eslint/consistent-type-assertions": [
20+
"error",
21+
{ assertionStyle: "as", objectLiteralTypeAssertions: "never" },
22+
],
23+
"@typescript-eslint/consistent-type-definitions": "error",
24+
"@typescript-eslint/explicit-member-accessibility": ["error", { overrides: { constructors: "no-public" } }],
25+
"@typescript-eslint/generic-type-naming": ["error", "^(T([A-Z][A-Za-z]*)?|U|P|K|V)$"],
26+
"@typescript-eslint/interface-name-prefix": "error",
27+
"no-array-constructor": "off",
28+
"@typescript-eslint/no-array-constructor": "error",
29+
"@typescript-eslint/no-empty-interface": "error",
30+
"@typescript-eslint/no-extra-non-null-assertion": "error",
31+
"@typescript-eslint/no-extraneous-class": "error",
32+
"@typescript-eslint/no-floating-promises": "error",
33+
"@typescript-eslint/no-for-in-array": "error",
34+
"@typescript-eslint/no-inferrable-types": "error",
35+
"@typescript-eslint/no-misused-new": "error",
36+
"@typescript-eslint/no-misused-promises": "error",
37+
"@typescript-eslint/no-namespace": "error",
38+
"@typescript-eslint/no-require-imports": "error",
39+
"@typescript-eslint/no-this-alias": "error",
40+
"no-throw-literal": "off",
41+
"@typescript-eslint/no-throw-literal": "error",
42+
"no-constant-condition": "off",
43+
"@typescript-eslint/no-unnecessary-condition": ["error", { ignoreRhs: true, allowConstantLoopConditions: true }],
44+
"@typescript-eslint/no-unnecessary-qualifier": "error",
45+
"@typescript-eslint/no-unnecessary-type-arguments": "error",
46+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
47+
"no-unused-expressions": "off",
48+
"@typescript-eslint/no-unused-expressions": "error",
49+
"no-useless-constructor": "off",
50+
"@typescript-eslint/no-useless-constructor": "error",
51+
"@typescript-eslint/prefer-function-type": "error",
52+
"@typescript-eslint/prefer-includes": "error",
53+
"@typescript-eslint/prefer-optional-chain": "error",
54+
"@typescript-eslint/prefer-namespace-keyword": "error",
55+
"@typescript-eslint/prefer-readonly": "error",
56+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
57+
"@typescript-eslint/promise-function-async": ["error", { checkArrowFunctions: false }],
58+
quotes: "off",
59+
"@typescript-eslint/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
60+
"@typescript-eslint/require-array-sort-compare": "error",
61+
"@typescript-eslint/require-await": "error",
62+
"@typescript-eslint/restrict-plus-operands": ["error", { checkCompoundAssignments: true }],
63+
"@typescript-eslint/return-await": "error",
64+
"@typescript-eslint/triple-slash-reference": "error",
65+
"@typescript-eslint/unified-signatures": "error",
66+
};
67+
68+
module.exports = {
69+
extends: ["plugin:jest/recommended", "plugin:jest/style"],
70+
parserOptions: {
71+
sourceType: "module",
72+
project: ["test/tsconfig.json", "src/lualib/tsconfig.json", "benchmark/tsconfig.json"],
73+
},
74+
env: { es6: true, node: true },
75+
plugins: ["import"],
76+
rules: {
77+
"arrow-body-style": "error",
78+
curly: ["error", "multi-line"],
79+
eqeqeq: ["error", "always", { null: "ignore" }],
80+
"no-caller": "error",
81+
"no-cond-assign": "error",
82+
"no-debugger": "error",
83+
"no-duplicate-case": "error",
84+
"no-new-wrappers": "error",
85+
"no-restricted-globals": ["error", "parseInt", "parseFloat"],
86+
"no-unused-labels": "error",
87+
"no-var": "error",
88+
"object-shorthand": "error",
89+
"prefer-const": ["error", { destructuring: "all" }],
90+
radix: "error",
91+
"use-isnan": "error",
92+
"object-shorthand": [
93+
"error",
94+
"always",
95+
{ avoidQuotes: true, ignoreConstructors: false, avoidExplicitReturnArrows: true },
96+
],
97+
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "SequenceExpression"],
98+
"spaced-comment": [
99+
"error",
100+
"always",
101+
{
102+
line: { exceptions: ["-", "+"], markers: ["=", "!", "/"] },
103+
block: { exceptions: ["-", "+"], markers: ["=", "!", ":", "::"], balanced: true },
104+
},
105+
],
106+
"no-delete-var": ["error"],
107+
"no-label-var": ["error"],
108+
yoda: ["error"],
109+
"prefer-numeric-literals": ["error"],
110+
"prefer-rest-params": ["error"],
111+
"prefer-spread": ["error"],
112+
"no-useless-computed-key": ["error"],
113+
"for-direction": ["error"],
114+
"no-compare-neg-zero": ["error"],
115+
"no-dupe-else-if": ["error"],
116+
"no-empty": ["error", { allowEmptyCatch: true }],
117+
"no-implicit-coercion": ["error", { boolean: true, number: true, string: true }],
118+
"operator-assignment": ["error"],
119+
"no-path-concat": ["error"],
120+
"no-compare-neg-zero": ["error"],
121+
"no-control-regex": ["error"],
122+
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
123+
"one-var": ["error", "never"],
124+
"prefer-exponentiation-operator": ["error"],
125+
"prefer-object-spread": ["error"],
126+
"no-useless-call": ["off"],
127+
"no-useless-catch": ["error"],
128+
"no-useless-concat": ["error"],
129+
"no-useless-escape": ["error"],
130+
"no-useless-return": ["error"],
131+
132+
"import/no-default-export": "error",
133+
134+
"jest/expect-expect": "off",
135+
"jest/consistent-test-it": ["error", { fn: "test", withinDescribe: "test" }],
136+
"jest/no-expect-resolves": "error",
137+
"jest/no-test-return-statement": "error",
138+
"jest/no-truthy-falsy": "error",
139+
"jest/prefer-spy-on": "error",
140+
"jest/prefer-todo": "error",
141+
"jest/valid-title": "error",
142+
// TODO:
143+
// "jest/lowercase-name": "error",
144+
},
145+
overrides: [
146+
{
147+
files: "**/*.ts",
148+
extends: ["plugin:@typescript-eslint/base"],
149+
rules: {
150+
...typescriptBase,
151+
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
152+
"@typescript-eslint/ban-types": ["error", { types: { null: null } }],
153+
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
154+
"@typescript-eslint/no-require-imports": "off",
155+
"@typescript-eslint/no-unnecessary-condition": "off",
156+
"@typescript-eslint/prefer-for-of": "error",
157+
// TODO: https://github.com/typescript-eslint/typescript-eslint/issues/1265
158+
// "@typescript-eslint/prefer-nullish-coalescing": "error",
159+
"@typescript-eslint/prefer-readonly": "off",
160+
"@typescript-eslint/quotes": ["error", "double", { avoidEscape: true, allowTemplateLiterals: false }],
161+
"@typescript-eslint/require-array-sort-compare": "off",
162+
"@typescript-eslint/camelcase": "off",
163+
164+
// TODO: https://github.com/typescript-eslint/typescript-eslint/issues/1712
165+
// "@typescript-eslint/naming-convention": [
166+
// "error",
167+
// {
168+
// selector: "default",
169+
// format: ["camelCase"],
170+
// leadingUnderscore: "allow",
171+
// },
172+
// {
173+
// selector: "variable",
174+
// format: ["camelCase", "UPPER_CASE"],
175+
// leadingUnderscore: "allow",
176+
// },
177+
// {
178+
// selector: "typeLike",
179+
// format: ["PascalCase"],
180+
// },
181+
// ],
182+
},
183+
},
184+
{
185+
files: "src/lualib/**/*.ts",
186+
rules: {
187+
"no-restricted-syntax": ["error", "LabeledStatement", "SequenceExpression"],
188+
"@typescript-eslint/no-throw-literal": "off",
189+
"@typescript-eslint/prefer-optional-chain": "off",
190+
},
191+
},
192+
{
193+
files: "benchmark/src/memory_benchmarks/**/*.ts",
194+
rules: {
195+
"import/no-default-export": "off",
196+
},
197+
},
198+
],
199+
};

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.github/workflows/ci.yml

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v1
14+
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
- run: npm ci
1717
- run: npm run lint
@@ -38,3 +38,101 @@ jobs:
3838
CI: true
3939
- if: matrix.os == 'ubuntu-latest'
4040
uses: codecov/codecov-action@v1
41+
42+
benchmark:
43+
name: Benchmark
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Lua Install
47+
run: sudo apt-get install lua5.3 luajit
48+
# Checkout master & commit
49+
- name: Checkout master
50+
uses: actions/checkout@v2
51+
with:
52+
ref: master
53+
path: master
54+
- name: Checkout commit
55+
uses: actions/checkout@v2
56+
with:
57+
path: commit
58+
- name: Use Node.js 12.13.1
59+
uses: actions/setup-node@v1
60+
with:
61+
node-version: 12.13.1
62+
# NPM
63+
- name: NPM master
64+
# TODO Lua types is only added manually to test the benchmark PR this can be removed again once the PR is merged
65+
run: npm ci && npm run build && npm install -D lua-types
66+
working-directory: master
67+
- name: NPM commit
68+
run: npm ci && npm run build
69+
working-directory: commit
70+
# Benchmark directory setup
71+
- name: Ensure benchmark data dir exists
72+
run: mkdir -p ./benchmark/data
73+
working-directory: commit
74+
- name: Copy commit benchmark to master
75+
run: rm -rf ./master/benchmark && cp -rf ./commit/benchmark ./master/benchmark
76+
# Run master benchmark first and output to commit benchmark data
77+
- name: Build benchmark Lua 5.3 master
78+
run: node ../dist/tstl.js -p tsconfig.53.json
79+
working-directory: master/benchmark
80+
- name: Run benchmark Lua 5.3 master
81+
id: benchmark-lua-master
82+
run: lua5.3 -- run.lua ../../../commit/benchmark/data/benchmark_master_53.json
83+
working-directory: master/benchmark/dist
84+
- name: Build benchmark LuaJIT master
85+
run: node ../dist/tstl.js -p tsconfig.jit.json
86+
working-directory: master/benchmark
87+
- name: Run benchmark LuaJIT master
88+
id: benchmark-jit-master
89+
run: luajit -- run.lua ../../../commit/benchmark/data/benchmark_master_jit.json
90+
working-directory: master/benchmark/dist
91+
# Run commit benchmark and compare with master
92+
- name: Build benchmark Lua 5.3 commit
93+
run: node ../dist/tstl.js -p tsconfig.53.json
94+
working-directory: commit/benchmark
95+
- name: Run benchmark Lua 5.3 commit
96+
id: benchmark-lua-commit
97+
run: echo ::set-output name=info::`lua5.3 -- run.lua ../data/benchmark_commit_53.json ../data/benchmark_master_53.json`
98+
working-directory: commit/benchmark/dist
99+
- name: Build benchmark LuaJIT commit
100+
run: node ../dist/tstl.js -p tsconfig.jit.json
101+
working-directory: commit/benchmark
102+
- name: Run benchmark LuaJIT commit
103+
id: benchmark-jit-commit
104+
run: echo ::set-output name=info::`luajit -- run.lua ../data/benchmark_commit_jit.json ../data/benchmark_master_jit.json`
105+
working-directory: commit/benchmark/dist
106+
- name: Create benchmark check
107+
uses: actions/github-script@0.9.0
108+
with:
109+
benchmark-info-lua: ${{steps.benchmark-lua-commit.outputs.info}}
110+
benchmark-info-jit: ${{steps.benchmark-jit-commit.outputs.info}}
111+
script: |
112+
const benchmarkInfoLua = JSON.parse(core.getInput('benchmark-info-lua', { required: true }));
113+
const benchmarkInfoJIT = JSON.parse(core.getInput('benchmark-info-jit', { required: true }));
114+
115+
const summary = `### Lua5.3\n${benchmarkInfoLua.summary}\n### LuaJIT\n${benchmarkInfoJIT.summary}`;
116+
117+
const text = `### Lua5.3\n${benchmarkInfoLua.text}\n### LuaJIT\n${benchmarkInfoJIT.text}`;
118+
119+
const pull_request = context.payload.pull_request;
120+
if (!pull_request || pull_request.head.repo.url === pull_request.base.repo.url) {
121+
// This only works if not in a fork.
122+
github.checks.create({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
name: "Benchmark results",
126+
head_sha: context.sha,
127+
status: "completed",
128+
conclusion: "neutral",
129+
output: {
130+
title: "Benchmark results",
131+
summary: summary,
132+
text: text
133+
}
134+
});
135+
} else {
136+
console.log(summary);
137+
console.log(text);
138+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ yarn.lock
66
.vscode
77
.idea
88
.DS_Store
9+
10+
benchmark/data/*
11+
benchmark/dist/*
12+
!benchmark/dist/json.lua

.prettierrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"printWidth": 120,
33
"tabWidth": 4,
4-
"trailingComma": "es5",
5-
"endOfLine": "lf",
4+
"arrowParens": "avoid",
65
"overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }]
76
}

CHANGELOG.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- `Function.length` is supported now
6+
7+
- Fixed `string.replace` incorrectly escaping some `replaceValue` characters (`().+-*?[^$`)
8+
9+
## 0.34.0
10+
11+
- Added new `"luaTarget"` option value - `"universal"`. Choosing this target makes TypeScriptToLua generate code compatible with all supported Lua targets.
12+
13+
- **BREAKING CHANGE:** This is a new default target. If you have been depending on LuaJIT being chosen implicitly, you now have to enable it explicitly with `"luaTarget": "JIT"` in the `tsconfig.json` file.
14+
15+
- TypeScript has been updated to **3.9**. See [release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html) for details. This update includes some fixes specific to our API usage:
16+
17+
- Importing a non-module using `import "./file"` produced a TS2307 error [#35973](https://github.com/microsoft/TypeScript/issues/35973)
18+
- TypeScript now tries to find a call signature even in presence of type errors [#36665](https://github.com/microsoft/TypeScript/pull/36665):
19+
```ts
20+
function foo(this: void, x: string) {}
21+
foo(1);
22+
```
23+
```lua
24+
-- Before: with 3.8 (this: void ignored due to signature mismatch)
25+
foo(nil, 1)
26+
-- Now: with 3.9
27+
foo(1)
28+
```
29+
30+
- Reduced memory consumption and optimized performance of generators and iterators
31+
- Fixed generator syntax being ignored on methods (`*foo() {}`) and function expressions (`function*() {}`)
32+
- Fixed iteration over generators stopping at first yielded `nil` value
33+
- Fixed `Array.prototype.join` throwing an error when array contains anything other than strings and numbers
34+
- Fixed extending a class not keeping `toString` implementation from a super class
35+
36+
- Fixed issue where CLI arguments were incorrectly removed.
37+
- Fixed issue where class accessors threw an error due to a missing dependency.
38+
39+
Under the hood:
40+
41+
- Upgraded to Prettier 2.0
42+
43+
## 0.33.0
44+
45+
- Added support for nullish coalescing `A ?? B`.
46+
- Annotation `/** @noSelf */` now also works directly on function declarations, not only on classes/interfaces.
47+
- Fixed incorrect file paths in source maps.
48+
- Fixed unknown node kind throwing an error instead of diagnostic.
49+
- Fixed string index with side-effects being evaluated twice.
50+
- Added check for node.js version when running tstl.
51+
- Fixed some issues with reflection class names.
52+
53+
- Fixed incorrectly escaped variable names.
54+
55+
Under the hood:
56+
57+
- Switched from TSLint to ESLint.
58+
- Added benchmarking capability for garbage collection.
59+
360
## 0.32.0
461

562
- **Deprecated:** The `noHoisting` option has been removed, hoisting will always be done.

0 commit comments

Comments
 (0)