mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 13:48:46 -05:00
@@ -401,7 +401,8 @@ namespace ts {
|
||||
}
|
||||
directoryPathMap.set(path, result);
|
||||
|
||||
const resolvedFileName = result.resolvedModule && result.resolvedModule.resolvedFileName;
|
||||
const resolvedFileName = result.resolvedModule &&
|
||||
(result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName);
|
||||
// find common prefix between directory and resolved file name
|
||||
// this common prefix should be the shorted path that has the same resolution
|
||||
// directory: /a/b/c/d/e
|
||||
|
||||
@@ -321,6 +321,27 @@ namespace ts {
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/ true));
|
||||
});
|
||||
}
|
||||
|
||||
it("uses originalPath for caching", () => {
|
||||
const host = createModuleResolutionHost(
|
||||
/*hasDirectoryExists*/ true,
|
||||
{
|
||||
name: "/a.ts",
|
||||
symlinks: ["/sub/node_modules/a/index.ts"],
|
||||
},
|
||||
);
|
||||
const cache = createModuleResolutionCache("/", (f) => f);
|
||||
let resolution = nodeModuleNameResolver("a", "/sub/foo.ts", {}, host, cache);
|
||||
checkResolvedModule(resolution.resolvedModule, {
|
||||
extension: Extension.Ts,
|
||||
isExternalLibraryImport: true,
|
||||
originalPath: "/sub/node_modules/a/index.ts",
|
||||
packageId: undefined,
|
||||
resolvedFileName: "/a.ts",
|
||||
});
|
||||
resolution = nodeModuleNameResolver("a", "/foo.ts", {}, host, cache);
|
||||
assert.isUndefined(resolution.resolvedModule, "lookup in parent directory doesn't hit the cache");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Module resolution - relative imports", () => {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
tests/cases/compiler/monorepo/context/src/bindingkey.ts(1,29): error TS2307: Cannot find module '@loopback/context'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/monorepo/core/src/application.ts (0 errors) ====
|
||||
import { Constructor } from "@loopback/context";
|
||||
export type ControllerClass = Constructor<any>;
|
||||
==== tests/cases/compiler/monorepo/core/src/usage.ts (0 errors) ====
|
||||
import { ControllerClass } from './application';
|
||||
import { BindingKey } from '@loopback/context';
|
||||
|
||||
export const CONTROLLER_CLASS = BindingKey.create<ControllerClass>(null as any); // line in question
|
||||
==== tests/cases/compiler/monorepo/context/src/value-promise.ts (0 errors) ====
|
||||
export type Constructor<T> = (...args: any[]) => T;
|
||||
==== tests/cases/compiler/monorepo/context/src/bindingkey.ts (1 errors) ====
|
||||
import { Constructor } from "@loopback/context"
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find module '@loopback/context'.
|
||||
export class BindingKey<T> {
|
||||
readonly __type: T;
|
||||
static create<T extends Constructor<any>>(ctor: T) {
|
||||
return new BindingKey<T>();
|
||||
}
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/monorepo/context/index.ts (0 errors) ====
|
||||
export * from "./src/value-promise";
|
||||
export * from "./src/bindingkey";
|
||||
|
||||
@@ -15,9 +15,9 @@ import { BindingKey } from '@loopback/context';
|
||||
export const CONTROLLER_CLASS = BindingKey.create<ControllerClass>(null as any); // line in question
|
||||
>CONTROLLER_CLASS : BindingKey<import("tests/cases/compiler/monorepo/context/src/value-promise").Constructor<any>>
|
||||
>BindingKey.create<ControllerClass>(null as any) : BindingKey<import("tests/cases/compiler/monorepo/context/src/value-promise").Constructor<any>>
|
||||
>BindingKey.create : <T extends import("tests/cases/compiler/monorepo/context/src/value-promise").Constructor<any>>(ctor: T) => BindingKey<T>
|
||||
>BindingKey.create : <T extends any>(ctor: T) => BindingKey<T>
|
||||
>BindingKey : typeof BindingKey
|
||||
>create : <T extends import("tests/cases/compiler/monorepo/context/src/value-promise").Constructor<any>>(ctor: T) => BindingKey<T>
|
||||
>create : <T extends any>(ctor: T) => BindingKey<T>
|
||||
>null as any : any
|
||||
>null : null
|
||||
|
||||
@@ -37,7 +37,7 @@ export class BindingKey<T> {
|
||||
>__type : T
|
||||
|
||||
static create<T extends Constructor<any>>(ctor: T) {
|
||||
>create : <T extends Constructor<any>>(ctor: T) => BindingKey<T>
|
||||
>create : <T extends any>(ctor: T) => BindingKey<T>
|
||||
>ctor : T
|
||||
|
||||
return new BindingKey<T>();
|
||||
|
||||
Reference in New Issue
Block a user