Skip to content

Commit dc18e47

Browse files
ark120202Perryvw
authored andcommitted
Upgrade dependencies (#763)
* Upgrade dependencies * Format with Prettier * Fix jest `Matchers` declaration * Fix tslint warning * Fix `isStrict` detection logic
1 parent e238cc7 commit dc18e47

37 files changed

+1078
-1373
lines changed

package-lock.json

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

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@
3939
"node": ">=8.5.0"
4040
},
4141
"dependencies": {
42-
"resolve": "^1.11.0",
42+
"resolve": "^1.13.1",
4343
"source-map": "^0.7.3",
44-
"typescript": "^3.6.2"
44+
"typescript": "^3.7.3"
4545
},
4646
"devDependencies": {
4747
"@types/fs-extra": "^8.0.1",
4848
"@types/glob": "^7.1.1",
49-
"@types/jest": "^24.0.15",
50-
"@types/node": "^11.13.14",
49+
"@types/jest": "^24.0.23",
50+
"@types/node": "^12.12.14",
5151
"@types/resolve": "0.0.8",
5252
"fengari": "^0.1.4",
5353
"fs-extra": "^8.1.0",
54-
"javascript-stringify": "^2.0.0",
55-
"jest": "^24.8.0",
56-
"jest-circus": "^24.8.0",
57-
"prettier": "^1.18.2",
58-
"ts-jest": "^24.0.2",
59-
"ts-node": "^7.0.1",
60-
"tslint": "^5.17.0"
54+
"javascript-stringify": "^2.0.1",
55+
"jest": "^24.9.0",
56+
"jest-circus": "^24.9.0",
57+
"prettier": "^1.19.1",
58+
"ts-jest": "^24.2.0",
59+
"ts-node": "^8.5.4",
60+
"tslint": "^5.20.1"
6161
}
6262
}

