1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

encode unicode src, test added

This commit is contained in:
Hao-kang Den 2013-03-20 16:39:36 +08:00
parent e26f982c24
commit b2d6997eff
2 changed files with 7 additions and 4 deletions

View file

@ -21,14 +21,15 @@ CoffeeScript.run = (code, options = {}) ->
# If we're not in a browser environment, we're finished with the public API.
return unless window?
# Include source maps where possible. If we've got a base64 encoder, and a
# JSON serializer, we're good to go.
if btoa? and JSON?
# Include source maps where possible. If we've got a base64 encoder, a
# JSON serializer, and tools for escaping unicode characters, we're good to go.
# Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa
if btoa? and JSON? and unescape? and encodeURIComponent?
compile = (code, options = {}) ->
options.sourceMap = true
options.inline = true
{js, v3SourceMap} = CoffeeScript.compile code, options
"#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa v3SourceMap}\n//@ sourceURL=coffeescript"
"#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa unescape encodeURIComponent v3SourceMap}\n//@ sourceURL=coffeescript"
# Load a remote script from the current domain via XHR.
CoffeeScript.load = (url, callback, options = {}) ->

View file

@ -112,6 +112,8 @@
'soaks'
'strings'
]
# allow utf-8 chars in comments
# 智に働けば角が立つ、情に掉させば流される。
</script>
</body>