Skip to content

Commit

Permalink
fix: use proper location data for parenthesized class values (#159)
Browse files Browse the repository at this point in the history
Fixes decaffeinate/decaffeinate#813

As with a few other cases, it's not actually safe to say that the range of a
node is from the start of the leftmost child to the end of the rightmost child,
since nodes can be wrapped in parens, so we call `mapBase` instead.
  • Loading branch information
alangpierce authored Feb 17, 2017
1 parent 5a9ec85 commit 4f5777b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mappers/mapClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function mapClass(context: ParseContext, node: CoffeeClass): Clas
if (property instanceof Comment) {
continue;
} else if (property instanceof Assign) {
let { line, column, start, end, raw } = mapBase(context, property);
let key = mapAny(context, property.variable);
let value = mapAny(context, property.value);
let Node = ClassProtoAssignOp;
Expand All @@ -35,8 +36,7 @@ export default function mapClass(context: ParseContext, node: CoffeeClass): Clas
}

let assignment = new Node(
key.line, key.column, key.start, value.end,
context.source.slice(key.start, value.end),
line, column, start, end, raw,
key,
value
);
Expand Down
2 changes: 2 additions & 0 deletions test/examples/class-with-parenthesized-value/input.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class A
b: (c)
102 changes: 102 additions & 0 deletions test/examples/class-with-parenthesized-value/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"type": "Program",
"line": 1,
"column": 1,
"range": [
0,
17
],
"raw": "class A\n b: (c)\n",
"body": {
"type": "Block",
"line": 1,
"column": 1,
"range": [
0,
16
],
"statements": [
{
"type": "Class",
"line": 1,
"column": 1,
"range": [
0,
16
],
"name": {
"type": "Identifier",
"line": 1,
"column": 7,
"raw": "A",
"range": [
6,
7
],
"data": "A"
},
"nameAssignee": {
"type": "Identifier",
"line": 1,
"column": 7,
"raw": "A",
"range": [
6,
7
],
"data": "A"
},
"body": {
"type": "Block",
"line": 2,
"column": 3,
"range": [
10,
16
],
"statements": [
{
"type": "ClassProtoAssignOp",
"line": 2,
"column": 3,
"range": [
10,
16
],
"assignee": {
"type": "Identifier",
"line": 2,
"column": 3,
"raw": "b",
"range": [
10,
11
],
"data": "b"
},
"expression": {
"type": "Identifier",
"line": 2,
"column": 7,
"raw": "c",
"range": [
14,
15
],
"data": "c"
},
"raw": "b: (c)"
}
],
"inline": false,
"raw": "b: (c)"
},
"boundMembers": [],
"parent": null,
"ctor": null,
"raw": "class A\n b: (c)"
}
],
"raw": "class A\n b: (c)"
}
}

0 comments on commit 4f5777b

Please sign in to comment.