Handle triple slash refs

This commit is contained in:
Sheetal Nandi
2019-01-25 14:31:41 -08:00
parent 36eae04120
commit ff027d41c9
9 changed files with 107 additions and 81 deletions
+8 -2
View File
@@ -2701,7 +2701,7 @@ namespace ts {
const node = <UnparsedSource>createNode(SyntaxKind.UnparsedSource);
if (!isString(textOrInputFiles)) {
Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
node.fileName = (mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath) || "";
node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
Object.defineProperties(node, {
text: { get() { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
@@ -2709,11 +2709,13 @@ namespace ts {
});
}
else {
node.fileName = "";
node.text = textOrInputFiles;
node.sourceMapPath = mapPathOrType;
node.sourceMapText = map;
}
const text = node.text;
node.languageVersion = ScriptTarget.Latest;
// Shebang
let pos = isShebangTrivia(text, 0) ? skipTrivia(text, 0, /*stopAfterLineBreak*/ true) : 0;
@@ -2742,8 +2744,12 @@ namespace ts {
(helpers || (helpers = [])).push(helperInfo.helper);
}
// triple slash directives
const newPos = processCommentPragmas(node as {} as PragmaContext, text);
processPragmasIntoFields(node as {} as PragmaContext, noop);
// Rest of the text
node.pos = pos;
node.pos = newPos > pos ? newPos : pos;
node.prologues = prologues || emptyArray;
node.helpers = helpers;
node.getLineAndCharacterOfPosition = pos => getLineAndCharacterOfPosition(node, pos);
+2 -1
View File
@@ -7721,7 +7721,7 @@ namespace ts {
}
/*@internal*/
export function processCommentPragmas(context: PragmaContext, sourceText: string): void {
export function processCommentPragmas(context: PragmaContext, sourceText: string) {
const triviaScanner = createScanner(context.languageVersion, /*skipTrivia*/ false, LanguageVariant.Standard, sourceText);
const pragmas: PragmaPseudoMapEntry[] = [];
@@ -7758,6 +7758,7 @@ namespace ts {
}
context.pragmas.set(pragma!.name, pragma!.args);
}
return triviaScanner.getStartPos();
}
type PragmaDiagnosticReporter = (pos: number, length: number, message: DiagnosticMessage) => void;
+8 -4
View File
@@ -207,7 +207,11 @@ namespace ts {
}
), mapDefined(node.prepends, prepend => {
if (prepend.kind === SyntaxKind.InputFiles) {
return createUnparsedSourceFile(prepend, "dts");
const sourceFile = createUnparsedSourceFile(prepend, "dts");
hasNoDefaultLib = hasNoDefaultLib || !!sourceFile.hasNoDefaultLib;
collectReferences(sourceFile, refs);
collectLibs(sourceFile, libs);
return sourceFile;
}
}));
bundle.syntheticFileReferences = [];
@@ -311,8 +315,8 @@ namespace ts {
}
}
function collectReferences(sourceFile: SourceFile, ret: Map<SourceFile>) {
if (noResolve || isSourceFileJS(sourceFile)) return ret;
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: Map<SourceFile>) {
if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret;
forEach(sourceFile.referencedFiles, f => {
const elem = tryResolveScriptReference(host, sourceFile, f);
if (elem) {
@@ -322,7 +326,7 @@ namespace ts {
return ret;
}
function collectLibs(sourceFile: SourceFile, ret: Map<boolean>) {
function collectLibs(sourceFile: SourceFile | UnparsedSource, ret: Map<boolean>) {
forEach(sourceFile.libReferenceDirectives, ref => {
const lib = host.getLibFileFromReference(ref);
if (lib) {
+6 -1
View File
@@ -2774,10 +2774,15 @@ namespace ts {
export interface UnparsedSource extends Node {
kind: SyntaxKind.UnparsedSource;
fileName?: string;
fileName: string;
text: string;
languageVersion: ScriptTarget;
prologues: ReadonlyArray<UnparsedPrologue>;
helpers: ReadonlyArray<UnscopedEmitHelpers> | undefined;
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
libReferenceDirectives: FileReference[];
hasNoDefaultLib?: boolean;
sourceMapPath?: string;
sourceMapText?: string;
/*@internal*/ parsedSourceMap?: RawSourceMap | false | undefined;
+1 -1
View File
@@ -2557,7 +2557,7 @@ namespace ts {
return undefined;
}
export function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile, reference: FileReference) {
export function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile | UnparsedSource, reference: FileReference) {
if (!host.getCompilerOptions().noResolve) {
const referenceFileName = isRootedDiskPath(reference.fileName) ? reference.fileName : combinePaths(getDirectoryPath(sourceFile.fileName), reference.fileName);
return host.getSourceFile(referenceFileName);