Skip to content
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

Reproduce issue described in #45 - multi-byte characters are counted incorrectly. #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/node-api.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ describe("parse", function () {
]);
});

it("multi-byte characters", function () {
let contentLength = "안녕하세요 세계".length;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined all these lengths here because I can't count myself

let openLength = "<template>".length;
let closeLength = "</template>".length;
let output = p.parse("<template>안녕하세요 세계</template>");

expect(output).to.eql([
{
type: "expression",
tagName: "template",
contents: "안녕하세요 세계",
range: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a range is always [start, end), just like String.prototype.slice
[inclusive, exclusive) or, from the frame of reference of the substring-in-question: [start index, index one character immediately after)

start: 0,
end: openLength + contentLength + closeLength,
},
contentRange: {
start: openLength,
end: openLength + contentLength,
},
startRange: {
end: openLength,
start: 0,
},
endRange: {
start: openLength + contentLength - 1,
end: openLength + contentLength + closeLength,
},
},
]);
});

it("expression position", function () {
let output = p.parse("const tpl = <template>Hello!</template>");

Expand Down