diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-05-17 16:59:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 16:59:35 +0200 |
commit | d76acfdc17e27b53fc53e6cd3051ff0acaefef42 (patch) | |
tree | 73a2f9984887f5403682de6100b7059b475ea25d /cli/tsc/99_main_compiler.js | |
parent | b2ba0c54afe806770a9a556b8e622b3c8c0bb5d1 (diff) |
fix: base64 encoding of source maps with emojis (#14607)
This commit fixes source maps for files that contain emojis.
This is done by updating "deno_ast" to "0.14.1" for the case
of "--no-check" flag (ie using SWC emit) and by overriding
TSC's default base64 encoder (which turned out to be buggy)
for the type checking case.
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r-- | cli/tsc/99_main_compiler.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 6d47b6ac7..362fdd762 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -72,6 +72,43 @@ delete Object.prototype.__proto__; } } + // deno-fmt-ignore + const base64abc = [ + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", + "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", + "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", + "8", "9", "+", "/", + ]; + + /** Taken from https://deno.land/std/encoding/base64.ts */ + function convertToBase64(data) { + const uint8 = core.encode(data); + let result = "", + i; + const l = uint8.length; + for (i = 2; i < l; i += 3) { + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; + result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)]; + result += base64abc[uint8[i] & 0x3f]; + } + if (i === l + 1) { + // 1 octet yet to write + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[(uint8[i - 2] & 0x03) << 4]; + result += "=="; + } + if (i === l) { + // 2 octets yet to write + result += base64abc[uint8[i - 2] >> 2]; + result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; + result += base64abc[(uint8[i - 1] & 0x0f) << 2]; + result += "="; + } + return result; + } + // In the case of the LSP, this is initialized with the assets // when snapshotting and never added to or removed after that. /** @type {Map<string, ts.SourceFile>} */ @@ -485,6 +522,14 @@ delete Object.prototype.__proto__; * @param {Request} request */ function exec({ config, debug: debugFlag, rootNames }) { + // https://github.com/microsoft/TypeScript/issues/49150 + ts.base64encode = function (host, input) { + if (host && host.base64encode) { + return host.base64encode(input); + } + return convertToBase64(input); + }; + setLogDebug(debugFlag, "TS"); performanceStart(); debug(">>> exec start", { rootNames }); |