This commit is contained in:
Andy Hanson 2017-05-31 07:36:24 -07:00
parent 51feae52b4
commit 619a5152df
7 changed files with 56 additions and 54 deletions

View file

@ -9675,7 +9675,6 @@ namespace ts {
return Ternary.False;
}
if (sourcePropAccessibility) {
//Hmm, this will have to take into account nominal equivalence?
if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) {
return Ternary.False;
}

View file

@ -103,7 +103,7 @@ namespace ts {
text = "";
}
return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes, /*scriptKind*/ undefined) : undefined;
return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
}
function directoryExists(directoryPath: string): boolean {
@ -449,7 +449,7 @@ namespace ts {
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => {
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.
if (!resolved || (resolved as ResolvedModuleFull).extension !== undefined) {
//Note: packageName may be undefined, I don't care
// Host may not have set packageName, but it's OK to leave it as undefined.
return resolved as ResolvedModuleFull;
}
const withExtension = clone(resolved) as ResolvedModuleFull;
@ -1527,19 +1527,19 @@ namespace ts {
function findSourceFile(fileName: string, path: Path, packageName: string | undefined, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
if (filesByName.contains(path)) {
const file = filesByName.get(path);
if (!file) return undefined;
//TODO: we do if (file) too much...
if (file) setPackageName(file, packageName);
setPackageName(file, packageName);
// try to check if we've already seen this file but with a different casing in path
// NOTE: this only makes sense for case-insensitive file systems
if (file && options.forceConsistentCasingInFileNames && getNormalizedAbsolutePath(file.fileName, currentDirectory) !== getNormalizedAbsolutePath(fileName, currentDirectory)) {
if (options.forceConsistentCasingInFileNames && getNormalizedAbsolutePath(file.fileName, currentDirectory) !== getNormalizedAbsolutePath(fileName, currentDirectory)) {
reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd);
}
// If the file was previously found via a node_modules search, but is now being processed as a root file,
// then everything it sucks in may also be marked incorrectly, and needs to be checked again.
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) {
if (sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) {
sourceFilesFoundSearchingNodeModules.set(file.path, false);
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
@ -1550,7 +1550,7 @@ namespace ts {
processImportedModules(file);
}
// See if we need to reprocess the imports due to prior skipped imports
else if (file && modulesWithElidedImports.get(file.path)) {
else if (modulesWithElidedImports.get(file.path)) {
if (currentNodeModulesDepth < maxNodeModuleJsDepth) {
modulesWithElidedImports.set(file.path, false);
processImportedModules(file);
@ -1572,48 +1572,51 @@ namespace ts {
});
filesByName.set(path, file);
if (file) {
sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
setPackageName(file, packageName);
file.path = path;
if (!file) return undefined;
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);
if (existingFile) {
reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile, refPos, refEnd);
}
else {
filesByNameIgnoreCase.set(path, file);
}
}
sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
setPackageName(file, packageName);
file.path = path;
skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
}
// always process imported modules to record module name resolutions
processImportedModules(file);
if (isDefaultLib) {
files.unshift(file);
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);
if (existingFile) {
reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile, refPos, refEnd);
}
else {
files.push(file);
filesByNameIgnoreCase.set(path, file);
}
}
skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
}
// always process imported modules to record module name resolutions
processImportedModules(file);
if (isDefaultLib) {
files.unshift(file);
}
else {
files.push(file);
}
return file;
}
//neater
function setPackageName(file: SourceFile, packageName: string | undefined) {
if (packageName === undefined) return;
if (file.packageName === undefined) {
function setPackageName(file: SourceFile, packageName: string | undefined): void {
if (packageName === undefined) {
return;
}
else if (file.packageName === undefined) {
file.packageName = packageName;
} else {
}
else {
Debug.assert(file.packageName === packageName, "Same source file loaded from two different packages", () =>
`Packages are ${file.packageName} and ${packageName}`);
}
@ -1652,6 +1655,7 @@ namespace ts {
let saveResolution = true;
if (resolvedTypeReferenceDirective) {
if (resolvedTypeReferenceDirective.primary) {
//pass along resolvedTypeReferenceDirective.packageName?
// resolved from the primary path
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, refFile, refPos, refEnd);
}

View file

@ -2280,12 +2280,12 @@ namespace ts {
fileName: string;
/* @internal */ path: Path;
//This will be set if this is resolved by getting something from node_modules.
/** This will be set if the source file is resolved from an external library import. */
/* @internal */ packageName: string | undefined;
text: string;
amdDependencies: AmdDependency[];
moduleName: string; //This is set by an `/// <amd-module name="foo" />` directive.
moduleName: string; // This is set by an `/// <amd-module name="foo" />` directive.
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
languageVariant: LanguageVariant;
@ -3851,8 +3851,11 @@ namespace ts {
* This is optional for backwards-compatibility, but will be added if not provided.
*/
extension: Extension;
//Note: this is a breaking change...
packageName: string | undefined;
/**
* Name of the external library that the resolution came from.
* For `node_modules/@types/foo/bar.d.ts`, the packageName should be `foo/bar`.
*/
packageName?: string;
}
export enum Extension {
@ -3870,6 +3873,7 @@ namespace ts {
failedLookupLocations: string[];
}
//packageName here?
export interface ResolvedTypeReferenceDirective {
// True if the type declaration file was found in a primary lookup location
primary: boolean;

View file

@ -19,7 +19,7 @@ namespace ts {
assert.deepEqual(actual.failedLookupLocations, expectedFailedLookupLocations);
}
export function createResolvedModule(resolvedFileName: string, isExternalLibraryImport = false, packageName: string | undefined = undefined): ResolvedModuleFull {
export function createResolvedModule(resolvedFileName: string, isExternalLibraryImport = false, packageName?: string): ResolvedModuleFull {
return { resolvedFileName, extension: extensionFromPath(resolvedFileName), packageName, isExternalLibraryImport };
}

View file

@ -12,7 +12,7 @@ namespace ts {
};
}
it("printFile", () => {
it("printFile", () => {
const printsCorrectly = makePrintsCorrectly("printsFileCorrectly");
const sourceFile = createSourceFile("source.ts", `
interface A<T> {

View file

@ -482,7 +482,7 @@ namespace ts {
public kind: SyntaxKind.SourceFile;
public _declarationBrand: any;
public fileName: string;
public packageName: string | undefined;
/* @internal */ public packageName: string | undefined;
public path: Path;
public text: string;
public scriptSnapshot: IScriptSnapshot;
@ -941,7 +941,6 @@ namespace ts {
sourceFile.scriptSnapshot = scriptSnapshot;
}
//TODO: this is public, so packageName must go on the end and be optional
export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile {
const text = scriptSnapshot.getText(0, scriptSnapshot.getLength());
const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents, scriptKind);
@ -1142,8 +1141,8 @@ namespace ts {
// Now create a new compiler
const compilerHost: CompilerHost = {
getSourceFile: getOrCreateSourceFile, //packageName
getSourceFileByPath: getOrCreateSourceFileByPath, //packageName
getSourceFile: getOrCreateSourceFile,
getSourceFileByPath: getOrCreateSourceFileByPath,
getCancellationToken: () => cancellationToken,
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitivefileNames,

View file

@ -1,4 +0,0 @@
[0531/071111.044:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:5959
[0531/071111.044:ERROR:node_debugger.cc(87)] Cannot start debugger server
[0531/071111.491:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:5960
[0531/071111.492:ERROR:node_debugger.cc(87)] Cannot start debugger server