Skip to content

Commit

Permalink
feat(string): add support for tagged templ strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Mar 2, 2020
1 parent 911e309 commit d6d81e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/transform/__snapshots__/string.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ exports[`compiles regex 1`] = `
line 2 with leading space
line 3\`;
const str2 = \`ab\`;
const str3 = foo\`bar spam \${shrub}\`;
Object.assign(module.exports, {
str1,
str2
str2,
str3
});"
`;
17 changes: 12 additions & 5 deletions src/transform/string.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {templateElement, templateLiteral} from '@babel/types';
import {templateElement, templateLiteral, taggedTemplateExpression} from '@babel/types';


export const transform_string = (node)=> (
templateLiteral(
export const transform_string = (node, {transform})=> {
const templ_str = templateLiteral(
node.parts.map((part)=> templateElement({raw: part, cooked: part})),
[]
)
);
);

if (node.tag) {

return taggedTemplateExpression(transform(node.tag), templ_str);
}

return templ_str;
};

2 changes: 2 additions & 0 deletions src/transform/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ test('compiles regex', ()=> {
line 3\`
str2 = \`ab\`
str3 = foo\`bar spam \${shrub}\`
`)
).toMatchSnapshot();
});

0 comments on commit d6d81e7

Please sign in to comment.