Skip to content

Commit 6a918af

Browse files
committed
Address #30, allow spreading reactive variables
1 parent 60da125 commit 6a918af

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/rules/reactivity.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
732732
const checkForTrackedScopes = (
733733
node:
734734
| T.JSXExpressionContainer
735+
| T.JSXSpreadAttribute
735736
| T.CallExpression
736737
| T.VariableDeclarator
737738
| T.AssignmentExpression
@@ -766,6 +767,9 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
766767
? "called-function"
767768
: "expression";
768769
pushTrackedScope(node.expression, expect);
770+
} else if (node.type === "JSXSpreadAttribute") {
771+
// allow <div {...props.nestedProps} />; {...props} is already ignored
772+
pushTrackedScope(node.argument, "expression");
769773
} else if (node.type === "CallExpression" && node.callee.type === "Identifier") {
770774
const {
771775
callee,
@@ -951,6 +955,9 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
951955
JSXExpressionContainer(node: T.JSXExpressionContainer) {
952956
checkForTrackedScopes(node);
953957
},
958+
JSXSpreadAttribute(node: T.JSXSpreadAttribute) {
959+
checkForTrackedScopes(node);
960+
},
954961
CallExpression(node: T.CallExpression) {
955962
checkForTrackedScopes(node);
956963
checkForSyncCallbacks(node);

test/rules/reactivity.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ export const cases = run("reactivity", rule, {
6868
on(value, () => console.log('hello'));`,
6969
`const [value, setValue] = createSignal();
7070
on([value], () => console.log('hello'));`,
71+
// spreading props
72+
`function Component(props) {
73+
return <div {...props} />;
74+
}`,
75+
`function Component(props) {
76+
return <div {...props.nestedProps} />;
77+
}`,
78+
`function Component() {
79+
const [signal, setSignal] = createSignal({});
80+
return <div {...signal()} />;
81+
}`,
7182
// Derived signals
7283
`let c = () => {
7384
const [signal] = createSignal();

0 commit comments

Comments
 (0)