Skip to content

Commit

Permalink
Exclude member expressions from permissive tracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwilsonvu committed Jan 1, 2024
1 parent a1a7dd7 commit ce5606e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ const Component = (props) => {
return <div>{value()}</div>;
};

const Component = (props) => {
const [value] = createSignal(props.value);
};

const Component = (props) => {
const derived = () => props.value;
const oops = derived();
Expand Down
1 change: 1 addition & 0 deletions src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ export default createRule<Options, MessageIds>({
if (
isFunctionNode(traced) ||
(traced.type === "Identifier" &&
traced.parent.type !== "MemberExpression" &&
!(traced.parent.type === "CallExpression" && traced.parent.callee === traced))
) {
pushTrackedScope(childNode, "called-function");
Expand Down
7 changes: 7 additions & 0 deletions test/rules/reactivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ export const cases = run("reactivity", rule, {
},
],
},
{
code: `
const Component = props => {
const [value] = createSignal(props.value);
}`,
errors: [{ messageId: "untrackedReactive", type: T.MemberExpression }],
},
// mark `props` as props by name before we've determined if Component is a component in :exit
{
code: `
Expand Down

0 comments on commit ce5606e

Please sign in to comment.