Skip to content

Commit 5abb60b

Browse files
authored
Remove deprecated annotations (#1032)
* Removed luaIterator, vararg, luaTable and forRange annotations * Fixed change missed in conflict resolve * Removed unused import * Remove unused diagnostics * Fixed deprecation tests working because tbl.new instead of get/set * Prettier 💅
1 parent 57fbef1 commit 5abb60b

File tree

23 files changed

+178
-1258
lines changed

23 files changed

+178
-1258
lines changed

src/lualib/declarations/luatable.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/transformation/utils/diagnostics.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export const annotationInvalidArgumentCount = createErrorDiagnosticFactory(
5858
(kind: AnnotationKind, got: number, expected: number) => `'@${kind}' expects ${expected} arguments, but got ${got}.`
5959
);
6060

61-
export const invalidForRangeCall = createErrorDiagnosticFactory(
62-
(message: string) => `Invalid @forRange call: ${message}.`
63-
);
64-
6561
export const invalidRangeUse = createErrorDiagnosticFactory("$range can only be used in a for...of loop.");
6662

6763
export const invalidVarargUse = createErrorDiagnosticFactory(
@@ -72,32 +68,6 @@ export const invalidRangeControlVariable = createErrorDiagnosticFactory(
7268
"For loop using $range must declare a single control variable."
7369
);
7470

75-
export const luaTableMustBeAmbient = createErrorDiagnosticFactory(
76-
"Classes with the '@luaTable' annotation must be ambient."
77-
);
78-
79-
export const luaTableCannotBeExtended = createErrorDiagnosticFactory(
80-
"Cannot extend classes with the '@luaTable' annotation."
81-
);
82-
83-
export const luaTableInvalidInstanceOf = createErrorDiagnosticFactory(
84-
"The instanceof operator cannot be used with a '@luaTable' class."
85-
);
86-
87-
export const luaTableCannotBeAccessedDynamically = createErrorDiagnosticFactory(
88-
"@luaTable cannot be accessed dynamically."
89-
);
90-
91-
export const luaTableForbiddenUsage = createErrorDiagnosticFactory(
92-
(description: string) => `Invalid @luaTable usage: ${description}.`
93-
);
94-
95-
export const luaIteratorForbiddenUsage = createErrorDiagnosticFactory(
96-
"Unsupported use of lua iterator with '@tupleReturn' annotation in for...of statement. " +
97-
"You must use a destructuring statement to catch results from a lua iterator with " +
98-
"the '@tupleReturn' annotation."
99-
);
100-
10171
export const invalidMultiIterableWithoutDestructuring = createErrorDiagnosticFactory(
10272
"LuaIterable with a LuaMultiReturn return value type must be destructured."
10373
);

src/transformation/visitors/access.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import * as lua from "../../LuaAST";
33
import { transformBuiltinPropertyAccessExpression } from "../builtins";
44
import { FunctionVisitor, TransformationContext } from "../context";
55
import { AnnotationKind, getTypeAnnotations } from "../utils/annotations";
6-
import { invalidMultiReturnAccess, optionalChainingNotSupported } from "../utils/diagnostics";
6+
import { annotationRemoved, invalidMultiReturnAccess, optionalChainingNotSupported } from "../utils/diagnostics";
77
import { addToNumericExpression } from "../utils/lua-ast";
88
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
99
import { isArrayType, isNumberType, isStringType } from "../utils/typescript";
1010
import { tryGetConstEnumValue } from "./enum";
1111
import { returnsMultiType } from "./language-extensions/multi";
12-
import { transformLuaTablePropertyAccessExpression, validateLuaTableElementAccessExpression } from "./lua-table";
1312

1413
export function transformElementAccessArgument(
1514
context: TransformationContext,
@@ -27,8 +26,6 @@ export function transformElementAccessArgument(
2726
}
2827

2928
export const transformElementAccessExpression: FunctionVisitor<ts.ElementAccessExpression> = (node, context) => {
30-
validateLuaTableElementAccessExpression(context, node);
31-
3229
const constEnumValue = tryGetConstEnumValue(context, node);
3330
if (constEnumValue) {
3431
return constEnumValue;
@@ -59,53 +56,50 @@ export const transformElementAccessExpression: FunctionVisitor<ts.ElementAccessE
5956
return lua.createTableIndexExpression(table, accessExpression, node);
6057
};
6158

62-
export const transformPropertyAccessExpression: FunctionVisitor<ts.PropertyAccessExpression> = (
63-
expression,
64-
context
65-
) => {
66-
if (ts.isOptionalChain(expression)) {
67-
context.diagnostics.push(optionalChainingNotSupported(expression));
59+
export const transformPropertyAccessExpression: FunctionVisitor<ts.PropertyAccessExpression> = (node, context) => {
60+
const property = node.name.text;
61+
const type = context.checker.getTypeAtLocation(node.expression);
62+
63+
const annotations = getTypeAnnotations(type);
64+
65+
if (annotations.has(AnnotationKind.LuaTable)) {
66+
context.diagnostics.push(annotationRemoved(node, AnnotationKind.LuaTable));
6867
}
6968

70-
const constEnumValue = tryGetConstEnumValue(context, expression);
71-
if (constEnumValue) {
72-
return constEnumValue;
69+
if (ts.isOptionalChain(node)) {
70+
context.diagnostics.push(optionalChainingNotSupported(node));
7371
}
7472

75-
const luaTableResult = transformLuaTablePropertyAccessExpression(context, expression);
76-
if (luaTableResult) {
77-
return luaTableResult;
73+
const constEnumValue = tryGetConstEnumValue(context, node);
74+
if (constEnumValue) {
75+
return constEnumValue;
7876
}
7977

80-
const builtinResult = transformBuiltinPropertyAccessExpression(context, expression);
78+
const builtinResult = transformBuiltinPropertyAccessExpression(context, node);
8179
if (builtinResult) {
8280
return builtinResult;
8381
}
8482

85-
if (ts.isCallExpression(expression.expression) && returnsMultiType(context, expression.expression)) {
86-
context.diagnostics.push(invalidMultiReturnAccess(expression));
83+
if (ts.isCallExpression(node.expression) && returnsMultiType(context, node.expression)) {
84+
context.diagnostics.push(invalidMultiReturnAccess(node));
8785
}
8886

89-
const property = expression.name.text;
90-
const type = context.checker.getTypeAtLocation(expression.expression);
91-
92-
const annotations = getTypeAnnotations(type);
9387
// Do not output path for member only enums
9488
if (annotations.has(AnnotationKind.CompileMembersOnly)) {
95-
if (ts.isPropertyAccessExpression(expression.expression)) {
89+
if (ts.isPropertyAccessExpression(node.expression)) {
9690
// in case of ...x.enum.y transform to ...x.y
9791
return lua.createTableIndexExpression(
98-
context.transformExpression(expression.expression.expression),
92+
context.transformExpression(node.expression.expression),
9993
lua.createStringLiteral(property),
100-
expression
94+
node
10195
);
10296
} else {
103-
return lua.createIdentifier(property, expression);
97+
return lua.createIdentifier(property, node);
10498
}
10599
}
106100

107-
const callPath = context.transformExpression(expression.expression);
108-
return lua.createTableIndexExpression(callPath, lua.createStringLiteral(property), expression);
101+
const callPath = context.transformExpression(node.expression);
102+
return lua.createTableIndexExpression(callPath, lua.createStringLiteral(property), node);
109103
};
110104

111105
export const transformQualifiedName: FunctionVisitor<ts.QualifiedName> = (node, context) => {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { createUnpackCall, wrapInTable } from "../../utils/lua-ast";
99
import { LuaLibFeature, transformLuaLibFunction } from "../../utils/lualib";
1010
import { isArrayType, isDestructuringAssignment } from "../../utils/typescript";
1111
import { transformElementAccessArgument } from "../access";
12-
import { transformLuaTablePropertyAccessInAssignment } from "../lua-table";
1312
import { isArrayLength, transformDestructuringAssignment } from "./destructuring-assignments";
1413
import { isMultiReturnCall } from "../language-extensions/multi";
1514
import { popScope, pushScope, ScopeType } from "../../utils/scope";
@@ -23,9 +22,7 @@ export function transformAssignmentLeftHandSideExpression(
2322
node: ts.Expression
2423
): lua.AssignmentLeftHandSideExpression {
2524
const symbol = context.checker.getSymbolAtLocation(node);
26-
const left = ts.isPropertyAccessExpression(node)
27-
? transformLuaTablePropertyAccessInAssignment(context, node) ?? context.transformExpression(node)
28-
: context.transformExpression(node);
25+
const left = context.transformExpression(node);
2926

3027
return lua.isIdentifier(left) && symbol && isSymbolExported(context, symbol)
3128
? createExportedIdentifier(context, left)
@@ -140,9 +137,6 @@ export function transformAssignmentExpression(
140137
const objExpression = context.transformExpression(expression.left.expression);
141138
let indexExpression: lua.Expression;
142139
if (ts.isPropertyAccessExpression(expression.left)) {
143-
// Called only for validation
144-
transformLuaTablePropertyAccessInAssignment(context, expression.left);
145-
146140
// Property access
147141
indexExpression = lua.createStringLiteral(expression.left.name.text);
148142
} else {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as ts from "typescript";
22
import * as lua from "../../../LuaAST";
33
import { FunctionVisitor, TransformationContext } from "../../context";
4-
import { AnnotationKind, getTypeAnnotations } from "../../utils/annotations";
5-
import { luaTableInvalidInstanceOf } from "../../utils/diagnostics";
64
import { wrapInToStringForConcat } from "../../utils/lua-ast";
75
import { LuaLibFeature, transformLuaLibFunction } from "../../utils/lualib";
86
import { isStandardLibraryType, isStringType, typeCanSatisfy } from "../../utils/typescript";
@@ -108,11 +106,6 @@ export const transformBinaryExpression: FunctionVisitor<ts.BinaryExpression> = (
108106
const lhs = context.transformExpression(node.left);
109107
const rhs = context.transformExpression(node.right);
110108
const rhsType = context.checker.getTypeAtLocation(node.right);
111-
const annotations = getTypeAnnotations(rhsType);
112-
113-
if (annotations.has(AnnotationKind.LuaTable)) {
114-
context.diagnostics.push(luaTableInvalidInstanceOf(node));
115-
}
116109

117110
if (isStandardLibraryType(context, rhsType, "ObjectConstructor")) {
118111
return transformLuaLibFunction(context, LuaLibFeature.InstanceOfObject, node, lhs);

src/transformation/visitors/call.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import * as ts from "typescript";
22
import * as lua from "../../LuaAST";
33
import { transformBuiltinCallExpression } from "../builtins";
44
import { FunctionVisitor, TransformationContext } from "../context";
5-
import { isInTupleReturnFunction, isTupleReturnCall } from "../utils/annotations";
5+
import { AnnotationKind, getTypeAnnotations, isInTupleReturnFunction, isTupleReturnCall } from "../utils/annotations";
66
import { validateAssignment } from "../utils/assignment-validation";
77
import { ContextType, getDeclarationContextType } from "../utils/function-context";
88
import { createUnpackCall, wrapInTable } from "../utils/lua-ast";
99
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
1010
import { isValidLuaIdentifier } from "../utils/safe-names";
1111
import { isExpressionWithEvaluationEffect, isInDestructingAssignment } from "../utils/typescript";
1212
import { transformElementAccessArgument } from "./access";
13-
import { transformLuaTableCallExpression } from "./lua-table";
1413
import { shouldMultiReturnCallBeWrapped } from "./language-extensions/multi";
1514
import { isOperatorMapping, transformOperatorMappingExpression } from "./language-extensions/operators";
1615
import {
@@ -23,7 +22,7 @@ import {
2322
transformTableHasExpression,
2423
transformTableSetExpression,
2524
} from "./language-extensions/table";
26-
import { invalidTableDeleteExpression, invalidTableSetExpression } from "../utils/diagnostics";
25+
import { annotationRemoved, invalidTableDeleteExpression, invalidTableSetExpression } from "../utils/diagnostics";
2726
import {
2827
ImmediatelyInvokedFunctionParameters,
2928
transformToImmediatelyInvokedFunctionExpression,
@@ -223,11 +222,6 @@ function transformElementCall(context: TransformationContext, node: ts.CallExpre
223222
}
224223

225224
export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node, context) => {
226-
const luaTableResult = transformLuaTableCallExpression(context, node);
227-
if (luaTableResult) {
228-
return luaTableResult;
229-
}
230-
231225
const isTupleReturn = isTupleReturnCall(context, node);
232226
const isTupleReturnForward =
233227
node.parent && ts.isReturnStatement(node.parent) && isInTupleReturnFunction(context, node);
@@ -273,6 +267,12 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
273267
}
274268

275269
if (ts.isPropertyAccessExpression(node.expression)) {
270+
const ownerType = context.checker.getTypeAtLocation(node.expression.expression);
271+
const annotations = getTypeAnnotations(ownerType);
272+
if (annotations.has(AnnotationKind.LuaTable)) {
273+
context.diagnostics.push(annotationRemoved(node, AnnotationKind.LuaTable));
274+
}
275+
276276
const result = transformPropertyCall(context, node as PropertyCallExpression);
277277
return wrapResult ? wrapInTable(result) : result;
278278
}

src/transformation/visitors/class/index.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as lua from "../../../LuaAST";
33
import { getOrUpdate } from "../../../utils";
44
import { FunctionVisitor, TransformationContext } from "../../context";
55
import { AnnotationKind, getTypeAnnotations } from "../../utils/annotations";
6-
import { annotationRemoved, luaTableCannotBeExtended, luaTableMustBeAmbient } from "../../utils/diagnostics";
6+
import { annotationRemoved } from "../../utils/diagnostics";
77
import {
88
createDefaultExportIdentifier,
99
createExportedIdentifier,
@@ -13,7 +13,6 @@ import {
1313
import { createSelfIdentifier, unwrapVisitorResult } from "../../utils/lua-ast";
1414
import { createSafeName, isUnsafeName } from "../../utils/safe-names";
1515
import { transformToImmediatelyInvokedFunctionExpression } from "../../utils/transform";
16-
import { isAmbientNode } from "../../utils/typescript";
1716
import { transformIdentifier } from "../identifier";
1817
import { createDecoratingExpression, transformDecoratorExpression } from "./decorators";
1918
import { transformAccessorDeclarations } from "./members/accessors";
@@ -97,18 +96,6 @@ function transformClassLikeDeclaration(
9796
checkForLuaLibType(context, extendedType);
9897
}
9998

100-
// You cannot extend LuaTable classes
101-
if (extendedType) {
102-
const annotations = getTypeAnnotations(extendedType);
103-
if (annotations.has(AnnotationKind.LuaTable)) {
104-
context.diagnostics.push(luaTableCannotBeExtended(extendedTypeNode!));
105-
}
106-
}
107-
108-
if (annotations.has(AnnotationKind.LuaTable) && !isAmbientNode(classDeclaration)) {
109-
context.diagnostics.push(luaTableMustBeAmbient(classDeclaration));
110-
}
111-
11299
// Get all properties with value
113100
const properties = classDeclaration.members.filter(ts.isPropertyDeclaration).filter(member => member.initializer);
114101

src/transformation/visitors/class/new.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import * as ts from "typescript";
22
import * as lua from "../../../LuaAST";
33
import { FunctionVisitor, TransformationContext } from "../../context";
44
import { AnnotationKind, getTypeAnnotations } from "../../utils/annotations";
5-
import { annotationInvalidArgumentCount } from "../../utils/diagnostics";
5+
import { annotationInvalidArgumentCount, annotationRemoved } from "../../utils/diagnostics";
66
import { importLuaLibFeature, LuaLibFeature, transformLuaLibFunction } from "../../utils/lualib";
77
import { transformArguments } from "../call";
88
import { isTableNewCall } from "../language-extensions/table";
9-
import { transformLuaTableNewExpression } from "../lua-table";
109

1110
const builtinErrorTypeNames = new Set([
1211
"Error",
@@ -49,9 +48,12 @@ export function checkForLuaLibType(context: TransformationContext, type: ts.Type
4948
}
5049

5150
export const transformNewExpression: FunctionVisitor<ts.NewExpression> = (node, context) => {
52-
const luaTableResult = transformLuaTableNewExpression(context, node);
53-
if (luaTableResult) {
54-
return luaTableResult;
51+
const type = context.checker.getTypeAtLocation(node);
52+
53+
const annotations = getTypeAnnotations(type);
54+
55+
if (annotations.has(AnnotationKind.LuaTable)) {
56+
context.diagnostics.push(annotationRemoved(node, AnnotationKind.LuaTable));
5557
}
5658

5759
if (isTableNewCall(context, node)) {
@@ -64,12 +66,8 @@ export const transformNewExpression: FunctionVisitor<ts.NewExpression> = (node,
6466
? transformArguments(context, node.arguments, signature)
6567
: [lua.createBooleanLiteral(true)];
6668

67-
const type = context.checker.getTypeAtLocation(node);
68-
6969
checkForLuaLibType(context, type);
7070

71-
const annotations = getTypeAnnotations(type);
72-
7371
const customConstructorAnnotation = annotations.get(AnnotationKind.CustomConstructor);
7472
if (customConstructorAnnotation) {
7573
if (customConstructorAnnotation.args.length === 1) {

src/transformation/visitors/expression-statement.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ import {
88
transformTableDeleteExpression,
99
transformTableSetExpression,
1010
} from "./language-extensions/table";
11-
import { transformLuaTableExpressionStatement } from "./lua-table";
1211
import { transformUnaryExpressionStatement } from "./unary-expression";
1312

1413
export const transformExpressionStatement: FunctionVisitor<ts.ExpressionStatement> = (node, context) => {
15-
const luaTableResult = transformLuaTableExpressionStatement(context, node);
16-
if (luaTableResult) {
17-
return luaTableResult;
18-
}
14+
const expression = node.expression;
1915

20-
if (ts.isCallExpression(node.expression) && isTableDeleteCall(context, node.expression)) {
21-
return transformTableDeleteExpression(context, node.expression);
16+
if (ts.isCallExpression(expression) && isTableDeleteCall(context, expression)) {
17+
return transformTableDeleteExpression(context, expression);
2218
}
2319

24-
if (ts.isCallExpression(node.expression) && isTableSetCall(context, node.expression)) {
25-
return transformTableSetExpression(context, node.expression);
20+
if (ts.isCallExpression(expression) && isTableSetCall(context, expression)) {
21+
return transformTableSetExpression(context, expression);
2622
}
2723

2824
const unaryExpressionResult = transformUnaryExpressionStatement(context, node);
@@ -35,7 +31,6 @@ export const transformExpressionStatement: FunctionVisitor<ts.ExpressionStatemen
3531
return binaryExpressionResult;
3632
}
3733

38-
const expression = ts.isExpressionStatement(node) ? node.expression : node;
3934
const result = context.transformExpression(expression);
4035
return lua.isCallExpression(result) || lua.isMethodCallExpression(result)
4136
? lua.createExpressionStatement(result)

0 commit comments

Comments
 (0)