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

Representation of negative integer literals in the v1 format is odd #239

Open
vdjeric opened this issue Dec 12, 2018 · 6 comments
Open

Representation of negative integer literals in the v1 format is odd #239

vdjeric opened this issue Dec 12, 2018 · 6 comments

Comments

@vdjeric
Copy link
Collaborator

vdjeric commented Dec 12, 2018

Unary expression to negate seems very inefficient

@Yoric
Copy link
Collaborator

Yoric commented Dec 12, 2018

This kind of sounds like a parser error. Normally, -1 should be represented as a negative float in multipart (and as a 8 bit integer in entropy). Do you have a minimal example to reproduce this?

@arai-a
Copy link
Collaborator

arai-a commented Dec 17, 2018

yes, it's from parser.
not sure if this is "error" tho.

$ node
> console.log(JSON.stringify(require('shift-parser').parseScript("-1"), undefined, 2))
{
  "type": "Script",
  "directives": [],
  "statements": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "UnaryExpression",
        "operator": "-",
        "operand": {
          "type": "LiteralNumericExpression",
          "value": 1
        }
      }
    }
  ]
}

we can apply some filter in shift.rs or somewhere.

@arai-a
Copy link
Collaborator

arai-a commented Dec 17, 2018

maybe we could solve this at the same time as #229 ?

@RReverser
Copy link
Member

RReverser commented Dec 17, 2018

FWIW this is a standard representation of negative numbers in JS parsers, as syntax spec technically doesn't define negative numbers. I agree it can be more efficient in custom formats like BinJS, but it's not really odd.

@RReverser
Copy link
Member

Actually disregard the deleted comment, I didn't see that Shift already converts any keys to strings.

@Yoric
Copy link
Collaborator

Yoric commented Jan 29, 2019

Would anyone be interested in rewriting negative number translation to get rid of such oddities?

@vdjeric maybe?

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

No branches or pull requests

4 participants