benbria / browserify-transform-tools

Utilities for writing browserify transforms.
MIT License
65 stars 15 forks source link

require transform parse error on 'const' (and probably others) #23

Open tfennelly opened 8 years ago

tfennelly commented 8 years ago

Hi.

We have a global require transform that balks on a module that uses a const variable decl. We get the following error:

error: SyntaxError: Unexpected token (83:6) (while requireTransform was processing /Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/pem-jwk/index.js) while parsing file: /Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/pem-jwk/index.js
    at Parser.pp.raise (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:1745:13)
    at Parser.pp.unexpected (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2264:8)
    at Parser.pp.semicolon (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2243:59)
    at Parser.pp.parseExpressionStatement (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2677:8)
    at Parser.pp.parseStatement (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2462:160)
    at Parser.pp.parseTopLevel (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2379:21)
    at parse (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:101:12)
    at module.exports (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/falafel/index.js:22:15)
    at Stream.<anonymous> (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/browserify-transform-tools/lib/transformTools.js:187:21)
    at Stream.end (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/browserify-transform-tools/lib/transformTools.js:108:30)

Where 83:6 is pointing at a const.

I tried the latest version of browserify and browserify-transform-tools.

Is there anything I can do? Maybe I need to apply a global babel transform or something? Seems bad to publish unprocessed modules with const etc in them.

jwalton commented 8 years ago

You're definitely not the first person to notice this. I haven't had any time to look into it. It seems like a global babel transform ought to fix this (and, you probably want one anyways if you don't want the finished result to have a "const" in it). The other alternative is to upgrade falafel to something more recent that understands ES6? If you submit a PR, you'll make more than a few people happy. :)

ghost commented 6 years ago

Same with async keyword