Skip to content

Commit 46e41aa

Browse files
authored
fix: remove comments from blocks contained within parens (#269)
Fixes decaffeinate/decaffeinate#1181
1 parent aea5273 commit 46e41aa

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/mappers/mapParens.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Block, Parens } from 'decaffeinate-coffeescript/lib/coffee-script/nodes';
1+
import {
2+
Block, Comment, Parens
3+
} from 'decaffeinate-coffeescript/lib/coffee-script/nodes';
24
import { Node, SeqOp } from '../nodes';
35
import ParseContext from '../util/ParseContext';
46
import mapAny from './mapAny';
@@ -9,6 +11,7 @@ export default function mapParens(context: ParseContext, node: Parens): Node {
911
}
1012

1113
let { expressions } = node.body;
14+
expressions = expressions.filter((expr) => !(expr instanceof Comment));
1215

1316
if (expressions.length === 1) {
1417
return mapAny(context, expressions[0]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
() -> (
2+
###yo###
3+
a
4+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"body": {
3+
"column": 1,
4+
"end": 24,
5+
"inline": false,
6+
"line": 1,
7+
"raw": "() -> (\n ###yo###\n a\n)",
8+
"start": 0,
9+
"statements": [
10+
{
11+
"body": {
12+
"column": 7,
13+
"end": 24,
14+
"inline": true,
15+
"line": 1,
16+
"raw": "(\n ###yo###\n a\n)",
17+
"start": 6,
18+
"statements": [
19+
{
20+
"column": 3,
21+
"data": "a",
22+
"end": 22,
23+
"line": 3,
24+
"raw": "a",
25+
"start": 21,
26+
"type": "Identifier"
27+
}
28+
],
29+
"type": "Block"
30+
},
31+
"column": 1,
32+
"end": 24,
33+
"line": 1,
34+
"parameters": [
35+
],
36+
"raw": "() -> (\n ###yo###\n a\n)",
37+
"start": 0,
38+
"type": "Function"
39+
}
40+
],
41+
"type": "Block"
42+
},
43+
"column": 1,
44+
"end": 25,
45+
"line": 1,
46+
"raw": "() -> (\n ###yo###\n a\n)\n",
47+
"start": 0,
48+
"type": "Program"
49+
}

0 commit comments

Comments
 (0)