Skip to content
New issue

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

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

Already on GitHub? # to your account

The JS version of the parser fails on some numbers starting with a 0 #3238

Closed
lydell opened this issue Jan 22, 2017 · 2 comments
Closed

The JS version of the parser fails on some numbers starting with a 0 #3238

lydell opened this issue Jan 22, 2017 · 2 comments
Assignees
Labels

Comments

@lydell
Copy link

lydell commented Jan 22, 2017

~/bugs/flow-parser-number-bug  
❯ node --version
v7.2.0

~/bugs/flow-parser-number-bug  
❯ npm i flow-parser
/home/lydell/bugs/flow-parser-number-bug
└─┬ flow-parser@0.38.0 
  ├── ast-types@0.8.18 
  ├── colors@1.1.2 
  └── minimist@1.2.0 

~/bugs/flow-parser-number-bug  
❯ node
> try { require('flow-parser').parse('0274134317073') } catch (e) { console.log('err', e) }
err [ 0,
  [ 248, aw { t: 0, c: 'Failure', l: 7 }, -3 ],
  aw { t: 0, c: 'int_of_string', l: 13 } ]
undefined
>

Expectations:

  • No error to be thrown. (And if one were to be thrown, I'd expect a real
    Error to be thrown, not an Array.)
  • An AST to be returned.

The non-JS version of the parser seems to be doing fine:

~/bugs/flow-parser-number-bug  
❯ npm i flow-bin
/home/lydell/bugs/flow-parser-number-bug
└── flow-bin@0.38.0 

~/bugs/flow-parser-number-bug  
❯ echo '0274134317073' | flow ast --pretty
{
  "errors":[],
  "tokens":[],
  "type":"Program",
  "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
  "range":[0,13],
  "body":[
    {
      "type":"ExpressionStatement",
      "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
      "range":[0,13],
      "expression":{
        "type":"Literal",
        "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
        "range":[0,13],
        "value":25257156155,
        "raw":"0274134317073"
      }
    }
  ],
  "comments":[]
}
@mroch mroch added the parsing label Jan 23, 2017
@mroch
Copy link
Contributor

mroch commented Jan 23, 2017

huh. the JS version of the flow parser uses js_of_ocaml which is apparently limited to 32-bit integers. the ocaml version uses 63-bit integers.

trying 25257156155;; or int_of_string "0o0274134317073;;" in Try OCaml similarly errors.

this might be a tough one to fix. definitely agreed that it shouldn't kill the parser, though.

@mroch
Copy link
Contributor

mroch commented Jan 23, 2017

oh, not as bad as I thought. will fix!

@mroch mroch self-assigned this Jan 23, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants