esrap 1.4.1 → 1.4.3

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 +19 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esrap",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Parse in reverse",
5
5
  "repository": {
6
6
  "type": "git",
package/src/handlers.js CHANGED
@@ -129,6 +129,8 @@ function quote(string, char) {
129
129
  out += '\\' + c;
130
130
  } else if (c === '\n') {
131
131
  out += '\\n';
132
+ } else if (c === '\r') {
133
+ out += '\\r';
132
134
  } else {
133
135
  out += c;
134
136
  }
@@ -656,16 +658,26 @@ const shared = {
656
658
  * @param {State} state
657
659
  */
658
660
  'BlockStatement|ClassBody': (node, state) => {
659
- if (node.body.length === 0) {
660
- state.commands.push('{}');
661
- return;
661
+ if (node.loc) {
662
+ const { line, column } = node.loc.start;
663
+ state.commands.push(l(line, column), '{', l(line, column + 1));
664
+ } else {
665
+ state.commands.push('{');
662
666
  }
663
667
 
664
- state.multiline = true;
668
+ if (node.body.length > 0) {
669
+ state.multiline = true;
670
+ state.commands.push(indent, newline);
671
+ handle_body(node.body, state);
672
+ state.commands.push(dedent, newline);
673
+ }
665
674
 
666
- state.commands.push('{', indent, newline);
667
- handle_body(node.body, state);
668
- state.commands.push(dedent, newline, '}');
675
+ if (node.loc) {
676
+ const { line, column } = node.loc.end;
677
+ state.commands.push(l(line, column - 1), '}', l(line, column));
678
+ } else {
679
+ state.commands.push('}');
680
+ }
669
681
  },
670
682
 
671
683
  /**