fix: css sourcemap generation with unicode filenames (#9120)

* fix: css sourcemap generation with unicode filenames

* format
pull/9126/head
gtmnayan 1 year ago committed by GitHub
parent 5a8c1d2caf
commit ba1e67844e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: css sourcemap generation with unicode filenames

@ -292,7 +292,18 @@ export function apply_preprocessor_sourcemap(filename, svelte_map, preprocessor_
toUrl: { toUrl: {
enumerable: false, enumerable: false,
value: function toUrl() { value: function toUrl() {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString()); let b64 = '';
if (typeof window !== 'undefined' && window.btoa) {
// btoa doesn't support multi-byte characters
b64 = window.btoa(unescape(encodeURIComponent(this.toString())));
} else if (typeof Buffer !== 'undefined') {
b64 = Buffer.from(this.toString(), 'utf8').toString('base64');
} else {
throw new Error(
'Unsupported environment: `window.btoa` or `Buffer` should be present to use toUrl.'
);
}
return 'data:application/json;charset=utf-8;base64,' + b64;
} }
} }
}); });

Loading…
Cancel
Save