Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to named parameters #30089

Merged
merged 57 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9aeeae5
create refactoring for converting to named parameters
Jan 16, 2019
705ac60
WIP
Jan 16, 2019
23fc65a
implement new parameter creation
Jan 17, 2019
919ed79
implement new parameter creation
Jan 17, 2019
bd290e6
add test for convert to named parameters refactoring
Jan 19, 2019
f3e60be
Move function getTypeNodeIfAccessible from inferFromUsage to utilities
Jan 28, 2019
3243b4b
Refactor direct function calls
Jan 28, 2019
b668e34
Add tests for convert to named parameters refactor
Jan 28, 2019
9e62eb9
Merge branch 'master' into convert-to-named-parameters
Jan 29, 2019
1d94322
preserve this parameter when refactoring
Jan 30, 2019
050c70a
update tests formatting
Jan 30, 2019
40987ec
add tests
Jan 30, 2019
bf25ba4
Don't refactor if variable declaration has type annotation
Feb 1, 2019
bde97d1
fix refactor to find super references
Feb 2, 2019
abb1155
add more tests
Feb 2, 2019
674800f
implement refactor for functions with a rest parameter
Feb 4, 2019
1d1c820
add tests for rest parameters
Feb 4, 2019
18b2b55
add option to suppressLeadingAndTrailingTrivia non recursively
Feb 6, 2019
b87392c
fix duplication of leading and trailing comments on refactored function
Feb 6, 2019
9270e58
Merge branch 'master' into convert-to-named-parameters
Feb 6, 2019
7d86fda
fix hasThisParameter to check for parameters length
Feb 7, 2019
26f8ddd
create functions for copying trailing comments and rename previous co…
Feb 11, 2019
dba631d
copy comments when refactoring
Feb 11, 2019
4e135f1
add tests for comments
Feb 11, 2019
dbd8499
don't apply refactor when parameter has decorators
Feb 11, 2019
ef4db31
don't apply changes when unexpected reference is found
Feb 13, 2019
ec0e734
return function expression name in getFunctionDeclarationNames
Feb 13, 2019
05e9d6c
fix reference checking
Feb 13, 2019
b93afff
rename refactor tests
Feb 15, 2019
eef3da5
create new ConfigurableStart and ConfigurableEnd options and rename them
Feb 15, 2019
b6c8382
replace argument list instead of whole call when refactoring
Feb 15, 2019
a773046
copy argument comments to property
Feb 16, 2019
78968b1
don't provide refactor in js file
Feb 19, 2019
17b8965
include trailing trivia after expression in getAdjustedEndPosition if…
Feb 19, 2019
edf0cec
add tests for inherited constructor and method
Feb 19, 2019
754f4a4
refactor expected test output
Feb 19, 2019
e40442d
minor refactors
Feb 20, 2019
6b53489
Merge branch 'master' into convert-to-named-parameters
Feb 20, 2019
ce42aa4
check usages of class if refactoring a constructor
Feb 23, 2019
640424e
fix comment
Feb 23, 2019
bc3611d
update failing tests
Feb 25, 2019
f571866
add new tests for bad class references
Feb 25, 2019
365967d
Merge branch 'master' into convert-to-named-parameters
Feb 25, 2019
a5153a9
add tests
Feb 25, 2019
e3a465f
change startPosition and endPosition to leadingTriviaOption and trail…
Feb 26, 2019
bf5123d
don't export useNonAjustedPositions
Feb 26, 2019
970ec62
remove unused LeadingTriviaOption and TrailingTriviaOption options
Feb 26, 2019
006fe14
refactor utilities
Feb 27, 2019
54c7996
refactor getGroupReferences
Feb 28, 2019
7fd6868
minor refactors to convertToNamedParameters
Feb 28, 2019
51616a4
use sortAndDeduplicate instead of deduplicate
Feb 28, 2019
617d5af
add diagnostics message for refactor description
Feb 28, 2019
1f91aa1
remove inlineable
Mar 1, 2019
cd060e7
use interface for ValidVariableDeclaration
Mar 1, 2019
98a146d
use getTouchingToken
Mar 1, 2019
8c4ab69
add test for non-transient symbol
Mar 4, 2019
60b2d6a
remove unnecessary closures
Mar 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ namespace ts {

/**
* Deduplicates an unsorted array.
* @param equalityComparer An optional `EqualityComparer` used to determine if two values are duplicates.
* @param equalityComparer An `EqualityComparer` used to determine if two values are duplicates.
* @param comparer An optional `Comparer` used to sort entries before comparison, though the
* result will remain in the original order in `array`.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/services/codefixes/convertFunctionToEs6Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace ts.codefix {
precedingNode = ctorDeclaration.parent.parent;
newClassDeclaration = createClassFromVariableDeclaration(ctorDeclaration as VariableDeclaration);
if ((<VariableDeclarationList>ctorDeclaration.parent).declarations.length === 1) {
copyComments(precedingNode, newClassDeclaration!, sourceFile); // TODO: GH#18217
copyLeadingComments(precedingNode, newClassDeclaration!, sourceFile); // TODO: GH#18217
changes.delete(sourceFile, precedingNode);
}
else {
Expand All @@ -48,7 +48,7 @@ namespace ts.codefix {
return undefined;
}

copyComments(ctorDeclaration, newClassDeclaration, sourceFile);
copyLeadingComments(ctorDeclaration, newClassDeclaration, sourceFile);

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

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

Expand All @@ -143,7 +143,7 @@ namespace ts.codefix {
}
const prop = createProperty(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined,
/*type*/ undefined, assignmentBinaryExpression.right);
copyComments(assignmentBinaryExpression.parent, prop, sourceFile);
copyLeadingComments(assignmentBinaryExpression.parent, prop, sourceFile);
return prop;
}
}
Expand Down
24 changes: 0 additions & 24 deletions src/services/codefixes/inferFromUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,30 +304,6 @@ namespace ts.codefix {
}
}

