Merge branch 'master' into 2

This commit is contained in:
Geoffrey Booth
2016-11-28 20:18:43 -08:00
3 changed files with 11 additions and 3 deletions

View File

@@ -115,7 +115,8 @@
<p>
The CoffeeScript compiler goes to great lengths to generate output JavaScript
that runs in every JavaScript runtime, but there are exceptions. Use
<a href="#generator-functions">generator functions</a> or
<a href="#generator-functions">generator functions</a>,
<a href="#generator-iteration"><code>for&hellip;from</code></a>, or
<a href="#tagged-template-literals">tagged template literals</a> only if you
know that your <a href="http://kangax.github.io/compat-table/es6/">target
runtimes can support them</a>. If you use <a href="#modules">modules</a>,

View File

@@ -28,7 +28,9 @@
case typeof Buffer !== 'function':
return Buffer.from(src).toString('base64');
case typeof btoa !== 'function':
return btoa(src);
return btoa(encodeURIComponent(src).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
default:
throw new Error('Unable to base64 encode inline sourcemap.');
}

View File

@@ -24,7 +24,12 @@ base64encode = (src) -> switch
when typeof Buffer is 'function'
Buffer.from(src).toString('base64')
when typeof btoa is 'function'
btoa(src)
# The contents of a <script> block are encoded via UTF-16, so if any extended
# characters are used in the block, btoa will fail as it maxes out at UTF-8.
# See https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
# for the gory details, and for the solution implemented here.
btoa encodeURIComponent(src).replace /%([0-9A-F]{2})/g, (match, p1) ->
String.fromCharCode '0x' + p1
else
throw new Error('Unable to base64 encode inline sourcemap.')