Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ namespace ts {
*/
export function matchedText(pattern: Pattern, candidate: string): string {
Debug.assert(isPatternMatch(pattern, candidate));
return candidate.substr(pattern.prefix.length, candidate.length - pattern.suffix.length);
return candidate.substring(pattern.prefix.length, candidate.length - pattern.suffix.length);
}

/** Return the object corresponding to the best pattern to match `candidate`. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/pathMappingBasedModuleResolution8_classic.ts] ////

//// [index.ts]
import {x} from "@speedy/folder1/testing"

//// [index.ts]
export const x = 1 + 2;


//// [index.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.__esModule = true;
exports.x = 1 + 2;
});
//// [index.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.__esModule = true;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== c:/root/index.ts ===
import {x} from "@speedy/folder1/testing"
>x : Symbol(x, Decl(index.ts, 0, 8))

=== c:/root/folder1/dist/index.ts ===
export const x = 1 + 2;
>x : Symbol(x, Decl(index.ts, 0, 12))

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"======== Resolving module '@speedy/folder1/testing' from 'c:/root/index.ts'. ========",
"Explicitly specified module resolution kind: 'Classic'.",
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name '@speedy/folder1/testing'.",
"'paths' option is specified, looking for a pattern to match module name '@speedy/folder1/testing'.",
"Module name '@speedy/folder1/testing', matched pattern '@speedy/*/testing'.",
"Trying substitution '*/dist/index.ts', candidate module location: 'folder1/dist/index.ts'.",
"File 'c:/root/folder1/dist/index.ts' exist - use it as a name resolution result.",
"======== Module name '@speedy/folder1/testing' was successfully resolved to 'c:/root/folder1/dist/index.ts'. ========"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== c:/root/index.ts ===
import {x} from "@speedy/folder1/testing"
>x : number

=== c:/root/folder1/dist/index.ts ===
export const x = 1 + 2;
>x : number
>1 + 2 : number
>1 : 1
>2 : 2

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/pathMappingBasedModuleResolution8_node.ts] ////

//// [index.ts]
import {x} from "@speedy/folder1/testing"

//// [index.ts]
export const x = 1 + 2;


//// [index.js]
"use strict";
exports.__esModule = true;
exports.x = 1 + 2;
//// [index.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== c:/root/index.ts ===
import {x} from "@speedy/folder1/testing"
>x : Symbol(x, Decl(index.ts, 0, 8))

=== c:/root/folder1/dist/index.ts ===
export const x = 1 + 2;
>x : Symbol(x, Decl(index.ts, 0, 12))

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"======== Resolving module '@speedy/folder1/testing' from 'c:/root/index.ts'. ========",
"Explicitly specified module resolution kind: 'NodeJs'.",
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name '@speedy/folder1/testing'.",
"'paths' option is specified, looking for a pattern to match module name '@speedy/folder1/testing'.",
"Module name '@speedy/folder1/testing', matched pattern '@speedy/*/testing'.",
"Trying substitution '*/dist/index.ts', candidate module location: 'folder1/dist/index.ts'.",
"File 'c:/root/folder1/dist/index.ts' exist - use it as a name resolution result.",
"======== Module name '@speedy/folder1/testing' was successfully resolved to 'c:/root/folder1/dist/index.ts'. ========"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== c:/root/index.ts ===
import {x} from "@speedy/folder1/testing"
>x : number

=== c:/root/folder1/dist/index.ts ===
export const x = 1 + 2;
>x : number
>1 + 2 : number
>1 : 1
>2 : 2

21 changes: 21 additions & 0 deletions tests/cases/compiler/pathMappingBasedModuleResolution8_classic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @moduleResolution: classic
// @module: amd
// @traceResolution: true

// @filename: c:/root/tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@speedy/*/testing": [
"*/dist/index.ts"
]
}
}
}

// @filename: c:/root/index.ts
import {x} from "@speedy/folder1/testing"

// @filename: c:/root/folder1/dist/index.ts
export const x = 1 + 2;
21 changes: 21 additions & 0 deletions tests/cases/compiler/pathMappingBasedModuleResolution8_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @moduleResolution: node
// @module: commonjs
// @traceResolution: true

// @filename: c:/root/tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@speedy/*/testing": [
"*/dist/index.ts"
]
}
}
}

// @filename: c:/root/index.ts
import {x} from "@speedy/folder1/testing"

// @filename: c:/root/folder1/dist/index.ts
export const x = 1 + 2;