src/Emit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function emitTranspiledFiles(
1919
let { outDir, luaLibImport, luaBundle } = options;
2020

2121
const rootDir = program.getCommonSourceDirectory();
22-
outDir = outDir || rootDir;
22+
outDir = outDir ?? rootDir;
2323

2424
const files: OutputFile[] = [];
2525
for (const { fileName, lua, sourceMap, declaration, declarationMap } of transpiledFiles) {
@@ -54,7 +54,7 @@ export function emitTranspiledFiles(
5454
luaLibImport === LuaLibImportKind.Require ||
5555
luaLibImport === LuaLibImportKind.Always)
5656
) {
57-
const lualibRequired = files.some(f => f.text && f.text.includes(`require("lualib_bundle")`));
57+
const lualibRequired = files.some(f => f.text?.includes(`require("lualib_bundle")`));
5858
if (lualibRequired) {
5959
if (lualibContent === undefined) {
6060
const lualibBundle = emitHost.readFile(path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"));

src/LuaAST.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export function setParent(node: Node | Node[] | undefined, parent: Node): void {
186186
}
187187

188188
function getSourcePosition(sourceNode: ts.Node): TextRange | undefined {
189-
if (sourceNode !== undefined && sourceNode.getSourceFile() !== undefined && sourceNode.pos >= 0) {
189+
if (sourceNode.getSourceFile() !== undefined && sourceNode.pos >= 0) {
190190
const { line, character } = ts.getLineAndCharacterOfPosition(
191191
sourceNode.getSourceFile(),
192192
sourceNode.pos + sourceNode.getLeadingTriviaWidth()
@@ -901,12 +901,7 @@ export type FunctionDefinition = (VariableDeclarationStatement | AssignmentState
901901
export function isFunctionDefinition(
902902
statement: VariableDeclarationStatement | AssignmentStatement
903903
): statement is FunctionDefinition {
904-
return (
905-
statement.left.length === 1 &&
906-
statement.right !== undefined &&
907-
statement.right.length === 1 &&
908-
isFunctionExpression(statement.right[0])
909-
);
904+
return statement.left.length === 1 && statement.right?.length === 1 && isFunctionExpression(statement.right[0]);
910905
}
911906

912907
export type InlineFunctionExpression = FunctionExpression & {
@@ -915,8 +910,7 @@ export type InlineFunctionExpression = FunctionExpression & {
915910

916911
export function isInlineFunctionExpression(expression: FunctionExpression): expression is InlineFunctionExpression {
917912
return (
918-
expression.body.statements !== undefined &&
919-
expression.body.statements.length === 1 &&
913+
expression.body.statements?.length === 1 &&
920914
isReturnStatement(expression.body.statements[0]) &&
921915
(expression.body.statements[0] as ReturnStatement).expressions !== undefined &&
922916
(expression.flags & FunctionExpressionFlags.Inline) !== 0

src/LuaPrinter.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const escapeStringMap: Record<string, string> = {
2323
"\0": "\\0",
2424
};
2525

26-
export const escapeString = (value: string) =>
27-
`"${value.replace(escapeStringRegExp, char => escapeStringMap[char] || char)}"`;
26+
export const escapeString = (value: string) => `"${value.replace(escapeStringRegExp, char => escapeStringMap[char])}"`;
2827

2928
/**
3029
* Checks that a name is valid for use in lua function declaration syntax:
@@ -198,7 +197,7 @@ export class LuaPrinter {
198197
header += `--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]\n`;
199198
}
200199

201-
const luaLibImport = this.options.luaLibImport || LuaLibImportKind.Require;
200+
const luaLibImport = this.options.luaLibImport ?? LuaLibImportKind.Require;
202201
if (
203202
luaLibImport === LuaLibImportKind.Always ||
204203
(luaLibImport === LuaLibImportKind.Require && luaLibFeatures.size > 0)
@@ -341,11 +340,21 @@ export class LuaPrinter {
341340
// Print all local functions as `local function foo()` instead of `local foo = function` to allow recursion
342341
chunks.push(this.printFunctionDefinition(statement));
343342
} else {
344-
chunks.push(...this.joinChunks(", ", statement.left.map(e => this.printExpression(e))));
343+
chunks.push(
344+
...this.joinChunks(
345+
", ",
346+
statement.left.map(e => this.printExpression(e))
347+
)
348+
);
345349

346350
if (statement.right) {
347351
chunks.push(" = ");
348-
chunks.push(...this.joinChunks(", ", statement.right.map(e => this.printExpression(e))));
352+
chunks.push(
353+
...this.joinChunks(
354+
", ",
355+
statement.right.map(e => this.printExpression(e))
356+
)
357+
);
349358
}
350359
}
351360

@@ -369,9 +378,19 @@ export class LuaPrinter {
369378
}
370379
}
371380

372-
chunks.push(...this.joinChunks(", ", statement.left.map(e => this.printExpression(e))));
381+
chunks.push(
382+
...this.joinChunks(
383+
", ",
384+
statement.left.map(e => this.printExpression(e))
385+
)
386+
);
373387
chunks.push(" = ");
374-
chunks.push(...this.joinChunks(", ", statement.right.map(e => this.printExpression(e))));
388+
chunks.push(
389+
...this.joinChunks(
390+
", ",
391+
statement.right.map(e => this.printExpression(e))
392+
)
393+
);
375394

376395
return this.createSourceNode(statement, chunks);
377396
}
@@ -458,8 +477,14 @@ export class LuaPrinter {
458477
}
459478

460479
public printForInStatement(statement: lua.ForInStatement): SourceNode {
461-
const names = this.joinChunks(", ", statement.names.map(i => this.printIdentifier(i)));
462-
const expressions = this.joinChunks(", ", statement.expressions.map(e => this.printExpression(e)));
480+
const names = this.joinChunks(
481+
", ",
482+
statement.names.map(i => this.printIdentifier(i))
483+
);
484+
const expressions = this.joinChunks(
485+
", ",
486+
statement.expressions.map(e => this.printExpression(e))
487+
);
463488

464489
const chunks: SourceChunk[] = [];
465490

@@ -488,7 +513,12 @@ export class LuaPrinter {
488513

489514
const chunks: SourceChunk[] = [];
490515

491-
chunks.push(...this.joinChunks(", ", statement.expressions.map(e => this.printExpression(e))));
516+
chunks.push(
517+
...this.joinChunks(
518+
", ",
519+
statement.expressions.map(e => this.printExpression(e))
520+
)
521+
);
492522

493523
return this.createSourceNode(statement, [this.indent(), "return ", ...chunks]);
494524
}
@@ -588,7 +618,10 @@ export class LuaPrinter {
588618
chunks.push(" ");
589619
const returnNode: SourceChunk[] = [
590620
"return ",
591-
...this.joinChunks(", ", returnStatement.expressions.map(e => this.printExpression(e))),
621+
...this.joinChunks(
622+
", ",
623+
returnStatement.expressions.map(e => this.printExpression(e))
624+
),
592625
];
593626
chunks.push(this.createSourceNode(returnStatement, returnNode));
594627
chunks.push(this.createSourceNode(expression, " end"));
@@ -780,7 +813,12 @@ export class LuaPrinter {
780813
const chunks: SourceChunk[] = [];
781814

782815
if (expressions.every(isSimpleExpression)) {
783-
chunks.push(...this.joinChunks(", ", expressions.map(e => this.printExpression(e))));
816+
chunks.push(
817+
...this.joinChunks(
818+
", ",
819+
expressions.map(e => this.printExpression(e))
820+
)
821+
);
784822
} else {
785823
chunks.push("\n");
786824
this.pushIndent();

src/TSTransformers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function getCustomTransformers(
2020
const transformersFromOptions = loadTransformersFromOptions(program, diagnostics);
2121

2222
const afterDeclarations = [
23-
...(transformersFromOptions.afterDeclarations || []),
24-
...(customTransformers.afterDeclarations || []),
23+
...(transformersFromOptions.afterDeclarations ?? []),
24+
...(customTransformers.afterDeclarations ?? []),
2525
];
2626

2727
const options = program.getCompilerOptions() as CompilerOptions;
@@ -32,11 +32,11 @@ export function getCustomTransformers(
3232
return {
3333
afterDeclarations,
3434
before: [
35-
...(customTransformers.before || []),
36-
...(transformersFromOptions.before || []),
35+
...(customTransformers.before ?? []),
36+
...(transformersFromOptions.before ?? []),
3737

38-
...(transformersFromOptions.after || []),
39-
...(customTransformers.after || []),
38+
...(transformersFromOptions.after ?? []),
39+
...(customTransformers.after ?? []),
4040
luaTransformer,
4141
],
4242
};
@@ -197,7 +197,7 @@ function loadTransformer(
197197
} else {
198198
const isValidGroupTransformer =
199199
typeof transformer === "object" &&
200-
(transformer.before || transformer.after || transformer.afterDeclarations);
200+
(transformer.before ?? transformer.after ?? transformer.afterDeclarations) !== undefined;
201201

202202
if (!isValidGroupTransformer) {
203203
return { error: diagnosticFactories.transformerShouldBeATsTransformerFactory(transform) };

src/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function bundleTranspiledFiles(
4141
);
4242

4343
// If any of the modules contains a require for lualib_bundle, add it to the module table.
44-
const lualibRequired = transpiledFiles.some(f => f.lua && f.lua.includes(`require("lualib_bundle")`));
44+
const lualibRequired = transpiledFiles.some(f => f.lua?.includes(`require("lualib_bundle")`));
4545
if (lualibRequired) {
4646
const lualibBundle = emitHost.readFile(path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"));
4747
moduleTableEntries.push(`["lualib_bundle"] = function() ${lualibBundle} end,\n`);

src/cli/information.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function getHelpString(): string {
1919

2020
result += "Options:\n";
2121
for (const option of optionDeclarations) {
22-
const aliasStrings = (option.aliases || []).map(a => "-" + a);
22+
const aliasStrings = (option.aliases ?? []).map(a => "-" + a);
2323
const optionString = aliasStrings.concat(["--" + option.name]).join("|");
2424

2525
const valuesHint = option.type === "enum" ? option.choices.join("|") : option.type;

src/transformation/builtins/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ts from "typescript";
22
import * as lua from "../../LuaAST";
3+
import { assume } from "../../utils";
34
import { TransformationContext } from "../context";
45
import { importLuaLibFeature, LuaLibFeature } from "../utils/lualib";
56
import { getIdentifierSymbolId } from "../utils/symbols";
@@ -60,8 +61,7 @@ export function transformBuiltinCallExpression(
6061
return;
6162
}
6263

63-
// TODO(TypeScript 3.7): assume
64-
const propertyCall = node as PropertyCallExpression;
64+
assume<PropertyCallExpression>(node);
6565

6666
// If the function being called is of type owner.func, get the type of owner
6767
const ownerType = context.checker.getTypeAtLocation(node.expression.expression);
@@ -71,40 +71,40 @@ export function transformBuiltinCallExpression(
7171
const symbolName = symbol && symbol.name;
7272
switch (symbolName) {
7373
case "Console":
74-
return transformConsoleCall(context, propertyCall);
74+
return transformConsoleCall(context, node);
7575
case "Math":
76-
return transformMathCall(context, propertyCall);
76+
return transformMathCall(context, node);
7777
case "StringConstructor":
78-
return transformStringConstructorCall(context, propertyCall);
78+
return transformStringConstructorCall(context, node);
7979
case "ObjectConstructor":
80-
return transformObjectConstructorCall(context, propertyCall);
80+
return transformObjectConstructorCall(context, node);
8181
case "SymbolConstructor":
82-
return transformSymbolConstructorCall(context, propertyCall);
82+
return transformSymbolConstructorCall(context, node);
8383
case "NumberConstructor":
84-
return transformNumberConstructorCall(context, propertyCall);
84+
return transformNumberConstructorCall(context, node);
8585
}
8686
}
8787

8888
if (isStringType(context, ownerType)) {
89-
return transformStringPrototypeCall(context, propertyCall);
89+
return transformStringPrototypeCall(context, node);
9090
}
9191

9292
if (isNumberType(context, ownerType)) {
93-
return transformNumberPrototypeCall(context, propertyCall);
93+
return transformNumberPrototypeCall(context, node);
9494
}
9595

9696
if (isArrayType(context, ownerType)) {
97-
const result = transformArrayPrototypeCall(context, propertyCall);
97+
const result = transformArrayPrototypeCall(context, node);
9898
if (result) {
9999
return result;
100100
}
101101
}
102102

103103
if (isFunctionType(context, ownerType)) {
104-
return transformFunctionPrototypeCall(context, propertyCall);
104+
return transformFunctionPrototypeCall(context, node);
105105
}
106106

107-
const objectResult = transformObjectPrototypeCall(context, propertyCall);
107+
const objectResult = transformObjectPrototypeCall(context, node);
108108
if (objectResult) {
109109
return objectResult;
110110
}

src/transformation/context/context.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@ export class TransformationContext {
2323
public readonly resolver: EmitResolver;
2424

2525
public readonly options: CompilerOptions = this.program.getCompilerOptions();
26-
public readonly luaTarget = this.options.luaTarget || LuaTarget.LuaJIT;
26+
public readonly luaTarget = this.options.luaTarget ?? LuaTarget.LuaJIT;
2727
public readonly isModule = isFileModule(this.sourceFile);
2828
public readonly isStrict =
29-
this.options.alwaysStrict !== undefined ||
30-
(this.options.strict !== undefined && this.options.alwaysStrict !== false) ||
29+
(this.options.alwaysStrict ?? this.options.strict) ||
3130
(this.isModule && this.options.target !== undefined && this.options.target >= ts.ScriptTarget.ES2015);
3231

3332
public constructor(public program: ts.Program, public sourceFile: ts.SourceFile, private visitorMap: VisitorMap) {
3433
// Use `getParseTreeNode` to get original SourceFile node, before it was substituted by custom transformers.
3534
// It's required because otherwise `getEmitResolver` won't use cached diagnostics, produced in `emitWorker`
3635
// and would try to re-analyze the file, which would fail because of replaced nodes.
37-
const originalSourceFile = ts.getParseTreeNode(sourceFile, ts.isSourceFile) || sourceFile;
36+
const originalSourceFile = ts.getParseTreeNode(sourceFile, ts.isSourceFile) ?? sourceFile;
3837
this.resolver = this.checker.getEmitResolver(originalSourceFile);
3938
}
4039

4140
private currentNodeVisitors: Array<ObjectVisitor<ts.Node>> = [];
4241
public transformNode(node: ts.Node): lua.Node[] {
4342
// TODO: Move to visitors?
44-
if (node.modifiers && node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
43+
if (node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
4544
return [];
4645
}
4746

0 commit comments

Comments
 (0)