Closed zaynv closed 6 years ago
Hi @zaynv - so sorry I couldn't respond sooner!
I have a hunch this is to do with the way template tags work - some can be nested, some cannot - depending on the logic performed in the tag. This case is an example of the latter: stripIndent
trims surrounding whitespace, then processes substitutions - so it's likely that this is correct output. I however am not 100% certain that what you're trying to accomplish here is impossible, so I will investigate it when I have some time.
This might be related: #109.
It turns out this was related. The reason for the code not working as expected is that sourceIndent
does not indent multiline strings from substitutions, unlike source
. What would work instead is using the source
tag again:
const template = source`
${generateFruits()}
`
This might be misleading, so I added a note to the docs.
Here is my current code:
If I do
console.log(generateFruits())
, I get the expected output:However, if I create a variable called
template
and usegenerateFruits()
inside of there, it doesn't seem to work:I thought that this would give the same output, but instead it seems to give this:
And if I remove the
stripIndent
, it gives this:Why does using
generateFruits()
inside a different template literal make it lose the indentation?