@overmvp/kumi 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
import { transformJsxForm } from "./jsx-form.mjs";
|
|
5
|
+
|
|
6
|
+
const ts = createRequire(import.meta.url)("typescript");
|
|
7
|
+
|
|
8
|
+
function transform(jsx) {
|
|
9
|
+
return transformJsxForm(ts, "fixture.tsx", 'import { Form } from "@kumi/form";\n' + jsx);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
test("keeps explicit render callbacks with a spread form controller", () => {
|
|
13
|
+
assert.equal(transform('<Form {...control}>{() => <Field />}</Form>'), undefined);
|
|
14
|
+
assert.equal(transform('<Form {...control}>{((function () { return <Field />; }))}</Form>'), undefined);
|
|
15
|
+
assert.equal(transform('<Form {...control}>{(() => <Field />)}</Form>'), undefined);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("keeps legacy callbacks with an explicit form prop", () => {
|
|
19
|
+
assert.equal(transform('<Form form={control}>{render}</Form>'), undefined);
|
|
20
|
+
assert.equal(transform('<Form form={control}>{form => <Field form={form} />}</Form>'), undefined);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("still delays direct JSX children inside nested forms", () => {
|
|
24
|
+
const result = transform('<Form {...outer}>{() => <Form {...inner}><Field /></Form>}</Form>');
|
|
25
|
+
assert.equal(result, 'import { Form } from "@kumi/form";\n'
|
|
26
|
+
+ '<Form {...outer}>{() => <Form {...inner}>{() => <Field />}</Form>}</Form>');
|
|
27
|
+
assert.equal(transform('<Form {...control}>{node}</Form>'),
|
|
28
|
+
'import { Form } from "@kumi/form";\n<Form {...control}>{() => <>{node}</>}</Form>');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("reports the original function position in a Form callback's returned fragment", () => {
|
|
32
|
+
const child = "() => <Field />";
|
|
33
|
+
for (const jsx of [
|
|
34
|
+
'<Form {...control}>{() => <>{' + child + '}</>}</Form>',
|
|
35
|
+
'<Form {...control}>{function () { return (<>{(' + child + ')}</>); }}</Form>',
|
|
36
|
+
'<Form {...control}><Note />{' + child + '}</Form>',
|
|
37
|
+
]) {
|
|
38
|
+
assert.throws(() => transform(jsx), {
|
|
39
|
+
message: "fixture.tsx:2:" + (jsx.indexOf(child) + 1) + ": Pass a Form render callback as its only child",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("leaves reactive children and callbacks of nested components alone", () => {
|
|
45
|
+
assert.equal(transform(
|
|
46
|
+
'<Form {...control}>{() => <><Widget onChange={() => apply()}>{() => <Field />}</Widget>{ref}</>}</Form>',
|
|
47
|
+
), undefined);
|
|
48
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { transformJsxForm } from "./jsx-form.mjs";
|
|
2
|
+
|
|
3
|
+
export function transformJsx(ts, path, source) {
|
|
4
|
+
const form = transformJsxForm(ts, path, source);
|
|
5
|
+
return transformJsxLists(ts, path, form ?? source) ?? form;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function unwrap(ts, expression) {
|
|
9
|
+
while (expression && ts.isParenthesizedExpression(expression)) expression = expression.expression;
|
|
10
|
+
return expression;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getReactiveMap(ts, node) {
|
|
14
|
+
if (!ts.isJsxExpression(node) || !(ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) return;
|
|
15
|
+
const call = unwrap(ts, node.expression);
|
|
16
|
+
if (!call || !ts.isCallExpression(call) || ts.isOptionalChain(call)) return;
|
|
17
|
+
const member = call.expression;
|
|
18
|
+
if (!ts.isPropertyAccessExpression(member) || member.name.text !== "map") return;
|
|
19
|
+
const array = member.expression;
|
|
20
|
+
const receiver = unwrap(ts, array);
|
|
21
|
+
if (ts.isOptionalChain(receiver)) return;
|
|
22
|
+
const ref = ts.isPropertyAccessExpression(receiver) && receiver.name.text === "value";
|
|
23
|
+
if (ref || ts.isCallExpression(receiver)) return { call, array };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isJsx(ts, node) {
|
|
27
|
+
return ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function containsJsx(ts, node) {
|
|
31
|
+
return isJsx(ts, node) || ts.forEachChild(node, child => containsJsx(ts, child));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addBindings(ts, binding, names) {
|
|
35
|
+
if (ts.isIdentifier(binding)) {
|
|
36
|
+
names.add(binding.text);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const element of binding.elements) if (ts.isBindingElement(element)) addBindings(ts, element.name, names);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function returnedRow(ts, body, locals) {
|
|
43
|
+
if (!ts.isBlock(body)) return unwrap(ts, body);
|
|
44
|
+
|
|
45
|
+
const returns = [];
|
|
46
|
+
function visit(node) {
|
|
47
|
+
if (ts.isReturnStatement(node)) {
|
|
48
|
+
returns.push(node);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (ts.isVariableDeclarationList(node) && !(node.flags & ts.NodeFlags.BlockScoped)) {
|
|
52
|
+
for (const declaration of node.declarations) addBindings(ts, declaration.name, locals);
|
|
53
|
+
}
|
|
54
|
+
if (!ts.isFunctionLike(node) && !ts.isClassLike(node)) ts.forEachChild(node, visit);
|
|
55
|
+
}
|
|
56
|
+
ts.forEachChild(body, visit);
|
|
57
|
+
|
|
58
|
+
if (returns.length !== 1 || returns[0].parent !== body) return;
|
|
59
|
+
for (const statement of body.statements) {
|
|
60
|
+
if (ts.isVariableStatement(statement)) {
|
|
61
|
+
for (const declaration of statement.declarationList.declarations) addBindings(ts, declaration.name, locals);
|
|
62
|
+
} else if (statement.name && ts.isIdentifier(statement.name)) {
|
|
63
|
+
locals.add(statement.name.text);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return unwrap(ts, returns[0].expression);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function refersToLocal(ts, node, locals) {
|
|
70
|
+
if (ts.isIdentifier(node) && locals.has(node.text)) {
|
|
71
|
+
const parent = node.parent;
|
|
72
|
+
if (!((ts.isPropertyAccessExpression(parent) || ts.isPropertyAssignment(parent)) && parent.name === node)) return true;
|
|
73
|
+
}
|
|
74
|
+
return ts.forEachChild(node, child => refersToLocal(ts, child, locals));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function canCopyParameter(ts, parameter) {
|
|
78
|
+
if (parameter.initializer || parameter.dotDotDotToken) return false;
|
|
79
|
+
return ts.isIdentifier(parameter.name) || parameter.name.elements.every(element => ts.isOmittedExpression(element)
|
|
80
|
+
|| (!element.propertyName || !ts.isComputedPropertyName(element.propertyName)) && canCopyParameter(ts, element));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function extractRow(ts, file, call, report) {
|
|
84
|
+
const original = call.arguments[0];
|
|
85
|
+
const callback = unwrap(ts, original);
|
|
86
|
+
if (!callback || !(ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) return;
|
|
87
|
+
|
|
88
|
+
const locals = new Set();
|
|
89
|
+
const row = returnedRow(ts, callback.body, locals);
|
|
90
|
+
if (!row || !(ts.isJsxElement(row) || ts.isJsxSelfClosingElement(row))) {
|
|
91
|
+
if (containsJsx(ts, callback.body)) report(callback.body, "Return one JSX element with an explicit key directly from the reactive map callback");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!ts.isArrowFunction(callback) || call.arguments.length !== 1 || callback.modifiers?.length
|
|
95
|
+
|| callback.typeParameters?.length || callback.parameters.length > 2 || !callback.parameters.every(param => canCopyParameter(ts, param))) {
|
|
96
|
+
report(callback, "Use an arrow callback with item and optional index parameters that returns the keyed JSX row directly");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const opening = ts.isJsxElement(row) ? row.openingElement : row;
|
|
100
|
+
const attributes = opening.attributes.properties;
|
|
101
|
+
const keys = attributes.filter(attr => ts.isJsxAttribute(attr) && ts.isIdentifier(attr.name) && attr.name.text === "key");
|
|
102
|
+
if (keys.length !== 1 || attributes.slice(attributes.indexOf(keys[0]) + 1).some(ts.isJsxSpreadAttribute)) {
|
|
103
|
+
report(opening, "Give the reactive map row one explicit key after any spread attributes");
|
|
104
|
+
}
|
|
105
|
+
const initializer = keys[0].initializer;
|
|
106
|
+
if (!initializer) report(keys[0], "Give the reactive map row a string or numeric key");
|
|
107
|
+
|
|
108
|
+
let key;
|
|
109
|
+
if (ts.isStringLiteral(initializer) && !initializer.text.includes("&")) {
|
|
110
|
+
key = JSON.stringify(initializer.text);
|
|
111
|
+
} else if (ts.isJsxExpression(initializer) && initializer.expression && !containsJsx(ts, initializer.expression)) {
|
|
112
|
+
if (locals.size && refersToLocal(ts, initializer.expression, locals)) {
|
|
113
|
+
report(initializer, "Derive the reactive map key from its parameters or the enclosing scope");
|
|
114
|
+
}
|
|
115
|
+
key = initializer.expression.getText(file);
|
|
116
|
+
} else {
|
|
117
|
+
report(initializer, "Use a string or numeric expression for the reactive map key");
|
|
118
|
+
}
|
|
119
|
+
return { original, callback, initializer, key };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Defer direct reactive JSX map children to the mounted list. */
|
|
123
|
+
export function transformJsxLists(ts, path, source) {
|
|
124
|
+
if (!path.endsWith(".tsx") || !source.includes("map")) return;
|
|
125
|
+
const file = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
126
|
+
const maps = [];
|
|
127
|
+
const names = new Set();
|
|
128
|
+
|
|
129
|
+
function visit(node) {
|
|
130
|
+
if (ts.isIdentifier(node)) names.add(node.text);
|
|
131
|
+
const mapping = getReactiveMap(ts, node);
|
|
132
|
+
if (mapping) maps.push(mapping);
|
|
133
|
+
ts.forEachChild(node, visit);
|
|
134
|
+
}
|
|
135
|
+
visit(file);
|
|
136
|
+
if (maps.length === 0) return;
|
|
137
|
+
|
|
138
|
+
function uniqueName(name) {
|
|
139
|
+
while (names.has(name)) name += "_";
|
|
140
|
+
names.add(name);
|
|
141
|
+
return name;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function report(node, message) {
|
|
145
|
+
const { line, character } = file.getLineAndCharacterOfPosition(node.getStart(file));
|
|
146
|
+
throw new Error(`${path}:${line + 1}:${character + 1}: ${message}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const map = uniqueName("__kumiJsxMap");
|
|
150
|
+
const list = uniqueName("__kumiJsxList");
|
|
151
|
+
const item = uniqueName("__kumiItem");
|
|
152
|
+
const index = uniqueName("__kumiIndex");
|
|
153
|
+
const key = uniqueName("__kumiKey");
|
|
154
|
+
const edits = [];
|
|
155
|
+
let hasMap = false;
|
|
156
|
+
let hasList = false;
|
|
157
|
+
|
|
158
|
+
function insert(offset, text) {
|
|
159
|
+
edits.push([offset, offset, text]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const { call, array } of maps) {
|
|
163
|
+
const row = extractRow(ts, file, call, report);
|
|
164
|
+
if (!row) {
|
|
165
|
+
hasList = true;
|
|
166
|
+
insert(call.getStart(file), list + "(() => ");
|
|
167
|
+
insert(call.end, ")");
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
hasMap = true;
|
|
172
|
+
const { original, callback, initializer } = row;
|
|
173
|
+
const params = callback.parameters;
|
|
174
|
+
const usesIndex = params.length === 2;
|
|
175
|
+
// Edit around the original receiver and render body so nested list edits keep their source offsets.
|
|
176
|
+
insert(call.getStart(file), map + "(() => (");
|
|
177
|
+
edits.push([array.end, original.getStart(file), `), (${params.map(param => param.getText(file)).join(", ")}) => (${row.key}), `]);
|
|
178
|
+
edits.push([initializer.getStart(file), initializer.end, `{${key}}`]);
|
|
179
|
+
insert(original.end, `, ${usesIndex}`);
|
|
180
|
+
|
|
181
|
+
const extra = [item, index, key].slice(params.length).join(", ");
|
|
182
|
+
if (callback.getFirstToken(file).kind === ts.SyntaxKind.OpenParenToken) {
|
|
183
|
+
const separator = params.length && !params.hasTrailingComma ? ", " : "";
|
|
184
|
+
insert(params.end, separator + extra);
|
|
185
|
+
} else {
|
|
186
|
+
insert(params[0].getStart(file), "(");
|
|
187
|
+
insert(params.end, `, ${extra})`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let output = source;
|
|
192
|
+
for (const [start, end, replacement] of edits.sort(([left], [right]) => right - left)) {
|
|
193
|
+
output = output.slice(0, start) + replacement + output.slice(end);
|
|
194
|
+
}
|
|
195
|
+
const imports = [];
|
|
196
|
+
if (hasMap) imports.push(`jsxMap as ${map}`);
|
|
197
|
+
if (hasList) imports.push(`jsxList as ${list}`);
|
|
198
|
+
return output + `\nimport { ${imports.join(", ")} } from "@kumi/core";\n`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function viteJsxLists(ts) {
|
|
202
|
+
return {
|
|
203
|
+
name: "kumi-jsx-lists",
|
|
204
|
+
enforce: "pre",
|
|
205
|
+
transform(source, id) {
|
|
206
|
+
return transformJsx(ts, id.split("?", 1)[0], source);
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { writeGeneratedText } from "./generated-output.mjs";
|
|
4
|
+
|
|
5
|
+
const magic = Buffer.from("kumi-addon-fragments-1\n");
|
|
6
|
+
|
|
7
|
+
function readFragment(path, packet) {
|
|
8
|
+
let offset = magic.length;
|
|
9
|
+
function field() {
|
|
10
|
+
if (offset + 4 > packet.length) throw new Error(`Truncated native fragment: ${path}`);
|
|
11
|
+
const size = packet.readUInt32LE(offset);
|
|
12
|
+
offset += 4;
|
|
13
|
+
const end = offset + size;
|
|
14
|
+
if (end > packet.length) throw new Error(`Truncated native fragment: ${path}`);
|
|
15
|
+
const value = packet.subarray(offset, end);
|
|
16
|
+
offset = end;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (!packet.subarray(0, offset).equals(magic)) throw new Error(`Unknown native fragment version: ${path}`);
|
|
20
|
+
const header = field();
|
|
21
|
+
const prelude = field();
|
|
22
|
+
const footer = field();
|
|
23
|
+
const modules = [];
|
|
24
|
+
while (offset < packet.length) {
|
|
25
|
+
const key = field().toString();
|
|
26
|
+
const fingerprint = field().toString();
|
|
27
|
+
modules.push({ key, fingerprint, prefix: field(), factory: field(), suffix: field() });
|
|
28
|
+
}
|
|
29
|
+
if (!modules.length) throw new Error(`Empty native fragment: ${path}`);
|
|
30
|
+
return { header, prelude, footer, modules };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function publish(path, parts, check) {
|
|
34
|
+
const source = Buffer.concat(parts.map(part => typeof part === "string" ? Buffer.from(part) : part));
|
|
35
|
+
if (check) {
|
|
36
|
+
if (!source.equals(await readFile(path))) throw new Error(`${path} is stale; link the native package again`);
|
|
37
|
+
} else await writeGeneratedText(path, source.toString());
|
|
38
|
+
return source.length;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Link opaque Rust codegen fragments. The entry order is fixed by the package manifest. */
|
|
42
|
+
export async function linkAddonPackage(entries, output, check = false) {
|
|
43
|
+
if (!entries.length) throw new Error("A native package requires at least one entry");
|
|
44
|
+
const chunks = [];
|
|
45
|
+
const candidates = new Map();
|
|
46
|
+
let prelude;
|
|
47
|
+
for (const { fragment, lua } of entries) {
|
|
48
|
+
const chunk = readFragment(fragment, await readFile(fragment));
|
|
49
|
+
prelude ??= chunk.prelude;
|
|
50
|
+
if (!prelude.equals(chunk.prelude)) throw new Error(`Mixed native package build stamps: ${fragment}`);
|
|
51
|
+
for (const module of chunk.modules) {
|
|
52
|
+
const hash = createHash("sha256").update(module.factory).digest("hex");
|
|
53
|
+
const id = `${module.key}\0${module.fingerprint}\0${hash}`;
|
|
54
|
+
let other = candidates.get(id);
|
|
55
|
+
if (other) {
|
|
56
|
+
if (!other.factory.equals(module.factory)) throw new Error(`Native factory hash collision for ${module.key}`);
|
|
57
|
+
other.count++;
|
|
58
|
+
} else {
|
|
59
|
+
other = { factory: module.factory, count: 1 };
|
|
60
|
+
candidates.set(id, other);
|
|
61
|
+
}
|
|
62
|
+
module.shared = other;
|
|
63
|
+
}
|
|
64
|
+
chunks.push({ lua, ...chunk });
|
|
65
|
+
}
|
|
66
|
+
let shared = 0;
|
|
67
|
+
let duplicateBytes = 0;
|
|
68
|
+
const pool = [prelude];
|
|
69
|
+
for (const candidate of candidates.values()) {
|
|
70
|
+
if (candidate.count < 2) continue;
|
|
71
|
+
candidate.slot = ++shared;
|
|
72
|
+
duplicateBytes += (candidate.count - 1) * candidate.factory.length;
|
|
73
|
+
pool.push(`definitions[${candidate.slot}] = `, candidate.factory, "\n");
|
|
74
|
+
}
|
|
75
|
+
pool.push("nativeRegistry.definitions = definitions\n");
|
|
76
|
+
let bytes = await publish(output, pool, check);
|
|
77
|
+
for (const chunk of chunks) {
|
|
78
|
+
const parts = [chunk.header];
|
|
79
|
+
for (const { prefix, shared, factory, suffix } of chunk.modules) {
|
|
80
|
+
parts.push(prefix, shared.slot ? `nativeDefinitions[${shared.slot}]` : factory, suffix);
|
|
81
|
+
}
|
|
82
|
+
parts.push(chunk.footer);
|
|
83
|
+
bytes += await publish(chunk.lua, parts, check);
|
|
84
|
+
}
|
|
85
|
+
return { shared, duplicateBytes, bytes };
|
|
86
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
|
|
8
|
+
const run = promisify(execFile);
|
|
9
|
+
const imageExtension = /\.(?:png|jpe?g|webp|tga)$/;
|
|
10
|
+
const textureDirectory = "KumiGenerated/Assets";
|
|
11
|
+
|
|
12
|
+
export async function prepareLuaImages({ ts, program, workspace, output, module, texturePath, pack, check, writeOutput }) {
|
|
13
|
+
if (typeof texturePath !== "string" || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(texturePath)) {
|
|
14
|
+
throw new Error("Expected a Lua texture path resolver name");
|
|
15
|
+
}
|
|
16
|
+
const root = realpathSync(workspace);
|
|
17
|
+
const paths = new Map();
|
|
18
|
+
const imports = new Map();
|
|
19
|
+
const files = new Set();
|
|
20
|
+
const key = (specifier, owner) => resolve(owner) + "\0" + specifier;
|
|
21
|
+
|
|
22
|
+
async function prepare(path) {
|
|
23
|
+
const data = await readFile(path);
|
|
24
|
+
const hash = createHash("sha256").update(data).digest("hex");
|
|
25
|
+
const texture = `${textureDirectory}/${hash}.tga`;
|
|
26
|
+
const filename = join(output, "asset-modules", module, hash + ".lua");
|
|
27
|
+
const target = join(output, "lua", texture);
|
|
28
|
+
const conversion = run(pack, ["image", "-", "--image-output", target,
|
|
29
|
+
...(path.endsWith(".tga") ? ["--image-input-tga"] : []), ...(check ? ["--check"] : [])],
|
|
30
|
+
{ windowsHide: true });
|
|
31
|
+
conversion.child.stdin.on("error", () => {});
|
|
32
|
+
conversion.child.stdin.end(data);
|
|
33
|
+
const { stdout } = await conversion;
|
|
34
|
+
const [width, height, textureWidth, textureHeight] = stdout.trim().split(/\s+/).map(Number);
|
|
35
|
+
if (![width, height, textureWidth, textureHeight].every(value => Number.isInteger(value) && value > 0)) {
|
|
36
|
+
throw new Error("kumi-pack returned invalid texture dimensions");
|
|
37
|
+
}
|
|
38
|
+
const relativePath = JSON.stringify(texture.replaceAll("/", "\\"));
|
|
39
|
+
const descriptor = `{path=${texturePath}(${relativePath}),width=${width},height=${height},uMax=${width / textureWidth},vMax=${height / textureHeight}}`;
|
|
40
|
+
await writeOutput(filename, `return {default=${descriptor}}\n`);
|
|
41
|
+
files.add(texture);
|
|
42
|
+
return filename;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const source of program.getSourceFiles()) {
|
|
46
|
+
if (source.isDeclarationFile) continue;
|
|
47
|
+
for (const statement of source.statements) {
|
|
48
|
+
if (!ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement)) continue;
|
|
49
|
+
const name = statement.moduleSpecifier;
|
|
50
|
+
if (!name || !ts.isStringLiteral(name) || !imageExtension.test(name.text)) continue;
|
|
51
|
+
if ((ts.isImportDeclaration(statement) && statement.importClause?.isTypeOnly)
|
|
52
|
+
|| (ts.isExportDeclaration(statement) && statement.isTypeOnly)) continue;
|
|
53
|
+
try {
|
|
54
|
+
if (!name.text.startsWith("./") && !name.text.startsWith("../")) {
|
|
55
|
+
throw new Error("Image imports must use a path relative to their source file");
|
|
56
|
+
}
|
|
57
|
+
const path = realpathSync(resolve(dirname(source.fileName), name.text));
|
|
58
|
+
const local = relative(root, path);
|
|
59
|
+
if (isAbsolute(local) || local === ".." || local.startsWith(".." + sep)) {
|
|
60
|
+
throw new Error("Image imports must stay inside the project workspace");
|
|
61
|
+
}
|
|
62
|
+
if (!paths.has(path)) paths.set(path, await prepare(path));
|
|
63
|
+
imports.set(key(name.text, source.fileName), paths.get(path));
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const { line, character } = source.getLineAndCharacterOfPosition(name.getStart(source));
|
|
66
|
+
throw new Error(`${source.fileName}:${line + 1}:${character + 1}: ${name.text}: ${error.message}`, { cause: error });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
plugin: { moduleResolution: (name, owner) => imports.get(key(name, owner)) },
|
|
72
|
+
writeManifest: () => writeOutput(join(output, "assets", module + ".json"), JSON.stringify([...files].sort()) + "\n"),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const builtins = new Set(["Boolean", "Number", "String"]);
|
|
2
|
+
|
|
3
|
+
function valueExpression(ts, reference) {
|
|
4
|
+
const parent = reference.parent;
|
|
5
|
+
if ((ts.isPropertyAccessExpression(parent) && parent.name === reference)
|
|
6
|
+
|| (ts.isElementAccessExpression(parent) && parent.argumentExpression === reference && ts.isStringLiteralLike(reference))) {
|
|
7
|
+
return parent;
|
|
8
|
+
}
|
|
9
|
+
return ts.isIdentifier(reference) ? reference : undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isAllowedUse(ts, original, allowCall) {
|
|
13
|
+
let expression = original;
|
|
14
|
+
while (expression.parent && ts.skipOuterExpressions(expression.parent) === original) expression = expression.parent;
|
|
15
|
+
|
|
16
|
+
const parent = expression.parent;
|
|
17
|
+
return parent?.expression === expression && (
|
|
18
|
+
ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)
|
|
19
|
+
|| allowCall && (ts.isCallExpression(parent) || ts.isNewExpression(parent))
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function valueSymbol(ts, checker, reference) {
|
|
24
|
+
const parent = reference.parent;
|
|
25
|
+
if (ts.isBindingElement(parent) && !parent.dotDotDotToken && ts.isObjectBindingPattern(parent.parent)
|
|
26
|
+
&& (parent.propertyName ?? parent.name) === reference) {
|
|
27
|
+
const input = checker.getTypeAtLocation(parent.parent);
|
|
28
|
+
return checker.getPropertyOfType(input, reference.text);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const expression = valueExpression(ts, reference);
|
|
32
|
+
if (!expression || isAllowedUse(ts, expression, reference.text !== "Boolean") || ts.isWriteOnlyAccess(expression)) return undefined;
|
|
33
|
+
return ts.isShorthandPropertyAssignment(parent) && parent.name === reference
|
|
34
|
+
? checker.getShorthandAssignmentValueSymbol(parent)
|
|
35
|
+
: checker.getSymbolAtLocation(reference);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function lintLuaBuiltinValues(ts, source, checker, report, program) {
|
|
39
|
+
if (source.isDeclarationFile) return;
|
|
40
|
+
|
|
41
|
+
function visit(node) {
|
|
42
|
+
if (ts.isTypeNode(node)) return;
|
|
43
|
+
if ((ts.isIdentifier(node) || ts.isStringLiteralLike(node)) && builtins.has(node.text)) {
|
|
44
|
+
const declaration = valueSymbol(ts, checker, node)?.valueDeclaration;
|
|
45
|
+
if (declaration && program.isSourceFileDefaultLibrary(declaration.getSourceFile())) {
|
|
46
|
+
const name = node.text;
|
|
47
|
+
const message = name === "Boolean"
|
|
48
|
+
? "Lua does not support the global Boolean conversion. Use an explicit comparison suited to the value type."
|
|
49
|
+
: "Lua requires a direct " + name + "(...) call. For a callback, use value => " + name + "(value).";
|
|
50
|
+
report(node, message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
ts.forEachChild(node, visit);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
visit(source);
|
|
57
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { test } from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { lintLuaBuiltinValues } from "./lua-builtin-values.mjs";
|
|
7
|
+
|
|
8
|
+
const ts = createRequire(import.meta.url)("typescript");
|
|
9
|
+
const directory = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const normalize = file => resolve(file).replaceAll("\\", "/");
|
|
11
|
+
const fixturePath = normalize(join(directory, "lua-builtin-values-fixture.ts"));
|
|
12
|
+
|
|
13
|
+
function diagnostics(text, extra = {}) {
|
|
14
|
+
const options = {
|
|
15
|
+
strict: true,
|
|
16
|
+
target: ts.ScriptTarget.ES2020,
|
|
17
|
+
module: ts.ModuleKind.ESNext,
|
|
18
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
19
|
+
types: [],
|
|
20
|
+
};
|
|
21
|
+
const files = new Map([
|
|
22
|
+
[fixturePath, text],
|
|
23
|
+
...Object.entries(extra).map(([name, source]) => [normalize(join(directory, name)), source]),
|
|
24
|
+
]);
|
|
25
|
+
const host = ts.createCompilerHost(options);
|
|
26
|
+
const { fileExists, readFile } = host;
|
|
27
|
+
host.fileExists = file => files.has(normalize(file)) || fileExists(file);
|
|
28
|
+
host.readFile = file => files.get(normalize(file)) ?? readFile(file);
|
|
29
|
+
const program = ts.createProgram([fixturePath], options, host);
|
|
30
|
+
assert.deepEqual(ts.getPreEmitDiagnostics(program).map(diagnostic => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")), []);
|
|
31
|
+
const source = program.getSourceFile(fixturePath);
|
|
32
|
+
const result = [];
|
|
33
|
+
lintLuaBuiltinValues(ts, source, program.getTypeChecker(), (node, message) => {
|
|
34
|
+
const reference = node.getText(source);
|
|
35
|
+
if (reference === "Boolean" || reference === '"Boolean"') {
|
|
36
|
+
assert.equal(message, "Lua does not support the global Boolean conversion. Use an explicit comparison suited to the value type.");
|
|
37
|
+
} else {
|
|
38
|
+
assert.match(message, /use value => (Number|String)\(value\)/);
|
|
39
|
+
}
|
|
40
|
+
const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
|
|
41
|
+
result.push([line + 1, character + 1, reference]);
|
|
42
|
+
}, program);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test("reports global constructor values at their source references", () => {
|
|
47
|
+
const fixture = [
|
|
48
|
+
"[1].filter(Boolean);",
|
|
49
|
+
"[1].map(String);",
|
|
50
|
+
'["1"].map(Number);',
|
|
51
|
+
"const alias = Number;",
|
|
52
|
+
"const options = { Boolean };",
|
|
53
|
+
"const qualified = globalThis.Number;",
|
|
54
|
+
'const indexed = globalThis["String"];',
|
|
55
|
+
"const wrapped = (String as StringConstructor)!;",
|
|
56
|
+
].join("\n");
|
|
57
|
+
assert.deepEqual(diagnostics(fixture), [
|
|
58
|
+
[1, 12, "Boolean"],
|
|
59
|
+
[2, 9, "String"],
|
|
60
|
+
[3, 11, "Number"],
|
|
61
|
+
[4, 15, "Number"],
|
|
62
|
+
[5, 19, "Boolean"],
|
|
63
|
+
[6, 30, "Number"],
|
|
64
|
+
[7, 28, '"String"'],
|
|
65
|
+
[8, 18, "String"],
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("reports destructured properties only when they resolve to a global builtin", () => {
|
|
70
|
+
const fixture = [
|
|
71
|
+
"export {};",
|
|
72
|
+
"const { Number: convert } = globalThis;",
|
|
73
|
+
"const { String } = globalThis;",
|
|
74
|
+
'const { "Boolean": toBoolean } = globalThis;',
|
|
75
|
+
"const local = { Number(value: string) { return value.length; } };",
|
|
76
|
+
"const { Number } = local;",
|
|
77
|
+
].join("\n");
|
|
78
|
+
assert.deepEqual(diagnostics(fixture), [
|
|
79
|
+
[2, 9, "Number"],
|
|
80
|
+
[3, 9, "String"],
|
|
81
|
+
[4, 9, '"Boolean"'],
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("reports calls and construction of the global Boolean builtin at the reference", () => {
|
|
86
|
+
const fixture = [
|
|
87
|
+
"Boolean(true);",
|
|
88
|
+
"globalThis.Boolean(false);",
|
|
89
|
+
'globalThis["Boolean"](0);',
|
|
90
|
+
"(((Boolean)))(true);",
|
|
91
|
+
"(Boolean as BooleanConstructor)(1);",
|
|
92
|
+
"Boolean!(1);",
|
|
93
|
+
"(Boolean satisfies BooleanConstructor)(1);",
|
|
94
|
+
"Boolean?.(0);",
|
|
95
|
+
"globalThis.Boolean?.(false);",
|
|
96
|
+
'globalThis["Boolean"]?.(0);',
|
|
97
|
+
"new Boolean(true);",
|
|
98
|
+
'new (globalThis["Boolean"])(1);',
|
|
99
|
+
].join("\n");
|
|
100
|
+
assert.deepEqual(diagnostics(fixture), [
|
|
101
|
+
[1, 1, "Boolean"],
|
|
102
|
+
[2, 12, "Boolean"],
|
|
103
|
+
[3, 12, '"Boolean"'],
|
|
104
|
+
[4, 4, "Boolean"],
|
|
105
|
+
[5, 2, "Boolean"],
|
|
106
|
+
[6, 1, "Boolean"],
|
|
107
|
+
[7, 2, "Boolean"],
|
|
108
|
+
[8, 1, "Boolean"],
|
|
109
|
+
[9, 12, "Boolean"],
|
|
110
|
+
[10, 12, '"Boolean"'],
|
|
111
|
+
[11, 5, "Boolean"],
|
|
112
|
+
[12, 17, '"Boolean"'],
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("allows Number and String calls, static properties, writes, and type positions", () => {
|
|
117
|
+
const fixture = [
|
|
118
|
+
'const converted = [Number("1"), String(1)];',
|
|
119
|
+
"[1].map(value => String(value));",
|
|
120
|
+
'(Number as NumberConstructor)!("1");',
|
|
121
|
+
"(String satisfies StringConstructor)(1);",
|
|
122
|
+
"Number.isFinite(1);",
|
|
123
|
+
"Boolean.prototype.valueOf;",
|
|
124
|
+
'globalThis["Boolean"].prototype;',
|
|
125
|
+
'const checks = { Boolean: Number["isNaN"], Number: Number.isFinite, String: 1 };',
|
|
126
|
+
'const value: String = "one";',
|
|
127
|
+
"type Globals = [typeof Boolean, Number, typeof String];",
|
|
128
|
+
"interface Numeric extends Number {}",
|
|
129
|
+
"declare const replacement: BooleanConstructor;",
|
|
130
|
+
"globalThis.Boolean = replacement;",
|
|
131
|
+
'globalThis["Boolean"] = replacement;',
|
|
132
|
+
].join("\n");
|
|
133
|
+
assert.deepEqual(diagnostics(fixture), []);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("allows values shadowed by local and imported symbols", () => {
|
|
137
|
+
const fixture = [
|
|
138
|
+
'import { Boolean, String } from "./lua-builtin-values-local";',
|
|
139
|
+
"function local(Boolean: (value: number) => boolean) { return Boolean(1) && [1].filter(Boolean).length > 0; }",
|
|
140
|
+
"Boolean(1);",
|
|
141
|
+
"(Boolean satisfies (value: number) => boolean)?.(1);",
|
|
142
|
+
"{ const Number = (value: string) => value.length; const alias = Number; }",
|
|
143
|
+
"const formatters = { String };",
|
|
144
|
+
"const values = [1].map(String);",
|
|
145
|
+
"const own = { Boolean(value: number) { return value !== 0; } };",
|
|
146
|
+
"[1].filter(own.Boolean);",
|
|
147
|
+
'own["Boolean"]?.(1);',
|
|
148
|
+
"{ const globalThis = own; globalThis.Boolean(0); }",
|
|
149
|
+
].join("\n");
|
|
150
|
+
const extra = {
|
|
151
|
+
"lua-builtin-values-local.ts": "export function String(value: number) { return value.toFixed(); }\n"
|
|
152
|
+
+ "export function Boolean(value: number) { return value !== 0; }",
|
|
153
|
+
};
|
|
154
|
+
assert.deepEqual(diagnostics(fixture, extra), []);
|
|
155
|
+
});
|