Closed minht11 closed 4 months ago
MouseEvent also fails with code below, interestingly only that part, interface itself does not produce any errors.
"Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax."
<script context="module" lang="ts">
export interface ButtonProps {
onclick?: (event: MouseEvent) => void
}
</script>
An option to override parsing would be great, forcing typescript on all "*.svelte" files might be an easy fix to this problem
The fix should be fairly easy, we need to update the regex to take context
into account:
Can anyone help?
@ematipico Instead of adding error prone syntaxes to our regexes, what do you think of using our jsx parser (for the time being of course) to parse the matched <script ... >
openning element? This works for both svelte and vue.
#[test]
pub fn jsx_test() {
let code = r#"
<script context="module" lang="ts">
"#;
let root = parse(code, JsFileSource::jsx(), JsParserOptions::default());
let syntax = root.syntax();
dbg!(&syntax, root.diagnostics(), root.has_errors());
}
I'm not sure how reliable that would be though. The regex is good because it gives us the offsets we need to extract the code.
With the parser, we need to calculate the offsets ourselves, and rely on how well our parser can recover itself and still provide the correct ranges of the script tag.
I'm not sure how reliable that would be though. The regex is good because it gives us the offsets we need to extract the code.
With the parser, we need to calculate the offsets ourselves, and rely on how well our parser can recover itself and still provide the correct ranges of the script tag.
What I wanted to say is that we still use regex to match the script block so we can still have our script body and offsets, but instead we use the JSX parser to parse the opening element to extract the lang
attribute reliably.
Environment information
What happened?
Expected result
No error
Code of Conduct