Skip to content

Commit

Permalink
fix: remove comments from blocks contained within parens (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangpierce authored Oct 22, 2017
1 parent aea5273 commit 46e41aa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mappers/mapParens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Block, Parens } from 'decaffeinate-coffeescript/lib/coffee-script/nodes';
import {
Block, Comment, Parens
} from 'decaffeinate-coffeescript/lib/coffee-script/nodes';
import { Node, SeqOp } from '../nodes';
import ParseContext from '../util/ParseContext';
import mapAny from './mapAny';
Expand All @@ -9,6 +11,7 @@ export default function mapParens(context: ParseContext, node: Parens): Node {
}

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

if (expressions.length === 1) {
return mapAny(context, expressions[0]);
Expand Down
4 changes: 4 additions & 0 deletions test/examples/comment-in-parenthesized-block/input.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
() -> (
###yo###
a
)
49 changes: 49 additions & 0 deletions test/examples/comment-in-parenthesized-block/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"body": {
"column": 1,
"end": 24,
"inline": false,
"line": 1,
"raw": "() -> (\n ###yo###\n a\n)",
"start": 0,
"statements": [
{
"body": {
"column": 7,
"end": 24,
"inline": true,
"line": 1,
"raw": "(\n ###yo###\n a\n)",
"start": 6,
"statements": [
{
"column": 3,
"data": "a",
"end": 22,
"line": 3,
"raw": "a",
"start": 21,
"type": "Identifier"
}
],
"type": "Block"
},
"column": 1,
"end": 24,
"line": 1,
"parameters": [
],
"raw": "() -> (\n ###yo###\n a\n)",
"start": 0,
"type": "Function"
}
],
"type": "Block"
},
"column": 1,
"end": 25,
"line": 1,
"raw": "() -> (\n ###yo###\n a\n)\n",
"start": 0,
"type": "Program"
}

0 comments on commit 46e41aa

Please sign in to comment.