mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(javascript): keep computed definition key conversion effects
Defining a computed class or object member converts its key to a property name, so preserve that coercion escape alongside the key expression walk. Reuse javaScriptComputedDefinitionKey for computed-key ownership in the getter result walker instead of repeating the check. Refs #9229 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
4a42707544
commit
f81cbd0c43
3 files changed
+35
-20
No files matched your search
@@ -89,6 +89,7 @@ import {
|
||||
childNodes,
|
||||
} from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
javaScriptComputedDefinitionKey,
|
||||
semanticStaticPropertyKey,
|
||||
semanticWriteSiteTarget,
|
||||
semanticWriteSiteReadsFirst,
|
||||
@@ -393,23 +394,25 @@ const accessorOperands = new WeakMap<
|
||||
readonly AccessorEffectOperand[]
|
||||
>();
|
||||
|
||||
/** Expressions a definition runs immediately; deferred bodies and class-receiver initializers stay out. */
|
||||
const definitionTimeExpressions = (node: t.Function | t.Class): t.Node[] => {
|
||||
if (t.isObjectMethod(node)) return node.computed ? [node.key] : [];
|
||||
/** Members whose computed keys a definition evaluates and converts immediately. */
|
||||
const computedDefinitionMembers = (node: t.Function | t.Class): t.Node[] => {
|
||||
if (t.isObjectMethod(node))
|
||||
return javaScriptComputedDefinitionKey(node, node.key) ? [node] : [];
|
||||
if (!t.isClass(node)) return [];
|
||||
return [
|
||||
...(node.superClass == null ? [] : [node.superClass]),
|
||||
...node.body.body.flatMap((member) =>
|
||||
(t.isClassMethod(member) ||
|
||||
t.isClassProperty(member) ||
|
||||
t.isClassAccessorProperty(member)) &&
|
||||
member.computed
|
||||
? [member.key]
|
||||
: [],
|
||||
),
|
||||
];
|
||||
return node.body.body.filter(
|
||||
(member) =>
|
||||
"key" in member && javaScriptComputedDefinitionKey(member, member.key),
|
||||
);
|
||||
};
|
||||
|
||||
/** Expressions a definition runs immediately; deferred bodies and class-receiver initializers stay out. */
|
||||
const definitionTimeExpressions = (node: t.Function | t.Class): t.Node[] => [
|
||||
...(t.isClass(node) && node.superClass != null ? [node.superClass] : []),
|
||||
...computedDefinitionMembers(node).flatMap((member) =>
|
||||
"key" in member ? [member.key] : [],
|
||||
),
|
||||
];
|
||||
|
||||
/** Collect invocation operands once; receiver interpretation belongs to the getter owner. */
|
||||
const accessorEffectOperands = (
|
||||
method: t.Function,
|
||||
@@ -426,6 +429,10 @@ const accessorEffectOperands = (
|
||||
// Defining a nested callable does not invoke it, but the definition itself
|
||||
// evaluates heritage and computed keys against the enclosing receiver.
|
||||
if (t.isFunction(node) || t.isClass(node)) {
|
||||
// Defining a computed member also converts its key to a property name.
|
||||
for (const member of computedDefinitionMembers(node))
|
||||
for (const operand of semanticCoercionOperands(member))
|
||||
operands.push({ kind: "escape", node: operand });
|
||||
for (const child of definitionTimeExpressions(node).reverse())
|
||||
pending.push({ node: child, parent: node });
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user