GerHobbelt / jison

bison / YACC / LEX in JavaScript (LALR(1), SLR(1), etc. lexer/parser generator)
https://gerhobbelt.github.io/jison/
MIT License
118 stars 20 forks source link

The lexer emitted by jison contains non-es5 code. #37

Open lddubeau opened 6 years ago

lddubeau commented 6 years ago

I took from #14 that jison should be producing es5 code. However, the lexer emitted by jison contains const, which is not a keyword recognized in es5. The code may misleadingly run just fine on browsers/JS engines that declare themselves to be es5 engines. The problem is that, historically, many engines declaring themselves to support es5, in fact support es5 and let and const though they are not part of es5 proper.

Steps to reproduce:

  1. Install the latest jison. (I used 0.6.1-215).

  2. Grab the basic_lex.jison example from the examples subdirectory.

  3. Run jison basic_lex.jison.

  4. Open the resulting basic_lex.js and search for const. You'll find some in the lexer_prettyPrintRange function.

GerHobbelt commented 6 years ago

Good catch!

Jison (jison-gho, rather) is being reworked to become a babel-assisted process: the goal with upcoming v0.6.5 is to have a parser-generator which can validate/parse modern JS code in action code and spit out JS that's suitable for modern platforms with babel-assisted support for older platforms where and when one wants. That includes ES5 support.

I don't plan to fix this in a 0.6.1 hotfix release as all effort should focus on 0.6.5 and making sure that one delivers as expected.