-
Notifications
You must be signed in to change notification settings - Fork 58
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
Inline runtime generation, fix test:browser #176
Conversation
Added Cakefile task to build inline runtime (iced-runtime-3) and save it to extras/inline-runtime.js. It is used in nodes.coffee when runtime: 'inline' is requested.
Improve IcedRuntime node to properly generate 'inline' and 'window' runtimes. It is done by including extras/inline-runtime.js file into the output. This file is generated with Cakefile build:inline_runtime task. Fix browser tests. When in test:browser task, test files will be compiled with runtime set to 'none'. `global.iced` will point to iced-runtime instead. This is done to simulate browser environment.
|
||
unless process.env.MINIFY is 'false' | ||
{code} = require('uglify-js').minify code, fromString: true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone check if uglifying works? It fails for me in both build:browser and build:inline_runtime with parse errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no dice: mishoo/UglifyJS#448
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aww, so it's related to es6 features? Ok...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems to be puking on function*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talking to @chrisnojima about this in the office, we probably shouldn't be outputting ES6 to browsers anyways. People should convert to ES6 via babel (or whatnot). This is of course a much deeper concern, and indicates a deeper change in workflow, so maybe we shouldn't spend too many cycles on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, if we did, it still wouldn't change the fact that the actual code emittted from iced3 is in ES6 (with function*
) and will break many browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is the point of this branch, no? To emit ES6 for future browsers or as input for babel translation.
We can optionally support browserify in compiler - but do not actually specify it as a dependency - so it will simplify the workflow for people who have it installed anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed all around. Probably the most useful workflow is for us to output ES6, and then for consumers of the output code to minify and transpile as they see fit. Meaning, the whole direct browser operation of CoffeeScript might be moot for us, or more charitably, best-effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In sum, let's stick with the previous plan of (1) outputting the inline-runtime via raw string inclusion, and add (2) disabling of minification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks! I have (1) almost done but I need to write some tests. I'll try to have it all committed here at the end of the day.
So what are we doing with this one? |
About That's correct, this would be a limitation of the compiler in browser for now. It wouldn't be able to compile code with runtime set to 'inline'. I don't really see a good way around it. I tried to make the compiler "decompile" it's own runtime and emit it, but it led to nowhere. I can try this again if it sounds like a reasonable solution to you. |
@@ -2437,6 +2438,10 @@ class IcedRuntime extends Block | |||
if @isEmpty() then [] | |||
else super o | |||
|
|||
inlineRuntime: (lefthand) -> | |||
fs = require('fs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only frustration is that we used to have something that did work here. So how do you think the browser compiler should work then --- the user has to insert their own runtime? I'm getting a little confused.
Here's an idea I had:
inlineRuntime: (lefthand) ->
inline_runtime = require('./inline-runtime).runtime
"#{lefthand} = #{inline_runtime};" |
OK, that was another idea that I've had before. I wasn't sure which one was better - decompiling or saving raw string. So I'll get to it later today. |
Just for reference (and for other people interested, maybe), |
(I editted my comment above, thank you @zapu!) |
Indeed, the previous solution was bad for several reasons, especially because the code was different/worse and drifted further apart over time. |
Inline runtime will now contain stringified copy of itself. This is done in order to be able to emit the runtime from a browser-based compiler (or any environment that does not have a filesystem or access to compiler files). Removed uglifyjs support as it did not work with ES6 code. Renamed "build:inline_runtime" task to "build:inline-runtime"
I added the commit, it's still pretty rough around the edges, but the tests pass and seems OK overall. |
Stringified inline runtime is now accessible via require('./inline-runtime-str') from both node version and the browser. Much cleaner solution than the previous one.
Changed this approach a little bit to be more lined up with your proposal, and removed irrelevant comments from this PR. Things are much cleaner right now. I should also squash the commits before eventual merge. |
Looking very good. Do you get all tests passing? I'm still seeing one failing (repl.coffee:69). |
|
Hm, there was a change in behavior in node but I'm no longer seeing that. I tried to make this change in upstream (jashkenas#4120) but it wasn't accepted. What node version do you have? I'll try to find some time and dig through the changelogs. Can you try something like this?
Also, what's with the versions? I guess their versioning changed after all the node.js/io.js things happened. |
Ah, I'm running |
The correct way would be to detect repl settings (because I think you can change the undefined behavior) and make test check result according to this setting. |
Well still broken for me on 5.10.1., but that's ok. 👍 Ok, to merge! |
Oh, cool! Thanks! |
Thank you! |
Added inline runtime generation with
build:inline_runtime
task. The runtime is generated toextras/inline-runtime.js
and is used innodes.coffee
to emit IcedRuntime, if the option is set toinline
orwindow
.This method, however, limits compilation capabilities of iced as browser library. Iced in browser will not be able to emit inline runtime, because there will be no
inline-runtime.js
text file anywhere. Compiling withruntime: none
and letting it use runtime fromiced
global variable will work - and that's whattest:browser
Cake task does right now.All tests pass, for both
test
andtest:browser
. Keep in mind thattest:browser
runs less tests, greptestingBrowser
to see which test files are skipped.