Skip to content

Commit 9faa80d

Browse files
ark120202Perryvw
authored andcommitted
Small improvements (#570)
* LuaJIT target in help now is uppercased * Unsupported for target error message now correctly formats `LuaJIT` * Remove some unused helpers * Specify only esnext lib in options It already references all previous ones. * Add lib to tsconfig and remove browser global `name` usage * Enable noUnusedLocals and noUnusedParameters * Fix `Function expression type inference in constructor` test * Move lua types in lualib to declarations directory * Remove unused string.gmatch declaration * Fix expectToBeDefined not checking for null * Improve toHaveDiagnostics message * Declare correct return type for custom jest matchers * Rename IdentifierOrTableIndexExpression to LeftHandSideExpression * Update dependencies * Remove unused rimraf dependency * Run CI on lowest supported node version * Upgrade npm on appveyor * Add tsconfig to lualib * Check diagnostics of lualib * Rename some variables in Map and Set to match decloration files * Use TypeScript 3.4 readonly array literals syntax * Simplify `expression + 1` for numeric literals * Simplify expression - 1 + 1 * Rename LeftHandSideExpression to AssignmentLeftHandSideExpression * Add generic and literal array form tests * Fix lint warning from tslint version upgrade * Change lualib tslint command to use project
1 parent 26cf33c commit 9faa80d

Some content is hidden

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

54 files changed

+4081
-1425
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
2-
node_js:
3-
- stable
2+
node_js: "8.5.0"
43

54
script:
65
- npm run build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/Type
4242
{
4343
"compilerOptions": {
4444
"target": "esnext",
45-
"lib": ["es2015", "es2016", "es2017", "es2018", "esnext"],
45+
"lib": ["esnext"],
4646
"strict": true
4747
},
4848
"tstl": {
49-
"luaTarget": "JIT"
49+
"luaTarget": "JIT"
5050
}
5151
}
5252
```

appveyor.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test against the latest version of this Node.js version
22
environment:
3-
nodejs_version: "8"
3+
nodejs_version: "8.5.0"
44

55
# Do not build feature branch with open Pull Requests
66
skip_branch_with_pr: true
@@ -13,15 +13,17 @@ cache:
1313
install:
1414
# Get the latest stable version of Node.js or io.js
1515
- ps: Install-Product node $env:nodejs_version
16-
# install modules
16+
# Upgrade npm
17+
- npm install --global npm@6
18+
# Install modules
1719
- npm ci
1820

1921
# Post-install test scripts.
2022
test_script:
2123
# Output useful info for debugging.
2224
- node --version
2325
- npm --version
24-
# run tests
26+
# Run tests
2527
- npm run build
2628
- npm test
2729

build_lualib.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
import * as fs from "fs";
2-
import * as glob from "glob";
32
import * as path from "path";
43
import * as ts from "typescript";
54
import * as tstl from "./src";
65
import { LuaLib } from "./src/LuaLib";
76

8-
const options: tstl.CompilerOptions = {
9-
skipLibCheck: true,
10-
types: [],
11-
target: ts.ScriptTarget.ESNext,
12-
lib: ["lib.esnext.d.ts"],
13-
14-
outDir: path.join(__dirname, "./dist/lualib"),
15-
rootDir: path.join(__dirname, "./src/lualib"),
16-
17-
luaLibImport: tstl.LuaLibImportKind.None,
18-
luaTarget: tstl.LuaTarget.Lua51,
19-
noHeader: true,
20-
};
21-
22-
// TODO: Check diagnostics
23-
const { emitResult } = tstl.transpileFiles(glob.sync("./src/lualib/**/*.ts"), options);
7+
const configFileName = path.resolve(__dirname, "src/lualib/tsconfig.json");
8+
const { emitResult, diagnostics } = tstl.transpileProject(configFileName);
249
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
2510

26-
const bundlePath = path.join(__dirname, "./dist/lualib/lualib_bundle.lua");
11+
const reportDiagnostic = tstl.createDiagnosticReporter(true);
12+
diagnostics.forEach(reportDiagnostic);
13+
14+
const bundlePath = path.join(__dirname, "dist/lualib/lualib_bundle.lua");
2715
if (fs.existsSync(bundlePath)) {
2816
fs.unlinkSync(bundlePath);
2917
}

package-lock.json

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

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test": "jest",
2525
"lint": "npm run lint:tslint && npm run lint:prettier",
2626
"lint:prettier": "prettier --check **/*.{js,ts,yml,json} || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
27-
"lint:tslint": "tslint -p . && tslint -p test && tslint src/lualib/*.ts",
27+
"lint:tslint": "tslint -p . && tslint -p test && tslint -p src/lualib",
2828
"fix:prettier": "prettier --check --write **/*.{js,ts,yml,json}",
2929
"release-major": "npm version major",
3030
"release-minor": "npm version minor",
@@ -40,20 +40,18 @@
4040
},
4141
"dependencies": {
4242
"source-map": "^0.7.3",
43-
"typescript": "^3.3.1"
43+
"typescript": "^3.4.5"
4444
},
4545
"devDependencies": {
46-
"@types/glob": "^5.0.35",
47-
"@types/jest": "^24.0.11",
46+
"@types/glob": "^7.1.1",
47+
"@types/jest": "^24.0.12",
4848
"@types/node": "^11.13.0",
49-
"fengari": "^0.1.2",
50-
"glob": "^7.1.2",
51-
"jest": "^24.5.0",
52-
"jest-circus": "^24.5.0",
53-
"prettier": "^1.16.4",
54-
"rimraf": "^2.6.3",
55-
"ts-jest": "^24.0.0",
49+
"fengari": "^0.1.4",
50+
"jest": "^24.8.0",
51+
"jest-circus": "^24.8.0",
52+
"prettier": "^1.17.0",
53+
"ts-jest": "^24.0.2",
5654
"ts-node": "^7.0.0",
57-
"tslint": "^5.10.0"
55+
"tslint": "^5.16.0"
5856
}
5957
}

src/CommandLineParser.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ function readValue(option: CommandLineOption, value: unknown): ReadValueResult {
211211
};
212212
}
213213

214-
const normalizedValue = value.toLowerCase();
215-
if (option.choices && !option.choices.includes(normalizedValue)) {
214+
const enumValue = option.choices.find(c => c.toLowerCase() === value.toLowerCase());
215+
if (enumValue === undefined) {
216216
const optionChoices = option.choices.join(", ");
217217
return {
218218
value: undefined,
219219
error: diagnostics.argumentForOptionMustBe(`--${option.name}`, optionChoices),
220220
};
221221
}
222222

223-
return { value: normalizedValue };
223+
return { value: enumValue };
224224
}
225225
}
226226
}
@@ -240,3 +240,14 @@ export function parseConfigFileWithSystem(
240240

241241
return updateParsedConfigFile(parsedConfigFile);
242242
}
243+
244+
export function createDiagnosticReporter(pretty: boolean, system = ts.sys): ts.DiagnosticReporter {
245+
const reporter: ts.DiagnosticReporter = (ts as any).createDiagnosticReporter(system, pretty);
246+
return diagnostic => {
247+
if (diagnostic.source === "typescript-to-lua") {
248+
diagnostic = { ...diagnostic, code: ("TL" + diagnostic.code) as any };
249+
}
250+
251+
reporter(diagnostic);
252+
};
253+
}

src/CompilerOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export enum LuaTarget {
1919
Lua51 = "5.1",
2020
Lua52 = "5.2",
2121
Lua53 = "5.3",
22-
LuaJIT = "jit",
22+
LuaJIT = "JIT",
2323
}

src/LuaAST.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export function createVariableDeclarationStatement(
253253
// `test1, test2 = 12, 42`
254254
export interface AssignmentStatement extends Statement {
255255
kind: SyntaxKind.AssignmentStatement;
256-
left: IdentifierOrTableIndexExpression[];
256+
left: AssignmentLeftHandSideExpression[];
257257
right: Expression[];
258258
}
259259

@@ -262,7 +262,7 @@ export function isAssignmentStatement(node: Node): node is AssignmentStatement {
262262
}
263263

264264
export function createAssignmentStatement(
265-
left: IdentifierOrTableIndexExpression | IdentifierOrTableIndexExpression[],
265+
left: AssignmentLeftHandSideExpression | AssignmentLeftHandSideExpression[],
266266
right?: Expression | Expression[],
267267
tsOriginal?: ts.Node,
268268
parent?: Node
@@ -874,7 +874,7 @@ export function createTableIndexExpression(
874874
return expression;
875875
}
876876

877-
export type IdentifierOrTableIndexExpression = Identifier | TableIndexExpression;
877+
export type AssignmentLeftHandSideExpression = Identifier | TableIndexExpression;
878878

879879
export type FunctionDefinition = (VariableDeclarationStatement | AssignmentStatement) & {
880880
right: [FunctionExpression];

0 commit comments

Comments
 (0)