AST: splat param location data (#5266)

* handle assignment to nested nontrailing splat

* splat param location data
This commit is contained in:
Julian Rosse
2019-12-18 00:19:09 -07:00
committed by Geoffrey Booth
parent a6d4bf1982
commit a091bb82f9
3 changed files with 78 additions and 2 deletions

View File

@@ -6326,7 +6326,7 @@
return new Splat(name, {
lhs: true,
postfix: splat.postfix
}).withLocationDataFrom(name);
}).withLocationDataFrom(param);
} else if (value != null) {
return new Assign(name, value, null, {
param: true

View File

@@ -4234,7 +4234,7 @@ exports.Code = class Code extends Base
{name, value, splat} = param
if splat
new Splat name, lhs: yes, postfix: splat.postfix
.withLocationDataFrom name
.withLocationDataFrom param
else if value?
new Assign name, value, null, param: yes
.withLocationDataFrom locationData: mergeLocationData name.locationData, value.locationData

View File

@@ -4556,6 +4556,82 @@ test "AST location data as expected for Code node", ->
line: 1
column: 2
testAstLocationData '''
(a...) ->
''',
type: 'FunctionExpression'
params: [
argument:
start: 1
end: 2
range: [1, 2]
loc:
start:
line: 1
column: 1
end:
line: 1
column: 2
start: 1
end: 5
range: [1, 5]
loc:
start:
line: 1
column: 1
end:
line: 1
column: 5
]
start: 0
end: 9
range: [0, 9]
loc:
start:
line: 1
column: 0
end:
line: 1
column: 9
testAstLocationData '''
(...a) ->
''',
type: 'FunctionExpression'
params: [
argument:
start: 4
end: 5
range: [4, 5]
loc:
start:
line: 1
column: 4
end:
line: 1
column: 5
start: 1
end: 5
range: [1, 5]
loc:
start:
line: 1
column: 1
end:
line: 1
column: 5
]
start: 0
end: 9
range: [0, 9]
loc:
start:
line: 1
column: 0
end:
line: 1
column: 9
test "AST location data as expected for Return node", ->
testAstLocationData 'return no',
type: 'ReturnStatement'