shama / yo-yoify

Transform choo, yo-yo or bel template strings into pure and fast document calls
111 stars 17 forks source link

Usage with import syntax #30

Closed dmotz closed 5 years ago

dmotz commented 7 years ago

I haven't found a way of getting yo-yoify to play nicely with babelify. Either yo-yoify chokes on import/export syntax or babelify transforms first and prevents yo-yoify from making its own changes or I end up with runtime issues similar to #26.

Has anyone had success with these in conjunction?

shama commented 7 years ago

What kind of error do you get with import/export? We could probably specify a custom parser for falafel to ignore them although it's kind of weird if it doesn't already.

dmotz commented 7 years ago

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'

shama commented 7 years ago

I think that is a babel error. I don't use babel, so you'll probably need to help me out with a stack trace or more details.

dmotz commented 7 years ago

Sure, looks to be via falafel:

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (4:0) while parsing file: src/app.js
    at Parser.pp.raise (node_modules/acorn/dist/acorn.js:1745:13)
    at Parser.pp.parseStatement (node_modules/acorn/dist/acorn.js:2450:34)
    at Parser.pp.parseTopLevel (node_modules/acorn/dist/acorn.js:2379:21)
    at parse (node_modules/acorn/dist/acorn.js:101:12)
    at module.exports (node_modules/falafel/index.js:22:15)
    at DestroyableTransform.end [as _flush] (node_modules/yo-yoify/index.js:54:13)
    at DestroyableTransform.<anonymous> (node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:115:49)
    at DestroyableTransform.g (events.js:292:16)
    at emitNone (events.js:86:13)
    at DestroyableTransform.emit (events.js:185:7)
dmotz commented 7 years ago

Did some digging and found this issue isn't babelify specific, it's just that yo-yoify's parser can't handle import syntax. This is handled down the chain by falafel and ultimately acorn. Falafel is using a fairly old version of acorn and I think this might get fixed once it updates its dependency target.