Files
ts2lua-unreal/src/plugin/diagnostics.ts
T

58 lines
1.8 KiB
TypeScript

import * as ts from "typescript";
export enum UnLuaDiagnosticCode {
// 2.x 禁用 TS/JS 通用语言特性 (90001 - 90099)
ForbiddenAccessor = 90001,
ForbiddenAsyncAwait = 90002,
ForbiddenPromise = 90003,
ForbiddenTryCatchThrow = 90004,
ForbiddenDecorator = 90005,
ForbiddenBuiltinType = 90006,
ForbiddenRegExp = 90007,
ForbiddenGenerator = 90008,
ForbiddenForIn = 90009,
ForbiddenRuntimeEnum = 90010,
ForbiddenDeleteOnArrayOrUObject = 90011,
ForbiddenInstanceOfUObject = 90012,
ForbiddenDynamicEvalOrWith = 90013,
ForbiddenArguments = 90014,
ForbiddenDynamicImport = 90015,
ForbiddenUObjectSpread = 90016,
// 3.x UnLua 绑定类专项约束 (90101 - 90199)
UnLuaClassMustBeDefaultExport = 90101,
UnLuaFileExtraRuntimeExport = 90102,
UnLuaClassForbiddenConstructor = 90103,
UnLuaClassForbiddenPropertyInitializer = 90104,
UnLuaClassForbiddenNew = 90105,
MissingUnLuaDecorator = 90106,
UnLuaDelegateForbiddenInlineFunction = 90107,
InvalidUnLuaDecoratorArgs = 90108,
UnLuaMultipleClassesInFile = 90109,
UnLuaForbiddenSuperUsage = 90110,
// 4.x 模块化与热更系统约束 (90201 - 90299)
InvalidModuleDataUsage = 90201,
ForbiddenExportEqualsInHotReload = 90202,
}
export function createUnLuaDiagnostic(
node: ts.Node,
code: UnLuaDiagnosticCode,
messageText: string,
category: ts.DiagnosticCategory = ts.DiagnosticCategory.Error
): ts.Diagnostic {
const sourceFile = node.getSourceFile();
const start = node.getStart(sourceFile);
const length = Math.max(1, node.getEnd() - start);
return {
file: sourceFile,
start,
length,
messageText: `[ts2lua-unlua] ${messageText}`,
category,
code,
source: "ts2lua-unlua",
};
}