-
Notifications
You must be signed in to change notification settings - Fork 39
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
CoffeeScript classes result in verbose compilation #26
Comments
Hi, |
Same here 👍 |
This is an interesting idea. Not sure if, or how I'd implement this, but I'll definitely consider it. Probably won't make it into the upcoming 2.0 release, but perhaps a release after. |
After further thought, this would be incredibly tricky to implement. Mainly due to snocket's mixed-asset nature. This becomes difficult or impossible as soon as there's a non-coffee file in the chain. If you can come up with a way around it, I'm open to pull requests. I'm working on the new 2.0.0 branch in #43 -- feel free to work off of that. It currently has source map support, and I've upgraded coffee-script and uglifyjs to latest. For now, I'm closing this issue. Thanks a ton for submitting this, and I look forward to any solutions you may have to offer. |
Cheap hack, but what if you just wrapped the contents of the js files in backticks? This is how embedded JavaScript works in CoffeeScript. Consider the following files:
That would result in a concatenation similar to the following:
Which, when run through
It results in an extra semi-colon but that doesn't matter once run through |
Consider the following example:
Animal.coffee
:Cat.coffee
:Dog.coffee
:app.coffee
:The following is the output of compiling
app.coffee
:There are two issues with the way this is compiled:
Cat
,Dog
, andAnimal
are out of scope of each other so inheritance doesn't work and they are defined outside the scope of the compiledapp.coffee
so they cannot be instantiated.__extends
and__hasProp
functions. Even if each file is compiled individually with--bare
a minifier would not know that only one of these declarations is necessary (I have tested uglifyjs and closure, they both overwrite the extension functionality for each declared class).My proposed solution is to concatenate CoffeeScript files in the proper order and then compile them. Following that process manually we end up with the following output:
Now we only have one declaration of
__extends
and__hasProp
and everything is in proper scope. I would be happy to go ahead and code this up and send a pull request but I just wanted to see if you had any concerns first.The text was updated successfully, but these errors were encountered: