From 51f566f8d3f2d98d5622bc2564c9fb0759b483b1 Mon Sep 17 00:00:00 2001 From: Julian Rosse Date: Mon, 8 Oct 2018 09:51:52 -0400 Subject: [PATCH] don't mutate locationData --- lib/coffeescript/nodes.js | 16 ++++++++++------ src/nodes.coffee | 28 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/coffeescript/nodes.js b/lib/coffeescript/nodes.js index 2b58398e4a..dce5a334f3 100644 --- a/lib/coffeescript/nodes.js +++ b/lib/coffeescript/nodes.js @@ -1964,14 +1964,18 @@ updateLocationDataIfMissing(locationData) { var base, ref1; if (this.locationData && this.needsUpdatedStartLocation) { - this.locationData.first_line = locationData.first_line; - this.locationData.first_column = locationData.first_column; - this.locationData.range = [locationData.range[0], this.locationData.range[1]]; + this.locationData = Object.assign({}, this.locationData, { + first_line: locationData.first_line, + first_column: locationData.first_column, + range: [locationData.range[0], this.locationData.range[1]] + }); base = ((ref1 = this.variable) != null ? ref1.base : void 0) || this.variable; if (base.needsUpdatedStartLocation) { - this.variable.locationData.first_line = locationData.first_line; - this.variable.locationData.first_column = locationData.first_column; - this.variable.locationData.range = [locationData.range[0], this.variable.locationData.range[1]]; + this.variable.locationData = Object.assign({}, this.variable.locationData, { + first_line: locationData.first_line, + first_column: locationData.first_column, + range: [locationData.range[0], this.variable.locationData.range[1]] + }); base.updateLocationDataIfMissing(locationData); } delete this.needsUpdatedStartLocation; diff --git a/src/nodes.coffee b/src/nodes.coffee index dd10a61fec..46afab1b17 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1305,20 +1305,24 @@ exports.Call = class Call extends Base # expands the range on the left, but not the right. updateLocationDataIfMissing: (locationData) -> if @locationData and @needsUpdatedStartLocation - @locationData.first_line = locationData.first_line - @locationData.first_column = locationData.first_column - @locationData.range = [ - locationData.range[0] - @locationData.range[1] - ] - base = @variable?.base or @variable - if base.needsUpdatedStartLocation - @variable.locationData.first_line = locationData.first_line - @variable.locationData.first_column = locationData.first_column - @variable.locationData.range = [ + @locationData = Object.assign {}, + @locationData, + first_line: locationData.first_line + first_column: locationData.first_column + range: [ locationData.range[0] - @variable.locationData.range[1] + @locationData.range[1] ] + base = @variable?.base or @variable + if base.needsUpdatedStartLocation + @variable.locationData = Object.assign {}, + @variable.locationData, + first_line: locationData.first_line + first_column: locationData.first_column + range: [ + locationData.range[0] + @variable.locationData.range[1] + ] base.updateLocationDataIfMissing locationData delete @needsUpdatedStartLocation super locationData