addFileScope
: Don't mangle non-template strings that contain newlines
#1406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1405.
TL;DR: multi-line strings with literal newlines were being manged by
dedent
(ultimately because of SWC, see extra notes below).These used to be correctly dedented by
outdent
in@vanilla-extract/integration@7.1.2
, but since swapping todedent
, it was no longer being handled correctly.The fix is simple though: call
dedent
as a function, rather than a string tag. This was actually a bug indedent
that was fixed relatively recently, hence the version bump.Extra notes
I was stumped for a while trying to reproduce this within VE's test suite. I was seeing identical output between
dedent
andoutdent
. I then realised that there are actually two loaders being used in the reproduction: Vanilla Extract's, and the swc loader.It turns out that swc targets ES3 syntax by default. This results in all template strings being converted to regular strings, because template strings were only added in ES6. In the case of multi-line strings, you end up with something like:
So an alternative way to fix this is to configure storybook to either not use SWC, or configure SWC to target ES6 or greater:
Obviously fixing the issue within VE is the best option, but I'm glad I'm at least aware of potential Storybook + SWC issues going forward.