Skip to content

Commit d5c4f2d

Browse files
author
Andy Hanson
committed
Test for scoped packages
1 parent c7bde6f commit d5c4f2d

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/compiler/moduleNameResolver.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ namespace ts {
832832
*/
833833
function parseNodeModuleFromPath(path: string): { packageDirectory: string, subModuleName: string } | undefined {
834834
path = normalizePath(path);
835-
const idx = path.indexOf(nodeModulesPathPart);
835+
const idx = path.lastIndexOf(nodeModulesPathPart);
836836
if (idx === -1) {
837837
return undefined;
838838
}
@@ -843,12 +843,12 @@ namespace ts {
843843
indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName);
844844
}
845845
const packageDirectory = path.slice(0, indexAfterPackageName);
846-
const subModuleName = removeExtensionAndIndex(path.slice(indexAfterPackageName));
846+
const subModuleName = removeExtensionAndIndex(path.slice(indexAfterPackageName + 1));
847847
return { packageDirectory, subModuleName };
848848
}
849849

850850
function moveToNextDirectorySeparatorIfAvailable(path: string, prevSeparatorIndex: number): number {
851-
const nextSeparatorIndex = path.indexOf(directorySeparator, prevSeparatorIndex);
851+
const nextSeparatorIndex = path.indexOf(directorySeparator, prevSeparatorIndex + 1);
852852
return nextSeparatorIndex === -1 ? prevSeparatorIndex : nextSeparatorIndex;
853853
}
854854

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @noImplicitReferences: true
2+
// @traceResolution: true
3+
4+
// @Filename: /node_modules/a/node_modules/@foo/bar/package.json
5+
{
6+
"name": "@foo/bar",
7+
"version": "1.2.3"
8+
}
9+
10+
// @Filename: /node_modules/a/node_modules/@foo/bar/index.d.ts
11+
export class C {
12+
private x: number;
13+
}
14+
15+
// @Filename: /node_modules/a/index.d.ts
16+
import { C } from "@foo/bar";
17+
export const o: C;
18+
19+
// @Filename: /node_modules/@foo/bar/use.d.ts
20+
import { C } from "./index";
21+
export function use(o: C): void;
22+
23+
// @Filename: /node_modules/@foo/bar/index.d.ts
24+
export class C {
25+
private x: number;
26+
}
27+
28+
// @Filename: /node_modules/@foo/bar/package.json
29+
{
30+
"name": "@foo/bar",
31+
"version": "1.2.3"
32+
}
33+
34+
// @Filename: /index.ts
35+
import { use } from "@foo/bar/use";
36+
import { o } from "a";
37+
38+
use(o);

0 commit comments

Comments
 (0)