The above issue is related to another bug in SWC that results in spans being accumalated. Internally this is done to get their sourcemap functionality working, but to workaround this, you will need to either:
Store the offset of the Module or Script in a separate variable and subtract all other spans by that number. This will require AST Explorer to also calculate an extra span offset for header comments, because the span of the Module excludes any header offsets
Reinitialize the parser every single time the user makes a change
Browser (please complete the following information):
OS: mac
Browser chrome
Version 120
astexplorer settings:
Selected parser: swc
Selected transformer (if applicable): none
Contents of the local storage key explorerSettingsV1 (code can be removed if you don't want it to be public)
Describe the bug A clear and concise description of what the bug is.
Multi-byte offsets
Currently, if you try to insert a multi-byte character in your code on AST Explorer, this eats up more space in the span.
This is related to the fact that the span values in SWC refer to byte positions instead of string indices: https://github.com/swc-project/swc/issues/1366#issuecomment-1576294504
Code:
Reproducing:
Accumalating Offsets
https://github.com/fkling/astexplorer/assets/53054099/1baefef0-a5cd-401e-8fc5-4229d2b82def
The above issue is related to another bug in SWC that results in spans being accumalated. Internally this is done to get their sourcemap functionality working, but to workaround this, you will need to either:
Module
orScript
in a separate variable and subtract all other spans by that number. This will require AST Explorer to also calculate an extra span offset for header comments, because the span of theModule
excludes any header offsetsBrowser (please complete the following information):
astexplorer settings:
explorerSettingsV1
(code can be removed if you don't want it to be public)Additional context Add any other context about the problem here.
Related to https://github.com/swc-project/swc/issues/1366
BTW thank you so much for making AST Explorer a thing, it helps me out a lot in my daily workflow :)
I can open up a PR to fix this if you want, bcuz I got these problems working in another project I am building that uses swc.