mirror of https://github.com/sveltejs/svelte
fix: no error assigning to a `const` property (#7966)
Fixes #7964 currently for a case where the parent type is ArrayPattern code needs to check if the elements are of direct type MemberExpression or Identifier, in the case of MemberExpression there will be an Identifier check for the Object of the MemberExpression. --------- Co-authored-by: Yuichiro Yamashita <xydybaseball@gmail.com>pull/8335/head
parent
9edd2df0d3
commit
26104eaaba
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: '<p>2, 1</p>'
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
const arr = [1, 2];
|
||||
[arr[0], arr[1]] = [arr[1], arr[0]];
|
||||
</script>
|
||||
|
||||
<p>{arr[0]}, {arr[1]}</p>
|
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: '<p>[{"a":2},100]</p>'
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
const a = 100;
|
||||
const arr = [{ a: 1 }, 2];
|
||||
[arr[0].a, arr[1] = a] = [arr[1]];
|
||||
</script>
|
||||
|
||||
<p>{JSON.stringify(arr)}</p>
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"code": "assignment-to-const",
|
||||
"message": "You are assigning to a const",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 1,
|
||||
"character": 31
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 33,
|
||||
"character": 63
|
||||
},
|
||||
"pos": 31
|
||||
}
|
||||
]
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
const arr = [1, 2];
|
||||
[arr, arr[1]] = [arr[1], arr[0]];
|
||||
</script>
|
||||
|
||||
{arr}
|
@ -0,0 +1 @@
|
||||
[]
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
const arr = [1, 2];
|
||||
[arr[0], arr[1]] = [arr[1], arr[0]];
|
||||
</script>
|
||||
|
||||
{arr}
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"code": "assignment-to-const",
|
||||
"message": "You are assigning to a const",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 1,
|
||||
"character": 43
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 42,
|
||||
"character": 84
|
||||
},
|
||||
"pos": 43
|
||||
}
|
||||
]
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
const arr = [{1: {arr: 2}}, 2];
|
||||
[{1: { arr }}, arr[1]] = [arr[1], arr[0]];
|
||||
</script>
|
||||
|
||||
{arr}
|
@ -0,0 +1 @@
|
||||
[]
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
const arr = [1, 2];
|
||||
[arr[0], arr[1] = arr] = [arr[1], arr[0]];
|
||||
</script>
|
||||
|
||||
{arr}
|
Loading…
Reference in new issue