mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Add utitlity for stringContains
This commit is contained in:
parent
aa22c56282
commit
e30a66d22f
@ -14012,7 +14012,7 @@ namespace ts {
|
||||
*/
|
||||
function isUnhyphenatedJsxName(name: string | __String) {
|
||||
// - is the only character supported in JSX attribute names that isn't valid in JavaScript identifiers
|
||||
return (name as string).indexOf("-") < 0;
|
||||
return !stringContains(name as string, "-");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1663,7 +1663,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function isUrl(path: string) {
|
||||
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
|
||||
return path && !isRootedDiskPath(path) && stringContains(path, "://");
|
||||
}
|
||||
|
||||
export function pathIsRelative(path: string): boolean {
|
||||
@ -1932,8 +1932,12 @@ namespace ts {
|
||||
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
|
||||
}
|
||||
|
||||
export function stringContains(str: string, substring: string): boolean {
|
||||
return str.indexOf(substring) !== -1;
|
||||
}
|
||||
|
||||
export function hasExtension(fileName: string): boolean {
|
||||
return getBaseFileName(fileName).indexOf(".") >= 0;
|
||||
return stringContains(getBaseFileName(fileName), ".");
|
||||
}
|
||||
|
||||
export function fileExtensionIs(path: string, extension: string): boolean {
|
||||
|
||||
@ -172,7 +172,7 @@ namespace ts {
|
||||
|
||||
function hasInternalAnnotation(range: CommentRange) {
|
||||
const comment = currentText.substring(range.pos, range.end);
|
||||
return comment.indexOf("@internal") >= 0;
|
||||
return stringContains(comment, "@internal");
|
||||
}
|
||||
|
||||
function stripInternal(node: Node) {
|
||||
|
||||
@ -1226,7 +1226,7 @@ namespace ts {
|
||||
// check if numeric literal is a decimal literal that was originally written with a dot
|
||||
const text = getLiteralTextOfNode(<LiteralExpression>expression);
|
||||
return !expression.numericLiteralFlags
|
||||
&& text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0;
|
||||
&& !stringContains(text, tokenToString(SyntaxKind.DotToken));
|
||||
}
|
||||
else if (isPropertyAccessExpression(expression) || isElementAccessExpression(expression)) {
|
||||
// check if constant enum value is integer
|
||||
|
||||
@ -1061,7 +1061,7 @@ namespace ts {
|
||||
export function getPackageNameFromAtTypesDirectory(mangledName: string): string {
|
||||
const withoutAtTypePrefix = removePrefix(mangledName, "@types/");
|
||||
if (withoutAtTypePrefix !== mangledName) {
|
||||
return withoutAtTypePrefix.indexOf(mangledScopedPackageSeparator) !== -1 ?
|
||||
return stringContains(withoutAtTypePrefix, mangledScopedPackageSeparator) ?
|
||||
"@" + withoutAtTypePrefix.replace(mangledScopedPackageSeparator, ts.directorySeparator) :
|
||||
withoutAtTypePrefix;
|
||||
}
|
||||
|
||||
@ -324,7 +324,7 @@ namespace ts {
|
||||
let dirPath = getDirectoryPath(failedLookupLocationPath);
|
||||
|
||||
// If directory path contains node module, get the most parent node_modules directory for watching
|
||||
while (dirPath.indexOf("/node_modules/") !== -1) {
|
||||
while (stringContains(dirPath, "/node_modules/")) {
|
||||
dir = getDirectoryPath(dir);
|
||||
dirPath = getDirectoryPath(dirPath);
|
||||
}
|
||||
@ -334,7 +334,6 @@ namespace ts {
|
||||
return { dir, dirPath };
|
||||
}
|
||||
|
||||
|
||||
// Use some ancestor of the root directory
|
||||
if (rootPath !== undefined) {
|
||||
while (!isInDirectoryPath(dirPath, rootPath)) {
|
||||
|
||||
@ -1205,7 +1205,7 @@ namespace ts.server {
|
||||
projectRootPath?: NormalizedPath) {
|
||||
let searchPath = asNormalizedPath(getDirectoryPath(info.fileName));
|
||||
|
||||
while (!projectRootPath || searchPath.indexOf(projectRootPath) >= 0) {
|
||||
while (!projectRootPath || stringContains(searchPath, projectRootPath)) {
|
||||
const canonicalSearchPath = normalizedPathToPath(searchPath, this.currentDirectory, this.toCanonicalFileName);
|
||||
const tsconfigFileName = asNormalizedPath(combinePaths(searchPath, "tsconfig.json"));
|
||||
let result = action(tsconfigFileName, combinePaths(canonicalSearchPath, "tsconfig.json"));
|
||||
|
||||
@ -1608,7 +1608,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
// No need to analyze lib.d.ts
|
||||
const fileNamesInProject = fileNames.filter(value => value.indexOf("lib.d.ts") < 0);
|
||||
const fileNamesInProject = fileNames.filter(value => !stringContains(value, "lib.d.ts"));
|
||||
if (fileNamesInProject.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ namespace ts.server.typingsInstaller {
|
||||
this.npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation(process.argv[0]);
|
||||
|
||||
// If the NPM path contains spaces and isn't wrapped in quotes, do so.
|
||||
if (this.npmPath.indexOf(" ") !== -1 && this.npmPath[0] !== `"`) {
|
||||
if (stringContains(this.npmPath, " ") && this.npmPath[0] !== `"`) {
|
||||
this.npmPath = `"${this.npmPath}"`;
|
||||
}
|
||||
if (this.log.isEnabled()) {
|
||||
|
||||
@ -195,7 +195,7 @@ namespace ts.Completions.PathCompletions {
|
||||
const normalizedPrefixDirectory = getDirectoryPath(normalizedPrefix);
|
||||
const normalizedPrefixBase = getBaseFileName(normalizedPrefix);
|
||||
|
||||
const fragmentHasPath = fragment.indexOf(directorySeparator) !== -1;
|
||||
const fragmentHasPath = stringContains(fragment, directorySeparator);
|
||||
|
||||
// Try and expand the prefix to include any path from the fragment so that we can limit the readDirectory call
|
||||
const expandedPrefixDirectory = fragmentHasPath ? combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + getDirectoryPath(fragment)) : normalizedPrefixDirectory;
|
||||
@ -235,7 +235,7 @@ namespace ts.Completions.PathCompletions {
|
||||
|
||||
function enumeratePotentialNonRelativeModules(fragment: string, scriptPath: string, options: CompilerOptions, typeChecker: TypeChecker, host: LanguageServiceHost): string[] {
|
||||
// Check If this is a nested module
|
||||
const isNestedModule = fragment.indexOf(directorySeparator) !== -1;
|
||||
const isNestedModule = stringContains(fragment, directorySeparator);
|
||||
const moduleNameFragment = isNestedModule ? fragment.substr(0, fragment.lastIndexOf(directorySeparator)) : undefined;
|
||||
|
||||
// Get modules that the type checker picked up
|
||||
|
||||
@ -660,7 +660,7 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
function getUniqueName(baseName: string, fileText: string): string {
|
||||
let nameText = baseName;
|
||||
for (let i = 1; fileText.indexOf(nameText) !== -1; i++) {
|
||||
for (let i = 1; stringContains(fileText, nameText); i++) {
|
||||
nameText = `${baseName}_${i}`;
|
||||
}
|
||||
return nameText;
|
||||
|
||||
@ -1952,7 +1952,7 @@ namespace ts {
|
||||
function isNodeModulesFile(path: string): boolean {
|
||||
const node_modulesFolderName = "/node_modules/";
|
||||
|
||||
return path.indexOf(node_modulesFolderName) !== -1;
|
||||
return stringContains(path, node_modulesFolderName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user