browserify / tinyify

a browserify plugin that runs various optimizations, so you don't have to install them all manually. makes your bundles tiny!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Unexpected token

josephg opened this issue · comments

Might be related to #14, but I'm getting more parsing errors when browserifying using tinyify. Using tinyify@2.5.0

My target is the json1 OT library at SHA 8907bf44049003efa0e3c26146fd891524b91264

The error seems to be related to environment variable handling. If I change this line:

const RELEASE_MODE = process.env.JSON1_RELEASE_MODE

to

const RELEASE_MODE = 0 // or 1 or any other constant

then browserify runs successfully. It crashes if I use process.env.NODE_ENV === 'production'.

I'll have a deeper look when I have some more time if nobody else gets to it by then.

sephsmac:json1 josephg$ browserify -p tinyify lib/json1.js 
Error: Line 1421: Unexpected token ...
    at ErrorHandler.constructError (/Users/josephg/src/ottypes/json1/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/Users/josephg/src/ottypes/json1/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/Users/josephg/src/ottypes/json1/node_modules/esprima/dist/esprima.js:1985:39)
..

Hmm, envify may not support object rest spread syntax yet.

envify uses Esprima which doesn't support {...x}. Esprima's master branch supports it but not the published version.
I tried to quickly switch envify to Acorn but it wasn't as trivial as I hoped. If someone feels like giving that a shot, please do!

I can try to take a look at this today!

Took a few days to get to but I'm just working on getting all the tests to pass -- acorn is luckily very similar to esprima :)

I spoke too soon! Variable assignments are a bit trickier to handle in acorn. Will try to wrap this up tonight

Had you much luck 🍀 @toddself ?

i had another shot just now and I think i got it to work: hughsk/envify#62

@goto-bus-stop can we get that merged?

📦 2.5.2