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

fix: support member exp before tagged template (String.raw) #253

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
jsep.hooks.add('gobble-token', gobbleTemplateLiteral);

jsep.hooks.add('after-token', function gobbleTaggedTemplateIdentifier(env) {
if (env.node.type === jsep.IDENTIFIER && this.code === BTICK_CODE) {
if ((env.node.type === jsep.IDENTIFIER || env.node.type === jsep.MEMBER_EXP) && this.code === BTICK_CODE) {
6utt3rfly marked this conversation as resolved.
Show resolved Hide resolved
env.node = {
type: TAGGED_TEMPLATE_EXPRESSION,
tag: env.node,
Expand Down
87 changes: 87 additions & 0 deletions packages/template/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,93 @@ const { test } = QUnit;
}, assert);
});

test('should parse String.raw tagged, nested template literal expression', (assert) => {
testParser('String.raw`token ${`nested ${`deeply` + "str"} blah`}`', {
type: 'TaggedTemplateExpression',
tag: {
type: "MemberExpression",
computed: false,
object: {
type: "Identifier",
name: "String"
},
property: {
type: "Identifier",
name:"raw"
}
},
quasi: {
type: 'TemplateLiteral',
quasis: [
{
type: 'TemplateElement',
value: {
raw: 'token ',
cooked: 'token ',
},
tail: false,
},
{
type: 'TemplateElement',
value: {
raw: '',
cooked: '',
},
tail: true,
},
],
expressions: [
{
type: 'TemplateLiteral',
quasis: [
{
type: 'TemplateElement',
value: {
raw: 'nested ',
cooked: 'nested ',
},
tail: false,
},
{
type: 'TemplateElement',
value: {
raw: ' blah',
cooked: ' blah',
},
tail: true,
},
],
expressions: [
{
type: 'BinaryExpression',
operator: '+',
left: {
type: 'TemplateLiteral',
quasis: [
{
type: 'TemplateElement',
value: {
raw: 'deeply',
cooked: 'deeply',
},
tail: true,
},
],
expressions: [],
},
right: {
type: 'Literal',
value: 'str',
raw: '"str"',
},
},
],
},
],
},
}, assert);
});

test('should parse multiple vars within template literal expression', (assert) => {
testParser('`hi ${last}, ${first} ${middle}!`', {
type: 'TemplateLiteral',
Expand Down
Loading