Skip to content

Commit d8f58bf

Browse files
committed
using the exported utf16 instead of utf8 to calculate text lengths
1 parent 04eaf25 commit d8f58bf

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/slang-nodes/Identifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Identifier implements SlangNode {
1919
this.comments = [];
2020
this.loc = {
2121
start: offset,
22-
end: offset + ast.textLength.utf8,
22+
end: offset + ast.textLength.utf16,
2323
leadingOffset: 0,
2424
trailingOffset: 0
2525
};

src/slang-nodes/YulIdentifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class YulIdentifier implements SlangNode {
1919
this.comments = [];
2020
this.loc = {
2121
start: offset,
22-
end: offset + ast.textLength.utf8,
22+
end: offset + ast.textLength.utf16,
2323
leadingOffset: 0,
2424
trailingOffset: 0
2525
};

src/slang-utils/metadata.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getLeadingOffset(children: Node[]): number {
2121
// non-whitespace token.
2222
return offset;
2323
}
24-
offset += child.textLength.utf8;
24+
offset += child.textLength.utf16;
2525
}
2626
return offset;
2727
}
@@ -59,7 +59,7 @@ export function getNodeMetadata(
5959
value: child.text,
6060
loc: {
6161
start: offset,
62-
end: offset + child.textLength.utf8
62+
end: offset + child.textLength.utf16
6363
}
6464
});
6565
break;
@@ -74,7 +74,7 @@ export function getNodeMetadata(
7474
}
7575
}
7676

77-
offset += child.textLength.utf8;
77+
offset += child.textLength.utf16;
7878
return offsetsArray;
7979
}, []);
8080

@@ -86,7 +86,7 @@ export function getNodeMetadata(
8686
: getLeadingOffset(children.reverse());
8787
const loc = {
8888
start: initialOffset + leadingOffset,
89-
end: initialOffset + ast.cst.textLength.utf8 - trailingOffset,
89+
end: initialOffset + ast.cst.textLength.utf16 - trailingOffset,
9090
leadingOffset,
9191
trailingOffset
9292
};

0 commit comments

Comments
 (0)