Skip to content

Commit

Permalink
fix: use correct location data for object initializer members (#144)
Browse files Browse the repository at this point in the history
Fixes decaffeinate/decaffeinate#778

The end position of the initializer member isn't just the end position of the
value, since the value might be wrapped in parens. Instead, I get the location
data using `mapBase` like in various other code paths.
  • Loading branch information
alangpierce authored Jan 17, 2017
1 parent 7cd51c3 commit a9a8c5a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mappers/mapObj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function mapObj(context: ParseContext, node: Obj): ObjectInitiali
value
);
} else if (property instanceof Assign && property.context === 'object') {
let { line, column, start, end, raw, virtual } = mapBase(context, property);

let key = mapAny(context, property.variable);
let expression = mapAny(context, property.value);

Expand All @@ -32,7 +34,7 @@ export default function mapObj(context: ParseContext, node: Obj): ObjectInitiali
}

return new ObjectInitialiserMember(
key.line, key.column, key.start, expression.end, context.source.slice(key.start, expression.end), false,
line, column, start, end, raw, virtual,
key,
expression
);
Expand Down
1 change: 1 addition & 0 deletions test/examples/object-with-parenthesized-value/input.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{a: (b), c}
98 changes: 98 additions & 0 deletions test/examples/object-with-parenthesized-value/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"type": "Program",
"line": 1,
"column": 1,
"range": [
0,
12
],
"raw": "{a: (b), c}\n",
"body": {
"type": "Block",
"line": 1,
"column": 1,
"range": [
0,
11
],
"statements": [
{
"type": "ObjectInitialiser",
"line": 1,
"column": 1,
"range": [
0,
11
],
"members": [
{
"type": "ObjectInitialiserMember",
"line": 1,
"column": 2,
"range": [
1,
7
],
"key": {
"type": "Identifier",
"line": 1,
"column": 2,
"range": [
1,
2
],
"raw": "a",
"data": "a"
},
"expression": {
"type": "Identifier",
"line": 1,
"column": 6,
"range": [
5,
6
],
"raw": "b",
"data": "b"
},
"raw": "a: (b)"
},
{
"type": "ObjectInitialiserMember",
"line": 1,
"column": 10,
"range": [
9,
10
],
"key": {
"type": "Identifier",
"line": 1,
"column": 10,
"range": [
9,
10
],
"raw": "c",
"data": "c"
},
"expression": {
"type": "Identifier",
"line": 1,
"column": 10,
"range": [
9,
10
],
"raw": "c",
"data": "c"
},
"raw": "c"
}
],
"raw": "{a: (b), c}"
}
],
"raw": "{a: (b), c}"
}
}

0 comments on commit a9a8c5a

Please sign in to comment.