Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polish: compact AST output #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JLHwung
Copy link

@JLHwung JLHwung commented Jul 8, 2020

This PR port compact Babel AST output used in Babel parser test fixtures. I am using this PR when working on babel/babel#11807

Here is a preview of error message after this PR, it helps people browsing AST by concatenating loc properties.

Do not reuse nodes. Use `t.cloneNode` (or `t.clone`/`t.cloneDeep` if using babel@6) to copy them.
    {
      "type": "Identifier",
      "name": "N",
      "loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"N"}
    }
    Parent:
    [
      {
        "type": "AssignmentExpression",
        "operator": "=",
        "left": {
          "type": "Identifier",
          "name": "N",
          "loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"N"}
        },
        "right": {
          "type": "ObjectExpression",
          "properties": []
        },
        "extra": {
          "parenthesized": true,
          "parenStart": 67
        }
      },
      {
        "type": "LogicalExpression",
        "operator": "||",
        "left": {
          "type": "Identifier",
          "name": "N",
          "loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"N"}
        },
        "right": {
          "type": "AssignmentExpression",
          "operator": "=",
          "left": {
            "type": "Identifier",
            "name": "N",
            "loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"N"}
          },
          "right": {
            "type": "ObjectExpression",
            "properties": []
          },
          "extra": {
            "parenthesized": true,
            "parenStart": 67
          }
        }
      }
    ]

@Andarist
Copy link
Owner

Andarist commented Jul 9, 2020

@nicolo-ribaudo do you recall why this piece of code is leaving outside of Babel monorepo? I don't mind it, but maybe worth moving it into Babel org or to the monorepo itself? I think I've extracted it to a separate repo as I've wanted to use this check in a couple of other projects (i.e. regenerator), but I see that Babel itself is now depending on this module.

@nicolo-ribaudo
Copy link
Sponsor Collaborator

I think that it's because it's used in regenerator tests. We can move it to the Babel org if you want.

@Andarist
Copy link
Owner

Andarist commented Jul 9, 2020

I'm ok either way - just let me know what works for you best and I will either merge this in or prepare a PR for Babel's monorepo.

@JLHwung
Copy link
Author

JLHwung commented Jul 9, 2020

I and good to move this package to monorepo.

@existentialism
Copy link

Agree w/ moving!

@nicolo-ribaudo
Copy link
Sponsor Collaborator

Do we need to move this in the monorepo as a new package, or is it possible to just inline it in the fixtures runner?

@Andarist
Copy link
Owner

I would be in favor of making this a helper package - it has been quite helpful for me in a few Babel transforms I was working on. I can prepare a PR for this - it would just take me a couple of days before I will be able to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants