-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(svelte): Track components without <script>
tags
#5930
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
Conversation
expect(preProc.markup).toBeUndefined(); | ||
expect(preProc.style).toBeUndefined(); | ||
}); | ||
describe('script hook', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewers: Nothing was changed in the tests within this new describe('script hook')
closure. I just added this level because the tests we had previously only test our preprocessor's script
hook, while the new tests I added test the markup
hook as well as the entire preprocessor
// A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot | ||
// think of why one would do this in Svelte components. | ||
// Also, we just want to know if there is a <script> tag in the entire file content; not if | ||
return /<script(\s+.+)?>.*<\/script>/s.test(content); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
// A case that is not covered by regex-testing HTML is e.g. nested <script> tags but I cannot | ||
// think of why one would do this in Svelte components. | ||
// Also, we just want to know if there is a <script> tag in the entire file content; not if | ||
return /<script(\s+.+)?>.*<\/script>/s.test(content); |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp
Trying a little different approach at the moment as this regex check is not great |
Closing this in favour of a new, more robust approach. See #5923 (To Do section) for more details |
This PR fixes a bug in our Svelte component tracking implementation where Svelte components without a
<script>
tag were not tracked.It adds a function to the preprocessor's
markup
hook that has access to the whole.svelte
component file. In this function we check if there is a script tag and in case there is not, we add an empty<script> </script>
tag to the code. This will later on be picked up by thescript
hook where we inject ourtrackComponent
function call.Furthermore, this PR adds a few tests to check this new behaviour. It's worth mentioning that I added two "higher level" tests that actually use the Svelte compiler's own
preprocess
function to which we pass our preprocessor. This gives us a more close to real-use testing scenario.fixes #5923