question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty lines are missing in parsed AST

See original GitHub issue

@wooorm

Related https://github.com/mdx-js/eslint-mdx/issues/217

Subject of the issue

Consider code like following:

<div>

<a>Test</a>

</div>

The parsedd AST is:

{
  "type": "root",
  "children": [
    {
      "type": "jsx",
      "value": "<div>",
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 6,
          "offset": 5
        },
        "indent": []
      }
    },
    {
      "type": "jsx",
      "value": "<a>Test</a>",
      "position": {
        "start": {
          "line": 3,
          "column": 1,
          "offset": 7
        },
        "end": {
          "line": 3,
          "column": 12,
          "offset": 18
        },
        "indent": []
      }
    },
    {
      "type": "jsx",
      "value": "</div>",
      "position": {
        "start": {
          "line": 5,
          "column": 1,
          "offset": 20
        },
        "end": {
          "line": 5,
          "column": 7,
          "offset": 26
        },
        "indent": []
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 6,
      "column": 1,
      "offset": 27
    }
  }
}

There is no \n node in the children property.

When using other parsers like babel, they are remained correctly: babel AST

My expected AST:

{
  "type": "root",
  "children": [
    {
      "type": "jsx",
      "value": "<div>",
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 6,
          "offset": 5
        },
        "indent": []
      }
    },
    {
      "type": "text",
      "value": "\n\n",
      "position": {
        "start": {
          "line": 1,
          "column": 6,
          "offset": 5
        },
        "end": {
          "line": 3,
          "column": 1,
          "offset": 7
        },
        "indent": []
      }
    },
    {
      "type": "jsx",
      "value": "<a>Test</a>",
      "position": {
        "start": {
          "line": 3,
          "column": 1,
          "offset": 7
        },
        "end": {
          "line": 3,
          "column": 12,
          "offset": 18
        },
        "indent": []
      }
    },
    {
      "type": "text",
      "value": "\n\n",
      "position": {
        "start": {
          "line": 3,
          "column": 12,
          "offset": 18
        },
        "end": {
          "line": 5,
          "column": 1,
          "offset": 20
        },
        "indent": []
      }
    },
    {
      "type": "jsx",
      "value": "</div>",
      "position": {
        "start": {
          "line": 5,
          "column": 1,
          "offset": 20
        },
        "end": {
          "line": 5,
          "column": 7,
          "offset": 26
        },
        "indent": []
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 6,
      "column": 1,
      "offset": 27
    }
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
wooormcommented, Jul 11, 2020

To clarify with an example, this doesn’t include the whitespace between blocks either: https://astexplorer.net/#/gist/11d0f7a6b98f4bb7dd69d1ed2db21f74/f969c99364f251942156e78f17f7f5d29665b117

0reactions
JounQincommented, Jul 14, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript AST transformation removes all blank lines
My issue is that after running ts.transform(...) and than convert transformed syntax tree back to text all empty lines are missing making the ......
Read more >
Blank lines in the body of messages are missing #31 - GitHub
with the ARTICLE command I cannot parse the content (a blank line is supposed to separate the headers and the body); because of...
Read more >
v3.20 on Windows not showing empty lines - meld - GitLab
Using Meld 3.20.2 Windows (current latest MSI) When diffing two files that have blank lines, those blank lines aren't shown.
Read more >
ast — Abstract Syntax Trees — Python 3.11.1 documentation
An abstract syntax tree can be generated by passing ast.PyCF_ONLY_AST as a flag to the compile() built-in function, or using the parse() helper...
Read more >
how to skip incomplete and missing lines when reading from ...
Empty lines are skipped. The real trouble is reading the incomplete lines. I suggest to read each line in as a string, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found