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

Optional raw identifiers #1919

Open
wisec opened this Issue Mar 12, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@wisec

wisec commented Mar 12, 2018

Steps to reproduce

esprima.parse('var \u00e0;')

Expected output

{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "Identifier",
        "name": "\u00e0"
      }
    }
  ],
  "sourceType": "script"
}

Actual output

{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "Identifier",
        "name": "à"
      }
    }
  ],
  "sourceType": "script"
}

I didn't expect identifiers in unicode format to be transformed, which is okay of course, I would like to ask if an option to keep Identifiers and function names unencoded can be added.

Thanks!

@michaelficarra

This comment has been minimized.

Contributor

michaelficarra commented Mar 13, 2018

@wisec Your expected and actual examples are indistinguishable. Did you mean to have "name": "\\u00e0" in your expected example? If so, this would be a backward-incompatible change. That won't happen. More likely would be the addition of a raw field which includes a slice of the source text.

@wisec

This comment has been minimized.

wisec commented Mar 13, 2018

@michaelficarra

Did you mean to have "name": "\\u00e0" in your expected example?

yes, sorry, I meant name:"\\u00e0"

If so, this would be a backward-incompatible change.

I was thinking something like:

esprima('var \\u00e0;',{rawidentifiers:true});

which I don't think it would be a breaking change since it's an option, besides that it would have a very low performance impact.

More likely would be the addition of a raw field which includes a slice of the source text.

That would work as well!

What do you think?
I can create a PR if you are ok with one of the above propositions.

@michaelficarra

This comment has been minimized.

Contributor

michaelficarra commented Mar 13, 2018

I would not be okay with an option changing the return type. But the raw field seems good. 👍 send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment