@overmvp/kumi 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -6
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +127 -23
- package/builder/css-v1.test.mjs +82 -2
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +205 -8
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +20 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +111 -0
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +10 -2
- package/router/link.tsx +32 -0
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +377 -0
- package/scripts/addon-project.mjs +89 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +12 -6
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +27 -13
- package/src/css-v1.ts +13 -0
- package/src/elements.ts +35 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +6 -2
- package/src/index.ts +2 -1
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +17 -11
- package/src/module-ui.ts +163 -0
- package/src/module.ts +51 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +42 -8
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/index.ts +6 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store.ts +2 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.css +91 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +244 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +38 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +230 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +46 -10
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +295 -43
- package/wow/cursor.ts +45 -0
- package/wow/element-events.ts +33 -13
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +19 -4
- package/wow/layout-view.ts +44 -23
- package/wow/locale-font.ts +15 -0
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +139 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +38 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +458 -228
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
|
@@ -11,10 +11,14 @@ const [entry, workspace, sdk, tsconfig, mode, link, assets, pack, checkAssets, f
|
|
|
11
11
|
const workspaceRoot = realpathSync(workspace);
|
|
12
12
|
const sdkRoot = realpathSync(sdk);
|
|
13
13
|
const entryPath = realpathSync(entry);
|
|
14
|
-
|
|
14
|
+
// SDK fixtures compile like an addon. Their ambient `declare` mocks bind to Lua globals.
|
|
15
|
+
const testMode = mode === "test";
|
|
16
|
+
const addon = mode === "addon" || testMode;
|
|
15
17
|
const rootSources = resolve(workspaceRoot, "src");
|
|
16
18
|
const rootEntry = relative(resolve(rootSources, "app"), entryPath);
|
|
17
|
-
const
|
|
19
|
+
const generatedLazyEntry = relative(resolve(workspaceRoot, "build/kumi/plugins"), entryPath);
|
|
20
|
+
const usesRootSources = [rootEntry, generatedLazyEntry].some(path => path !== "" && !isAbsolute(path)
|
|
21
|
+
&& path.split(/[\\/]/)[0] !== "..");
|
|
18
22
|
const addonSources = usesRootSources ? rootSources : resolve(workspaceRoot, "dev/uikit/src");
|
|
19
23
|
const addonPlatform = resolve(addonSources, "platform/ui-globals.d.ts");
|
|
20
24
|
const options = { strict: true, noEmit: true, target: ts.ScriptTarget.ES2020, types: [] };
|
|
@@ -45,6 +49,32 @@ function moduleMarker(symbol, name = symbol?.name) {
|
|
|
45
49
|
&& relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/") === expected;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
const kumiJsxFactories = new Map();
|
|
53
|
+
|
|
54
|
+
function jsxPragma(file, key, argument) {
|
|
55
|
+
const found = file.pragmas.get(key);
|
|
56
|
+
return (Array.isArray(found) ? found[0] : found)?.arguments[argument];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function withKumiJsx(file, source) {
|
|
60
|
+
if (options.jsx !== ts.JsxEmit.ReactJSX || !file.fileName.endsWith(".tsx")) return source;
|
|
61
|
+
const runtime = jsxPragma(file, "jsxruntime", "runtime");
|
|
62
|
+
const importSource = jsxPragma(file, "jsximportsource", "factory") ?? options.jsxImportSource;
|
|
63
|
+
if (runtime === "classic" || importSource !== "@kumi/core") return source;
|
|
64
|
+
function hasJsx(node) {
|
|
65
|
+
return ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)
|
|
66
|
+
|| ts.forEachChild(node, hasJsx);
|
|
67
|
+
}
|
|
68
|
+
if (!hasJsx(file)) return source;
|
|
69
|
+
let suffix = 0;
|
|
70
|
+
while (source.includes("__kumiCreateElement" + suffix) || source.includes("__kumiFragment" + suffix)) suffix += 1;
|
|
71
|
+
const factory = "__kumiCreateElement" + suffix;
|
|
72
|
+
const fragment = "__kumiFragment" + suffix;
|
|
73
|
+
kumiJsxFactories.set(file.fileName, { factory, fragment });
|
|
74
|
+
// Imports are hoisted. Append the aliases to preserve source diagnostic positions.
|
|
75
|
+
return source + `\nimport { createElement as ${factory}, Fragment as ${fragment} } from "@kumi/core";\n`;
|
|
76
|
+
}
|
|
77
|
+
|
|
48
78
|
async function checkedProgram() {
|
|
49
79
|
const paths = [entry, ...declarations];
|
|
50
80
|
const host = ts.createCompilerHost(options);
|
|
@@ -78,7 +108,7 @@ async function checkedProgram() {
|
|
|
78
108
|
const declared = transformModuleDeclarations(ts, path, file.text, {
|
|
79
109
|
program: secured, rejectUnknown: true, isMarkerSymbol: moduleMarker,
|
|
80
110
|
}) ?? file.text;
|
|
81
|
-
const source = transformJsx(ts, path, declared) ?? declared;
|
|
111
|
+
const source = withKumiJsx(file, transformJsx(ts, path, declared) ?? declared);
|
|
82
112
|
if (source === file.text) continue;
|
|
83
113
|
rewritten = true;
|
|
84
114
|
changes.set(canonical(path), source);
|
|
@@ -142,15 +172,18 @@ function identifier(node) {
|
|
|
142
172
|
|
|
143
173
|
const hostGlobals = new Map([
|
|
144
174
|
["pcall", ["wow/protect.ts"]],
|
|
175
|
+
["xpcall", ["wow/protect.ts"]],
|
|
145
176
|
["_G", ["wow/native.ts"]],
|
|
146
177
|
["issecretvalue", ["wow/native.ts"]],
|
|
147
178
|
["rawget", ["wow/lua-table.ts", "wow/frames.ts", "wow/native-hooks.ts", "wow/secure-transaction.ts", "wow/aura-container.ts"]],
|
|
148
179
|
["rawset", ["wow/lua-table.ts", "wow/frames.ts", "wow/native-hooks.ts", "wow/secure-transaction.ts", "wow/aura-container.ts"]],
|
|
149
180
|
["getmetatable", ["wow/native-placement.ts"]],
|
|
150
|
-
["setmetatable", ["wow/lua-table.ts", "wow/native-hooks.ts"]],
|
|
181
|
+
["setmetatable", ["wow/lua-table.ts", "wow/native-hooks.ts", "wow/readable-api.ts"]],
|
|
182
|
+
["error", ["wow/readable-api.ts"]],
|
|
151
183
|
["string", ["wow/lua-string.ts"]],
|
|
152
184
|
["CreateFrame", ["wow/frames.ts"]],
|
|
153
185
|
["GameFontNormal", ["wow/view.ts"]],
|
|
186
|
+
["rawequal", ["wow/view.ts"]],
|
|
154
187
|
["DoReadyCheck", ["wow/index.ts"]],
|
|
155
188
|
["pairs", ["wow/special-window.ts"]],
|
|
156
189
|
["table", ["wow/special-window.ts"]],
|
|
@@ -170,7 +203,7 @@ const addonHostGlobals = new Set([
|
|
|
170
203
|
|
|
171
204
|
function hostGlobal(symbol) {
|
|
172
205
|
const sources = hostGlobals.get(symbol?.name);
|
|
173
|
-
const addonHost = addon && addonHostGlobals.has(symbol?.name);
|
|
206
|
+
const addonHost = addon && (addonHostGlobals.has(symbol?.name) || testMode && symbol?.name !== undefined);
|
|
174
207
|
if (!sources && !addonHost) return false;
|
|
175
208
|
const declarations = symbol.declarations?.filter(declaration => !ts.isTypeAliasDeclaration(declaration) && !ts.isInterfaceDeclaration(declaration));
|
|
176
209
|
return declarations?.length && declarations.every(declaration => {
|
|
@@ -192,8 +225,12 @@ function ambientVariable(declaration) {
|
|
|
192
225
|
|
|
193
226
|
function addonBinding(symbol) {
|
|
194
227
|
const declaration = symbol?.valueDeclaration;
|
|
195
|
-
if (!
|
|
228
|
+
if (!ambientVariable(declaration)) return;
|
|
196
229
|
const path = realpathSync(declaration.getSourceFile().fileName);
|
|
230
|
+
if (symbol.name === "kumiAddonTable" && relative(sdkRoot, path).replaceAll("\\", "/") === "wow/addon-manifest.ts") {
|
|
231
|
+
return addon ? "addonApp" : "nil";
|
|
232
|
+
}
|
|
233
|
+
if (!addon) return;
|
|
197
234
|
if (path === entryPath) {
|
|
198
235
|
if (symbol.name === "addonName") return "addonName";
|
|
199
236
|
if (symbol.name === "addonTable") return "addonTable";
|
|
@@ -218,7 +255,7 @@ function nativeMultiFunction(symbol) {
|
|
|
218
255
|
|| !(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Ambient)) return false;
|
|
219
256
|
if (nativeLuaDeclaration(declaration)) return true;
|
|
220
257
|
const file = relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/");
|
|
221
|
-
if (
|
|
258
|
+
if (!["wow/class-colors.ts", "wow/cursor.ts", "wow/map-position.ts", "wow/readable-api.ts"].includes(file)) return false;
|
|
222
259
|
const marker = checker.getTypeOfSymbolAtLocation(symbol, declaration).getProperty("__tstlExtension");
|
|
223
260
|
return marker && checker.getTypeOfSymbolAtLocation(marker, declaration).value === "MultiFunction";
|
|
224
261
|
}
|
|
@@ -250,6 +287,8 @@ function rememberCapturedVariables(file) {
|
|
|
250
287
|
function reference(symbol, node) {
|
|
251
288
|
if (symbol?.name === "Infinity" && symbol.declarations?.some(declaration =>
|
|
252
289
|
program.isSourceFileDefaultLibrary(declaration.getSourceFile()))) return emit("global", "math.huge");
|
|
290
|
+
if (symbol?.name === "NaN" && symbol.declarations?.some(declaration =>
|
|
291
|
+
program.isSourceFileDefaultLibrary(declaration.getSourceFile()))) return emit("literal", "nan");
|
|
253
292
|
if (symbol?.name === "String" && symbol.declarations?.some(declaration =>
|
|
254
293
|
program.isSourceFileDefaultLibrary(declaration.getSourceFile()))) {
|
|
255
294
|
return emit("global", "tostring");
|
|
@@ -258,6 +297,7 @@ function reference(symbol, node) {
|
|
|
258
297
|
program.isSourceFileDefaultLibrary(declaration.getSourceFile()))) return emit("global", "numberValue");
|
|
259
298
|
if (hostGlobal(symbol)) return emit("host-global", symbol.name);
|
|
260
299
|
const addonGlobal = addonBinding(symbol);
|
|
300
|
+
if (addonGlobal === "nil") return emit("literal", "nil");
|
|
261
301
|
if (addonGlobal) return emit("addon-global", addonGlobal);
|
|
262
302
|
if (addon && symbol?.name === "$vararg" && nativeLuaDeclaration(symbol.valueDeclaration) && realpathSync(node.getSourceFile().fileName) === entryPath) {
|
|
263
303
|
return emit("addon-global", "addonArgs");
|
|
@@ -280,6 +320,16 @@ function reference(symbol, node) {
|
|
|
280
320
|
emit("ref", binding(symbol, node));
|
|
281
321
|
}
|
|
282
322
|
|
|
323
|
+
// True when every value of the type is truthy in Lua: never nil or false. Lua treats 0 and "" as true.
|
|
324
|
+
function luaAlwaysTruthy(input) {
|
|
325
|
+
const type = nativeBase(input);
|
|
326
|
+
if (type.isUnion()) return type.types.every(luaAlwaysTruthy);
|
|
327
|
+
if (type.isIntersection()) return type.types.some(luaAlwaysTruthy);
|
|
328
|
+
if (type.flags & (T.Any | T.Unknown | T.Null | T.Undefined | T.Void | T.Never | T.BooleanLike | T.TypeParameter)) return false;
|
|
329
|
+
return Boolean(type.flags & (T.NumberLike | T.StringLike | T.BigIntLike | T.ESSymbolLike | T.Object | T.NonPrimitive))
|
|
330
|
+
|| type.getCallSignatures().length > 0;
|
|
331
|
+
}
|
|
332
|
+
|
|
283
333
|
function luaTruthValue(input) {
|
|
284
334
|
const type = nativeBase(input);
|
|
285
335
|
if (type.isUnionOrIntersection()) return type.types.every(luaTruthValue);
|
|
@@ -300,12 +350,12 @@ function body(node, params = []) {
|
|
|
300
350
|
statements(ts.isBlock(node) ? node.statements : [node], parameterPrelude(params));
|
|
301
351
|
}
|
|
302
352
|
|
|
303
|
-
function
|
|
304
|
-
if (declaration.name?.text !== "reveal"
|
|
305
|
-
||
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
353
|
+
function canonicalReveal(declaration, guard) {
|
|
354
|
+
if (!declaration || !ts.isFunctionDeclaration(declaration) || declaration.name?.text !== "reveal"
|
|
355
|
+
|| !declaration.body || declaration.parameters.length !== 1) return false;
|
|
356
|
+
const file = declaration.getSourceFile();
|
|
357
|
+
if (relative(sdkRoot, realpathSync(file.fileName)).replaceAll("\\", "/") !== "wow/native.ts"
|
|
358
|
+
|| !guard?.body || !ts.isFunctionDeclaration(guard) || guard.getSourceFile() !== file) return false;
|
|
309
359
|
|
|
310
360
|
// The Rust lowering inlines this exact pair, including its single read of the host predicate.
|
|
311
361
|
// A changed SDK body uses ordinary function emission.
|
|
@@ -314,8 +364,13 @@ function emitCanonicalReveal(path, file, declaration, exports, params) {
|
|
|
314
364
|
if (createHash("sha256").update(source).digest("hex") !== "b37a4d648682becadede60fa3a88813830eb3c65cac2a1d2acc23d1a320fdd1b") return false;
|
|
315
365
|
const callee = declaration.body.statements[0].expression.condition.expression;
|
|
316
366
|
const predicate = guard.body.statements[0].declarationList.declarations[0].initializer;
|
|
317
|
-
|
|
318
|
-
|
|
367
|
+
return checker.getSymbolAtLocation(callee)?.valueDeclaration === guard
|
|
368
|
+
&& hostGlobal(checker.getSymbolAtLocation(predicate));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function emitCanonicalReveal(declaration, exports, params) {
|
|
372
|
+
if (params.length !== 1 || exports.get("reveal")?.valueDeclaration !== declaration
|
|
373
|
+
|| !canonicalReveal(declaration, exports.get("isSecret")?.valueDeclaration)) return false;
|
|
319
374
|
|
|
320
375
|
emit("block", 1);
|
|
321
376
|
emit("return-wow-reveal", params[0]);
|
|
@@ -367,6 +422,264 @@ function valueSymbol(node) {
|
|
|
367
422
|
return symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
368
423
|
}
|
|
369
424
|
|
|
425
|
+
const readableOverrides = new WeakMap();
|
|
426
|
+
|
|
427
|
+
function sdkVariable(symbol, name, path) {
|
|
428
|
+
const declaration = symbol?.valueDeclaration;
|
|
429
|
+
return symbol?.name === name && declaration && ts.isVariableDeclaration(declaration)
|
|
430
|
+
&& relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/") === path
|
|
431
|
+
&& (declaration.parent.flags & ts.NodeFlags.Const) !== 0 ? declaration : undefined;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function readableMetatable(init, fieldCount) {
|
|
435
|
+
if (!init || !ts.isCallExpression(init) || init.arguments.length !== 2
|
|
436
|
+
|| !ts.isIdentifier(init.expression) || init.expression.text !== "setmetatable"
|
|
437
|
+
|| !hostGlobal(valueSymbol(init.expression))) return;
|
|
438
|
+
const [table, meta] = init.arguments;
|
|
439
|
+
if (!ts.isObjectLiteralExpression(table) || !ts.isObjectLiteralExpression(meta)
|
|
440
|
+
|| meta.properties.length !== fieldCount
|
|
441
|
+
|| !meta.properties.every(field => ts.isPropertyAssignment(field) && ts.isIdentifier(field.name))) return;
|
|
442
|
+
const fields = new Map(meta.properties.map(field => [field.name.text, field.initializer]));
|
|
443
|
+
return { table, fields };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function readOnlyApiMetatable(initializer) {
|
|
447
|
+
const view = readableMetatable(initializer, 3);
|
|
448
|
+
if (!view || view.table.properties.length !== 0) return;
|
|
449
|
+
const index = view.fields.get("__index");
|
|
450
|
+
const write = view.fields.get("__newindex");
|
|
451
|
+
if (!index || !ts.isIdentifier(index) || !write || !ts.isIdentifier(write)
|
|
452
|
+
|| view.fields.get("__metatable")?.kind !== K.FalseKeyword) return;
|
|
453
|
+
return { index, reject: valueSymbol(write)?.valueDeclaration };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function readReadableNamespace(initializer, name, host, reject) {
|
|
457
|
+
if (!ts.isIdentifier(initializer)) return;
|
|
458
|
+
const symbol = valueSymbol(initializer);
|
|
459
|
+
const declaration = sdkVariable(symbol, symbol?.name, "wow/readable-api.ts");
|
|
460
|
+
const view = readOnlyApiMetatable(declaration?.initializer);
|
|
461
|
+
if (!view || view.reject !== reject) return;
|
|
462
|
+
const lookup = valueSymbol(view.index)?.valueDeclaration;
|
|
463
|
+
if (!lookup || !ts.isFunctionDeclaration(lookup) || lookup.getSourceFile() !== declaration.getSourceFile()
|
|
464
|
+
|| !lookup.body || lookup.parameters.length !== 3) return;
|
|
465
|
+
const [receiver, , key] = lookup.parameters;
|
|
466
|
+
if (!ts.isIdentifier(receiver.name) || receiver.name.text !== "this"
|
|
467
|
+
|| !(checker.getTypeAtLocation(receiver).flags & T.Void) || !ts.isIdentifier(key.name)) return;
|
|
468
|
+
|
|
469
|
+
const keySymbol = valueSymbol(key.name);
|
|
470
|
+
const statements = lookup.body.statements;
|
|
471
|
+
const exit = statements.at(-1);
|
|
472
|
+
if (!exit || !ts.isReturnStatement(exit) || !exit.expression || !ts.isElementAccessExpression(exit.expression)) return;
|
|
473
|
+
const nativeLookup = exit.expression;
|
|
474
|
+
const target = nativeLookup.expression;
|
|
475
|
+
if (!ts.isPropertyAccessExpression(target) || target.name.text !== name || !ts.isIdentifier(target.expression)
|
|
476
|
+
|| valueSymbol(target.expression) !== host || !ts.isIdentifier(nativeLookup.argumentExpression)
|
|
477
|
+
|| valueSymbol(nativeLookup.argumentExpression) !== keySymbol) return;
|
|
478
|
+
|
|
479
|
+
const keys = new Set();
|
|
480
|
+
for (const statement of statements.slice(0, -1)) {
|
|
481
|
+
if (!ts.isIfStatement(statement) || statement.elseStatement || !ts.isReturnStatement(statement.thenStatement)
|
|
482
|
+
|| !statement.thenStatement.expression || !ts.isBinaryExpression(statement.expression)) return;
|
|
483
|
+
const { left, operatorToken, right } = statement.expression;
|
|
484
|
+
if (operatorToken.kind !== K.EqualsEqualsEqualsToken || !ts.isIdentifier(left)
|
|
485
|
+
|| valueSymbol(left) !== keySymbol || !ts.isStringLiteralLike(right)) return;
|
|
486
|
+
keys.add(right.text);
|
|
487
|
+
}
|
|
488
|
+
return keys;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function readReadableOverrides(symbol) {
|
|
492
|
+
const declaration = sdkVariable(symbol, "readableApi", "wow/readable-api.ts");
|
|
493
|
+
const view = readOnlyApiMetatable(declaration?.initializer);
|
|
494
|
+
if (!view) return;
|
|
495
|
+
const { index, reject } = view;
|
|
496
|
+
if (!reject || !ts.isFunctionDeclaration(reject) || reject.getSourceFile() !== declaration.getSourceFile()
|
|
497
|
+
|| reject.body?.statements.length !== 1) return;
|
|
498
|
+
const [exit] = reject.body.statements;
|
|
499
|
+
if (!ts.isReturnStatement(exit) || !exit.expression || !ts.isCallExpression(exit.expression)
|
|
500
|
+
|| !ts.isIdentifier(exit.expression.expression) || exit.expression.expression.text !== "error"
|
|
501
|
+
|| !hostGlobal(valueSymbol(exit.expression.expression))) return;
|
|
502
|
+
const methods = sdkVariable(valueSymbol(index), "readableMethods", "wow/readable-api.ts");
|
|
503
|
+
const lookup = readableMetatable(methods?.initializer, 1);
|
|
504
|
+
const raw = lookup?.fields.get("__index");
|
|
505
|
+
if (!raw || !ts.isIdentifier(raw)) return;
|
|
506
|
+
const hostSymbol = valueSymbol(raw);
|
|
507
|
+
const host = sdkVariable(hostSymbol, "api", "wow/native.ts")?.initializer;
|
|
508
|
+
if (!host || !ts.isIdentifier(host) || host.text !== "_G" || !hostGlobal(valueSymbol(host))) return;
|
|
509
|
+
const keys = new Set();
|
|
510
|
+
const guardedReads = new Map();
|
|
511
|
+
const guardedTuples = new Map();
|
|
512
|
+
const namespaces = new Map();
|
|
513
|
+
for (const field of lookup.table.properties) {
|
|
514
|
+
if ((!ts.isMethodDeclaration(field) && !ts.isPropertyAssignment(field)) || !ts.isIdentifier(field.name)) return;
|
|
515
|
+
const name = field.name.text;
|
|
516
|
+
keys.add(name);
|
|
517
|
+
if (ts.isMethodDeclaration(field)) {
|
|
518
|
+
const forwarding = readableHostForwarding(field, hostSymbol, name);
|
|
519
|
+
if (forwarding) guardedReads.set(name, forwarding);
|
|
520
|
+
else {
|
|
521
|
+
const tuple = readableHostTupleForwarding(field, hostSymbol, name);
|
|
522
|
+
if (tuple) guardedTuples.set(name, tuple);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (ts.isPropertyAssignment(field)) {
|
|
526
|
+
const nested = readReadableNamespace(field.initializer, name, hostSymbol, reject);
|
|
527
|
+
if (nested) namespaces.set(name, nested);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return { keys, guardedReads, guardedTuples, namespaces };
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function readableHostForwarding(field, host, name) {
|
|
534
|
+
if (field.parameters.length !== 2 || field.body?.statements.length !== 1) return false;
|
|
535
|
+
const [receiver, rest] = field.parameters;
|
|
536
|
+
if (!ts.isIdentifier(receiver.name) || receiver.name.text !== "this"
|
|
537
|
+
|| !(checker.getTypeAtLocation(receiver).flags & T.Void)
|
|
538
|
+
|| !rest.dotDotDotToken || !ts.isIdentifier(rest.name)) return false;
|
|
539
|
+
const [exit] = field.body.statements;
|
|
540
|
+
if (!ts.isReturnStatement(exit) || !exit.expression || !ts.isCallExpression(exit.expression)
|
|
541
|
+
|| exit.expression.arguments.length !== 1 || !ts.isIdentifier(exit.expression.expression)) return false;
|
|
542
|
+
if (!canonicalRevealCall(exit.expression)) return false;
|
|
543
|
+
|
|
544
|
+
const [raw] = exit.expression.arguments;
|
|
545
|
+
if (!ts.isCallExpression(raw) || !ts.isPropertyAccessExpression(raw.expression)
|
|
546
|
+
|| raw.expression.name.text !== name || !ts.isIdentifier(raw.expression.expression)
|
|
547
|
+
|| valueSymbol(raw.expression.expression) !== host || raw.arguments.length !== 1) return false;
|
|
548
|
+
const [arg] = raw.arguments;
|
|
549
|
+
if (!ts.isSpreadElement(arg) || !ts.isIdentifier(arg.expression)
|
|
550
|
+
|| valueSymbol(arg.expression)?.valueDeclaration !== rest || raw.expression.questionDotToken) return false;
|
|
551
|
+
return raw.questionDotToken ? "optional" : "required";
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function canonicalRevealCall(node) {
|
|
555
|
+
if (!ts.isCallExpression(node) || node.flags & ts.NodeFlags.OptionalChain || node.arguments.length !== 1
|
|
556
|
+
|| !ts.isIdentifier(node.expression)) return false;
|
|
557
|
+
const reveal = valueSymbol(node.expression)?.valueDeclaration;
|
|
558
|
+
const guard = reveal && checker.resolveName("isSecret", reveal, ts.SymbolFlags.Value, false)?.valueDeclaration;
|
|
559
|
+
return canonicalReveal(reveal, guard);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function readableHostTupleForwarding(field, host, name) {
|
|
563
|
+
if (field.parameters.length < 1 || field.parameters.length > 2 || field.body?.statements.length !== 2) return;
|
|
564
|
+
const [receiver, input] = field.parameters;
|
|
565
|
+
if (!ts.isIdentifier(receiver.name) || receiver.name.text !== "this"
|
|
566
|
+
|| !(checker.getTypeAtLocation(receiver).flags & T.Void)
|
|
567
|
+
|| input && (!ts.isIdentifier(input.name) || input.dotDotDotToken || input.initializer)) return;
|
|
568
|
+
const [assignment, exit] = field.body.statements;
|
|
569
|
+
if (!ts.isVariableStatement(assignment) || !(assignment.declarationList.flags & ts.NodeFlags.Const)
|
|
570
|
+
|| assignment.declarationList.declarations.length !== 1
|
|
571
|
+
|| !ts.isReturnStatement(exit) || !exit.expression || !ts.isCallExpression(exit.expression)
|
|
572
|
+
|| !ts.isIdentifier(exit.expression.expression) || !nativeMultiFunction(valueSymbol(exit.expression.expression))) return;
|
|
573
|
+
const { name: pattern, initializer: raw } = assignment.declarationList.declarations[0];
|
|
574
|
+
if (!ts.isArrayBindingPattern(pattern) || !raw || !nativeMultiCall(raw) || !ts.isPropertyAccessExpression(raw.expression)
|
|
575
|
+
|| raw.expression.name.text !== name || valueSymbol(raw.expression.expression) !== host
|
|
576
|
+
|| raw.arguments.length !== field.parameters.length - 1
|
|
577
|
+
|| input && (!ts.isIdentifier(raw.arguments[0]) || valueSymbol(raw.arguments[0])?.valueDeclaration !== input)) return;
|
|
578
|
+
|
|
579
|
+
const guards = exit.expression.arguments;
|
|
580
|
+
if (pattern.elements.length === 0 || guards.length !== pattern.elements.length) return;
|
|
581
|
+
for (const [index, slot] of pattern.elements.entries()) {
|
|
582
|
+
const guard = guards[index];
|
|
583
|
+
if (!ts.isBindingElement(slot) || slot.initializer || slot.dotDotDotToken || !ts.isIdentifier(slot.name)
|
|
584
|
+
|| !canonicalRevealCall(guard) || !ts.isIdentifier(guard.arguments[0])
|
|
585
|
+
|| valueSymbol(guard.arguments[0])?.valueDeclaration !== slot) return;
|
|
586
|
+
}
|
|
587
|
+
return { count: guards.length, arity: raw.arguments.length };
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function readableHostOverrides(source) {
|
|
591
|
+
const symbol = valueSymbol(ts.isPropertyAccessExpression(source) ? source.name : source);
|
|
592
|
+
if (symbol?.name !== "readableApi") return;
|
|
593
|
+
let overrides = readableOverrides.get(symbol);
|
|
594
|
+
if (overrides === undefined) {
|
|
595
|
+
overrides = readReadableOverrides(symbol) ?? false;
|
|
596
|
+
readableOverrides.set(symbol, overrides);
|
|
597
|
+
}
|
|
598
|
+
return overrides || undefined;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function staticMemberName(node) {
|
|
602
|
+
if (node.flags & ts.NodeFlags.OptionalChain) return;
|
|
603
|
+
if (ts.isPropertyAccessExpression(node)) return node.name.text;
|
|
604
|
+
if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression)) {
|
|
605
|
+
return node.argumentExpression.text;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function emitReadableHostProperty(source, name) {
|
|
610
|
+
const overrides = readableHostOverrides(source);
|
|
611
|
+
if (overrides && !overrides.keys.has(name)) {
|
|
612
|
+
emit("property", text(name));
|
|
613
|
+
emit("host-global", "_G");
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const namespace = staticMemberName(source);
|
|
618
|
+
if (namespace === undefined) return false;
|
|
619
|
+
const nested = readableHostOverrides(source.expression)?.namespaces.get(namespace);
|
|
620
|
+
if (!nested || nested.has(name)) return false;
|
|
621
|
+
|
|
622
|
+
// Keep an escaping namespace as the facade. A direct unguarded lookup has
|
|
623
|
+
// the same host receiver and key as the proven __index fallback.
|
|
624
|
+
emit("property", text(name));
|
|
625
|
+
emit("property", text(namespace));
|
|
626
|
+
emit("host-global", "_G");
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function stableReadableArgument(node) {
|
|
631
|
+
return ts.isIdentifier(node) || ts.isStringLiteralLike(node) || ts.isNumericLiteral(node)
|
|
632
|
+
|| node.kind === K.TrueKeyword || node.kind === K.FalseKeyword || node.kind === K.NullKeyword;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function emitReadableHostCall(node) {
|
|
636
|
+
const callee = node.expression;
|
|
637
|
+
const name = staticMemberName(callee);
|
|
638
|
+
if (name === undefined) return false;
|
|
639
|
+
const forwarding = readableHostOverrides(callee.expression)?.guardedReads.get(name);
|
|
640
|
+
if (!forwarding || !node.arguments.every(stableReadableArgument)) return false;
|
|
641
|
+
|
|
642
|
+
// The facade reads the host member after evaluating the caller's arguments.
|
|
643
|
+
// Use the ordinary dispatch for arguments that can change that member.
|
|
644
|
+
if (forwarding === "optional") {
|
|
645
|
+
emit("call", node.arguments.length + 1);
|
|
646
|
+
emit("global", "wowOptionalReadable");
|
|
647
|
+
} else {
|
|
648
|
+
emit("call", 1);
|
|
649
|
+
emit("global", "wowReadable");
|
|
650
|
+
emit("call", node.arguments.length);
|
|
651
|
+
}
|
|
652
|
+
emit("property", text(name));
|
|
653
|
+
emit("host-global", "_G");
|
|
654
|
+
callArguments(node.arguments);
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function readableHostTuple(node) {
|
|
659
|
+
const callee = node.expression;
|
|
660
|
+
const name = staticMemberName(callee);
|
|
661
|
+
if (name === undefined || !node.arguments.every(stableReadableArgument)) return;
|
|
662
|
+
const read = readableHostOverrides(callee.expression)?.guardedTuples.get(name);
|
|
663
|
+
if (read && node.arguments.length === read.arity) return { name, count: read.count };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function emitReadableTupleRead(node, name) {
|
|
667
|
+
emit("call", node.arguments.length);
|
|
668
|
+
emit("property", text(name));
|
|
669
|
+
emit("host-global", "_G");
|
|
670
|
+
callArguments(node.arguments);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function bindNativeTuple(names, node, predeclared) {
|
|
674
|
+
const readable = readableHostTuple(node);
|
|
675
|
+
if (readable && names.length <= readable.count) {
|
|
676
|
+
emit(predeclared ? "readable-multi-binding" : "readable-multi-local", ...names);
|
|
677
|
+
return emitReadableTupleRead(node, readable.name);
|
|
678
|
+
}
|
|
679
|
+
emit(predeclared ? "multi-binding" : "multi-local", ...names);
|
|
680
|
+
return call(node, "multi");
|
|
681
|
+
}
|
|
682
|
+
|
|
370
683
|
function nativeClass(node) {
|
|
371
684
|
const declaration = valueSymbol(ts.isPropertyAccessExpression(node) ? node.name : node)?.valueDeclaration;
|
|
372
685
|
return declaration && ts.isClassDeclaration(declaration) && ts.isSourceFile(declaration.parent)
|
|
@@ -524,8 +837,9 @@ function collectionReference(node) {
|
|
|
524
837
|
if (constructed) return constructed;
|
|
525
838
|
const type = checker.getNonNullableType(checker.getTypeAtLocation(node));
|
|
526
839
|
const symbol = type.getSymbol();
|
|
527
|
-
if (["OwnedMap", "OwnedReadonlyMap", "OwnedSet"].includes(symbol?.name) && symbol.declarations?.some(declaration =>
|
|
840
|
+
if (["OwnedMap", "OwnedReadonlyMap", "OwnedSet", "OwnedWeakMap"].includes(symbol?.name) && symbol.declarations?.some(declaration =>
|
|
528
841
|
relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/") === "src/owned-collections.ts")) {
|
|
842
|
+
if (symbol.name === "OwnedWeakMap") return "weakmap";
|
|
529
843
|
return symbol.name === "OwnedSet" ? "set" : "map";
|
|
530
844
|
}
|
|
531
845
|
const field = privateReadonlyInitializer(node);
|
|
@@ -960,6 +1274,14 @@ function arrayChainTarget(node, declaration) {
|
|
|
960
1274
|
return arrayCallbackTarget(node, method);
|
|
961
1275
|
}
|
|
962
1276
|
|
|
1277
|
+
// A namespace holding only types, such as the JSX namespace, has no runtime value.
|
|
1278
|
+
function typeOnlyNamespace(node) {
|
|
1279
|
+
if (!ts.isModuleDeclaration(node) || !node.body) return false;
|
|
1280
|
+
if (ts.isModuleDeclaration(node.body)) return typeOnlyNamespace(node.body);
|
|
1281
|
+
return ts.isModuleBlock(node.body) && node.body.statements.every(statement => ts.isInterfaceDeclaration(statement)
|
|
1282
|
+
|| ts.isTypeAliasDeclaration(statement) || typeOnlyNamespace(statement));
|
|
1283
|
+
}
|
|
1284
|
+
|
|
963
1285
|
function standardMember(node, ownerName, key) {
|
|
964
1286
|
if (!ts.isPropertyAccessExpression(node) || !ts.isIdentifier(node.expression) || node.name.text !== key) return false;
|
|
965
1287
|
const owner = checker.getSymbolAtLocation(node.expression);
|
|
@@ -1340,6 +1662,13 @@ function call(node, mode = "scalar") {
|
|
|
1340
1662
|
}
|
|
1341
1663
|
return optionalCall(node, signature);
|
|
1342
1664
|
}
|
|
1665
|
+
if (mode === "scalar" && emitReadableHostCall(node)) return;
|
|
1666
|
+
if (standardMember(node.expression, "Object", "defineProperties") && node.arguments.length === 2
|
|
1667
|
+
&& relative(sdkRoot, realpathSync(node.getSourceFile().fileName)).replaceAll("\\", "/") === "state/setup-store-view.ts") {
|
|
1668
|
+
emit("call", 2);
|
|
1669
|
+
emit("global", "setupStoreView");
|
|
1670
|
+
return callArguments(node.arguments);
|
|
1671
|
+
}
|
|
1343
1672
|
if (nativeStringCall(node, declaration)) return;
|
|
1344
1673
|
if (nativeFixedNumber(node, declaration)) return;
|
|
1345
1674
|
if (standardMember(node.expression, "Array", "isArray") && node.arguments.length === 1) {
|
|
@@ -1390,8 +1719,10 @@ function call(node, mode = "scalar") {
|
|
|
1390
1719
|
}
|
|
1391
1720
|
const number = numericIntrinsic(node.expression);
|
|
1392
1721
|
if (number) {
|
|
1722
|
+
const numericPair = (number === "numberMin" || number === "numberMax") && node.arguments.length === 2
|
|
1723
|
+
&& node.arguments.every(argument => !ts.isSpreadElement(argument) && knownNumber(checker.getTypeAtLocation(argument)));
|
|
1393
1724
|
emit("call", node.arguments.length);
|
|
1394
|
-
emit("global", number);
|
|
1725
|
+
emit("global", numericPair ? number + "2" : number);
|
|
1395
1726
|
callArguments(node.arguments);
|
|
1396
1727
|
return;
|
|
1397
1728
|
}
|
|
@@ -1799,13 +2130,10 @@ function jsxProps(attributes) {
|
|
|
1799
2130
|
}
|
|
1800
2131
|
|
|
1801
2132
|
function jsx(node) {
|
|
1802
|
-
const
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
};
|
|
1807
|
-
if (options.jsx !== ts.JsxEmit.React || pragma("jsxruntime", "runtime") === "automatic") {
|
|
1808
|
-
unsupported(node, "The native compiler requires classic JSX factories");
|
|
2133
|
+
const pragma = (key, argument) => jsxPragma(node.getSourceFile(), key, argument);
|
|
2134
|
+
const automatic = kumiJsxFactories.get(node.getSourceFile().fileName);
|
|
2135
|
+
if (!automatic && (options.jsx !== ts.JsxEmit.React || pragma("jsxruntime", "runtime") === "automatic")) {
|
|
2136
|
+
unsupported(node, "The native compiler requires classic JSX or Kumi's automatic JSX runtime");
|
|
1809
2137
|
}
|
|
1810
2138
|
const fragment = ts.isJsxFragment(node);
|
|
1811
2139
|
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
@@ -1820,8 +2148,8 @@ function jsx(node) {
|
|
|
1820
2148
|
} else children.push(child);
|
|
1821
2149
|
}
|
|
1822
2150
|
emit("call", 2 + children.length);
|
|
1823
|
-
jsxFactory(pragma("jsx", "factory") ?? options.jsxFactory, node, true);
|
|
1824
|
-
if (fragment) jsxFactory(pragma("jsxfrag", "factory") ?? options.jsxFragmentFactory, node);
|
|
2151
|
+
jsxFactory(automatic?.factory ?? pragma("jsx", "factory") ?? options.jsxFactory, node, true);
|
|
2152
|
+
if (fragment) jsxFactory(automatic?.fragment ?? pragma("jsxfrag", "factory") ?? options.jsxFragmentFactory, node);
|
|
1825
2153
|
else if (ts.isIdentifier(opening.tagName) && ts.isIntrinsicJsxName(opening.tagName.text)) emit("string", text(opening.tagName.text));
|
|
1826
2154
|
else expression(opening.tagName);
|
|
1827
2155
|
jsxProps(opening.attributes?.properties);
|
|
@@ -1881,6 +2209,12 @@ function expression(node) {
|
|
|
1881
2209
|
}
|
|
1882
2210
|
if (ts.isPropertyAccessExpression(node)) {
|
|
1883
2211
|
if (standardMember(node, "Math", "PI")) return emit("global", "math.pi");
|
|
2212
|
+
if (standardMember(node, "Number", "NaN")) return emit("literal", "nan");
|
|
2213
|
+
if (standardMember(node, "Number", "POSITIVE_INFINITY")) return emit("global", "math.huge");
|
|
2214
|
+
if (standardMember(node, "Number", "NEGATIVE_INFINITY")) return emit("literal", "-inf");
|
|
2215
|
+
for (const name of ["MAX_SAFE_INTEGER", "MIN_SAFE_INTEGER", "EPSILON", "MAX_VALUE", "MIN_VALUE"]) {
|
|
2216
|
+
if (standardMember(node, "Number", name)) return emit("number", String(Number[name]));
|
|
2217
|
+
}
|
|
1884
2218
|
if (node.flags & ts.NodeFlags.OptionalChain && (!node.questionDotToken || node.expression.flags & ts.NodeFlags.OptionalChain)) {
|
|
1885
2219
|
return optionalChain(node);
|
|
1886
2220
|
}
|
|
@@ -1910,7 +2244,10 @@ function expression(node) {
|
|
|
1910
2244
|
unsupported(node, "Optional access requires a table or undefined");
|
|
1911
2245
|
}
|
|
1912
2246
|
emit("optional-property", text(node.name.text));
|
|
1913
|
-
} else
|
|
2247
|
+
} else {
|
|
2248
|
+
if (emitReadableHostProperty(node.expression, node.name.text)) return;
|
|
2249
|
+
emit("property", text(node.name.text));
|
|
2250
|
+
}
|
|
1914
2251
|
return expression(node.expression);
|
|
1915
2252
|
}
|
|
1916
2253
|
if (ts.isElementAccessExpression(node) && node.flags & ts.NodeFlags.OptionalChain
|
|
@@ -1926,6 +2263,7 @@ function expression(node) {
|
|
|
1926
2263
|
}
|
|
1927
2264
|
if (ts.isElementAccessExpression(node) && !(node.flags & ts.NodeFlags.OptionalChain)) {
|
|
1928
2265
|
const source = node.expression;
|
|
2266
|
+
if (ts.isStringLiteralLike(node.argumentExpression) && emitReadableHostProperty(source, node.argumentExpression.text)) return;
|
|
1929
2267
|
if (knownString(checker.getTypeAtLocation(source))) {
|
|
1930
2268
|
emit("call", 2);
|
|
1931
2269
|
emit("global", "byteAt");
|
|
@@ -1935,7 +2273,16 @@ function expression(node) {
|
|
|
1935
2273
|
if (nativeMultiCall(source)) {
|
|
1936
2274
|
const index = node.argumentExpression;
|
|
1937
2275
|
if (ts.isNumericLiteral(index) && Number.isSafeInteger(Number(index.text)) && Number(index.text) < 1000) {
|
|
1938
|
-
|
|
2276
|
+
const offset = Number(index.text) + 1;
|
|
2277
|
+
const readable = readableHostTuple(source);
|
|
2278
|
+
const guard = ["wowReadable", "wowReadableSecond", "wowReadableThird"][offset - 1];
|
|
2279
|
+
if (readable && offset <= readable.count && guard !== undefined) {
|
|
2280
|
+
emit("call", 1);
|
|
2281
|
+
emit("global", guard);
|
|
2282
|
+
emit("spread-native");
|
|
2283
|
+
return emitReadableTupleRead(source, readable.name);
|
|
2284
|
+
}
|
|
2285
|
+
emit("multi-slot", offset);
|
|
1939
2286
|
return call(source, "multi");
|
|
1940
2287
|
}
|
|
1941
2288
|
emit("array-index");
|
|
@@ -2125,7 +2472,7 @@ function expression(node) {
|
|
|
2125
2472
|
return expression(node.expression);
|
|
2126
2473
|
}
|
|
2127
2474
|
if (ts.isConditionalExpression(node)) {
|
|
2128
|
-
emit("select");
|
|
2475
|
+
emit(luaAlwaysTruthy(checker.getTypeAtLocation(node.whenTrue)) ? "select-truthy" : "select");
|
|
2129
2476
|
booleanCondition(node.condition);
|
|
2130
2477
|
expression(node.whenTrue);
|
|
2131
2478
|
expression(node.whenFalse);
|
|
@@ -2386,8 +2733,7 @@ function localDeclaration(declaration, predeclared) {
|
|
|
2386
2733
|
if (!nativeMultiCall(initializer) || compoundTuple(declaration.name) || bindings.some(element => element.initializer)) {
|
|
2387
2734
|
return bindTuple(declaration.name, () => multiArrayValue(initializer), predeclared);
|
|
2388
2735
|
}
|
|
2389
|
-
|
|
2390
|
-
return call(initializer, "multi");
|
|
2736
|
+
return bindNativeTuple(tupleLocals(declaration.name), initializer, predeclared);
|
|
2391
2737
|
}
|
|
2392
2738
|
if (!knownTuple(type) && !nativeArrayReference(initializer)) unsupported(declaration, "Array destructuring requires a native tuple or sequence");
|
|
2393
2739
|
return bindTuple(declaration.name, () => expression(initializer), predeclared);
|
|
@@ -2457,8 +2803,7 @@ function assignTuple(node) {
|
|
|
2457
2803
|
unsupported(node.left, "Tuple assignment requires distinct local targets");
|
|
2458
2804
|
}
|
|
2459
2805
|
if (nativeCall && !marker) {
|
|
2460
|
-
|
|
2461
|
-
return call(source, "multi");
|
|
2806
|
+
return bindNativeTuple(names, source, true);
|
|
2462
2807
|
}
|
|
2463
2808
|
if (nativeCall || ts.isArrayLiteralExpression(source) && source.elements.every(element => !ts.isSpreadElement(element))) {
|
|
2464
2809
|
const values = nativeCall ? source.arguments : source.elements;
|
|
@@ -3135,6 +3480,11 @@ function moduleInitializer(node) {
|
|
|
3135
3480
|
ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))
|
|
3136
3481
|
&& property.name.text === "providers")) return moduleInitializer(node.arguments[0]);
|
|
3137
3482
|
}
|
|
3483
|
+
if (target.name === "defineStore" && declaration && (node.arguments.length === 2 || node.arguments.length === 3)
|
|
3484
|
+
&& relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/") === "state/setup-store.ts") {
|
|
3485
|
+
for (const argument of node.arguments) moduleInitializer(argument);
|
|
3486
|
+
return;
|
|
3487
|
+
}
|
|
3138
3488
|
if (target.name === "createSignalFactory" && declaration &&
|
|
3139
3489
|
relative(sdkRoot, realpathSync(declaration.getSourceFile().fileName)).replaceAll("\\", "/") === "src/signal-kernel.ts"
|
|
3140
3490
|
&& node.arguments.every(arg => ts.isIdentifier(arg) || ts.isArrowFunction(arg))) return;
|
|
@@ -3233,6 +3583,7 @@ async function visit(file, origin) {
|
|
|
3233
3583
|
if (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isImportDeclaration(node)) continue;
|
|
3234
3584
|
if (ts.isClassDeclaration(node) && node.name && moduleMarker(checker.getSymbolAtLocation(node.name))) continue;
|
|
3235
3585
|
if (ts.isModuleDeclaration(node) && ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Ambient) continue;
|
|
3586
|
+
if (typeOnlyNamespace(node)) continue;
|
|
3236
3587
|
if (ts.isExportDeclaration(node)) {
|
|
3237
3588
|
if (node.isTypeOnly || node.moduleSpecifier) continue;
|
|
3238
3589
|
if (!node.exportClause || !ts.isNamedExports(node.exportClause)) unsupported(node);
|
|
@@ -3305,7 +3656,7 @@ async function visit(file, origin) {
|
|
|
3305
3656
|
const params = parameters(node.parameters, usesSelf);
|
|
3306
3657
|
emit(usesSelf ? "function-self" : "function", key === undefined ? "-" : text(key),
|
|
3307
3658
|
name, ...params);
|
|
3308
|
-
if (!emitCanonicalReveal(
|
|
3659
|
+
if (!emitCanonicalReveal(node, exports, params)) body(node.body, node.parameters);
|
|
3309
3660
|
}
|
|
3310
3661
|
emit("end-module");
|
|
3311
3662
|
}
|