Skip to content

Commit a3a9732

Browse files
committed
Remove some errors that already have TypeScript diagnostics
1 parent 6ecdec3 commit a3a9732

3 files changed

Lines changed: 12 additions & 30 deletions

File tree

src/transformation/utils/errors.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,9 @@ export const MissingClassName = (node: ts.Node) => new TranspileError(`Class dec
5353
export const MissingForOfVariables = (node: ts.Node) =>
5454
new TranspileError("Transpiled ForOf variable declaration list contains no declarations.", node);
5555

56-
export const MissingFunctionName = (declaration: ts.FunctionLikeDeclaration) =>
57-
new TranspileError("Unsupported function declaration without name.", declaration);
58-
5956
export const MissingMetaExtension = (node: ts.Node) =>
6057
new TranspileError(`'@metaExtension' annotation requires the extension of the metatable class.`, node);
6158

62-
export const NonFlattenableDestructure = (node: ts.Node) =>
63-
new TranspileError(`This node cannot be destructured using a standard Lua assignment statement.`, node);
64-
6559
export const UndefinedFunctionDefinition = (functionSymbolId: number) =>
6660
new Error(`Function definition for function symbol ${functionSymbolId} is undefined.`);
6761

@@ -72,11 +66,6 @@ export const UndefinedScope = () => new Error("Expected to pop a scope, but foun
7266

7367
export const UndefinedTypeNode = (node: ts.Node) => new TranspileError("Failed to resolve required type node.", node);
7468

75-
export const UnknownSuperType = (node: ts.Node) =>
76-
new TranspileError("Unable to resolve type of super expression.", node);
77-
78-
export const UnsupportedImportType = (node: ts.Node) => new TranspileError(`Unsupported import type.`, node);
79-
8069
export const UnsupportedKind = (description: string, kind: ts.SyntaxKind, node: ts.Node) =>
8170
new TranspileError(`Unsupported ${description} kind: ${ts.SyntaxKind[kind]}`, node);
8271

@@ -86,9 +75,6 @@ export const UnsupportedProperty = (parentName: string, property: string, node:
8675
export const UnsupportedForTarget = (functionality: string, version: LuaTarget, node: ts.Node) =>
8776
new TranspileError(`${functionality} is/are not supported for target ${getLuaTargetName(version)}.`, node);
8877

89-
export const UnsupportedFunctionWithoutBody = (node: ts.FunctionLikeDeclaration) =>
90-
new TranspileError("Functions with undefined bodies are not supported.", node);
91-
9278
export const UnsupportedNoSelfFunctionConversion = (node: ts.Node, name?: string) => {
9379
const nameReference = name ? ` '${name}'` : "";
9480
return new TranspileError(

src/transformation/visitors/class/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
InvalidExtensionMetaExtension,
1212
MissingClassName,
1313
MissingMetaExtension,
14-
UnknownSuperType,
1514
} from "../../utils/errors";
1615
import {
1716
createDefaultExportIdentifier,
@@ -85,7 +84,9 @@ export function transformClassDeclaration(
8584

8685
return lua.createAssignmentStatement(left, right, classDeclaration);
8786
} else {
88-
throw MissingClassName(classDeclaration);
87+
// TypeScript error
88+
className = lua.createAnonymousIdentifier();
89+
classNameText = className.text;
8990
}
9091

9192
const annotations = getTypeAnnotations(context, context.checker.getTypeAtLocation(classDeclaration));
@@ -317,14 +318,11 @@ export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (ex
317318
const classStack = getOrUpdate(classStacks, context, () => []);
318319
const classDeclaration = classStack[classStack.length - 1];
319320
const typeNode = getExtendedTypeNode(context, classDeclaration);
320-
if (typeNode === undefined) {
321-
throw UnknownSuperType(expression);
322-
}
323-
324-
const extendsExpression = typeNode.expression;
321+
// `undefined` is a TypeScript error
322+
const extendsExpression = typeNode?.expression;
325323
let baseClassName: lua.AssignmentLeftHandSideExpression | undefined;
326324

327-
if (ts.isIdentifier(extendsExpression)) {
325+
if (extendsExpression && ts.isIdentifier(extendsExpression)) {
328326
const symbol = context.checker.getSymbolAtLocation(extendsExpression);
329327
if (symbol && !isSymbolExported(context, symbol)) {
330328
// Use "baseClassName" if base is a simple identifier

src/transformation/visitors/function.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as ts from "typescript";
22
import * as lua from "../../LuaAST";
33
import { FunctionVisitor, TransformationContext } from "../context";
44
import { isVarArgType } from "../utils/annotations";
5-
import { MissingFunctionName, UnsupportedFunctionWithoutBody } from "../utils/errors";
65
import { createDefaultExportStringLiteral, hasDefaultExportModifier } from "../utils/export";
76
import { ContextType, getFunctionContextType } from "../utils/function-context";
87
import {
@@ -187,7 +186,8 @@ export function transformFunctionLikeDeclaration(
187186
let flags = lua.FunctionExpressionFlags.None;
188187

189188
if (node.body === undefined) {
190-
throw UnsupportedFunctionWithoutBody(node);
189+
// This code can be reached only from object methods, which is TypeScript error
190+
return lua.createNilLiteral();
191191
}
192192

193193
let body: ts.Block;
@@ -257,18 +257,16 @@ export const transformFunctionDeclaration: FunctionVisitor<ts.FunctionDeclaratio
257257
lua.FunctionExpressionFlags.Declaration
258258
);
259259

260-
const name = node.name ? transformIdentifier(context, node.name) : undefined;
261-
262-
const isDefaultExport = hasDefaultExportModifier(node);
263-
if (isDefaultExport) {
260+
if (hasDefaultExportModifier(node)) {
264261
return lua.createAssignmentStatement(
265262
lua.createTableIndexExpression(createExportsIdentifier(), createDefaultExportStringLiteral(node)),
266263
transformFunctionLikeDeclaration(node, context)
267264
);
268-
} else if (!name) {
269-
throw MissingFunctionName(node);
270265
}
271266

267+
// Name being undefined without default export is a TypeScript error
268+
const name = node.name ? transformIdentifier(context, node.name) : lua.createAnonymousIdentifier();
269+
272270
// Remember symbols referenced in this function for hoisting later
273271
if (!context.options.noHoisting && name.symbolId !== undefined) {
274272
const scope = peekScope(context);

0 commit comments

Comments
 (0)