Skip to content

Commit a9a8c5a

Browse files
authored
fix: use correct location data for object initializer members (#144)
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.
1 parent 7cd51c3 commit a9a8c5a

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

src/mappers/mapObj.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default function mapObj(context: ParseContext, node: Obj): ObjectInitiali
2424
value
2525
);
2626
} else if (property instanceof Assign && property.context === 'object') {
27+
let { line, column, start, end, raw, virtual } = mapBase(context, property);
28+
2729
let key = mapAny(context, property.variable);
2830
let expression = mapAny(context, property.value);
2931

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

3436
return new ObjectInitialiserMember(
35-
key.line, key.column, key.start, expression.end, context.source.slice(key.start, expression.end), false,
37+
line, column, start, end, raw, virtual,
3638
key,
3739
expression
3840
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{a: (b), c}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"type": "Program",
3+
"line": 1,
4+
"column": 1,
5+
"range": [
6+
0,
7+
12
8+
],
9+
"raw": "{a: (b), c}\n",
10+
"body": {
11+
"type": "Block",
12+
"line": 1,
13+
"column": 1,
14+
"range": [
15+
0,
16+
11
17+
],
18+
"statements": [
19+
{
20+
"type": "ObjectInitialiser",
21+
"line": 1,
22+
"column": 1,
23+
"range": [
24+
0,
25+
11
26+
],
27+
"members": [
28+
{
29+
"type": "ObjectInitialiserMember",
30+
"line": 1,
31+
"column": 2,
32+
"range": [
33+
1,
34+
7
35+
],
36+
"key": {
37+
"type": "Identifier",
38+
"line": 1,
39+
"column": 2,
40+
"range": [
41+
1,
42+
2
43+
],
44+
"raw": "a",
45+
"data": "a"
46+
},
47+
"expression": {
48+
"type": "Identifier",
49+
"line": 1,
50+
"column": 6,
51+
"range": [
52+
5,
53+
6
54+
],
55+
"raw": "b",
56+
"data": "b"
57+
},
58+
"raw": "a: (b)"
59+
},
60+
{
61+
"type": "ObjectInitialiserMember",
62+
"line": 1,
63+
"column": 10,
64+
"range": [
65+
9,
66+
10
67+
],
68+
"key": {
69+
"type": "Identifier",
70+
"line": 1,
71+
"column": 10,
72+
"range": [
73+
9,
74+
10
75+
],
76+
"raw": "c",
77+
"data": "c"
78+
},
79+
"expression": {
80+
"type": "Identifier",
81+
"line": 1,
82+
"column": 10,
83+
"range": [
84+
9,
85+
10
86+
],
87+
"raw": "c",
88+
"data": "c"
89+
},
90+
"raw": "c"
91+
}
92+
],
93+
"raw": "{a: (b), c}"
94+
}
95+
],
96+
"raw": "{a: (b), c}"
97+
}
98+
}

0 commit comments

Comments
 (0)