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

Fix extraneous semicolon #168

Merged

Conversation

eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Oct 15, 2018

Followup on #167

This was caused because the transformed AST was invalid when VariableDeclarator was wrapped because it returned an AssignmentExpression that was used as the variableDeclarator for a VariableDeclaration.

To be more specific it previously created nodes similar to this:

{
  "type": "VariableDeclaration",
  "declarations": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "AssignmentExpression",
        "operator": "=",
        "left": {
          "type": "Identifier",
          "loc": {
            "identifierName": "referencedPropTypes"
          },
          "name": "referencedPropTypes"
        },
        "right": {
          "type": "ConditionalExpression",
          "test": {},
          "consequent": {},
          "alternate": {}
        }
      },
    }
  ],
  "kind": "const"
},
const referencedPropTypes = process.env.NODE_ENV !== "production" ? {} : {};;

which would never be created by any parser but @babel/generator is robust enough to handle it.

Now we get a valid AST:

{
  "type": "VariableDeclaration",
  "declarations": [
    {
      "type": "VariableDeclarator",
      "id": {
        "type": "Identifier",
        "loc": {
          "identifierName": "referencedPropTypes"
        },
        "name": "referencedPropTypes"
      },
      "init": {
        "type": "ConditionalExpression",
        "test": {},
        "consequent": {},
        "alternate": {},
        "extra": {
          "parenthesized": true,
          "parenStart": 0
        }
      }
    }
  ],
  "kind": "const"
},
const referencedPropTypes = process.env.NODE_ENV !== "production" ? {} : {};

This was caused because the transformed AST was invalid when
VariableDeclarator was wrapped because it returned an AssignmentExpression
that was used as the variableDeclarator for a VariableDeclaration.
Copy link
Collaborator

@lencioni lencioni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@oliviertassinari oliviertassinari merged commit ef9b3d2 into oliviertassinari:master Oct 15, 2018
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

3 participants