Skip to content

Commit 29dba98

Browse files
authored
Replaced deprecated factory functions (#1008)
* Replaced deprecated factory functions Also enabled some eslint rules & fixed violations * Caught to more deprecated function calls * Fixed typo
1 parent 759090a commit 29dba98

File tree

19 files changed

+85
-67
lines changed

19 files changed

+85
-67
lines changed

.eslintrc.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ module.exports = {
130130
"no-useless-return": ["error"],
131131

132132
"import/no-default-export": "error",
133+
// TODO currently only works for direct imports (useless for now) https://github.com/benmosher/eslint-plugin-import/issues/1729
134+
// "import/no-deprecated": "error",
133135

134136
"jest/expect-expect": "off",
135137
"jest/consistent-test-it": ["error", { fn: "test", withinDescribe: "test" }],
@@ -154,31 +156,33 @@ module.exports = {
154156
"@typescript-eslint/no-require-imports": "off",
155157
"@typescript-eslint/no-unnecessary-condition": "off",
156158
"@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-nullish-coalescing": "error",
159160
"@typescript-eslint/prefer-readonly": "off",
160161
"@typescript-eslint/quotes": ["error", "double", { avoidEscape: true, allowTemplateLiterals: false }],
161162
"@typescript-eslint/require-array-sort-compare": "off",
162163
"@typescript-eslint/camelcase": "off",
163164

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-
// ],
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+
selector: "enumMember",
183+
format: ["PascalCase"],
184+
},
185+
],
182186
},
183187
},
184188
{
@@ -187,6 +191,13 @@ module.exports = {
187191
"no-restricted-syntax": ["error", "LabeledStatement", "SequenceExpression"],
188192
"@typescript-eslint/no-throw-literal": "off",
189193
"@typescript-eslint/prefer-optional-chain": "off",
194+
"@typescript-eslint/naming-convention": "off",
195+
},
196+
},
197+
{
198+
files: "language-extensions/index.d.ts",
199+
rules: {
200+
"@typescript-eslint/naming-convention": "off",
190201
},
191202
},
192203
{

src/LuaLib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export enum LuaLibFeature {
8787
Unpack = "Unpack",
8888
}
8989

90+
/* eslint-disable @typescript-eslint/naming-convention */
9091
const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
9192
ArrayConcat: [LuaLibFeature.ArrayIsArray],
9293
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
@@ -108,6 +109,7 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
108109
StringSplit: [LuaLibFeature.StringSubstring],
109110
SymbolRegistry: [LuaLibFeature.Symbol],
110111
};
112+
/* eslint-enable @typescript-eslint/naming-convention */
111113

112114
export function loadLuaLibFeatures(features: Iterable<LuaLibFeature>, emitHost: EmitHost): string {
113115
let result = "";

src/LuaPrinter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class LuaPrinter {
272272
}
273273
}
274274
});
275-
return result || false;
275+
return result ?? false;
276276
}
277277

278278
protected printStatementArray(statements: lua.Statement[]): SourceChunk[] {

src/transformation/visitors/binary-expression/compound.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export function parseAccessExpressionWithEvaluationEffects(
2222
const type = context.checker.getTypeAtLocation(node.expression);
2323
if (isArrayType(context, type)) {
2424
// Offset arrays by one
25-
const oneLit = ts.createNumericLiteral("1");
26-
const exp = ts.createParen(node.argumentExpression);
27-
const addExp = ts.createBinary(exp, ts.SyntaxKind.PlusToken, oneLit);
25+
const oneLit = ts.factory.createNumericLiteral("1");
26+
const exp = ts.factory.createParenthesizedExpression(node.argumentExpression);
27+
const addExp = ts.factory.createBinaryExpression(exp, ts.SyntaxKind.PlusToken, oneLit);
2828
return [node.expression, addExp];
2929
} else {
3030
return [node.expression, node.argumentExpression];
3131
}
3232
} else if (ts.isPropertyAccessExpression(node) && isExpressionWithEvaluationEffect(node.expression)) {
33-
return [node.expression, ts.createStringLiteral(node.name.text)];
33+
return [node.expression, ts.factory.createStringLiteral(node.name.text)];
3434
}
3535

3636
return [];

src/transformation/visitors/binary-expression/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const transformBinaryExpression: FunctionVisitor<ts.BinaryExpression> = (
125125
return transformToImmediatelyInvokedFunctionExpression(
126126
context,
127127
() => ({
128-
statements: context.transformStatements(ts.createExpressionStatement(node.left)),
128+
statements: context.transformStatements(ts.factory.createExpressionStatement(node.left)),
129129
result: context.transformExpression(node.right),
130130
}),
131131
node
@@ -159,8 +159,8 @@ export function transformBinaryExpressionStatement(
159159
return transformAssignmentStatement(context, expression as ts.AssignmentExpression<ts.EqualsToken>);
160160
} else if (operator === ts.SyntaxKind.CommaToken) {
161161
const statements = [
162-
...context.transformStatements(ts.createExpressionStatement(expression.left)),
163-
...context.transformStatements(ts.createExpressionStatement(expression.right)),
162+
...context.transformStatements(ts.factory.createExpressionStatement(expression.left)),
163+
...context.transformStatements(ts.factory.createExpressionStatement(expression.right)),
164164
];
165165

166166
return lua.createDoStatement(statements, expression);

src/transformation/visitors/call.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function transformPropertyCall(context: TransformationContext, node: PropertyCal
183183

184184
if (node.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
185185
// Super calls take the format of super.call(self,...)
186-
const parameters = transformArguments(context, node.arguments, signature, ts.createThis());
186+
const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
187187
return lua.createCallExpression(context.transformExpression(node.expression), parameters);
188188
}
189189

@@ -267,11 +267,11 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
267267

268268
// Handle super calls properly
269269
if (node.expression.kind === ts.SyntaxKind.SuperKeyword) {
270-
const parameters = transformArguments(context, node.arguments, signature, ts.createThis());
270+
const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
271271

272272
return lua.createCallExpression(
273273
lua.createTableIndexExpression(
274-
context.transformExpression(ts.createSuper()),
274+
context.transformExpression(ts.factory.createSuper()),
275275
lua.createStringLiteral("____constructor")
276276
),
277277
parameters
@@ -285,7 +285,7 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
285285
if (signatureDeclaration && getDeclarationContextType(context, signatureDeclaration) === ContextType.Void) {
286286
parameters = transformArguments(context, node.arguments, signature);
287287
} else {
288-
const callContext = context.isStrict ? ts.createNull() : ts.createIdentifier("_G");
288+
const callContext = context.isStrict ? ts.factory.createNull() : ts.factory.createIdentifier("_G");
289289
parameters = transformArguments(context, node.arguments, signature, callContext);
290290
}
291291

src/transformation/visitors/class/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function transformClassLikeDeclaration(
152152
// Generate a constructor if none was defined in a base class
153153
const constructorResult = transformConstructorDeclaration(
154154
context,
155-
ts.createConstructor([], [], [], ts.createBlock([], true)),
155+
ts.factory.createConstructorDeclaration([], [], [], ts.factory.createBlock([], true)),
156156
localClassName,
157157
instanceFields,
158158
classDeclaration
@@ -168,7 +168,7 @@ function transformClassLikeDeclaration(
168168
const superCall = lua.createExpressionStatement(
169169
lua.createCallExpression(
170170
lua.createTableIndexExpression(
171-
context.transformExpression(ts.createSuper()),
171+
context.transformExpression(ts.factory.createSuper()),
172172
lua.createStringLiteral("____constructor")
173173
),
174174
[createSelfIdentifier(), lua.createDotsLiteral()]

src/transformation/visitors/literal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createShorthandIdentifier(
3838

3939
const name = isUnsafeName ? createSafeName(propertyName) : propertyName;
4040

41-
let identifier = context.transformExpression(ts.createIdentifier(name));
41+
let identifier = context.transformExpression(ts.factory.createIdentifier(name));
4242
lua.setNodeOriginal(identifier, propertyIdentifier);
4343
if (valueSymbol !== undefined && lua.isIdentifier(identifier)) {
4444
identifier.symbolId = getSymbolIdOfSymbol(context, valueSymbol);
@@ -137,7 +137,7 @@ const transformObjectLiteralExpression: FunctionVisitor<ts.ObjectLiteralExpressi
137137

138138
const transformArrayLiteralExpression: FunctionVisitor<ts.ArrayLiteralExpression> = (expression, context) => {
139139
const filteredElements = expression.elements.map(e =>
140-
ts.isOmittedExpression(e) ? ts.createIdentifier("undefined") : e
140+
ts.isOmittedExpression(e) ? ts.factory.createIdentifier("undefined") : e
141141
);
142142
const values = flattenSpreadExpressions(context, filteredElements).map(e => lua.createTableFieldExpression(e));
143143

src/transformation/visitors/loops/for.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const transformForStatement: FunctionVisitor<ts.ForStatement> = (statemen
1313
// local initializer = value
1414
result.push(...statement.initializer.declarations.flatMap(d => transformVariableDeclaration(context, d)));
1515
} else {
16-
result.push(...context.transformStatements(ts.createExpressionStatement(statement.initializer)));
16+
result.push(...context.transformStatements(ts.factory.createExpressionStatement(statement.initializer)));
1717
}
1818
}
1919

@@ -25,7 +25,7 @@ export const transformForStatement: FunctionVisitor<ts.ForStatement> = (statemen
2525
const body: lua.Statement[] = transformLoopBody(context, statement);
2626

2727
if (statement.incrementor) {
28-
body.push(...context.transformStatements(ts.createExpressionStatement(statement.incrementor)));
28+
body.push(...context.transformStatements(ts.factory.createExpressionStatement(statement.incrementor)));
2929
}
3030

3131
// while (condition) do ... end

src/transformation/visitors/loops/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function getVariableDeclarationBinding(
3636
checkVariableDeclarationList(context, node);
3737

3838
if (node.declarations.length === 0) {
39-
return ts.createIdentifier("____");
39+
return ts.factory.createIdentifier("____");
4040
}
4141

4242
return node.declarations[0].name;

0 commit comments

Comments
 (0)