nolanlawson / optimize-js

Optimize a JS file for faster parsing (UNMAINTAINED)
https://nolanlawson.github.io/optimize-js
Apache License 2.0
3.75k stars 104 forks source link

walk.js aborts with error if input contains ES6 code #3

Open sergejmueller opened 8 years ago

sergejmueller commented 8 years ago

Perhaps because walk.js does not support ES6?

Example: start.js.txt

TypeError: types[type] is not a function
    at walk (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/walk.js:17:16)
    at Object.skip (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/types.js:293:3)
    at walk (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/walk.js:17:16)
    at Object.exports.BinaryExpression.exports.LogicalExpression.exports.AssignmentExpression (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/types.js:243:3)
    at walk (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/walk.js:17:16)
    at Object.skip (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/types.js:293:3)
    at walk (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/walk.js:17:16)
    at Object.exports.ExpressionStatement (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/types.js:32:3)
    at walk (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/walk.js:17:16)
    at Object.skip (/usr/local/lib/node_modules/optimize-js/node_modules/walk-ast/lib/types.js:293:3)
nolanlawson commented 8 years ago

I'm using acorn and acorn-walk. Maybe there's a way to make it support ES6?

sergejmueller commented 8 years ago

I don't know. A another acorn-walk plugin? https://npmdaily.com/search/acorn

austinkelleher commented 8 years ago

This may not work for your use case, but I transpile to ES5 using Babel and then use optimize-js.

nolanlawson commented 8 years ago

@rich-harris would switching to https://www.npmjs.com/package/estree-walker solve this?

Rich-Harris commented 8 years ago

@nolanlawson yes

sanex3339 commented 8 years ago

esprima has nice support of es6 and es7 https://github.com/jquery/esprima https://github.com/estools/estraverse https://github.com/estools/escodegen

lattsi commented 7 years ago

this is already patched with the use of estree-walker.

benderTheCrime commented 7 years ago

Question: wouldn't it just be possible to give acorn different options? For instance, imports/exports should work just fine if the sourceType: 'module' option was provided.