mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Skip lone variable declarations
This commit is contained in:
@@ -18,16 +18,19 @@ namespace ts.SelectionRange {
|
||||
}
|
||||
|
||||
if (positionShouldSnapToNode(pos, node, nextNode)) {
|
||||
// Blocks are effectively redundant with SyntaxLists.
|
||||
// TemplateSpans, along with the SyntaxLists containing them,
|
||||
// are a somewhat unintuitive grouping of things that should be
|
||||
// considered independently. A VariableStatement’s children are just
|
||||
// a VaraiableDeclarationList and a semicolon.
|
||||
// 1. Blocks are effectively redundant with SyntaxLists.
|
||||
// 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
|
||||
// of things that should be considered independently.
|
||||
// 3. A VariableStatement’s children are just a VaraiableDeclarationList and a semicolon.
|
||||
// 4. A lone VariableDeclaration in a VaraibleDeclaration feels redundant with the VariableStatement.
|
||||
//
|
||||
// Dive in without pushing a selection range.
|
||||
if (isBlock(node)
|
||||
|| isTemplateSpan(node) || isTemplateHead(node)
|
||||
|| prevNode && isTemplateHead(prevNode)
|
||||
|| isVariableDeclarationList(node) && isVariableStatement(parentNode)) {
|
||||
|| isVariableDeclarationList(node) && isVariableStatement(parentNode)
|
||||
|| isSyntaxList(node) && isVariableDeclarationList(parentNode)
|
||||
|| isVariableDeclaration(node) && isSyntaxList(parentNode) && children.length === 1) {
|
||||
parentNode = node;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -568,18 +568,13 @@ const { x, y: a, ...zs = {} } = {};`);
|
||||
start: { line: 2, offset: 7 },
|
||||
end: { line: 2, offset: 30 } },
|
||||
parent: {
|
||||
textSpan: { // { x, y: a, ...zs = {} } = {}
|
||||
start: { line: 2, offset: 7 },
|
||||
end: { line: 2, offset: 35 } },
|
||||
textSpan: { // whole line
|
||||
start: { line: 2, offset: 1 },
|
||||
end: { line: 2, offset: 36 } },
|
||||
parent: {
|
||||
textSpan: { // whole line
|
||||
start: { line: 2, offset: 1 },
|
||||
end: { line: 2, offset: 36 } },
|
||||
parent: {
|
||||
textSpan: {
|
||||
start: { line: 1, offset: 1 },
|
||||
end: { line: 2, offset: 36 } } } } } } } } },
|
||||
});
|
||||
textSpan: {
|
||||
start: { line: 1, offset: 1 },
|
||||
end: { line: 2, offset: 36 } } } } } } } } });
|
||||
});
|
||||
|
||||
it("consumes all whitespace in a multi-line function parameter list", () => {
|
||||
@@ -644,5 +639,18 @@ function square(x) {
|
||||
start: { line: 1, offset: 1 },
|
||||
end: { line: 7, offset: 2 } } } } } }]);
|
||||
});
|
||||
|
||||
it("skips lone VariableDeclarations in a declaration list", () => {
|
||||
const getSelectionRange = setup("/file.ts", `const x = 3;`);
|
||||
const locations = getSelectionRange([{ line: 1, offset: 7 }]); // x
|
||||
assert.deepEqual(locations, [{
|
||||
textSpan: {
|
||||
start: { line: 1, offset: 7 },
|
||||
end: { line: 1, offset: 8 } },
|
||||
parent: {
|
||||
textSpan: {
|
||||
start: { line: 1, offset: 1 },
|
||||
end: { line: 1, offset: 13 } } } }]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user