@@ -56,30 +56,46 @@ module.exports = function(acorn) {
56
56
return nextMethod . apply ( this , arguments )
57
57
} ; } )
58
58
instance . extend ( "checkLVal" , getCheckLVal )
59
- instance . extend ( "toAssignable" , function ( nextMethod ) { return function ( node , isBinding ) {
59
+
60
+ // This backports toAssignable from 5.3.0 to 5.2.x
61
+ instance . extend ( "toAssignable" , function ( nextMethod ) { return function ( node , isBinding , refDestructuringErrors ) {
60
62
var this$1 = this ;
61
63
62
64
if ( this . options . ecmaVersion >= 6 && node ) {
63
65
if ( node . type == "ObjectExpression" ) {
64
66
node . type = "ObjectPattern"
67
+ if ( refDestructuringErrors ) { this . checkPatternErrors ( refDestructuringErrors , true ) }
65
68
for ( var i = 0 , list = node . properties ; i < list . length ; i += 1 )
66
69
{
67
70
var prop = list [ i ] ;
68
71
69
- this$1 . toAssignable ( prop , isBinding )
72
+ this$1 . toAssignable ( prop , isBinding , refDestructuringErrors )
70
73
}
71
74
return node
72
75
} else if ( node . type === "Property" ) {
73
76
// AssignmentProperty has type == "Property"
74
77
if ( node . kind !== "init" ) { this . raise ( node . key . start , "Object pattern can't contain getter or setter" ) }
75
- return this . toAssignable ( node . value , isBinding )
78
+ return this . toAssignable ( node . value , isBinding , refDestructuringErrors )
76
79
} else if ( node . type === "SpreadElement" ) {
77
80
node . type = "RestElement"
78
- return this . toAssignable ( node . argument , isBinding )
81
+ this . toAssignable ( node . argument , isBinding , refDestructuringErrors )
82
+ if ( node . argument . type === "AssignmentPattern" )
83
+ { this . raise ( node . argument . start , "Rest elements cannot have a default value" ) }
84
+ return
79
85
}
80
86
}
81
87
return nextMethod . apply ( this , arguments )
82
88
} ; } )
89
+ instance . extend ( "toAssignableList" , function ( nextMethod ) { return function ( exprList , isBinding ) {
90
+ var result = nextMethod . call ( this , exprList , isBinding )
91
+ if ( exprList . length && exprList [ exprList . length - 1 ] && exprList [ exprList . length - 1 ] . type === "RestElement" ) {
92
+ // Backport check from 5.3.0
93
+ if ( exprList [ exprList . length - 1 ] . argument . type === "AssignmentPattern" )
94
+ { this . raise ( exprList [ exprList . length - 1 ] . argument . start , "Rest elements cannot have a default value" ) }
95
+ }
96
+ return result
97
+ } ; } )
98
+
83
99
instance . extend ( "checkPatternExport" , function ( nextMethod ) { return function ( exports , pat ) {
84
100
var this$1 = this ;
85
101
0 commit comments