This commit is contained in:
Andy Hanson 2016-11-02 11:59:12 -07:00
parent 960b99aae7
commit 90882626dd
11 changed files with 47 additions and 20 deletions

View file

@ -1430,6 +1430,7 @@ namespace ts {
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
}
else {
debugger;
error(errorNode, moduleNotFoundError, moduleName);
}
}

View file

@ -571,7 +571,7 @@ namespace ts {
}
function resolvedWithRealpath(resolved: Resolved, host: ModuleResolutionHost, traceEnabled: boolean): Resolved {
if (!host.realpath || resolved.extension !== Extension.Dts) {//(!false) {//(!host.realpath) { //TODO: Kill this fn
if (!false) {//if (!host.realpath || resolved.extension !== Extension.Dts) {//(!false) {//(!host.realpath) { //TODO: Kill this fn
return resolved;
}

View file

@ -359,7 +359,10 @@ namespace ts {
}
//Keys must be real paths!!!
//above not quite true any more
const filesByName = createFileMap<SourceFile>();
const symlinkedFiles = createFileMap<SourceFile>();
// stores 'filename -> file association' ignoring case
// used to track cases when two file names differ only in casing
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap<SourceFile>(fileName => fileName.toLowerCase()) : undefined;
@ -578,6 +581,7 @@ namespace ts {
for (let i = 0, len = newSourceFiles.length; i < len; i++) {
filesByName.set(filePaths[i], newSourceFiles[i]);
}
//update symlinkedFiles too?
files = newSourceFiles;
fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics();
@ -686,13 +690,13 @@ namespace ts {
}
function getSourceFileByPath(path: Path): SourceFile { //path is logical
return filesByName.get(path); //realpath(path));
return filesByName.get(path) || symlinkedFiles.get(path); //realpath(path));
}
//neater
//function realpath(path: Path): Path {
// return host.realpath ? (host.realpath(path) as Path) : path;
//}
function realpath(path: Path): Path {
return host.realpath ? (host.realpath(path) as Path) : path;
}
function getDiagnosticsHelper(
sourceFile: SourceFile,
@ -1183,10 +1187,6 @@ namespace ts {
}
//name, move below findSourceFile
function bar(file: SourceFile, fileName: string, path: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0);
//This sets file.path to the *realpath*
file.path = path;
if (host.useCaseSensitiveFileNames()) {
// for case-sensitive file systems check if we've already seen some file with similar filename ignoring case
const existingFile = filesByNameIgnoreCase.get(path);
@ -1220,8 +1220,13 @@ namespace ts {
//!!!
//fileName is a relative path, thus not a realpath.
//does getCanonicalFileName need to be an input?
function findSourceFile(fileName: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
const path = toPath(fileName, currentDirectory, getCanonicalFileName); //realpath(...)
//TODO: fix up parameters -- resolution and fileName are redundatn
function findSourceFile(fileName: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number/*, resolution?: ResolvedModuleFull*/): SourceFile {
const originalPath = toPath(fileName, currentDirectory, getCanonicalFileName); //realpath(...)
//need resolution.isExternalLibraryImport...
const foundSearchingNodeModules = currentNodeModulesDepth > 0;
//Support `npm link` scenario -- use real path
const path = foundSearchingNodeModules ? realpath(originalPath) : originalPath;
let fileFromFiles = filesByName.get(path);
//This might be a symlink.
//if (!fileFromFiles) {
@ -1234,6 +1239,12 @@ namespace ts {
//}
if (fileFromFiles) {
//still might need to add realpath
//duplicate code
if (originalPath !== path) {
symlinkedFiles.set(originalPath, fileFromFiles);
}
return foo(fileFromFiles, fileName, isDefaultLib, refFile, refPos, refEnd);
}
@ -1249,7 +1260,15 @@ namespace ts {
});
filesByName.set(path, file);
if (originalPath !== path) {
//this is needed for getSourceFileByPath to work when given relative paths
symlinkedFiles.set(originalPath, file); //!!!
}
if (file) {
//move these back inside `bar`?
sourceFilesFoundSearchingNodeModules[path] = foundSearchingNodeModules;
file.path = path;
bar(file, fileName, path, isDefaultLib, refFile, refPos, refEnd);
}

View file

@ -2551,7 +2551,7 @@ namespace ts {
* Whether a file should be emitted in a non-`--outFile` case.
* Don't emit if source file is a declaration file, or was located under node_modules
*/
function shouldEmitInDirectory(sourceFile: SourceFile, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): boolean {
export function shouldEmitInDirectory(sourceFile: SourceFile, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): boolean {
return isNonDeclarationFile(sourceFile) && !isSourceFileFromExternalLibrary(sourceFile);
}

View file

@ -976,10 +976,10 @@ namespace Harness {
}
}
//!!! Problem: this may not represent what the command line compiler actually does!!!
//!!! Problem: this may not represent what the command line compiler actually does!!! So test in real projects too!
function getSourceFile(fileName: string) {
fileName = ts.normalizePath(fileName);
const path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); //was realPath(...)
const path = realPath(fileName); //was realPath(...)
const fromMap = fileMap.get(path);
if (fromMap) {
return fromMap();
@ -1002,7 +1002,7 @@ namespace Harness {
Harness.IO.newLine();
//move
function realPath(f: ts.Path): ts.Path {
function realPath(f: string): ts.Path {
const path = ts.toPath(f, currentDirectory, getCanonicalFileName);
return realPathMap
? (realPathMap.get(path) as ts.Path) || path

View file

@ -17,6 +17,14 @@ let y: MyClass2;
x = y;
y = x;
//// [/src/library-a/index.js]
"use strict";
var MyClass = (function () {
function MyClass() {
}
return MyClass;
}());
exports.MyClass = MyClass;
//// [/src/library-b/index.js]
"use strict";
var library_a_1 = require("library-a");

View file

@ -6,7 +6,7 @@
export const x = 0;
//// [app.ts]
import { x } from './shared/abc';
import { x } from "./shared/abc";
x + 1;

View file

@ -1,5 +1,5 @@
=== /src/app.ts ===
import { x } from './shared/abc';
import { x } from "./shared/abc";
>x : Symbol(x, Decl(app.ts, 0, 8))
x + 1;

View file

@ -1,5 +1,5 @@
=== /src/app.ts ===
import { x } from './shared/abc';
import { x } from "./shared/abc";
>x : 0
x + 1;

View file

@ -1,4 +1,3 @@
// Symlinks for '.ts' files are *not* resolved
// @module: commonjs
// @noImplicitReferences: true
// @traceResolution: true

View file

@ -8,7 +8,7 @@
export const x = 0;
// @filename: /src/app.ts
import { x } from './shared/abc';
import { x } from "./shared/abc";
x + 1;
// @filename: /src/tsconfig.json