Skip to content

Commit 461f123

Browse files
committed
Refactor part length logic into its own function
1 parent fec398c commit 461f123

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/parsing/virtual-document/virtual-ast-document.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { Range } from "../../types/range";
44
import { intersects } from "../../util/util";
55
import { VirtualDocument } from "./virtual-document";
66

7+
function getPartLength(part: Node): number {
8+
const end = part.parent && tsModule.ts.isTemplateSpan(part.parent) ? part.parent.literal.getStart() : part.getEnd();
9+
return end - part.getFullStart();
10+
}
11+
712
export class VirtualAstDocument implements VirtualDocument {
813
readonly fileName: string;
914
readonly location: Range;
@@ -23,8 +28,7 @@ export class VirtualAstDocument implements VirtualDocument {
2328
str += part.substring(i === 0 ? 0 : 1, part.length - (isLastPart ? 0 : 2));
2429
prevPart = part;
2530
} else {
26-
const end = part.parent && tsModule.ts.isTemplateSpan(part.parent) ? part.parent.literal.getStart() : part.getEnd();
27-
const length = end - part.getFullStart() + 3;
31+
const length = getPartLength(part) + 3;
2832
const substitution = this.substituteExpression(length, part, prevPart, this.parts[i + 1] as string);
2933
str += substitution;
3034
}
@@ -67,7 +71,7 @@ export class VirtualAstDocument implements VirtualDocument {
6771
resultParts.push(substr);
6872
}
6973
} else {
70-
offset += part.getEnd() - part.getStart();
74+
offset += getPartLength(part);
7175

7276
const expressionPartRange: Range = {
7377
start: startOffset,

0 commit comments

Comments
 (0)