feat: add UnLua TS spec, TSTL compiler plugin, types, examples, and tests
This commit is contained in:
1 parent
68852d049c
commit
c0ac6eaad6
19 files changed
+3273
-1
No files matched your search
@@ -0,0 +1,53 @@
|
||||
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,
|
||||
}
|
||||
|
||||
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",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user