expose isExternalModuleNameRelative and moduleHasNonRelativeName (#17971)
* expose isExternalModuleNameRelative and moduleHasNonRelativeName Fixes: #17890 * only expose isExternalModuleNameRelative
This commit is contained in:
parent
c82881f36e
commit
69933bd4d1
1 changed files with 9 additions and 20 deletions
|
@ -9,6 +9,15 @@ namespace ts {
|
||||||
export const version = `${versionMajorMinor}.0`;
|
export const version = `${versionMajorMinor}.0`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 "..".
|
||||||
|
// Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module.
|
||||||
|
return pathIsRelative(moduleName) || isRootedDiskPath(moduleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* @internal */
|
/* @internal */
|
||||||
namespace ts {
|
namespace ts {
|
||||||
|
|
||||||
|
@ -40,7 +49,6 @@ namespace ts {
|
||||||
return new MapCtr<T>() as UnderscoreEscapedMap<T>;
|
return new MapCtr<T>() as UnderscoreEscapedMap<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function createSymbolTable(symbols?: ReadonlyArray<Symbol>): SymbolTable {
|
export function createSymbolTable(symbols?: ReadonlyArray<Symbol>): SymbolTable {
|
||||||
const result = createMap<Symbol>() as SymbolTable;
|
const result = createMap<Symbol>() as SymbolTable;
|
||||||
if (symbols) {
|
if (symbols) {
|
||||||
|
@ -1604,18 +1612,10 @@ namespace ts {
|
||||||
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
|
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function pathIsRelative(path: string): boolean {
|
export function pathIsRelative(path: string): boolean {
|
||||||
return /^\.\.?($|[\\/])/.test(path);
|
return /^\.\.?($|[\\/])/.test(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 "..".
|
|
||||||
// Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module.
|
|
||||||
return pathIsRelative(moduleName) || isRootedDiskPath(moduleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use `!isExternalModuleNameRelative(moduleName)` instead. */
|
/** @deprecated Use `!isExternalModuleNameRelative(moduleName)` instead. */
|
||||||
export function moduleHasNonRelativeName(moduleName: string): boolean {
|
export function moduleHasNonRelativeName(moduleName: string): boolean {
|
||||||
return !isExternalModuleNameRelative(moduleName);
|
return !isExternalModuleNameRelative(moduleName);
|
||||||
|
@ -1639,7 +1639,6 @@ namespace ts {
|
||||||
return moduleResolution;
|
return moduleResolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function hasZeroOrOneAsteriskCharacter(str: string): boolean {
|
export function hasZeroOrOneAsteriskCharacter(str: string): boolean {
|
||||||
let seenAsterisk = false;
|
let seenAsterisk = false;
|
||||||
for (let i = 0; i < str.length; i++) {
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
@ -1864,17 +1863,14 @@ namespace ts {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function startsWith(str: string, prefix: string): boolean {
|
export function startsWith(str: string, prefix: string): boolean {
|
||||||
return str.lastIndexOf(prefix, 0) === 0;
|
return str.lastIndexOf(prefix, 0) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function removePrefix(str: string, prefix: string): string {
|
export function removePrefix(str: string, prefix: string): string {
|
||||||
return startsWith(str, prefix) ? str.substr(prefix.length) : str;
|
return startsWith(str, prefix) ? str.substr(prefix.length) : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function endsWith(str: string, suffix: string): boolean {
|
export function endsWith(str: string, suffix: string): boolean {
|
||||||
const expectedPos = str.length - suffix.length;
|
const expectedPos = str.length - suffix.length;
|
||||||
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
|
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
|
||||||
|
@ -1888,7 +1884,6 @@ namespace ts {
|
||||||
return path.length > extension.length && endsWith(path, extension);
|
return path.length > extension.length && endsWith(path, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function fileExtensionIsOneOf(path: string, extensions: ReadonlyArray<string>): boolean {
|
export function fileExtensionIsOneOf(path: string, extensions: ReadonlyArray<string>): boolean {
|
||||||
for (const extension of extensions) {
|
for (const extension of extensions) {
|
||||||
if (fileExtensionIs(path, extension)) {
|
if (fileExtensionIs(path, extension)) {
|
||||||
|
@ -1905,7 +1900,6 @@ namespace ts {
|
||||||
const reservedCharacterPattern = /[^\w\s\/]/g;
|
const reservedCharacterPattern = /[^\w\s\/]/g;
|
||||||
const wildcardCharCodes = [CharacterCodes.asterisk, CharacterCodes.question];
|
const wildcardCharCodes = [CharacterCodes.asterisk, CharacterCodes.question];
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export const commonPackageFolders: ReadonlyArray<string> = ["node_modules", "bower_components", "jspm_packages"];
|
export const commonPackageFolders: ReadonlyArray<string> = ["node_modules", "bower_components", "jspm_packages"];
|
||||||
|
|
||||||
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
|
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
|
||||||
|
@ -2523,7 +2517,6 @@ namespace ts {
|
||||||
* Return an exact match if possible, or a pattern match, or undefined.
|
* Return an exact match if possible, or a pattern match, or undefined.
|
||||||
* (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
|
* (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
|
||||||
*/
|
*/
|
||||||
/* @internal */
|
|
||||||
export function matchPatternOrExact(patternStrings: ReadonlyArray<string>, candidate: string): string | Pattern | undefined {
|
export function matchPatternOrExact(patternStrings: ReadonlyArray<string>, candidate: string): string | Pattern | undefined {
|
||||||
const patterns: Pattern[] = [];
|
const patterns: Pattern[] = [];
|
||||||
for (const patternString of patternStrings) {
|
for (const patternString of patternStrings) {
|
||||||
|
@ -2540,7 +2533,6 @@ namespace ts {
|
||||||
return findBestPatternMatch(patterns, _ => _, candidate);
|
return findBestPatternMatch(patterns, _ => _, candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function patternText({prefix, suffix}: Pattern): string {
|
export function patternText({prefix, suffix}: Pattern): string {
|
||||||
return `${prefix}*${suffix}`;
|
return `${prefix}*${suffix}`;
|
||||||
}
|
}
|
||||||
|
@ -2549,14 +2541,12 @@ namespace ts {
|
||||||
* Given that candidate matches pattern, returns the text matching the '*'.
|
* Given that candidate matches pattern, returns the text matching the '*'.
|
||||||
* E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
|
* E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
|
||||||
*/
|
*/
|
||||||
/* @internal */
|
|
||||||
export function matchedText(pattern: Pattern, candidate: string): string {
|
export function matchedText(pattern: Pattern, candidate: string): string {
|
||||||
Debug.assert(isPatternMatch(pattern, candidate));
|
Debug.assert(isPatternMatch(pattern, candidate));
|
||||||
return candidate.substr(pattern.prefix.length, candidate.length - pattern.suffix.length);
|
return candidate.substr(pattern.prefix.length, candidate.length - pattern.suffix.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the object corresponding to the best pattern to match `candidate`. */
|
/** Return the object corresponding to the best pattern to match `candidate`. */
|
||||||
/* @internal */
|
|
||||||
export function findBestPatternMatch<T>(values: ReadonlyArray<T>, getPattern: (value: T) => Pattern, candidate: string): T | undefined {
|
export function findBestPatternMatch<T>(values: ReadonlyArray<T>, getPattern: (value: T) => Pattern, candidate: string): T | undefined {
|
||||||
let matchedValue: T | undefined = undefined;
|
let matchedValue: T | undefined = undefined;
|
||||||
// use length of prefix as betterness criteria
|
// use length of prefix as betterness criteria
|
||||||
|
@ -2579,7 +2569,6 @@ namespace ts {
|
||||||
endsWith(candidate, suffix);
|
endsWith(candidate, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @internal */
|
|
||||||
export function tryParsePattern(pattern: string): Pattern | undefined {
|
export function tryParsePattern(pattern: string): Pattern | undefined {
|
||||||
// This should be verified outside of here and a proper error thrown.
|
// This should be verified outside of here and a proper error thrown.
|
||||||
Debug.assert(hasZeroOrOneAsteriskCharacter(pattern));
|
Debug.assert(hasZeroOrOneAsteriskCharacter(pattern));
|
||||||
|
|
Loading…
Reference in a new issue