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 null object conversion error in AST node #380

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix null object conversion error in AST node #380

wants to merge 3 commits into from

Commits on Aug 28, 2018

  1. Fix null object conversion error in AST node

    In escodegen.js, converting a null object into source code in AST will generate an error on toString(). This is because the original judgment considers that the null object node has a "value" key value.
    Previous code:escodegen.js-----Lines 2310 to 2313:
    if (expr.value === null) {return 'null'; }
    I think I can change the above code to:
    if (expr.raw === 'null' && expr.value===undefined) {return 'null'; }
    This way it can be converted from the ast tree to the original code when it encounters a null object normally.
    testcase code(Nodejs environment):
    var esprima=require("esprima");
    var escodegen=require("escodegen");
    var ast=esprima.parse("var a=null;");
    var code=escodegen.generate(ast);
    b1rdfree committed Aug 28, 2018
    Configuration menu
    Copy the full SHA
    641d459 View commit details
    Browse the repository at this point in the history
  2. Fix null object conversion error in AST node

    In escodegen.js, converting a null object into source code in AST will generate an error on toString(). This is because the original judgment considers that the null object node has a "value" key value.
    Previous code:escodegen.js-----Lines 2310 to 2313:
    if (expr.value === null || expr.raw === 'null' && expr.value===undefined) {return 'null'; }
    I think I can change the above code to:
    if (expr.raw === 'null' && expr.value===undefined) {return 'null'; }
    This way it can be converted from the ast tree to the original code when it encounters a null object normally.
    testcase code(Nodejs environment):
    var esprima=require("esprima");
    var escodegen=require("escodegen");
    var ast=esprima.parse("var a=null;");
    var code=escodegen.generate(ast);
    b1rdfree committed Aug 28, 2018
    Configuration menu
    Copy the full SHA
    5d2df84 View commit details
    Browse the repository at this point in the history
  3. Update escodegen.js

    b1rdfree committed Aug 28, 2018
    Configuration menu
    Copy the full SHA
    b8908b4 View commit details
    Browse the repository at this point in the history