Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ab7cb27
Add compiler option to enable declaration sourcemaps
weswigham Feb 15, 2018
91cc19c
Transparent goto definition for sourcemapped declaration files
weswigham Feb 17, 2018
c291828
Post-rebase touchups
weswigham Mar 16, 2018
2b26a27
Rename API methods
weswigham Mar 16, 2018
ec44da5
Fix lints
weswigham Mar 16, 2018
ffb7f85
Fix typo in name XD
weswigham Mar 16, 2018
589ac28
Log sourcemap decode errors
weswigham Mar 16, 2018
5584a2d
Share the cache more, but also invalidate it more
weswigham Mar 16, 2018
238ba98
Remove todo
weswigham Mar 16, 2018
ff158cf
Enable mapping on go to implementation as well
weswigham Mar 17, 2018
b9f6149
Allow fourslash to test declaration maps mroe easily
weswigham Mar 19, 2018
53f72de
more test
weswigham Mar 19, 2018
29c732e
Merge branch 'master' into decl-maps
weswigham Mar 19, 2018
6070108
Handle sourceRoot
weswigham Mar 19, 2018
0a63553
Add tests documenting current behavior with other sourcemapping flags
weswigham Mar 19, 2018
d8480b2
Ignore inline options for declaration file maps, simplify dispatch in…
weswigham Mar 20, 2018
ca88d5e
Change program diagnostic
weswigham Mar 20, 2018
2b231d7
Fix nit
weswigham Mar 20, 2018
fed6132
Use charCodeAt
weswigham Mar 20, 2018
509e4f3
Rename internal methods + veriables
weswigham Mar 20, 2018
0c44ba1
Avoid filter
weswigham Mar 20, 2018
c8620e3
span -> position
weswigham Mar 20, 2018
5687e10
Use character codes
weswigham Mar 20, 2018
e64e73d
Dont parse our sourcemap names until we need to start using them
weswigham Mar 20, 2018
47e701a
zero-index parsed positions
weswigham Mar 20, 2018
6a467ba
Handle sourceMappingURL comments, including base64 encoded ones
weswigham Mar 20, 2018
f2c8d3f
Unittest b64 decoder, make mroe robust to handle unicode properly
weswigham Mar 20, 2018
bd9cccf
Fix lint
weswigham Mar 20, 2018
c7a5296
declarationMaps -> declarationMap
weswigham Mar 20, 2018
f6e81f2
Merge branch 'master' into decl-maps
weswigham Mar 24, 2018
d0a5e28
Even more feedback
weswigham Mar 24, 2018
943dc12
USE Mroe lenient combined regexp
weswigham Mar 26, 2018
265cc1a
only match base64 characters
weswigham Mar 26, 2018
e34a6bd
Fix nit
weswigham Mar 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unittest b64 decoder, make mroe robust to handle unicode properly
  • Loading branch information
weswigham committed Mar 20, 2018
commit f2c8d3fa82beb4a248b9431ef89f732e39facd02
1 change: 1 addition & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var harnessCoreSources = [
});

var harnessSources = harnessCoreSources.concat([
"base64.ts",
"incrementalParser.ts",
"jsDocParsing.ts",
"services/colorization.ts",
Expand Down
51 changes: 42 additions & 9 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ namespace ts {
for (let i = 0; i < length; i++) {
const charCode = input.charCodeAt(i);

// handel utf8
// handle utf8
if (charCode < 0x80) {
output.push(charCode);
}
Expand Down Expand Up @@ -3463,12 +3463,45 @@ namespace ts {
return result;
}

function getStringFromExpandedCharCodes(codes: number[]): string {
let output = "";
let i = 0;
const length = codes.length;
while (i < length) {
const charCode = codes[i];

if (charCode < 0x80) {
output += String.fromCharCode(charCode);
i++;
}
else if ((charCode & 0B11000000) === 0B11000000) {
let value = charCode & 0B00111111;
i++;
let nextCode: number = codes[i];
while ((nextCode & 0B11000000) === 0B10000000) {
value = (value << 6) | (nextCode & 0B00111111);
i++;
nextCode = codes[i];
}
// `value` may be greater than 10FFFF (the maximum unicode codepoint) - JS will just make this into an invalid character for us
output += String.fromCharCode(value);
}
else {
// We don't want to kill the process when decoding fails (due to a following char byte not
// following a leading char), so we just print the (bad) value
output += String.fromCharCode(charCode);
i++;
}
}
return output;
}

export function base64decode(host: { base64decode?(input: string): string }, input: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're inconsistent with naming between base64decode and convertToBase64 above it. Please choose a more consistent name.

if (host.base64decode) {
return host.base64decode(input);
}
let result = "";
const length = input.length;
let expandedCharCodes: number[] = [];
let i = 0;
while (i < length) {
// Stop decoding once padding characters are present
Expand All @@ -3481,22 +3514,22 @@ namespace ts {
const ch3 = base64Digits.indexOf(input[i + 2]);
const ch4 = base64Digits.indexOf(input[i + 3]);

const code1 = (ch1 & 0B00111111 << 2) | (ch2 & 0B00000011);
const code2 = (ch2 & 0B00001111 << 4) | (ch3 & 0B00001111);
const code3 = (ch3 & 0B00000011 << 6) | (ch4 & 0B00111111);
const code1 = ((ch1 & 0B00111111) << 2) | ((ch2 >> 4) & 0B00000011);
const code2 = ((ch2 & 0B00001111) << 4) | ((ch3 >> 2) & 0B00001111);
const code3 = ((ch3 & 0B00000011) << 6) | (ch4 & 0B00111111);

if (code2 === 0 && ch3 !== 0) { // code2 decoded to zero, but ch3 was padding - elide code2 and code3
result += String.fromCharCode(code1);
expandedCharCodes.push(code1);
}
else if (code3 === 0 && ch4 !== 0) { // code3 decoded to zero, but ch4 was padding, elide code3
result += `${String.fromCharCode(code1)}${String.fromCharCode(code2)}`;
expandedCharCodes.push(code1, code2);
}
else {
result += `${String.fromCharCode(code1)}${String.fromCharCode(code2)}${String.fromCharCode(code3)}`;
expandedCharCodes.push(code1, code2, code3);
}
i += 4;
}
return result;
return getStringFromExpandedCharCodes(expandedCharCodes);
}

const carriageReturnLineFeed = "\r\n";
Expand Down
1 change: 1 addition & 0 deletions src/harness/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"../server/session.ts",
"../server/client.ts",
"../server/editorServices.ts",
"./unittests/base64.ts",
"./unittests/incrementalParser.ts",
"./unittests/jsDocParsing.ts",
"./unittests/services/colorization.ts",
Expand Down
23 changes: 23 additions & 0 deletions src/harness/unittests/base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path="../harness.ts" />
namespace ts {
describe("base64", () => {
describe("base64decode", () => {
it("can decode input strings correctly without needing a host implementation", () => {
const tests = [
// "a",
// "this is a test",
// " !\"#$ %&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
"日本語",
"🐱",
"\x00\x01",
"\t\n\r\\\"\'\u0062",
"====",
"",
];
for (const test of tests) {
assert.equal(base64decode({}, convertToBase64(test)), test);
}
});
});
});
}