Skip to content

Commit d2364f5

Browse files
authored
Merge pull request #30089 from Microsoft/convert-to-named-parameters
Convert to named parameters
2 parents d62c8a4 + 60b2d6a commit d2364f5

File tree

48 files changed

+1387
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1387
-80
lines changed

src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ namespace ts {
917917

918918
/**
919919
* Deduplicates an unsorted array.
920-
* @param equalityComparer An optional `EqualityComparer` used to determine if two values are duplicates.
920+
* @param equalityComparer An `EqualityComparer` used to determine if two values are duplicates.
921921
* @param comparer An optional `Comparer` used to sort entries before comparison, though the
922922
* result will remain in the original order in `array`.
923923
*/

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -4875,5 +4875,9 @@
48754875
"Enable the 'experimentalDecorators' option in your configuration file": {
48764876
"category": "Message",
48774877
"code": 95074
4878+
},
4879+
"Convert to named parameters": {
4880+
"category": "Message",
4881+
"code": 95075
48784882
}
48794883
}

src/services/codefixes/convertFunctionToEs6Class.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace ts.codefix {
3535
precedingNode = ctorDeclaration.parent.parent;
3636
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
3737
if ((<VariableDeclarationList>ctorDeclaration.parent).declarations.length === 1) {
38-
copyComments(precedingNode, newClassDeclaration!, sourceFile); // TODO: GH#18217
38+
copyLeadingComments(precedingNode, newClassDeclaration!, sourceFile); // TODO: GH#18217
3939
changes.delete(sourceFile, precedingNode);
4040
}
4141
else {
@@ -48,7 +48,7 @@ namespace ts.codefix {
4848
return undefined;
4949
}
5050

51-
copyComments(ctorDeclaration, newClassDeclaration, sourceFile);
51+
copyLeadingComments(ctorDeclaration, newClassDeclaration, sourceFile);
5252

5353
// Because the preceding node could be touched, we need to insert nodes before delete nodes.
5454
changes.insertNodeAfter(sourceFile, precedingNode!, newClassDeclaration);
@@ -112,7 +112,7 @@ namespace ts.codefix {
112112
const fullModifiers = concatenate(modifiers, getModifierKindFromSource(functionExpression, SyntaxKind.AsyncKeyword));
113113
const method = createMethod(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
114114
/*typeParameters*/ undefined, functionExpression.parameters, /*type*/ undefined, functionExpression.body);
115-
copyComments(assignmentBinaryExpression, method, sourceFile);
115+
copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
116116
return method;
117117
}
118118

@@ -132,7 +132,7 @@ namespace ts.codefix {
132132
const fullModifiers = concatenate(modifiers, getModifierKindFromSource(arrowFunction, SyntaxKind.AsyncKeyword));
133133
const method = createMethod(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, memberDeclaration.name, /*questionToken*/ undefined,
134134
/*typeParameters*/ undefined, arrowFunction.parameters, /*type*/ undefined, bodyBlock);
135-
copyComments(assignmentBinaryExpression, method, sourceFile);
135+
copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
136136
return method;
137137
}
138138

@@ -143,7 +143,7 @@ namespace ts.codefix {
143143
}
144144
const prop = createProperty(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined,
145145
/*type*/ undefined, assignmentBinaryExpression.right);
146-
copyComments(assignmentBinaryExpression.parent, prop, sourceFile);
146+
copyLeadingComments(assignmentBinaryExpression.parent, prop, sourceFile);
147147
return prop;
148148
}
149149
}

src/services/codefixes/inferFromUsage.ts

-24
Original file line numberDiff line numberDiff line change
@@ -304,30 +304,6 @@ namespace ts.codefix {
304304
}
305305
}
306306

307-
function getTypeNodeIfAccessible(type: Type, enclosingScope: Node, program: Program, host: LanguageServiceHost): TypeNode | undefined {
308-
const checker = program.getTypeChecker();
309-
let typeIsAccessible = true;
310-
const notAccessible = () => { typeIsAccessible = false; };
311-
const res = checker.typeToTypeNode(type, enclosingScope, /*flags*/ undefined, {
312-
trackSymbol: (symbol, declaration, meaning) => {
313-
// TODO: GH#18217
314-
typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning!, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible;
315-
},
316-
reportInaccessibleThisError: notAccessible,
317-
reportPrivateInBaseOfClassExpression: notAccessible,
318-
reportInaccessibleUniqueSymbolError: notAccessible,
319-
moduleResolverHost: {
320-
readFile: host.readFile,
321-
fileExists: host.fileExists,
322-
directoryExists: host.directoryExists,
323-
getSourceFiles: program.getSourceFiles,
324-
getCurrentDirectory: program.getCurrentDirectory,
325-
getCommonSourceDirectory: program.getCommonSourceDirectory,
326-
}
327-
});
328-
return typeIsAccessible ? res : undefined;
329-
}
330-
331307
function getReferences(token: PropertyName | Token<SyntaxKind.ConstructorKeyword>, program: Program, cancellationToken: CancellationToken): ReadonlyArray<Identifier> {
332308
// Position shouldn't matter since token is not a SourceFile.
333309
return mapDefined(FindAllReferences.getReferenceEntriesForNode(-1, token, program, program.getSourceFiles(), cancellationToken), entry =>

src/services/organizeImports.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ namespace ts.OrganizeImports {
6868
else {
6969
// Note: Delete the surrounding trivia because it will have been retained in newImportDecls.
7070
changeTracker.replaceNodeWithNodes(sourceFile, oldImportDecls[0], newImportDecls, {
71-
useNonAdjustedStartPosition: true, // Leave header comment in place
72-
useNonAdjustedEndPosition: false,
71+
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude, // Leave header comment in place
72+
trailingTriviaOption: textChanges.TrailingTriviaOption.Include,
7373
suffix: getNewLineOrDefaultFromHost(host, formatContext.options),
7474
});
7575
}

src/services/refactors/addOrRemoveBracesToArrowFunction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
4848
const returnStatement = createReturn(expression);
4949
body = createBlock([returnStatement], /* multiLine */ true);
5050
suppressLeadingAndTrailingTrivia(body);
51-
copyComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
51+
copyLeadingComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
5252
}
5353
else if (actionName === removeBracesActionName && returnStatement) {
5454
const actualExpression = expression || createVoidZero();
5555
body = needsParentheses(actualExpression) ? createParen(actualExpression) : actualExpression;
5656
suppressLeadingAndTrailingTrivia(body);
57-
copyComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
57+
copyLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
5858
}
5959
else {
6060
Debug.fail("invalid action");

0 commit comments

Comments
 (0)