mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-07 17:29:36 -05:00
Fix comments on pull request
This commit is contained in:
@@ -14,25 +14,10 @@ namespace ts.codefix {
|
||||
|
||||
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
|
||||
const token = getTokenAtPosition(sourceFile, pos);
|
||||
|
||||
const asExpression = findAncestor<AsExpression>(token, isAsExpression)!;
|
||||
if (!!asExpression) {
|
||||
const nodeBeingConverted = asExpression.getChildAt(0);
|
||||
const expressionBeingConverted = findAncestor<Expression>(nodeBeingConverted, isExpression)!;
|
||||
Debug.assert(!!expressionBeingConverted, "Expected position to be owned by an expression.");
|
||||
|
||||
const replacement = createAsExpression(expressionBeingConverted, createKeywordTypeNode(SyntaxKind.UnknownKeyword));
|
||||
changeTracker.replaceNode(sourceFile, expressionBeingConverted, replacement);
|
||||
}
|
||||
|
||||
const typeAssertion = findAncestor<TypeAssertion>(token, isTypeAssertion)!;
|
||||
if (!!typeAssertion) {
|
||||
const nodeBeingConverted = typeAssertion.getLastToken();
|
||||
const expressionBeingConverted = findAncestor<Expression>(nodeBeingConverted, isExpression)!;
|
||||
Debug.assert(!!expressionBeingConverted, "Expected position to be owned by an expression.");
|
||||
|
||||
const replacement = createTypeAssertion(createKeywordTypeNode(SyntaxKind.UnknownKeyword), expressionBeingConverted);
|
||||
changeTracker.replaceNode(sourceFile, expressionBeingConverted, replacement);
|
||||
}
|
||||
const assertion = Debug.assertDefined(findAncestor(token, (n): n is AsExpression | TypeAssertion => isAsExpression(n) || isTypeAssertion(n)));
|
||||
const replacement = isAsExpression(assertion)
|
||||
? createAsExpression(assertion.expression, createKeywordTypeNode(SyntaxKind.UnknownKeyword))
|
||||
: createTypeAssertion(createKeywordTypeNode(SyntaxKind.UnknownKeyword), assertion.expression);
|
||||
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|0 as string|]
|
||||
////0 as string
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `0 as unknown as string`
|
||||
newFileContent: `0 as unknown as string`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|0 * (4 + 3) / 100 as string|]
|
||||
////0 * (4 + 3) / 100 as string
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `0 * (4 + 3) / 100 as unknown as string`
|
||||
newFileContent: `0 * (4 + 3) / 100 as unknown as string`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|["words"] as string|]
|
||||
////["words"] as string
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `["words"] as unknown as string`
|
||||
newFileContent: `["words"] as unknown as string`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|"words" as object|]
|
||||
////"words" as object
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `"words" as unknown as object`
|
||||
newFileContent: `"words" as unknown as object`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|<string>0|]
|
||||
////<string>0
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `<string><unknown>0`
|
||||
newFileContent: `<string><unknown>0`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|<string>0 * (4 + 3) / 100|]
|
||||
////<string>0 * (4 + 3) / 100
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `<string><unknown>0 * (4 + 3) / 100`
|
||||
newFileContent: `<string><unknown>0 * (4 + 3) / 100`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|<string>["words"]|]
|
||||
////<string>["words"]
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `<string><unknown>["words"]`
|
||||
newFileContent: `<string><unknown>["words"]`
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////[|<object>"words"|]
|
||||
////<object>"words"
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add 'unknown' conversion for non-overlapping types",
|
||||
newRangeContent: `<object><unknown>"words"`
|
||||
newFileContent: `<object><unknown>"words"`
|
||||
});
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class C {
|
||||
//// const s1 = 1 as string;
|
||||
//// const o1 = s + " word" as object;
|
||||
////const s1 = 1 as string;
|
||||
////const o1 = s + " word" as object;
|
||||
////
|
||||
//// const s2 = <string>2;
|
||||
//// const o2 = <object>s2;
|
||||
////}
|
||||
////const s2 = <string>2;
|
||||
////const o2 = <object>s2;
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "addConvertToUnknownForNonOverlappingTypes",
|
||||
fixAllDescription: "Add 'unknown' to all conversions of non-overlapping types",
|
||||
newFileContent:
|
||||
`class C {
|
||||
const s1 = 1 as unknown as string;
|
||||
const o1 = s + " word" as unknown as object;
|
||||
`const s1 = 1 as unknown as string;
|
||||
const o1 = s + " word" as unknown as object;
|
||||
|
||||
const s2 = <string><unknown>2;
|
||||
const o2 = <object>s2;
|
||||
}`
|
||||
const s2 = <string><unknown>2;
|
||||
const o2 = <object><unknown>s2;`
|
||||
});
|
||||
Reference in New Issue
Block a user