diff --git a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts index 8382d456f5..7731f5fea6 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts @@ -119,7 +119,7 @@ export abstract class MockFileSystem implements FileSystem { } ensureDir(path: AbsoluteFsPath): void { - const segments = this.splitPath(path).map(segment => this.getCanonicalPath(segment)); + const segments = this.splitPath(path); let current: Folder = this._fileTree; // Convert the root folder to a canonical empty string `''` (on Windows it would be `'C:'`). @@ -212,29 +212,12 @@ export abstract class MockFileSystem implements FileSystem { protected abstract splitPath(path: T): string[]; dump(): Folder { - return this.cloneFolder(this._fileTree); + return cloneFolder(this._fileTree); } init(folder: Folder): void { - this._fileTree = this.cloneFolder(folder); + this._fileTree = cloneFolder(folder); } - private cloneFolder(folder: Folder): Folder { - const clone: Folder = {}; - for (const path in folder) { - const item = folder[path]; - const canonicalPath = this.getCanonicalPath(path); - if (isSymLink(item)) { - clone[canonicalPath] = new SymLink(this.getCanonicalPath(item.path)); - } else if (isFolder(item)) { - clone[canonicalPath] = this.cloneFolder(item); - } else { - clone[canonicalPath] = folder[path]; - } - } - return clone; - } - - protected findFromPath(path: AbsoluteFsPath, options?: {followSymLinks: boolean}): FindResult { const followSymLinks = !!options && options.followSymLinks; const segments = this.splitPath(path); @@ -246,7 +229,7 @@ export abstract class MockFileSystem implements FileSystem { segments[0] = ''; let current: Entity|null = this._fileTree; while (segments.length) { - current = current[this.getCanonicalPath(segments.shift()!)]; + current = current[segments.shift()!]; if (current === undefined) { return {path, entity: null}; } @@ -269,14 +252,10 @@ export abstract class MockFileSystem implements FileSystem { } protected splitIntoFolderAndFile(path: AbsoluteFsPath): [AbsoluteFsPath, string] { - const segments = this.splitPath(this.getCanonicalPath(path)); + const segments = this.splitPath(path); const file = segments.pop()!; return [path.substring(0, path.length - file.length - 1) as AbsoluteFsPath, file]; } - - protected getCanonicalPath(p: T): T { - return this.isCaseSensitive() ? p : p.toLowerCase() as T; - } } export interface FindResult { path: AbsoluteFsPath; @@ -321,3 +300,18 @@ export function isSymLink(item: Entity|null): item is SymLink { export function isFolder(item: Entity|null): item is Folder { return item !== null && !isFile(item) && !isSymLink(item); } + +function cloneFolder(folder: Folder): Folder { + const clone: Folder = {}; + for (const path in folder) { + const item = folder[path]; + if (isSymLink(item)) { + clone[path] = new SymLink(item.path); + } else if (isFolder(item)) { + clone[path] = cloneFolder(item); + } else { + clone[path] = folder[path]; + } + } + return clone; +}