Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05c1f46

Browse files
committed
Obj::isAssignable should not mutate; passlhs property in fromAssign orCode to child arrays and objects so that those child nodes are set as allowable for destructuring
1 parent60f046e commit05c1f46

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

‎lib/coffeescript/nodes.js

Lines changed: 26 additions & 12 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/nodes.coffee

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,18 +1108,14 @@ exports.Slice = class Slice extends Base
11081108

11091109
# An object literal, nothing fancy.
11101110
exports.Obj=classObjextendsBase
1111-
constructor: (props,@generated=no)->
1111+
constructor: (props,@generated=no,@lhs=no)->
11121112
super()
11131113

11141114
@objects=@properties= propsor []
11151115

11161116
children: ['properties']
11171117

11181118
isAssignable:->
1119-
# Is this object the left-hand side of an assignment? If it is, this object
1120-
# is part of a destructuring assignment.
1121-
@lhs=yes
1122-
11231119
for propin@properties
11241120
# Check for reserved words.
11251121
message=isUnassignableprop.unwrapAll().value
@@ -1199,7 +1195,7 @@ exports.Obj = class Obj extends Base
11991195

12001196
# An array literal.
12011197
exports.Arr=classArrextendsBase
1202-
constructor: (objs)->
1198+
constructor: (objs,@lhs=no)->
12031199
super()
12041200

12051201
@objects= objsor []
@@ -1222,6 +1218,12 @@ exports.Arr = class Arr extends Base
12221218
o.indent+= TAB
12231219

12241220
answer= []
1221+
# If this array is the left-hand side of an assignment, all its children
1222+
# are too.
1223+
if@lhs
1224+
for objin@objects
1225+
unwrappedObj=obj.unwrapAll()
1226+
unwrappedObj.lhs=yesif unwrappedObjinstanceof Arror unwrappedObjinstanceof Obj
12251227
compiledObjs= (obj.compileToFragments o, LEVEL_LISTfor objin@objects)
12261228
for fragments, indexin compiledObjs
12271229
if index
@@ -1727,7 +1729,8 @@ exports.Assign = class Assign extends Base
17271729
# we've been assigned to, for correct internal references. If the variable
17281730
# has not been seen yet within the current scope, declare it.
17291731
compileNode: (o)->
1730-
ifisValue=@variableinstanceof Value
1732+
isValue=@variableinstanceof Value
1733+
if isValue
17311734
# When compiling `@variable`, remember if it is part of a function parameter.
17321735
@variable.param=@param
17331736

@@ -1736,6 +1739,10 @@ exports.Assign = class Assign extends Base
17361739
# in ES and we can output it as is; otherwise we `@compileDestructuring`
17371740
# and convert this ES-unsupported destructuring into acceptable output.
17381741
if@variable.isArray()or@variable.isObject()
1742+
# This is the left-hand side of an assignment; let `Arr` and `Obj`
1743+
# know that, so that those nodes know that they’re assignable as
1744+
# destructured variables.
1745+
@variable.base.lhs=yes
17391746
return@compileDestructuring ounless@variable.isAssignable()
17401747

17411748
return@compileSplice oif@variable.isSplice()
@@ -1750,14 +1757,14 @@ exports.Assign = class Assign extends Base
17501757
varBase.eachName (name)=>
17511758
returnifname.hasProperties?()
17521759

1753-
name.error messageifmessage=isUnassignablename.value
1760+
message=isUnassignablename.value
1761+
name.error messageif message
17541762

17551763
# `moduleDeclaration` can be `'import'` or `'export'`
1764+
@checkAssignability o, name
17561765
if@moduleDeclaration
1757-
@checkAssignability o, name
17581766
o.scope.addname.value,@moduleDeclaration
17591767
else
1760-
@checkAssignability o, name
17611768
o.scope.findname.value
17621769

17631770
if@valueinstanceof Code
@@ -2122,6 +2129,7 @@ exports.Code = class Code extends Base
21222129
# Add this parameter’s reference(s) to the function scope.
21232130
ifparam.nameinstanceof Arrorparam.nameinstanceof Obj
21242131
# This parameter is destructured.
2132+
param.name.lhs=yes
21252133
param.name.eachName (prop)->
21262134
o.scope.parameterprop.value
21272135
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp