boolean-trivia lint rule: Enforce space between comment and argument
This commit is contained in:
parent
c38d2a188a
commit
ed5eca2b7b
18
Gulpfile.ts
18
Gulpfile.ts
|
@ -384,7 +384,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) {
|
|||
}
|
||||
|
||||
gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
|
||||
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
|
||||
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
|
||||
return localCompilerProject.src()
|
||||
.pipe(newer(builtLocalCompiler))
|
||||
.pipe(sourcemaps.init())
|
||||
|
@ -395,14 +395,14 @@ gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
|
|||
});
|
||||
|
||||
gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
|
||||
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
|
||||
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ false));
|
||||
const {js, dts} = servicesProject.src()
|
||||
.pipe(newer(servicesFile))
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(servicesProject());
|
||||
const completedJs = js.pipe(prependCopyright())
|
||||
.pipe(sourcemaps.write("."));
|
||||
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
|
||||
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/ true))
|
||||
.pipe(insert.transform((contents, file) => {
|
||||
file.path = standaloneDefinitionsFile;
|
||||
return contents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4");
|
||||
|
@ -429,7 +429,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
|
|||
// cancellationToken.js
|
||||
const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js");
|
||||
gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
|
||||
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
|
||||
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
|
||||
return cancellationTokenProject.src()
|
||||
.pipe(newer(cancellationTokenJs))
|
||||
.pipe(sourcemaps.init())
|
||||
|
@ -442,7 +442,7 @@ gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
|
|||
// typingsInstallerFile.js
|
||||
const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js");
|
||||
gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
|
||||
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
|
||||
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
|
||||
return cancellationTokenProject.src()
|
||||
.pipe(newer(typingsInstallerJs))
|
||||
.pipe(sourcemaps.init())
|
||||
|
@ -455,7 +455,7 @@ gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
|
|||
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
|
||||
|
||||
gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => {
|
||||
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
|
||||
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
|
||||
return serverProject.src()
|
||||
.pipe(newer(serverFile))
|
||||
.pipe(sourcemaps.init())
|
||||
|
@ -479,7 +479,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => {
|
|||
js.pipe(prependCopyright())
|
||||
.pipe(sourcemaps.write("."))
|
||||
.pipe(gulp.dest("src/server")),
|
||||
dts.pipe(prependCopyright(/*outputCopyright*/true))
|
||||
dts.pipe(prependCopyright(/*outputCopyright*/ true))
|
||||
.pipe(insert.transform((content) => {
|
||||
return content + "\r\nexport = ts;\r\nexport as namespace ts;";
|
||||
}))
|
||||
|
@ -551,7 +551,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
|
|||
// Task to build the tests infrastructure using the built compiler
|
||||
const run = path.join(builtLocalDirectory, "run.js");
|
||||
gulp.task(run, /*help*/ false, [servicesFile], () => {
|
||||
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
|
||||
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
|
||||
return testProject.src()
|
||||
.pipe(newer(run))
|
||||
.pipe(sourcemaps.init())
|
||||
|
@ -757,7 +757,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
|
|||
browserify(intoStream(file.contents), { debug: true })
|
||||
.bundle((err, res) => {
|
||||
// assumes file.contents is a Buffer
|
||||
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON());
|
||||
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/ true).toJSON());
|
||||
delete maps.sourceRoot;
|
||||
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
|
||||
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
|
||||
|
|
|
@ -8,7 +8,8 @@ export class Rule extends Lint.Rules.AbstractRule {
|
|||
}
|
||||
|
||||
function walk(ctx: Lint.WalkContext<void>): void {
|
||||
ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void {
|
||||
const { sourceFile } = ctx;
|
||||
ts.forEachChild(sourceFile, function recur(node: ts.Node): void {
|
||||
if (node.kind === ts.SyntaxKind.CallExpression) {
|
||||
checkCall(node as ts.CallExpression);
|
||||
}
|
||||
|
@ -16,61 +17,79 @@ function walk(ctx: Lint.WalkContext<void>): void {
|
|||
});
|
||||
|
||||
function checkCall(node: ts.CallExpression): void {
|
||||
for (const arg of node.arguments) {
|
||||
switch (arg.kind) {
|
||||
case ts.SyntaxKind.TrueKeyword:
|
||||
case ts.SyntaxKind.FalseKeyword:
|
||||
case ts.SyntaxKind.NullKeyword:
|
||||
break;
|
||||
case ts.SyntaxKind.Identifier:
|
||||
if ((arg as ts.Identifier).originalKeywordKind !== ts.SyntaxKind.UndefinedKeyword) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
|
||||
const methodName = (node.expression as ts.PropertyAccessExpression).name.text;
|
||||
// Skip certain method names whose parameter names are not informative
|
||||
if (methodName.indexOf("set") === 0) {
|
||||
continue;
|
||||
}
|
||||
switch (methodName) {
|
||||
case "apply":
|
||||
case "assert":
|
||||
case "call":
|
||||
case "equal":
|
||||
case "fail":
|
||||
case "isTrue":
|
||||
case "output":
|
||||
case "stringify":
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (node.expression.kind === ts.SyntaxKind.Identifier) {
|
||||
const functionName = (node.expression as ts.Identifier).text;
|
||||
// Skip certain function names whose parameter names are not informative
|
||||
if (functionName.indexOf("set") === 0) {
|
||||
continue;
|
||||
}
|
||||
switch (functionName) {
|
||||
case "assert":
|
||||
case "contains":
|
||||
case "createAnonymousType":
|
||||
case "createImportSpecifier":
|
||||
case "createProperty":
|
||||
case "createSignature":
|
||||
case "resolveName":
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0);
|
||||
if (!(ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia)) {
|
||||
ctx.addFailureAtNode(arg, 'Tag boolean argument with parameter name');
|
||||
if (!shouldIgnoreCalledExpression(node.expression)) {
|
||||
for (const arg of node.arguments) {
|
||||
checkArg(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Skip certain function/method names whose parameter names are not informative. */
|
||||
function shouldIgnoreCalledExpression(expression: ts.Expression): boolean {
|
||||
if (expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
|
||||
const methodName = (expression as ts.PropertyAccessExpression).name.text;
|
||||
if (methodName.indexOf("set") === 0) {
|
||||
return true;
|
||||
}
|
||||
switch (methodName) {
|
||||
case "apply":
|
||||
case "assert":
|
||||
case "call":
|
||||
case "equal":
|
||||
case "fail":
|
||||
case "isTrue":
|
||||
case "output":
|
||||
case "stringify":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (expression.kind === ts.SyntaxKind.Identifier) {
|
||||
const functionName = (expression as ts.Identifier).text;
|
||||
if (functionName.indexOf("set") === 0) {
|
||||
return true;
|
||||
}
|
||||
switch (functionName) {
|
||||
case "assert":
|
||||
case "contains":
|
||||
case "createAnonymousType":
|
||||
case "createImportSpecifier":
|
||||
case "createProperty":
|
||||
case "createSignature":
|
||||
case "resolveName":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkArg(arg: ts.Expression): void {
|
||||
if (!isTrivia(arg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ranges = ts.getTrailingCommentRanges(sourceFile.text, arg.pos) || ts.getLeadingCommentRanges(sourceFile.text, arg.pos);
|
||||
if (ranges === undefined || ranges.length !== 1 || ranges[0].kind !== ts.SyntaxKind.MultiLineCommentTrivia) {
|
||||
ctx.addFailureAtNode(arg, "Tag boolean argument with parameter name");
|
||||
return;
|
||||
}
|
||||
|
||||
const range = ranges[0];
|
||||
const argStart = arg.getStart(sourceFile);
|
||||
if (range.end + 1 !== argStart && sourceFile.text.slice(range.end, argStart).indexOf("\n") === -1) {
|
||||
ctx.addFailureAtNode(arg, "There should be 1 space between an argument and its comment.");
|
||||
}
|
||||
}
|
||||
|
||||
function isTrivia(arg: ts.Expression): boolean {
|
||||
switch (arg.kind) {
|
||||
case ts.SyntaxKind.TrueKeyword:
|
||||
case ts.SyntaxKind.FalseKeyword:
|
||||
case ts.SyntaxKind.NullKeyword:
|
||||
return true;
|
||||
case ts.SyntaxKind.Identifier:
|
||||
return (arg as ts.Identifier).originalKeywordKind === ts.SyntaxKind.UndefinedKeyword;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -453,7 +453,7 @@ namespace ts {
|
|||
return local;
|
||||
}
|
||||
else {
|
||||
return declareSymbol(container.locals, /*parent*/undefined, node, symbolFlags, symbolExcludes);
|
||||
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2333,7 +2333,7 @@ namespace ts {
|
|||
|
||||
function bindThisPropertyAssignment(node: BinaryExpression) {
|
||||
Debug.assert(isInJavaScriptFile(node));
|
||||
const container = getThisContainer(node, /*includeArrowFunctions*/false);
|
||||
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
|
||||
switch (container.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
|
@ -2423,7 +2423,7 @@ namespace ts {
|
|||
function bindCallExpression(node: CallExpression) {
|
||||
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
|
||||
// this check if we've already seen the module indicator
|
||||
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) {
|
||||
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/ false)) {
|
||||
setCommonJsModuleIndicator(node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2620,7 +2620,7 @@ namespace ts {
|
|||
propertyName,
|
||||
optionalToken,
|
||||
propertyTypeNode,
|
||||
/*initializer*/undefined));
|
||||
/*initializer*/ undefined));
|
||||
}
|
||||
}
|
||||
return typeElements.length ? typeElements : undefined;
|
||||
|
@ -2754,7 +2754,7 @@ namespace ts {
|
|||
|
||||
/** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */
|
||||
function getSymbolChain(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): Symbol[] | undefined {
|
||||
let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/false);
|
||||
let accessibleSymbolChain = getAccessibleSymbolChain(symbol, context.enclosingDeclaration, meaning, /*useOnlyExternalAliasing*/ false);
|
||||
let parentSymbol: Symbol;
|
||||
|
||||
if (!accessibleSymbolChain ||
|
||||
|
@ -13386,7 +13386,7 @@ namespace ts {
|
|||
/// non-intrinsic elements' attributes type is the element instance type)
|
||||
function getJsxElementPropertiesName() {
|
||||
// JSX
|
||||
const jsxNamespace = getGlobalSymbol(JsxNames.JSX, SymbolFlags.Namespace, /*diagnosticMessage*/undefined);
|
||||
const jsxNamespace = getGlobalSymbol(JsxNames.JSX, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined);
|
||||
// JSX.ElementAttributesProperty [symbol]
|
||||
const attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, SymbolFlags.Type);
|
||||
// JSX.ElementAttributesProperty [type]
|
||||
|
@ -15615,7 +15615,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function isCommonJsRequire(node: Node) {
|
||||
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
return false;
|
||||
}
|
||||
// Make sure require is not a local function
|
||||
|
@ -17071,7 +17071,7 @@ namespace ts {
|
|||
function getTypeOfExpression(node: Expression, cache?: boolean) {
|
||||
// Optimize for the common case of a call to a function with a single non-generic call
|
||||
// signature where we can just fetch the return type without checking the arguments.
|
||||
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
const funcType = checkNonNullExpression((<CallExpression>node).expression);
|
||||
const signature = getSingleCallSignature(funcType);
|
||||
if (signature && !signature.typeParameters) {
|
||||
|
@ -21859,7 +21859,7 @@ namespace ts {
|
|||
}
|
||||
else if (isTypeReferenceIdentifier(<EntityName>entityName)) {
|
||||
const meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace;
|
||||
return resolveEntityName(<EntityName>entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/true);
|
||||
return resolveEntityName(<EntityName>entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
|
||||
}
|
||||
else if (entityName.parent.kind === SyntaxKind.JsxAttribute) {
|
||||
return getJsxAttributePropertySymbol(<JsxAttribute>entityName.parent);
|
||||
|
@ -22682,7 +22682,7 @@ namespace ts {
|
|||
? SymbolFlags.Value | SymbolFlags.ExportValue
|
||||
: SymbolFlags.Type | SymbolFlags.Namespace;
|
||||
|
||||
const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/true);
|
||||
const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/ true);
|
||||
return symbol && symbol !== unknownSymbol ? getTypeReferenceDirectivesForSymbol(symbol, meaning) : undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -1170,7 +1170,7 @@ namespace ts {
|
|||
const relativeDifference = convertToRelativePath(extendedDirname, basePath, getCanonicalFileName);
|
||||
const updatePath: (path: string) => string = path => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
|
||||
// Merge configs (copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios)
|
||||
const result = parseJsonConfigFileContent(extendedResult.config, host, extendedDirname, /*existingOptions*/undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath]));
|
||||
const result = parseJsonConfigFileContent(extendedResult.config, host, extendedDirname, /*existingOptions*/ undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath]));
|
||||
errors.push(...result.errors);
|
||||
const [include, exclude, files] = map(["include", "exclude", "files"], key => {
|
||||
if (!json[key] && extendedResult.config[key]) {
|
||||
|
|
|
@ -656,7 +656,7 @@ namespace ts {
|
|||
// A path mapping may have a ".ts" extension; in contrast to an import, which should omit it.
|
||||
const tsExtension = tryGetExtensionFromPath(candidate);
|
||||
if (tsExtension !== undefined) {
|
||||
const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/false, state);
|
||||
const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
return path && { path, extension: tsExtension };
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ namespace ts {
|
|||
return { resolvedModule: undefined, failedLookupLocations };
|
||||
|
||||
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> {
|
||||
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/true);
|
||||
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true);
|
||||
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
return toSearchResult({ resolved, isExternalLibraryImport: false });
|
||||
|
@ -710,7 +710,7 @@ namespace ts {
|
|||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/true);
|
||||
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
|
||||
return resolved && toSearchResult({ resolved, isExternalLibraryImport: false });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3039,7 +3039,7 @@ namespace ts {
|
|||
// If we have an arrow, then try to parse the body. Even if not, try to parse if we
|
||||
// have an opening brace, just in case we're in an error state.
|
||||
const lastToken = token();
|
||||
arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>");
|
||||
arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "=>");
|
||||
arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken)
|
||||
? parseArrowFunctionExpressionBody(isAsync)
|
||||
: parseIdentifier();
|
||||
|
@ -3808,7 +3808,7 @@ namespace ts {
|
|||
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
|
||||
// of one sort or another.
|
||||
if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
|
||||
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/true));
|
||||
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true));
|
||||
if (invalidElement) {
|
||||
parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element);
|
||||
const badNode = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, result.pos);
|
||||
|
@ -5818,7 +5818,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function processReferenceComments(sourceFile: SourceFile): void {
|
||||
const triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, LanguageVariant.Standard, sourceText);
|
||||
const triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, LanguageVariant.Standard, sourceText);
|
||||
const referencedFiles: FileReference[] = [];
|
||||
const typeReferenceDirectives: FileReference[] = [];
|
||||
const amdDependencies: { path: string; name: string }[] = [];
|
||||
|
|
|
@ -1291,7 +1291,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function collectRequireCalls(node: Node): void {
|
||||
if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
|
||||
if (isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
(imports || (imports = [])).push(<StringLiteral>(<CallExpression>node).arguments[0]);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3787,11 +3787,11 @@ namespace FourSlashInterface {
|
|||
}
|
||||
|
||||
public printCurrentFileStateWithWhitespace() {
|
||||
this.state.printCurrentFileState(/*makeWhitespaceVisible*/true);
|
||||
this.state.printCurrentFileState(/*makeWhitespaceVisible*/ true);
|
||||
}
|
||||
|
||||
public printCurrentFileStateWithoutCaret() {
|
||||
this.state.printCurrentFileState(/*makeWhitespaceVisible*/false, /*makeCaretVisible*/false);
|
||||
this.state.printCurrentFileState(/*makeWhitespaceVisible*/ false, /*makeCaretVisible*/ false);
|
||||
}
|
||||
|
||||
public printCurrentQuickInfo() {
|
||||
|
|
|
@ -210,7 +210,7 @@ namespace Harness.LanguageService {
|
|||
}
|
||||
readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[] {
|
||||
return ts.matchFiles(path, extensions, exclude, include,
|
||||
/*useCaseSensitiveFileNames*/false,
|
||||
/*useCaseSensitiveFileNames*/ false,
|
||||
this.getCurrentDirectory(),
|
||||
(p) => this.virtualFileSystem.getAccessibleFileSystemEntries(p));
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace ts {
|
|||
};
|
||||
|
||||
const projectService = new server.ProjectService(serverHost, logger, { isCancellationRequested: () => false }, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
|
||||
const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /* openedByClient */true, /*containingProject*/ undefined);
|
||||
const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /*openedByClient*/ true, /*containingProject*/ undefined);
|
||||
const project = projectService.createInferredProjectWithRootFileIfNecessary(rootScriptInfo);
|
||||
project.setCompilerOptions({ module: ts.ModuleKind.AMD } );
|
||||
return {
|
||||
|
|
|
@ -144,14 +144,14 @@ namespace ts {
|
|||
|
||||
const resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile, indexFile));
|
||||
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(indexPath, /*isExternalLibraryImport*/true));
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(indexPath, /*isExternalLibraryImport*/ true));
|
||||
}
|
||||
}
|
||||
|
||||
it("module name as directory - handle invalid 'typings'", () => {
|
||||
testTypingsIgnored(["a", "b"]);
|
||||
testTypingsIgnored({ "a": "b" });
|
||||
testTypingsIgnored(/*typings*/true);
|
||||
testTypingsIgnored(/*typings*/ true);
|
||||
testTypingsIgnored(/*typings*/ null); // tslint:disable-line no-null-keyword
|
||||
testTypingsIgnored(/*typings*/ undefined);
|
||||
});
|
||||
|
@ -530,7 +530,7 @@ import b = require("./moduleB");
|
|||
check("m1", main, m1);
|
||||
check("m2", main, m2);
|
||||
check("m3", main, m3Typings);
|
||||
check("m4", main, m4, /*isExternalLibraryImport*/true);
|
||||
check("m4", main, m4, /*isExternalLibraryImport*/ true);
|
||||
|
||||
function check(name: string, caller: File, expected: File, isExternalLibraryImport = false) {
|
||||
const result = resolveModuleName(name, caller.name, options, host);
|
||||
|
|
|
@ -34,7 +34,7 @@ describe("PreProcessFile:", function () {
|
|||
describe("Test preProcessFiles,", function () {
|
||||
it("Correctly return referenced files from triple slash", function () {
|
||||
test("///<reference path = \"refFile1.ts\" />" + "\n" + "///<reference path =\"refFile2.ts\"/>" + "\n" + "///<reference path=\"refFile3.ts\" />" + "\n" + "///<reference path= \"..\\refFile4d.ts\" />",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 37 }, { fileName: "refFile2.ts", pos: 38, end: 73 },
|
||||
|
@ -48,7 +48,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Do not return reference path because of invalid triple-slash syntax", function () {
|
||||
test("///<reference path\"refFile1.ts\" />" + "\n" + "///<reference path =\"refFile2.ts\">" + "\n" + "///<referencepath=\"refFile3.ts\" />" + "\n" + "///<reference pat= \"refFile4d.ts\" />",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: <ts.FileReference[]>[],
|
||||
|
@ -61,7 +61,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Correctly return imported files", function () {
|
||||
test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: <ts.FileReference[]>[],
|
||||
|
@ -88,7 +88,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Do not return import path because of invalid import syntax", function () {
|
||||
test("import i1 require(\"r1.ts\"); import = require(\"r2.ts\") import i3= require(\"r3.ts\"); import i5",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: <ts.FileReference[]>[],
|
||||
|
@ -101,7 +101,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Correctly return referenced files and import files", function () {
|
||||
test("///<reference path=\"refFile1.ts\" />" + "\n" + "///<reference path =\"refFile2.ts\"/>" + "\n" + "import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\");",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 35 }, { fileName: "refFile2.ts", pos: 36, end: 71 }],
|
||||
|
@ -114,7 +114,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Correctly return referenced files and import files even with some invalid syntax", function () {
|
||||
test("///<reference path=\"refFile1.ts\" />" + "\n" + "///<reference path \"refFile2.ts\"/>" + "\n" + "import i1 = require(\"r1.ts\"); import = require(\"r2.ts\"); import i2 = require(\"r3.ts\");",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [{ fileName: "refFile1.ts", pos: 0, end: 35 }],
|
||||
|
@ -133,7 +133,7 @@ describe("PreProcessFile:", function () {
|
|||
"import {a as A} from \"m5\";" + "\n" +
|
||||
"import {a as A, b, c as C} from \"m6\";" + "\n" +
|
||||
"import def , {a, b, c as C} from \"m7\";" + "\n",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
@ -157,7 +157,7 @@ describe("PreProcessFile:", function () {
|
|||
"export {a} from \"m2\";" + "\n" +
|
||||
"export {a as A} from \"m3\";" + "\n" +
|
||||
"export {a as A, b, c as C} from \"m4\";" + "\n",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
@ -194,7 +194,7 @@ describe("PreProcessFile:", function () {
|
|||
|
||||
it("Correctly handles export import declarations", function () {
|
||||
test("export import a = require(\"m1\");",
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ false,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
@ -213,7 +213,7 @@ describe("PreProcessFile:", function () {
|
|||
foo(require('m3'));
|
||||
var z = { f: require('m4') }
|
||||
`,
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ true,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
@ -233,7 +233,7 @@ describe("PreProcessFile:", function () {
|
|||
define(["mod1", "mod2"], (m1, m2) => {
|
||||
});
|
||||
`,
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ true,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
@ -251,7 +251,7 @@ describe("PreProcessFile:", function () {
|
|||
define("mod", ["mod1", "mod2"], (m1, m2) => {
|
||||
});
|
||||
`,
|
||||
/*readImportFile*/true,
|
||||
/*readImportFile*/ true,
|
||||
/*detectJavaScriptImports*/ true,
|
||||
{
|
||||
referencedFiles: [],
|
||||
|
|
|
@ -1795,9 +1795,9 @@ namespace ts.projectSystem {
|
|||
|
||||
// Open HTML file
|
||||
projectService.applyChangesInOpenFiles(
|
||||
/*openFiles*/[{ fileName: file2.path, hasMixedContent: true, scriptKind: ScriptKind.JS, content: `var hello = "hello";` }],
|
||||
/*changedFiles*/undefined,
|
||||
/*closedFiles*/undefined);
|
||||
/*openFiles*/ [{ fileName: file2.path, hasMixedContent: true, scriptKind: ScriptKind.JS, content: `var hello = "hello";` }],
|
||||
/*changedFiles*/ undefined,
|
||||
/*closedFiles*/ undefined);
|
||||
|
||||
// Now HTML file is included in the project
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
|
@ -1810,9 +1810,9 @@ namespace ts.projectSystem {
|
|||
|
||||
// Close HTML file
|
||||
projectService.applyChangesInOpenFiles(
|
||||
/*openFiles*/undefined,
|
||||
/*changedFiles*/undefined,
|
||||
/*closedFiles*/[file2.path]);
|
||||
/*openFiles*/ undefined,
|
||||
/*changedFiles*/ undefined,
|
||||
/*closedFiles*/ [file2.path]);
|
||||
|
||||
// HTML file is still included in project
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
|
@ -2270,12 +2270,12 @@ namespace ts.projectSystem {
|
|||
projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;");
|
||||
|
||||
projectService.checkNumberOfProjects({ externalProjects: 1 });
|
||||
projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
|
||||
projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(f1.path);
|
||||
projectService.closeClientFile(f1.path);
|
||||
|
||||
projectService.openClientFile(f1.path);
|
||||
projectService.checkNumberOfProjects({ externalProjects: 1 });
|
||||
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path);
|
||||
const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(f1.path);
|
||||
assert.equal(navbar[0].spans[0].length, f1.content.length);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1091,7 +1091,7 @@ namespace ts.server {
|
|||
const { success, projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.getConfigFilePath());
|
||||
if (!success) {
|
||||
// reset project settings to default
|
||||
this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/false, configFileErrors);
|
||||
this.updateNonInferredProject(project, [], fileNamePropertyReader, {}, {}, /*compileOnSave*/ false, configFileErrors);
|
||||
return configFileErrors;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace ts.codefix {
|
|||
stringTypeNode,
|
||||
/*initializer*/ undefined);
|
||||
const indexSignature = createIndexSignatureDeclaration(
|
||||
/*decorators*/undefined,
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
[indexingParameter],
|
||||
typeNode);
|
||||
|
|
|
@ -194,7 +194,7 @@ namespace ts.codefix {
|
|||
modifiers,
|
||||
name,
|
||||
optional,
|
||||
/*typeParameters*/undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
parameters,
|
||||
/*returnType*/ undefined);
|
||||
}
|
||||
|
@ -217,9 +217,9 @@ namespace ts.codefix {
|
|||
[createThrow(
|
||||
createNew(
|
||||
createIdentifier("Error"),
|
||||
/*typeArguments*/undefined,
|
||||
/*typeArguments*/ undefined,
|
||||
[createLiteral("Method not implemented.")]))],
|
||||
/*multiline*/true);
|
||||
/*multiline*/ true);
|
||||
}
|
||||
|
||||
function createVisibilityModifier(flags: ModifierFlags) {
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace ts.codefix {
|
|||
const nextToken = getTokenAtPosition(sourceFile, importClause.name.end);
|
||||
if (nextToken && nextToken.kind === SyntaxKind.CommaToken) {
|
||||
// shift first non-whitespace position after comma to the start position of the node
|
||||
return deleteRange({ pos: start, end: skipTrivia(sourceFile.text, nextToken.end, /*stopAfterLineBreaks*/ false, /*stopAtComments*/true) });
|
||||
return deleteRange({ pos: start, end: skipTrivia(sourceFile.text, nextToken.end, /*stopAfterLineBreaks*/ false, /*stopAtComments*/ true) });
|
||||
}
|
||||
else {
|
||||
return deleteNode(importClause.name);
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace ts.Completions {
|
|||
const type = typeChecker.getContextualType((<ObjectLiteralExpression>element.parent));
|
||||
const entries: CompletionEntry[] = [];
|
||||
if (type) {
|
||||
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/false, typeChecker, target, log);
|
||||
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/ false, typeChecker, target, log);
|
||||
if (entries.length) {
|
||||
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries };
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ namespace ts.Completions {
|
|||
const type = typeChecker.getTypeAtLocation(node.expression);
|
||||
const entries: CompletionEntry[] = [];
|
||||
if (type) {
|
||||
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, node, /*performCharacterChecks*/false, typeChecker, target, log);
|
||||
getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, node, /*performCharacterChecks*/ false, typeChecker, target, log);
|
||||
if (entries.length) {
|
||||
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: true, entries };
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey): void {
|
||||
const bucket = getBucketForCompilationSettings(key, /*createIfMissing*/false);
|
||||
const bucket = getBucketForCompilationSettings(key, /*createIfMissing*/ false);
|
||||
Debug.assert(bucket !== undefined);
|
||||
|
||||
const entry = bucket.get(path);
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ts.GoToImplementation {
|
|||
else {
|
||||
// Perform "Find all References" and retrieve only those that are implementations
|
||||
const referencedSymbols = FindAllReferences.getReferencedSymbolsForNode(context,
|
||||
node, sourceFiles, /*findInStrings*/false, /*findInComments*/false, /*isForRename*/false, /*implementations*/true);
|
||||
node, sourceFiles, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false, /*implementations*/ true);
|
||||
const result = flatMap(referencedSymbols, symbol => symbol.references);
|
||||
|
||||
return result && result.length > 0 ? result : undefined;
|
||||
|
|
|
@ -12,11 +12,11 @@ namespace ts.Completions.PathCompletions {
|
|||
const extensions = getSupportedExtensions(compilerOptions);
|
||||
if (compilerOptions.rootDirs) {
|
||||
entries = getCompletionEntriesForDirectoryFragmentWithRootDirs(
|
||||
compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/false, span, compilerOptions, host, scriptPath);
|
||||
compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, span, compilerOptions, host, scriptPath);
|
||||
}
|
||||
else {
|
||||
entries = getCompletionEntriesForDirectoryFragment(
|
||||
literalValue, scriptDirectory, extensions, /*includeExtensions*/false, span, host, scriptPath);
|
||||
literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, span, host, scriptPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -94,7 +94,7 @@ namespace ts.Completions.PathCompletions {
|
|||
|
||||
if (tryDirectoryExists(host, baseDirectory)) {
|
||||
// Enumerate the available files if possible
|
||||
const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]);
|
||||
const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/ undefined, /*include*/ ["./*"]);
|
||||
|
||||
if (files) {
|
||||
/**
|
||||
|
@ -153,7 +153,7 @@ namespace ts.Completions.PathCompletions {
|
|||
const fileExtensions = getSupportedExtensions(compilerOptions);
|
||||
const projectDir = compilerOptions.project || host.getCurrentDirectory();
|
||||
const absolute = isRootedDiskPath(baseUrl) ? baseUrl : combinePaths(projectDir, baseUrl);
|
||||
result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/false, span, host);
|
||||
result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/ false, span, host);
|
||||
|
||||
if (paths) {
|
||||
for (const path in paths) {
|
||||
|
@ -267,7 +267,7 @@ namespace ts.Completions.PathCompletions {
|
|||
nonRelativeModules.push(visibleModule.moduleName);
|
||||
}
|
||||
else if (startsWith(visibleModule.moduleName, moduleNameFragment)) {
|
||||
const nestedFiles = tryReadDirectory(host, visibleModule.moduleDir, supportedTypeScriptExtensions, /*exclude*/undefined, /*include*/["./*"]);
|
||||
const nestedFiles = tryReadDirectory(host, visibleModule.moduleDir, supportedTypeScriptExtensions, /*exclude*/ undefined, /*include*/ ["./*"]);
|
||||
if (nestedFiles) {
|
||||
for (let f of nestedFiles) {
|
||||
f = normalizePath(f);
|
||||
|
@ -327,7 +327,7 @@ namespace ts.Completions.PathCompletions {
|
|||
if (kind === "path") {
|
||||
// Give completions for a relative path
|
||||
const span: TextSpan = getDirectoryFragmentTextSpan(toComplete, range.pos + prefix.length);
|
||||
completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, host, sourceFile.path);
|
||||
completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/ true, span, host, sourceFile.path);
|
||||
}
|
||||
else {
|
||||
// Give completions based on the typings available
|
||||
|
|
|
@ -1472,17 +1472,17 @@ namespace ts {
|
|||
}
|
||||
|
||||
function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] {
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments, /*isForRename*/true);
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments, /*isForRename*/ true);
|
||||
return FindAllReferences.convertReferences(referencedSymbols);
|
||||
}
|
||||
|
||||
function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/false);
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false);
|
||||
return FindAllReferences.convertReferences(referencedSymbols);
|
||||
}
|
||||
|
||||
function findReferences(fileName: string, position: number): ReferencedSymbol[] {
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/false);
|
||||
const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/ false);
|
||||
// Only include referenced symbols that have a valid definition.
|
||||
return filter(referencedSymbols, rs => !!rs.definition);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue