-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: account for sourcemap in meta info (#8778)
We need to use a different method for getting the meta info because `locate` is used to help construct the source map that references the preprocessed Svelte file. If we would now add source maps to that `locate` function it would go the the original source directly which means skipping potentially intermediate source maps which we would need in other situations. Sadly we can't map the character offset because for that we would need to the original source contents which we don't have in this context. fixes #8360 closes #8362
- Loading branch information
1 parent
5702142
commit ef1b98f
Showing
9 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: account for preprocessor source maps when calculating meta info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/svelte/test/runtime/samples/element-source-location-preprocessed/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import MagicString from 'magic-string'; | ||
import * as path from 'node:path'; | ||
|
||
// fake preprocessor by doing transforms on the source | ||
const str = new MagicString( | ||
`<script> | ||
type Foo = 'foo'; | ||
let foo = 'foo'; | ||
</script> | ||
<h1>{foo}</h1> | ||
`.replace(/\r\n/g, '\n') | ||
); | ||
str.remove(8, 26); // remove line type Foo = ... | ||
str.remove(55, 56); // remove whitespace before <h1> | ||
|
||
export default { | ||
compileOptions: { | ||
dev: true, | ||
sourcemap: str.generateMap({ hires: true }) | ||
}, | ||
|
||
test({ assert, target }) { | ||
const h1 = target.querySelector('h1'); | ||
|
||
assert.deepEqual(h1.__svelte_meta.loc, { | ||
file: path.relative(process.cwd(), path.resolve(__dirname, 'main.svelte')), | ||
line: 5, // line 4 in main.svelte, but that's the preprocessed code, the original code is above in the fake preprocessor | ||
column: 1, // line 0 in main.svelte, but that's the preprocessed code, the original code is above in the fake preprocessor | ||
char: 38 // TODO this is wrong but we can't backtrace it due to limitations, see add_location function usage comment for more info | ||
}); | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/svelte/test/runtime/samples/element-source-location-preprocessed/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let foo = 'foo'; | ||
</script> | ||
|
||
<h1>{foo}</h1> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.