Skip to content

Commit c5ef3b6

Browse files
committed
fix: should only check assignment when is left of assignment
1 parent e033f42 commit c5ef3b6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: packages/reactivity-transform/__tests__/reactivityTransform.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -509,5 +509,12 @@ describe('errors', () => {
509509
foo++
510510
`)
511511
).toThrow(`Assignment to constant variable.`)
512+
513+
expect(() =>
514+
transform(`
515+
const foo = $ref(0)
516+
bar = foo
517+
`)
518+
).not.toThrow()
512519
})
513520
})

Diff for: packages/reactivity-transform/src/reactivityTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ export function transformAST(
548548
if (binding) {
549549
if (
550550
binding.isConst &&
551-
(parent.type === 'AssignmentExpression' ||
551+
((parent.type === 'AssignmentExpression' && id === parent.left) ||
552552
parent.type === 'UpdateExpression')
553553
) {
554554
error(`Assignment to constant variable.`, id)

0 commit comments

Comments
 (0)