-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Declaration maps and transparent goto definition using them #22658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ab7cb27
91cc19c
c291828
2b26a27
ec44da5
ffb7f85
589ac28
5584a2d
238ba98
ff158cf
b9f6149
53f72de
29c732e
6070108
0a63553
d8480b2
ca88d5e
2b231d7
fed6132
509e4f3
0c44ba1
c8620e3
5687e10
e64e73d
47e701a
6a467ba
f2c8d3f
bd9cccf
c7a5296
f6e81f2
d0a5e28
943dc12
265cc1a
e34a6bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -457,6 +457,7 @@ namespace ts { | |
| clearTimeout?(timeoutId: any): void; | ||
| clearScreen?(): void; | ||
| /*@internal*/ setBlocking?(): void; | ||
| base64decode?(input: string): string; | ||
| } | ||
|
|
||
| export interface FileWatcher { | ||
|
|
@@ -528,6 +529,8 @@ namespace ts { | |
| _crypto = undefined; | ||
| } | ||
|
|
||
| const Buffer: typeof global.Buffer = require("buffer").Buffer; | ||
|
||
|
|
||
| const nodeVersion = getNodeMajorVersion(); | ||
| const isNode4OrLater = nodeVersion >= 4; | ||
|
|
||
|
|
@@ -620,6 +623,9 @@ namespace ts { | |
| if (process.stdout && process.stdout._handle && process.stdout._handle.setBlocking) { | ||
| process.stdout._handle.setBlocking(true); | ||
| } | ||
| }, | ||
| base64decode: input => { | ||
| return Buffer.from(input, "base64").toString("utf8"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| }; | ||
| return nodeSystem; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3463,6 +3463,42 @@ namespace ts { | |
| return result; | ||
| } | ||
|
|
||
| export function base64decode(host: { base64decode?(input: string): string }, input: string): string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're inconsistent with naming between |
||
| if (host.base64decode) { | ||
| return host.base64decode(input); | ||
| } | ||
| let result = ""; | ||
| const length = input.length; | ||
| let i = 0; | ||
| while (i < length) { | ||
| // Stop decoding once padding characters are present | ||
| if (input.charCodeAt(i) === base64Digits.charCodeAt(64)) { | ||
| break; | ||
| } | ||
| // convert 4 input digits into three characters, ignoring padding characters at the end | ||
| const ch1 = base64Digits.indexOf(input[i]); | ||
| const ch2 = base64Digits.indexOf(input[i + 1]); | ||
| 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); | ||
|
|
||
| if (code2 === 0 && ch3 !== 0) { // code2 decoded to zero, but ch3 was padding - elide code2 and code3 | ||
| result += String.fromCharCode(code1); | ||
| } | ||
| else if (code3 === 0 && ch4 !== 0) { // code3 decoded to zero, but ch4 was padding, elide code3 | ||
| result += `${String.fromCharCode(code1)}${String.fromCharCode(code2)}`; | ||
| } | ||
| else { | ||
| result += `${String.fromCharCode(code1)}${String.fromCharCode(code2)}${String.fromCharCode(code3)}`; | ||
| } | ||
| i += 4; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| const carriageReturnLineFeed = "\r\n"; | ||
| const lineFeed = "\n"; | ||
| export function getNewLineCharacter(options: CompilerOptions | PrinterOptions, getNewLine?: () => string): string { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1573,22 +1573,29 @@ namespace ts { | |
| return checker.getSymbolAtLocation(node); | ||
| } | ||
|
|
||
| function getSourceMapper(fileName: string, file: { sourceMapper?: sourcemaps.SourceMapper }) { | ||
| if (!host.readFile || !host.fileExists) { | ||
| return file.sourceMapper = sourcemaps.identitySourceMapper; | ||
| } | ||
| if (file.sourceMapper) { | ||
| return file.sourceMapper; | ||
|
|
||
| const sourceMapCommentRE = /^\/\/[@#] sourceMappingURL=(.+)$/gm; | ||
| const dataURLRE = /^data:/; | ||
| const base64URLRE = /^data:application\/json;charset=utf-8;base64,(.+)$/; | ||
|
||
| function scanForSourcemapURL(fileName: string) { | ||
| const mappedFile = sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName)); | ||
| if (!mappedFile) { | ||
| return; | ||
| } | ||
| // TODO (weswigham): Read sourcemappingurl from last line of .d.ts if present | ||
| const mapFileName = fileName + ".map"; | ||
| if (!host.fileExists(mapFileName)) { | ||
| return file.sourceMapper = sourcemaps.identitySourceMapper; | ||
| const starts = getLineStarts(mappedFile); | ||
| for (let index = starts.length - 1; index--; index >= 0) { | ||
|
||
| sourceMapCommentRE.lastIndex = starts[index]; | ||
| const comment = sourceMapCommentRE.exec(mappedFile.text); | ||
| if (comment) { | ||
| return comment[1]; | ||
| } | ||
| } | ||
| const doc = host.readFile(mapFileName); | ||
| } | ||
|
|
||
| function convertDocumentToSourceMapper(file: { sourceMapper?: sourcemaps.SourceMapper }, contents: string, mapFileName: string) { | ||
| let maps: sourcemaps.SourceMapData; | ||
| try { | ||
| maps = JSON.parse(doc); | ||
| maps = JSON.parse(contents); | ||
| } | ||
| catch { | ||
| // swallow error | ||
|
|
@@ -1605,6 +1612,36 @@ namespace ts { | |
| }, mapFileName, maps, program, sourcemappedFileCache); | ||
| } | ||
|
|
||
| function getSourceMapper(fileName: string, file: { sourceMapper?: sourcemaps.SourceMapper }) { | ||
| if (!host.readFile || !host.fileExists) { | ||
| return file.sourceMapper = sourcemaps.identitySourceMapper; | ||
| } | ||
| if (file.sourceMapper) { | ||
| return file.sourceMapper; | ||
| } | ||
| let mapFileName = scanForSourcemapURL(fileName); | ||
| if (mapFileName && dataURLRE.exec(mapFileName)) { | ||
|
||
| const b64EncodedMatch = base64URLRE.exec(mapFileName); | ||
| if (b64EncodedMatch) { | ||
| const base64Object = b64EncodedMatch[1]; | ||
| return convertDocumentToSourceMapper(file, base64decode(sys, base64Object), fileName); | ||
| } | ||
| mapFileName = undefined; | ||
| } | ||
| const possibleMapLocations: string[] = []; | ||
| if (mapFileName) { | ||
| possibleMapLocations.push(mapFileName); | ||
| } | ||
| possibleMapLocations.push(fileName + ".map"); | ||
| for (const location of possibleMapLocations) { | ||
| const mapPath = toPath(location, getDirectoryPath(fileName), getCanonicalFileName); | ||
| if (host.fileExists(mapPath)) { | ||
| return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); | ||
| } | ||
| } | ||
| return file.sourceMapper = sourcemaps.identitySourceMapper; | ||
| } | ||
|
|
||
| function makeGetTargetOfMappedPosition<TIn>( | ||
| extract: (original: TIn) => sourcemaps.SourceMappableLocation, | ||
| create: (result: sourcemaps.SourceMappableLocation, original: TIn) => TIn | ||
|
|
||
There was a problem hiding this comment.
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
sysmember forbase64encode?