Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix null object conversion error in AST node#380

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
b1rdfree wants to merge3 commits intoestools:master
base:master
Choose a base branch
Loading
fromb1rdfree:master
Open

Fix null object conversion error in AST node#380

b1rdfree wants to merge3 commits intoestools:masterfromb1rdfree:master

Conversation

@b1rdfree
Copy link

@b1rdfreeb1rdfree commentedAug 28, 2018
edited
Loading

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.value === null || (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);

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);
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);
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@b1rdfree

[8]ページ先頭

©2009-2025 Movatter.jp