esrap 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/handlers.js +17 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esrap",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Parse in reverse",
5
5
  "repository": {
6
6
  "type": "git",
package/src/handlers.js CHANGED
@@ -656,16 +656,26 @@ const shared = {
656
656
  * @param {State} state
657
657
  */
658
658
  'BlockStatement|ClassBody': (node, state) => {
659
- if (node.body.length === 0) {
660
- state.commands.push('{}');
661
- return;
659
+ if (node.loc) {
660
+ const { line, column } = node.loc.start;
661
+ state.commands.push(l(line, column), '{', l(line, column + 1));
662
+ } else {
663
+ state.commands.push('{');
662
664
  }
663
665
 
664
- state.multiline = true;
666
+ if (node.body.length > 0) {
667
+ state.multiline = true;
668
+ state.commands.push(indent, newline);
669
+ handle_body(node.body, state);
670
+ state.commands.push(dedent, newline);
671
+ }
665
672
 
666
- state.commands.push('{', indent, newline);
667
- handle_body(node.body, state);
668
- state.commands.push(dedent, newline, '}');
673
+ if (node.loc) {
674
+ const { line, column } = node.loc.end;
675
+ state.commands.push(l(line, column - 1), '}', l(line, column));
676
+ } else {
677
+ state.commands.push('}');
678
+ }
669
679
  },
670
680
 
671
681
  /**