-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel script: 'import' in tag script will get error #21
Comments
This is caused by the babel parser. babel 6 doesn't allow toplevel this and destroys references (#15) so the parser wraps code in a function. The import statements are executed within this wrapper function and that is causing the error. I can't think of an easy solution right now. The two hard solutions I can think of right now are:
|
I think previously it works because of the blacklist 'strict' setting, not sure if babel 6 still have something similar. |
@appedemic , it is true. I'm not a babel user, but in tests babel-core 5.8.x was the cleaner and faster solution, v6 was complicated and slower. |
@aMarCruz right, I also noticed that v6 is slower, but seems v5 is not maintained any more, I think we still need to go with v6. |
It seems so. I'm closing this issue by now. |
@aMarCruz why close this? We don't want to support babel v6, then? |
I have just seen that babeljs has already fixed the issue we just need to implement this option 🎉 |
👍 |
Yeah, "Add allowTopLevelThis option to babel-plugin-transform-es2015-modules-commonjs" 💃 I can probably create a patch today |
Currently there is no way to add plugin options to a preset, so this allowTopLevelThis cannot be used directly with presets:['es2015']. There is an ongoing discussion about how to support this... |
@appedemic , thanks. we hope your PR. |
@GianlucaGuarini putting import in the very beginning of the tag file does not work, riot-loader will throw error:
|
I've asked support to the babel maintainers babel/babel#3055 I hope to get a valid answer soon |
For fun I created a modified es2015 preset: https://github.com/appedemic/babel-preset-es2015-riot However, npm has some trouble accepting logins right now so I can't publish this as a package right now |
is babel-preset-es2015-riot still going to be pushed to npm? Just tested and as far as I can tell even using this allowTopLevelThis option doesn't seem to fix this error. :( So for now stay with babel v5.x I suppose? |
Right now it's not possible to send the allowTopLevelThis option to the right plugin within the preset. I've been thinking, if we add an option to the compiler where the end user can supply a list of presets/plugins to use, it would be the most flexible. For example, I really like to use some ES7 features (async/await and Object.entries) and they are not part of the es2015 preset, but stage-0 and stage-3. For these features I need to add a preset/plugin to the babel compiler. I could create a pr that takes the compiler plugins/preset options from the configuration and defaults to es2015. Then, I can supply my desired configuration into riotify and it will be passed on nicely. |
There is an idea of a possible system of plugins that should solve some issues like this in riot/riot#1272. |
Ok, so the plan is to make packages for the parsers? So to have some npm packages like riot-compiler-parser-babel and riot-compiler-parser-jade, etc.? And provide some mechanism to configure the compiler with said packages?
If implemented correctly it would be a nice future-ready solution |
@appedemic , yeah, I hope soon, after stabilizing the current version, the changes have been many. |
Ok this issue was solved in the |
@GianlucaGuarini sure. the |
Let's keep it for now we will delete it if everything will run smooth |
ok |
@aMarCruz can we infer the url param for the compile method from the first one ( src ) at least on node? |
@appedemic can we use your riot-bable preset in our official repo? I woul like to publish it on npm with the new release of the compiler |
@GianlucaGuarini , no way to infer the url from the |
@appedemic I have published on npm the riot-preset based on your setup thank you and feel free to pull request on this repo |
@appedemic I thought the function wrapper was only necessary for this bug. The top-level this issue should be resolved now with the babel-riot preset. Removing the wrapper function from the compiled templates should allow If not, for now we could revert to using |
@creatorrr you are right this bug was fixed and it can be closed |
environment: riot 2.3.1, webpack latest, babel v6.
tag example:
This will get error when running babel:
error 'import' and 'export' may only appear at the top level
The text was updated successfully, but these errors were encountered: