Skip to content

Commit

Permalink
fix: tag name source positions
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 9, 2022
1 parent 2c7451e commit eae21f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Parser, TempParser } from "./internal";

export type { Events, Range, ValueRange, TemplateRange } from "./internal";

export { EventTypes, OpenTagEnding } from "./internal";

export function createParser(text: string, filename: string) {
return new Parser(text, filename);
}
Expand Down
8 changes: 5 additions & 3 deletions src/states/TAG_NAME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export const TAG_NAME: StateDefinition<TagNameMeta> = {
name: "TAG_NAME",

enter(tagName) {
const start = tagName.start + (tagName.shorthandCode ? 1 : 0);
tagName.expressions = [];
tagName.quasis = [{ start: tagName.start, end: tagName.end }];
tagName.quasis = [{ start, end: start }];
},

exit(tagName) {
const { start, end, quasis, expressions } = tagName;
peek(quasis)!.end = end;
const last = peek(quasis)!;
if (last.end < end) last.end = end;

switch (tagName.shorthandCode) {
case CODE.NUMBER_SIGN:
Expand Down Expand Up @@ -134,7 +136,7 @@ export const TAG_NAME: StateDefinition<TagNameMeta> = {
const interpolationStart = childPart.start - 2; // include ${
const interpolationEnd = this.skip(1); // include }
const nextQuasiStart = interpolationEnd + 1;
peek(tagName.quasis)!.end = interpolationStart - 1;
peek(tagName.quasis)!.end = interpolationStart;
tagName.expressions.push({
start: interpolationStart,
end: interpolationEnd,
Expand Down

0 comments on commit eae21f2

Please sign in to comment.