estools / escodegen

ECMAScript code generator
BSD 2-Clause "Simplified" License
2.64k stars 334 forks source link

escodegen expects value in Property key:value pair to have a type; crashes on null #461

Open KevinCarhart opened 6 months ago

KevinCarhart commented 6 months ago

Hello Thank you for the project. We have used it for many years on the edbrowse project, a CLI web browser. We use esprima-next and escodegen in succession in order to deminify a wide variety of JS files from the internet at large.

escodegen is crashing on an esprima-next AST built from https://goodcleanhumor.com/_next/static/chunks/502-b51afe70c57c9f6e.js

from the site goodcleanhumor.com


Here is a more concise piece of JS to recreate the problem: hey = esprima.parse('class tb extends Error{sys;details}') escodegen.generate(hey)


Here is the runtime error text and the end of the stack trace. It is called from Property. The portion that resolves the key ("sys") succeeds, and then it crashes in the portion that resolves the value.

(the line numbers won't align because we combine esprima and escodegen in one file)

jdb line 9187: TypeError: cannot read property 'type' of null at (demin.js:9187) at Property (demin.js:8928) at (demin.js:9191) at (demin.js:8075) at withIndent (demin.js:7601) at ClassBody (demin.js:8080) at (demin.js:9199) at ClassDeclaration (demin.js:8099)


Here is the result of JSON.stringify of the AST that we are running generate on. So that I'm not giving you an example that requires running esprima first in order to recreate.

{"type":"Program","body":[{"type":"ClassDeclaration","id":{"type":"Identifier","name":"tb"},"superClass":{"type":"Identifier","name":"Error"},"body":{"type":"ClassBody","body":[{"type":"Property","key":{"type":"Identifier","name":"sys"},"computed":false,"value":null,"static":false,"decorators":null},{"type":"Property","key":{"type":"Identifier","name":"details"},"computed":false,"value":null,"static":false,"decorators":null}]},"decorators":null}],"sourceType":"script"}

thank you Kevin Carhart