|
| 1 | +import * as ts from "typescript"; |
| 2 | + |
| 3 | +import { TSHelper as tsHelper } from "./TSHelper"; |
| 4 | + |
| 5 | +export class TranspileError extends Error { |
| 6 | + public node: ts.Node; |
| 7 | + constructor(message: string, node: ts.Node) { |
| 8 | + super(message); |
| 9 | + this.node = node; |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +export class TSTLErrors { |
| 14 | + public static DefaultImportsNotSupported = (node: ts.Node) => |
| 15 | + new TranspileError(`Default Imports are not supported, please use named imports instead!`, node) |
| 16 | + |
| 17 | + public static ForbiddenEllipsisDestruction = (node: ts.Node) => |
| 18 | + new TranspileError(`Ellipsis destruction is not allowed.`, node) |
| 19 | + |
| 20 | + public static ForbiddenForIn = (node: ts.Node) => |
| 21 | + new TranspileError(`Iterating over arrays with 'for ... in' is not allowed.`, node) |
| 22 | + |
| 23 | + public static HeterogeneousEnum = (node: ts.Node) => |
| 24 | + new TranspileError(`Invalid heterogeneous enum. Enums should either specify no member values, ` + |
| 25 | + `or specify values (of the same type) for all members.`, |
| 26 | + node) |
| 27 | + |
| 28 | + public static InvalidEnumMember = (node: ts.Node) => |
| 29 | + new TranspileError(`Only numeric or string initializers allowed for enums.`, node) |
| 30 | + |
| 31 | + public static InvalidDecoratorArgumentNumber = (name: string, got: number, expected: number, node: ts.Node) => |
| 32 | + new TranspileError(`${name} expects ${expected} argument(s) but got ${got}.`, node) |
| 33 | + |
| 34 | + public static InvalidExtensionMetaExtension = (node: ts.Node) => |
| 35 | + new TranspileError(`Cannot use both '!Extension' and '!MetaExtension' decorators on the same class.`, node) |
| 36 | + |
| 37 | + public static InvalidPropertyCall = (node: ts.Node) => |
| 38 | + new TranspileError(`Tried to transpile a non-property call as property call.`, node) |
| 39 | + |
| 40 | + public static InvalidThrowExpression = (node: ts.Node) => |
| 41 | + new TranspileError(`Invalid throw expression, only strings can be thrown.`, node) |
| 42 | + |
| 43 | + public static KeywordIdentifier = (node: ts.Identifier) => |
| 44 | + new TranspileError(`Cannot use Lua keyword ${node.escapedText} as identifier.`, node) |
| 45 | + |
| 46 | + public static MissingClassName = (node: ts.Node) => |
| 47 | + new TranspileError(`Class declarations must have a name.`, node) |
| 48 | + |
| 49 | + public static MissingMetaExtension = (node: ts.Node) => |
| 50 | + new TranspileError(`!MetaExtension requires the extension of the metatable class.`, node) |
| 51 | + |
| 52 | + public static UnsupportedImportType = (node: ts.Node) => |
| 53 | + new TranspileError(`Unsupported import type.`, node) |
| 54 | + |
| 55 | + public static UnsupportedKind = (description: string, kind: ts.SyntaxKind, node: ts.Node) => { |
| 56 | + const kindName = tsHelper.enumName(kind, ts.SyntaxKind); |
| 57 | + return new TranspileError(`Unsupported ${description} kind: ${kindName}`, node); |
| 58 | + } |
| 59 | + |
| 60 | + public static UnsupportedProperty = (parentName: string, property: string, node: ts.Node) => |
| 61 | + new TranspileError(`Unsupported property on ${parentName}: ${property}`, node) |
| 62 | + |
| 63 | + public static UnsupportedForTarget = (functionality: string, version: string, node: ts.Node) => |
| 64 | + new TranspileError(`${functionality} is/are not supported for target Lua ${version}.`, node) |
| 65 | + |
| 66 | + public static UnsupportedObjectLiteralElement = (elementKind: ts.SyntaxKind, node: ts.Node) => |
| 67 | + new TranspileError(`Unsupported object literal element: ${elementKind}.`, node) |
| 68 | +} |
0 commit comments