This commit is contained in:
Arthur Ozga 2017-03-27 12:01:56 -07:00
parent 7340c4ca1e
commit 4329b4524e
4 changed files with 12 additions and 9 deletions

View file

@ -326,10 +326,12 @@ namespace ts {
case SyntaxKind.TypeOperator: case SyntaxKind.TypeOperator:
return updateTypeOperatorNode(<TypeOperatorNode>node, visitNode((<TypeOperatorNode>node).type, visitor, isTypeNode)); return updateTypeOperatorNode(<TypeOperatorNode>node, visitNode((<TypeOperatorNode>node).type, visitor, isTypeNode));
case SyntaxKind.IndexedAccessType: case SyntaxKind.IndexedAccessType:
return updateIndexedAccessTypeNode((<IndexedAccessTypeNode>node), return updateIndexedAccessTypeNode((<IndexedAccessTypeNode>node),
visitNode((<IndexedAccessTypeNode>node).objectType, visitor, isTypeNode), visitNode((<IndexedAccessTypeNode>node).objectType, visitor, isTypeNode),
visitNode((<IndexedAccessTypeNode>node).indexType, visitor, isTypeNode)); visitNode((<IndexedAccessTypeNode>node).indexType, visitor, isTypeNode));
case SyntaxKind.MappedType: case SyntaxKind.MappedType:
return updateMappedTypeNode((<MappedTypeNode>node), return updateMappedTypeNode((<MappedTypeNode>node),
visitNode((<MappedTypeNode>node).readonlyToken, tokenVisitor, isToken), visitNode((<MappedTypeNode>node).readonlyToken, tokenVisitor, isToken),

View file

@ -1676,7 +1676,7 @@ namespace FourSlash {
// We get back a set of edits, but langSvc.editScript only accepts one at a time. Use this to keep track // We get back a set of edits, but langSvc.editScript only accepts one at a time. Use this to keep track
// of the incremental offset from each edit to the next. Assumption is that these edit ranges don't overlap // of the incremental offset from each edit to the next. Assumption is that these edit ranges don't overlap
let runningOffset = 0; let runningOffset = 0;
edits = ts.stableSort(edits, (a, b) => a.span.start - b.span.start); edits = edits.sort((a, b) => a.span.start - b.span.start);
// Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters // Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
const oldContent = this.getFileContent(fileName); const oldContent = this.getFileContent(fileName);

View file

@ -11,7 +11,7 @@ namespace ts.codefix {
} }
const changes = changeTracker.getChanges(); const changes = changeTracker.getChanges();
if (!(changes && changes.length > 0)) { if (!some(changes)) {
return changes; return changes;
} }
@ -93,7 +93,7 @@ namespace ts.codefix {
// (eg: an abstract method or interface declaration), there is a 1-1 // (eg: an abstract method or interface declaration), there is a 1-1
// correspondence of declarations and signatures. // correspondence of declarations and signatures.
const signatures = checker.getSignaturesOfType(type, SignatureKind.Call); const signatures = checker.getSignaturesOfType(type, SignatureKind.Call);
if (!(signatures && signatures.length > 0)) { if (!some(signatures)) {
return undefined; return undefined;
} }
@ -103,7 +103,7 @@ namespace ts.codefix {
return signatureToMethodDeclaration(signature, enclosingDeclaration, createStubbedMethodBody()); return signatureToMethodDeclaration(signature, enclosingDeclaration, createStubbedMethodBody());
} }
const signatureDeclarations = []; const signatureDeclarations: MethodDeclaration[] = [];
for (let i = 0; i < signatures.length; i++) { for (let i = 0; i < signatures.length; i++) {
const signature = signatures[i]; const signature = signatures[i];
const methodDeclaration = signatureToMethodDeclaration(signature, enclosingDeclaration); const methodDeclaration = signatureToMethodDeclaration(signature, enclosingDeclaration);
@ -132,6 +132,7 @@ namespace ts.codefix {
function signatureToMethodDeclaration(signature: Signature, enclosingDeclaration: Node, body?: Block) { function signatureToMethodDeclaration(signature: Signature, enclosingDeclaration: Node, body?: Block) {
const signatureDeclaration = <MethodDeclaration>checker.signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration); const signatureDeclaration = <MethodDeclaration>checker.signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration);
if (signatureDeclaration) { if (signatureDeclaration) {
signatureDeclaration.decorators = undefined;
signatureDeclaration.modifiers = modifiers; signatureDeclaration.modifiers = modifiers;
signatureDeclaration.name = name; signatureDeclaration.name = name;
signatureDeclaration.questionToken = optional ? createToken(SyntaxKind.QuestionToken) : undefined; signatureDeclaration.questionToken = optional ? createToken(SyntaxKind.QuestionToken) : undefined;
@ -142,8 +143,6 @@ namespace ts.codefix {
} }
function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration { function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration {
Debug.assert(signatures && signatures.length > 0);
/** This is *a* signature with the maximal number of arguments, /** This is *a* signature with the maximal number of arguments,
* such that if there is a "maximal" signature without rest arguments, * such that if there is a "maximal" signature without rest arguments,
* this is one of them. * this is one of them.
@ -154,7 +153,9 @@ namespace ts.codefix {
for (let i = 0; i < signatures.length; i++) { for (let i = 0; i < signatures.length; i++) {
const sig = signatures[i]; const sig = signatures[i];
minArgumentCount = Math.min(sig.minArgumentCount, minArgumentCount); minArgumentCount = Math.min(sig.minArgumentCount, minArgumentCount);
someSigHasRestParameter = someSigHasRestParameter || sig.hasRestParameter; if (sig.hasRestParameter) {
someSigHasRestParameter = true;
}
if (sig.parameters.length >= maxArgsSignature.parameters.length && (!sig.hasRestParameter || maxArgsSignature.hasRestParameter)) { if (sig.parameters.length >= maxArgsSignature.parameters.length && (!sig.hasRestParameter || maxArgsSignature.hasRestParameter)) {
maxArgsSignature = sig; maxArgsSignature = sig;
} }

View file

@ -276,7 +276,7 @@ namespace ts.textChanges {
/** /**
* This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range, * This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
* i.e. arguments in arguments lists, parameters in parameter lists etc. * i.e. arguments in arguments lists, parameters in parameter lists etc.
* Note that separators are art of the node in statements and class elements. * Note that separators are part of the node in statements and class elements.
*/ */
public insertNodeInListAfter(sourceFile: SourceFile, after: Node, newNode: Node) { public insertNodeInListAfter(sourceFile: SourceFile, after: Node, newNode: Node) {
const containingList = formatting.SmartIndenter.getContainingList(after, sourceFile); const containingList = formatting.SmartIndenter.getContainingList(after, sourceFile);
@ -484,7 +484,7 @@ namespace ts.textChanges {
private static normalize(changes: Change[]) { private static normalize(changes: Change[]) {
// order changes by start position // order changes by start position
const normalized = stableSort(changes, (a, b) => a.range.pos - b.range.pos); const normalized = stableSort(changes, (a, b) => a.range.pos - b.range.pos);
// verify that change intervals to not overlap, except possible at end points. // verify that change intervals do not overlap, except possibly at end points.
for (let i = 0; i < normalized.length - 2; i++) { for (let i = 0; i < normalized.length - 2; i++) {
Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos); Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos);
} }