-
Notifications
You must be signed in to change notification settings - Fork 113
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 trim bug with intro/outro #144
Conversation
Well, semantically the original behaviour of magic-string was correct. If you "appendRight" then you tell magic-string that the appended code belongs to the code to the right of the insertion. If there is only whitespace which is removed by "trim" or there is no code at all, then it is correct to remove the appended code. But then again, I guess this makes things a little easier for rollup. But the new behaviour is inconsistent. |
The correct way to add an outro is "appendLeft" |
That said, the concept of using One thing that might be useful here is a Alternatively we could look at an |
I think most of our problems with magic-string are related to the fact that magic-string tries to associate appended and prepended code with neighbouring content and remove it together with this code. Because as far as I know this is virtually NEVER what we want because removed nodes are not rendered at all for performance considerations. |
@lukastaegert I agree with your take in the comment above mine. Perhaps expose a // Avoid adding the given content to an `intro` or `outro` of some existing chunk.
magicString.appendLeft(index, chunk(content)); Also, the documentation isn't clear enough about the existing behavior. The concepts of Perhaps all inserted content should get its own @guybedford The |
This fixes a bug where the intro and outro were being removed on trimmed chunks.
This caused issues where
magicSting.appendRight('x').trim()
would remove the'x'
part.