Skip to content

Commit

Permalink
fix: fix wrong loc in template expressions
Browse files Browse the repository at this point in the history
closes #123
  • Loading branch information
3cp committed Oct 27, 2020
1 parent d968dd8 commit aa0e992
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4554,7 +4554,7 @@ export function parseTemplate(
parseTemplateElement(parser, context, tokenValue, tokenRaw, tokenPos, linePos, colPos, /* tail */ false)
);

expressions.push(parseExpressions(parser, context, 0, 1, tokenPos, linePos, colPos));
expressions.push(parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos));
if (parser.token !== Token.RightBrace) report(parser, Errors.InvalidTemplateContinuation);
}

Expand Down
190 changes: 190 additions & 0 deletions test/parser/expressions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3671,6 +3671,196 @@ describe('Expressions - Template', () => {
}
}
}
],
[
'`${b()}${c()}`',
Context.None | Context.OptionsRanges | Context.OptionsLoc,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'TemplateLiteral',
expressions: [
{
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'b',
start: 3,
end: 4,
range: [3, 4],
loc: {
start: {
line: 1,
column: 3
},
end: {
line: 1,
column: 4
}
}
},
arguments: [],
start: 3,
end: 6,
range: [3, 6],
loc: {
start: {
line: 1,
column: 3
},
end: {
line: 1,
column: 6
}
}
},
{
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'c',
start: 9,
end: 10,
range: [9, 10],
loc: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 10
}
}
},
arguments: [],
start: 9,
end: 12,
range: [9, 12],
loc: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 12
}
}
}
],
quasis: [
{
type: 'TemplateElement',
value: {
cooked: '',
raw: ''
},
tail: false,
start: 1,
end: 1,
range: [1, 1],
loc: {
start: {
line: 1,
column: 1
},
end: {
line: 1,
column: 1
}
}
},
{
type: 'TemplateElement',
value: {
cooked: '',
raw: ''
},
tail: false,
start: 7,
end: 7,
range: [7, 7],
loc: {
start: {
line: 1,
column: 7
},
end: {
line: 1,
column: 7
}
}
},
{
type: 'TemplateElement',
value: {
cooked: '',
raw: ''
},
tail: true,
start: 13,
end: 13,
range: [13, 13],
loc: {
start: {
line: 1,
column: 13
},
end: {
line: 1,
column: 13
}
}
}
],
start: 0,
end: 14,
range: [0, 14],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 14
}
}
},
start: 0,
end: 14,
range: [0, 14],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 14
}
}
}
],
start: 0,
end: 14,
range: [0, 14],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 14
}
}
}
]
]);
});

0 comments on commit aa0e992

Please sign in to comment.