function getTypeNodeIfAccessible(type: Type, enclosingScope: Node, program: Program, host: LanguageServiceHost): TypeNode | undefined {
const checker = program.getTypeChecker();
let typeIsAccessible = true;
const notAccessible = () => { typeIsAccessible = false; };
const res = checker.typeToTypeNode(type, enclosingScope, /*flags*/ undefined, {
trackSymbol: (symbol, declaration, meaning) => {
// TODO: GH#18217
typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning!, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible;
},
reportInaccessibleThisError: notAccessible,
reportPrivateInBaseOfClassExpression: notAccessible,
reportInaccessibleUniqueSymbolError: notAccessible,
moduleResolverHost: {
readFile: host.readFile,
fileExists: host.fileExists,
directoryExists: host.directoryExists,
getSourceFiles: program.getSourceFiles,
getCurrentDirectory: program.getCurrentDirectory,
getCommonSourceDirectory: program.getCommonSourceDirectory,
}
});
return typeIsAccessible ? res : undefined;
}

function getReferences(token: PropertyName | Token<SyntaxKind.ConstructorKeyword>, program: Program, cancellationToken: CancellationToken): ReadonlyArray<Identifier> {
// Position shouldn't matter since token is not a SourceFile.
return mapDefined(FindAllReferences.getReferenceEntriesForNode(-1, token, program, program.getSourceFiles(), cancellationToken), entry =>
Expand Down
4 changes: 2 additions & 2 deletions src/services/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ namespace ts.OrganizeImports {
else {
// Note: Delete the surrounding trivia because it will have been retained in newImportDecls.
changeTracker.replaceNodeWithNodes(sourceFile, oldImportDecls[0], newImportDecls, {
useNonAdjustedStartPosition: true, // Leave header comment in place
useNonAdjustedEndPosition: false,
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude, // Leave header comment in place
trailingTriviaOption: textChanges.TrailingTriviaOption.Include,
suffix: getNewLineOrDefaultFromHost(host, formatContext.options),
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/refactors/addOrRemoveBracesToArrowFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
const returnStatement = createReturn(expression);
body = createBlock([returnStatement], /* multiLine */ true);
suppressLeadingAndTrailingTrivia(body);
copyComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
copyLeadingComments(expression!, returnStatement, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ true);
}
else if (actionName === removeBracesActionName && returnStatement) {
const actualExpression = expression || createVoidZero();
body = needsParentheses(actualExpression) ? createParen(actualExpression) : actualExpression;
suppressLeadingAndTrailingTrivia(body);
copyComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
copyLeadingComments(returnStatement, body, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
}
else {
Debug.fail("invalid action");
Expand Down
Loading