release: v0.2.2 fix optional chaining, static self, destructuring, mixed imports and add UnLua.Delegate/Input types

This commit is contained in:
szy73711 committed 2026-11-29 03:34:45 +08:00
1 parent 70630f689f
commit cb1539d738
9 files changed
+754 -36

No files matched your search

+14
View File
@@ -4,6 +4,20 @@ All notable changes to `ts2lua-unreal` will be documented in this file.
The format is based on [Semantic Versioning](https://semver.org/).
## [0.2.2] - 2026-11-29
### Fixed
- **修复可选链(`a?.b?.c`)触发插件崩溃**:TSTL 转译可选链时会合成无 `SourceFile` / 无 `parent` 的临时 `Identifier` 节点;为 `tryTransformUnLuaSelfClassIdentifier`、`hasAllowTryComment` 与 `arguments` 校验补齐空值保护。
- **修复 `@unlua` 类静态方法 `self` 参数不匹配 Bug**:移除 `methodHasSelfParam` 中无条件剔除 `static` 方法 `self` 的错误逻辑,使其与 TSTL 调用侧的冒号调用(`ClassName:StaticMethod(...)`)一致,并支持 `this: void`、`/** @noSelf */` 与 `/** @noSelfInFile */` 点号调用;同时在 `super.Method(...)` 调用 `@unlua` 父类方法时尊重目标方法的 `@noSelf` 声明。
- **修复 `@unlua` 类方法解构参数未展开 Bug**:完整支持对象解构、数组解构、重命名、嵌套解构、默认值与剩余元素(`...rest`)展开。
- **修复混合默认导入与纯类型命名导入(`import Base, { type BaseCfg } from "./Base"`)生成 `.default` 的 Bug**:当命名导入全为编译期擦除类型时,仍直接生成 `local Base = require("...")`。
### Added
- **编译期宏 `UnLua.Delegate(target, callback)`**:在 [types/unlua.d.ts](types/unlua.d.ts) 中声明并在插件编译期直接内联为 `{ target, callback }`,用于类型安全且零开销地调用 `K2_SetTimerDelegate` / `LoadAsset` / `BindToAnimationFinished` 等接收 `UE.FScriptDelegate` 参数的 UE API;同时在编译期拦截对 `UnLua.Delegate` 传入箭头函数或匿名函数(`90107`)。
- **补齐 UnLua 全局运行时类型声明**:新增 `UnLua.Log` / `LogWarn` / `LogError`、`UnLua.Input`(`BindKey` / `BindAction` / `BindAxis`)及 `UnLua.EnhancedInput`(`BindAction`),并让 `UE.TArray<T>` / `UE.TMap<K, V>` 继承 `LuaPairsIterable`,支持 `for (const [k, v] of container)` 直接编译为 Lua 原生 `pairs()` 遍历。
- **增强编译期约束检查**:新增拦截 `BigInt` 字面量(`123n`)、`new UE.AActor()` / `new UE.UObject()` 误实例化,以及继承独立 `@unlua` 类时漏标 `@unlua` 的防呆检查。
- **扩展插件测试套件**:[test/plugin.test.mjs](test/plugin.test.mjs) 增至 23 组测试,并结合本机 `lua5.4` 执行编译产物验证运行时语义。
## [0.2.1] - 2026-11-29
### Fixed