-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add preceding semicolon on await insertion when parentheses are included #34627
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
Changes from all commits
345cb58
4590d12
0e01c7f
7f672c8
d743f0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -257,6 +257,7 @@ namespace ts.codefix { | |||||
sourceFile, | ||||||
insertionSite.parent.expression, | ||||||
createParen(createAwait(insertionSite.parent.expression))); | ||||||
insertLeadingSemicolonIfNeeded(changeTracker, insertionSite.parent.expression, sourceFile); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current indentation is correct (the preceding three lines are arguments to |
||||||
} | ||||||
else if (contains(callableConstructableErrorCodes, errorCode) && isCallOrNewExpression(insertionSite.parent)) { | ||||||
if (fixedDeclarations && isIdentifier(insertionSite)) { | ||||||
|
@@ -266,6 +267,7 @@ namespace ts.codefix { | |||||
} | ||||||
} | ||||||
changeTracker.replaceNode(sourceFile, insertionSite, createParen(createAwait(insertionSite))); | ||||||
insertLeadingSemicolonIfNeeded(changeTracker, insertionSite, sourceFile); | ||||||
} | ||||||
else { | ||||||
if (fixedDeclarations && isVariableDeclaration(insertionSite.parent) && isIdentifier(insertionSite.parent.name)) { | ||||||
|
@@ -277,4 +279,11 @@ namespace ts.codefix { | |||||
changeTracker.replaceNode(sourceFile, insertionSite, createAwait(insertionSite)); | ||||||
} | ||||||
} | ||||||
|
||||||
function insertLeadingSemicolonIfNeeded(changeTracker: textChanges.ChangeTracker, beforeNode: Node, sourceFile: SourceFile) { | ||||||
const precedingToken = findPrecedingToken(beforeNode.pos, sourceFile); | ||||||
if (precedingToken && positionIsASICandidate(precedingToken.end, precedingToken.parent, sourceFile)) { | ||||||
changeTracker.insertText(sourceFile, beforeNode.getStart(sourceFile), ";"); | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/// <reference path="fourslash.ts" /> | ||
////async function fn(a: Promise<{ x: string }>) { | ||
//// console.log(3) | ||
//// a.x; | ||
////} | ||
|
||
verify.codeFix({ | ||
description: ts.Diagnostics.Add_await.message, | ||
index: 0, | ||
newFileContent: | ||
`async function fn(a: Promise<{ x: string }>) { | ||
console.log(3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually the typical preferred style for non-semicoloners. See https://standardjs.com/rules.html#semicolons There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /cc @orta to confirm people actually do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier does it this way, to which I give more credence than StandardJS anyway. I feel good about keeping it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, confirming, this is what I'm used to |
||
;(await a).x; | ||
}` | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/// <reference path="fourslash.ts" /> | ||
////async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { | ||
//// a() | ||
//// b() | ||
//// new C() | ||
////} | ||
|
||
verify.codeFix({ | ||
description: ts.Diagnostics.Add_await.message, | ||
index: 0, | ||
newFileContent: | ||
`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { | ||
(await a)() | ||
b() | ||
new C() | ||
}` | ||
}); | ||
|
||
verify.codeFix({ | ||
description: ts.Diagnostics.Add_await.message, | ||
index: 1, | ||
newFileContent: | ||
`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { | ||
a() | ||
;(await b)() | ||
new C() | ||
}` | ||
}); | ||
|
||
verify.codeFix({ | ||
description: ts.Diagnostics.Add_await.message, | ||
index: 2, | ||
newFileContent: | ||
`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { | ||
a() | ||
b() | ||
new (await C)() | ||
}` | ||
}); | ||
|
||
verify.codeFixAll({ | ||
fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, | ||
fixId: "addMissingAwait", | ||
newFileContent: | ||
`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { | ||
(await a)() | ||
;(await b)() | ||
new (await C)() | ||
}` | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
////async function foo(x: Promise<string>) { | ||
//// console.log | ||
//// [|x./**/|] | ||
////} | ||
|
||
const replacementSpan = test.ranges()[0]; | ||
verify.completions({ | ||
marker: "", | ||
includes: [ | ||
"then", | ||
{ name: "trim", insertText: ';(await x).trim', replacementSpan }, | ||
], | ||
preferences: { | ||
includeInsertTextCompletions: true, | ||
}, | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.