mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Merge pull request #9676 from Microsoft/relative_module
Treat "." and ".." as relative module names
This commit is contained in:
@@ -900,9 +900,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function fileExtensionIs(path: string, extension: string): boolean {
|
||||
const pathLen = path.length;
|
||||
const extLen = extension.length;
|
||||
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
|
||||
return path.length > extension.length && endsWith(path, extension);
|
||||
}
|
||||
|
||||
export function fileExtensionIsAny(path: string, extensions: string[]): boolean {
|
||||
@@ -915,7 +913,6 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
|
||||
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
|
||||
// proof.
|
||||
|
||||
@@ -112,13 +112,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function moduleHasNonRelativeName(moduleName: string): boolean {
|
||||
if (isRootedDiskPath(moduleName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const i = moduleName.lastIndexOf("./", 1);
|
||||
const startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === CharacterCodes.dot);
|
||||
return !startsWithDotSlashOrDotDotSlash;
|
||||
return !(isRootedDiskPath(moduleName) || isExternalModuleNameRelative(moduleName));
|
||||
}
|
||||
|
||||
interface ModuleResolutionState {
|
||||
|
||||
@@ -1218,7 +1218,7 @@ namespace ts {
|
||||
export function isExternalModuleNameRelative(moduleName: string): boolean {
|
||||
// TypeScript 1.0 spec (April 2014): 11.2.1
|
||||
// An external module name is "relative" if the first term is "." or "..".
|
||||
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
|
||||
return /^\.\.?($|[\\/])/.test(moduleName);
|
||||
}
|
||||
|
||||
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
|
||||
@@ -3120,6 +3120,6 @@ namespace ts {
|
||||
|
||||
export function endsWith(str: string, suffix: string): boolean {
|
||||
const expectedPos = str.length - suffix.length;
|
||||
return str.indexOf(suffix, expectedPos) === expectedPos;
|
||||
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1377,31 +1377,27 @@ namespace Harness {
|
||||
writeByteOrderMark: boolean;
|
||||
}
|
||||
|
||||
function stringEndsWith(str: string, end: string) {
|
||||
return str.substr(str.length - end.length) === end;
|
||||
}
|
||||
|
||||
export function isTS(fileName: string) {
|
||||
return stringEndsWith(fileName, ".ts");
|
||||
return ts.endsWith(fileName, ".ts");
|
||||
}
|
||||
|
||||
export function isTSX(fileName: string) {
|
||||
return stringEndsWith(fileName, ".tsx");
|
||||
return ts.endsWith(fileName, ".tsx");
|
||||
}
|
||||
|
||||
export function isDTS(fileName: string) {
|
||||
return stringEndsWith(fileName, ".d.ts");
|
||||
return ts.endsWith(fileName, ".d.ts");
|
||||
}
|
||||
|
||||
export function isJS(fileName: string) {
|
||||
return stringEndsWith(fileName, ".js");
|
||||
return ts.endsWith(fileName, ".js");
|
||||
}
|
||||
export function isJSX(fileName: string) {
|
||||
return stringEndsWith(fileName, ".jsx");
|
||||
return ts.endsWith(fileName, ".jsx");
|
||||
}
|
||||
|
||||
export function isJSMap(fileName: string) {
|
||||
return stringEndsWith(fileName, ".js.map") || stringEndsWith(fileName, ".jsx.map");
|
||||
return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map");
|
||||
}
|
||||
|
||||
/** Contains the code and errors of a compilation and some helper methods to check its status. */
|
||||
|
||||
@@ -514,16 +514,6 @@ namespace ts {
|
||||
return str === str.toLowerCase();
|
||||
}
|
||||
|
||||
function startsWith(string: string, search: string) {
|
||||
for (let i = 0, n = search.length; i < n; i++) {
|
||||
if (string.charCodeAt(i) !== search.charCodeAt(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Assumes 'value' is already lowercase.
|
||||
function indexOfIgnoringCase(string: string, value: string): number {
|
||||
for (let i = 0, n = string.length - value.length; i <= n; i++) {
|
||||
|
||||
Reference in New Issue
Block a user