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

Add feature: copy, like move #193

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mvolfik
Copy link
Contributor

@mvolfik mvolfik commented Oct 17, 2021

(I'm lazy, so description just copied from commits)
Just like move (from where the main idea is copied), but keeps the original
chunks in place.

The implementation currently suffers from one drawback - the new chunks
aren't added into the byStart/byEnd indexes - since these index by original
location, the index would now have to lead to 2 locations. So if you copy
first, then overwrite/append/prepend, the changes are only written in the
original location, not on the copied snippet. However, if you do anything
before copying, the changes are carried over.


Regarding the added test and changes in package.json:

In test/dev builds, DEBUG is replaced with true, which runs additional
code marking the 'duplicate' chunks created by .copy() with chunk.isCopy.

This is detected in integrity checker in tests - these chunks are,
as described in previous commit, not included in the indexes, which
isn't easy to solve, so these chunks are just excluded from the check.

In production code (verified with npm run publish), DEBUG is replaced
with false and the code becomes unreachable and is tree-shaked.


Why I'm implementing this

For svelte-check - the type-checking (the svelte2tsx step) around svelte:component this={x} bind:this={y} is simplified (well, pretty much non-existent), and the copy feature is required for implementing it correctly. I hope this could help other projects as well.

Does the resulting source map work

I believe so

Just like move (from where the main idea is copied), but keeps the original
chunks in place.

The implementation currently suffers from one drawback - the new chunks
aren't added into the byStart/byEnd indexes - since these index by original
location, the index would now have to lead to 2 locations. So if you copy
first, then overwrite/append/prepend, the changes are only written in the
original location, not on the copied snippet. However, if you do anything
before copying, the changes are carried over.
In test/dev builds, DEBUG is replaced with true, which runs additional
code marking the 'duplicate' chunks created by .copy() with chunk.isCopy.

This is detected in integrity checker in tests - these chunks are,
as described in previous commit, not included in the indexes, which
isn't easy to solve, so these chunks are just excluded from the check.

In production code (verified with npm run publish), DEBUG is replaced
with false and the code becomes unreachable and is tree-shaked.
@mvolfik
Copy link
Contributor Author

mvolfik commented Oct 17, 2021

(I am actually surprised that copying an insertion again works, though it leads to madness so I hope noone will be doing this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant