Skip to content

Commit 42daa43

Browse files
committed
add sourcemap mappings for block statements
1 parent c64eda1 commit 42daa43

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/handlers.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,26 @@ const shared = {
637637
* @param {State} state
638638
*/
639639
'BlockStatement|ClassBody': (node, state) => {
640-
if (node.body.length === 0) {
641-
state.commands.push('{}');
642-
return;
640+
if (node.loc) {
641+
const { line, column } = node.loc.start;
642+
state.commands.push(l(line, column), '{', l(line, column + 1));
643+
} else {
644+
state.commands.push('{');
643645
}
644646

645-
state.multiline = true;
647+
if (node.body.length > 0) {
648+
state.multiline = true;
649+
state.commands.push(indent, newline);
650+
handle_body(node.body, state);
651+
state.commands.push(dedent, newline);
652+
}
646653

647-
state.commands.push('{', indent, newline);
648-
handle_body(node.body, state);
649-
state.commands.push(dedent, newline, '}');
654+
if (node.loc) {
655+
const { line, column } = node.loc.end;
656+
state.commands.push(l(line, column - 1), '}', l(line, column));
657+
} else {
658+
state.commands.push('}');
659+
}
650660
},
651661

652662
/**

0 commit comments

Comments
 (0)