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
Even more feedback
  • Loading branch information
weswigham committed Mar 24, 2018
commit d0a5e2863bf2d21b4c11ca19765a1501086c964d
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace ts {
onEmitSourceMapOfNode: declarationSourceMap.emitNodeWithSourceMap,
onEmitSourceMapOfToken: declarationSourceMap.emitTokenWithSourceMap,
onEmitSourceMapOfPosition: declarationSourceMap.emitPos,
onSetSourceFile: setSourceFileDeclarationMaps,
onSetSourceFile: setSourceFileForDeclarationSourceMaps,

// transform hooks
onEmitNode: declarationTransform.emitNodeWithNotification,
Expand Down Expand Up @@ -258,7 +258,7 @@ namespace ts {
sourceMap.setSourceFile(node);
}

function setSourceFileDeclarationMaps(node: SourceFile) {
function setSourceFileForDeclarationSourceMaps(node: SourceFile) {
currentSourceFile = node;
declarationSourceMap.setSourceFile(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ namespace ts {

if (compilerOptions.inlineSourceMap) {
// Encode the sourceMap into the sourceMap url
const base64SourceMapText = convertToBase64(getText());
const base64SourceMapText = base64encode(sys, getText());
return sourceMapData.jsSourceMappingURL = `data:application/json;base64,${base64SourceMapText}`;
}
else {
Expand Down
15 changes: 13 additions & 2 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ namespace ts {
clearScreen?(): void;
/*@internal*/ setBlocking?(): void;
base64decode?(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.

Shouldn't we also add an optional sys member for base64encode?

base64encode?(input: string): string;
}

export interface FileWatcher {
Expand Down Expand Up @@ -529,7 +530,10 @@ namespace ts {
_crypto = undefined;
}

const Buffer: typeof global.Buffer = require("buffer").Buffer;
const Buffer: {
new (input: string, encoding?: string): any;
from?(input: string, encoding?: string): any;
} = require("buffer").Buffer;

const nodeVersion = getNodeMajorVersion();
const isNode4OrLater = nodeVersion >= 4;
Expand Down Expand Up @@ -624,8 +628,15 @@ namespace ts {
process.stdout._handle.setBlocking(true);
}
},
base64decode: input => {
base64decode: Buffer.from ? input => {
return Buffer.from(input, "base64").toString("utf8");
Copy link
Contributor

Choose a reason for hiding this comment

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

Buffer.from was added in NodeJS v5.10.0. We should feature test for Buffer.from and either don't add base64decode if it isn't present, or fall back to the deprecated new Buffer(string, encoding) form that was used prior to NodeJS v6.0.0.

} : input => {
return new Buffer(input, "base64").toString("utf8");
},
base64encode: Buffer.from ? input => {
return Buffer.from(input).toString("base64");
} : input => {
return new Buffer(input).toString("base64");
}
};
return nodeSystem;
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,13 @@ namespace ts {
return output;
}

export function base64encode(host: { base64encode?(input: string): string }, input: string): string {
if (host.base64encode) {
return host.base64encode(input);
}
return convertToBase64(input);
}

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);
Expand Down
16 changes: 8 additions & 8 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1581,18 +1581,18 @@ namespace ts {
}


const sourceMapCommentRE = /^\/\/[@#] sourceMappingURL=(.+)$/gm;
const dataURLRE = /^data:/;
const base64URLRE = /^data:application\/json;charset=utf-8;base64,(.+)$/;
const sourceMapCommentRegExp = /^\/\/[@#] sourceMappingURL=(.+)$/gm;
const dataURLRegExp = /^data:/;
const base64UrlRegExp = /^data:application\/json;charset=utf-8;base64,(.+)$/;
function scanForSourcemapURL(fileName: string) {
const mappedFile = sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName));
if (!mappedFile) {
return;
}
const starts = getLineStarts(mappedFile);
for (let index = starts.length - 1; index--; index >= 0) {
sourceMapCommentRE.lastIndex = starts[index];
const comment = sourceMapCommentRE.exec(mappedFile.text);
for (let index = starts.length - 1; index >= 0; index--) {
sourceMapCommentRegExp.lastIndex = starts[index];
const comment = sourceMapCommentRegExp.exec(mappedFile.text);
if (comment) {
return comment[1];
}
Expand Down Expand Up @@ -1627,8 +1627,8 @@ namespace ts {
return file.sourceMapper;
}
let mapFileName = scanForSourcemapURL(fileName);
if (mapFileName && dataURLRE.exec(mapFileName)) {
const b64EncodedMatch = base64URLRE.exec(mapFileName);
if (mapFileName && dataURLRegExp.exec(mapFileName)) {
const b64EncodedMatch = base64UrlRegExp.exec(mapFileName);
if (b64EncodedMatch) {
const base64Object = b64EncodedMatch[1];
return convertDocumentToSourceMapper(file, base64decode(sys, base64Object), fileName);
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,7 @@ declare namespace ts {
clearTimeout?(timeoutId: any): void;
clearScreen?(): void;
base64decode?(input: string): string;
base64encode?(input: string): string;
}
interface FileWatcher {
close(): void;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,7 @@ declare namespace ts {
clearTimeout?(timeoutId: any): void;
clearScreen?(): void;
base64decode?(input: string): string;
base64encode?(input: string): string;
}
interface FileWatcher {
close(): void;
Expand Down