1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! Destructuring assignment patterns (ECMAScript §13.15.5).
//!
//! # These are not literals, and they are written exactly like literals
//!
//! `[a, b] = c` begins with something that reads as an array literal and is not one: `a` and `b`
//! are places to put values rather than values to collect. The specification handles that with a
//! *cover grammar* — the source is parsed as an `ArrayLiteral`, and when an `=` turns up the tree
//! is refined into the `ArrayAssignmentPattern` "that is covered by" it (§13.15.5). This module is
//! what it is refined into, and [`crate::parser`] does the refining.
//!
//! Refining rather than reinterpreting matters because the two grammars are not the same shape:
//!
//! - `{a = 1}` is a pattern and is **not** a literal — §13.2.5.1 says a `CoverInitializedName` is
//! always a Syntax Error where an object literal stays an object literal.
//! - `[...a, ]` is a literal and is **not** a pattern — an `AssignmentRestElement` is last, and
//! nothing may follow it, not even a comma.
//!
//! So a tree that kept the literal and left the reading to whoever came later would be a tree
//! that means two things at once. These types mean one.
//!
//! # Where a pattern is stricter than an assignment
//!
//! §13.15.5.1 says a `DestructuringAssignmentTarget` that is not itself a pattern is a Syntax
//! Error unless its `AssignmentTargetType` is **simple** — where §13.15.1 refuses only *invalid*.
//! The difference is the `web-compat` case of §8.6.4, so `f() = 1` is a runtime error on a web
//! host and `[f()] = 1` is a Syntax Error on every host. ViperJS refuses both, being no web host,
//! but the two are refused for different reasons and the second would still be refused if it were.
use ;
use crateSpan;
/// The left of an assignment (§13.15).
///
/// Two cases because the specification has two: an ordinary `LeftHandSideExpression`, and a
/// pattern that was covered by a literal. Only `=` admits the second — `[a] += b` has no
/// derivation, the compound forms taking a `LeftHandSideExpression` and nothing else.
/// An `ArrayAssignmentPattern` or an `ObjectAssignmentPattern` (§13.15.5).
/// `ArrayAssignmentPattern` (§13.15.5).
/// `ObjectAssignmentPattern` (§13.15.5).
/// One property of an object pattern (§13.15.5).
/// A target and the value to use when what arrives is `undefined` (§13.15.5).
///
/// `AssignmentElement : DestructuringAssignmentTarget Initializer_opt`. The default is not a
/// fallback for a missing property but for an `undefined` one, which is a distinction that only
/// shows up at run time — and is why it is kept rather than folded into the target.