Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"printWidth": 120,
"tabWidth": 4,
"trailingComma": "es5",
"endOfLine": "lf",
"arrowParens": "avoid",
"overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }]
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"pretest": "npm run lint && npm run build-lualib",
"test": "jest",
"lint": "npm run lint:eslint && npm run lint:prettier",
"lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
"lint:eslint": "eslint . --ext .js,.ts",
"fix:prettier": "prettier --check --write \"**/*.{js,ts,yml,json,md}\"",
"fix:prettier": "prettier --write .",
"preversion": "npm run build && npm test",
"postversion": "git push && git push --tags"
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"lua-types": "^2.8.0",
"prettier": "^1.19.1",
"prettier": "^2.0.5",
"ts-jest": "^25.2.1",
"ts-node": "^8.6.2"
}
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function __TS__GetErrorStack(constructor: Function): string {
}

function __TS__WrapErrorToString<T extends Error>(getDescription: (this: T) => string): (this: T) => string {
return function(this: Error): string {
return function (this: Error): string {
const description = getDescription.call(this);
const caller = debug.getinfo(3, "f");
if (_VERSION === "Lua 5.1" || (caller && caller.func !== error)) {
Expand Down
2 changes: 1 addition & 1 deletion src/lualib/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function __TS__GeneratorNext(this: GeneratorIterator, ...args: Vararg<any[]>) {
}

function __TS__Generator(this: void, fn: (this: void, ...args: any[]) => any) {
return function(this: void, ...args: Vararg<any[]>): GeneratorIterator {
return function (this: void, ...args: Vararg<any[]>): GeneratorIterator {
const argsLength = select("#", ...args);
return {
// Using explicit this there, since we don't pass arguments after the first nil and context is likely to be nil
Expand Down
9 changes: 1 addition & 8 deletions src/transformation/utils/safe-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ export function hasUnsafeIdentifierName(
}

const fixInvalidLuaIdentifier = (name: string) =>
name.replace(
/[^a-zA-Z0-9_]/g,
c =>
`_${c
.charCodeAt(0)
.toString(16)
.toUpperCase()}`
);
name.replace(/[^a-zA-Z0-9_]/g, c => `_${c.charCodeAt(0).toString(16).toUpperCase()}`);

export const createSafeName = (name: string) => "____" + fixInvalidLuaIdentifier(name);
5 changes: 1 addition & 4 deletions src/transpilation/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ export function transpile({
diagnostics.push(...program.emit(undefined, writeFile, undefined, false, transformers).diagnostics);

// JSON files don't get through transformers and aren't written when outDir is the same as rootDir
program
.getSourceFiles()
.filter(isEmittableJsonFile)
.forEach(processSourceFile);
program.getSourceFiles().filter(isEmittableJsonFile).forEach(processSourceFile);
}

options.noEmit = oldNoEmit;
Expand Down
5 changes: 1 addition & 4 deletions src/tstl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ function updateWatchCompilationHost(
}

function checkNodeVersion(): void {
const [major, minor] = process.version
.slice(1)
.split(".")
.map(Number);
const [major, minor] = process.version.slice(1).split(".").map(Number);
const isValid = major > 12 || (major === 12 && minor >= 13);
if (!isValid) {
console.error(`TypeScriptToLua requires Node.js >=12.13.0, the current version is ${process.version}`);
Expand Down
24 changes: 6 additions & 18 deletions test/unit/builtins/console.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ test.each([
'console.log("Hello %%s", "there")',
'console.log("Hello", "There")',
])("console.log (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test.each([
Expand All @@ -21,9 +19,7 @@ test.each([
'console.info("Hello %%s", "there")',
'console.info("Hello", "There")',
])("console.info (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test.each([
Expand All @@ -33,9 +29,7 @@ test.each([
'console.error("Hello %%s", "there")',
'console.error("Hello", "There")',
])("console.error (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test.each([
Expand All @@ -45,9 +39,7 @@ test.each([
'console.warn("Hello %%s", "there")',
'console.warn("Hello", "There")',
])("console.warn (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test.each([
Expand All @@ -57,9 +49,7 @@ test.each([
'console.trace("Hello %%s", "there")',
'console.trace("Hello", "there")',
])("console.trace (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test.each([
Expand All @@ -69,9 +59,7 @@ test.each([
'console.assert(false, "message %%s", "info")',
'console.assert(false, "message", "more")',
])("console.assert (%p)", code => {
util.testFunction(code)
.setOptions(compilerOptions)
.expectLuaToMatchSnapshot();
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
});

test("console.differentiation", () => {
Expand Down
4 changes: 1 addition & 3 deletions test/unit/builtins/math.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ test.each([
"Math.PI",
])("%s", code => {
// TODO: Remove?
util.testFunction(code)
.disableSemanticCheck()
.expectLuaToMatchSnapshot();
util.testFunction(code).disableSemanticCheck().expectLuaToMatchSnapshot();
});

test.each(["E", "LN10", "LN2", "LOG10E", "LOG2E", "SQRT1_2", "SQRT2"])("Math.%s", constant => {
Expand Down
4 changes: 1 addition & 3 deletions test/unit/expressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ test.each([
"let a = delete tbl.test",
"delete tbl.test",
])("Unary expressions basic (%p)", input => {
util.testFunction(input)
.disableSemanticCheck()
.expectLuaToMatchSnapshot();
util.testFunction(input).disableSemanticCheck().expectLuaToMatchSnapshot();
});

test.each(["3+4", "5-2", "6*3", "6**3", "20/5", "15/10", "15%3"])("Binary expressions basic numeric (%p)", input => {
Expand Down
4 changes: 1 addition & 3 deletions test/unit/json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as util from "../util";

test.each([0, "", [], [1, "2", []], { a: "b" }, { a: { b: "c" } }])("JSON (%p)", json => {
util.testModule(JSON.stringify(json))
.setMainFileName("main.json")
.expectToEqual(json);
util.testModule(JSON.stringify(json)).setMainFileName("main.json").expectToEqual(json);
});

test("Empty JSON file error", () => {
Expand Down
10 changes: 2 additions & 8 deletions test/unit/printer/sourcemaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ test.each([
],
},
])("Source map has correct mapping (%p)", async ({ code, assertPatterns }) => {
const file = util
.testModule(code)
.expectToHaveNoDiagnostics()
.getMainLuaFileResult();
const file = util.testModule(code).expectToHaveNoDiagnostics().getMainLuaFileResult();

const consumer = await new SourceMapConsumer(file.sourceMap);
for (const { luaPattern, typeScriptPattern } of assertPatterns) {
Expand Down Expand Up @@ -228,10 +225,7 @@ test.each([
{ code: "class $$$ {}", name: "$$$" },
{ code: 'namespace $$$ { const foo = "bar"; }', name: "$$$" },
])("Source map has correct name mappings (%p)", async ({ code, name }) => {
const file = util
.testModule(code)
.expectToHaveNoDiagnostics()
.getMainLuaFileResult();
const file = util.testModule(code).expectToHaveNoDiagnostics().getMainLuaFileResult();

const consumer = await new SourceMapConsumer(file.sourceMap);
const typescriptPosition = lineAndColumnOf(code, name);
Expand Down
2 changes: 1 addition & 1 deletion test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function executeJsModule(code: string): any {
const memoize: MethodDecorator = (_target, _propertyKey, descriptor) => {
const originalFunction = descriptor.value as any;
const memoized = new WeakMap();
descriptor.value = function(this: any, ...args: any[]): any {
descriptor.value = function (this: any, ...args: any[]): any {
if (!memoized.has(this)) {
memoized.set(this, originalFunction.apply(this, args));
}
Expand Down