You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently the svelte parser fails to parse typescript
when the first script tag is javascript
<script>
console.log("hello from javascript")
</script>
<scriptlang="ts">
console.log("hello from typescript")exportlet name:string|null;
</script>
CompileError [ParseError]: Unexpected token
at error (node_modules/svelte/compiler.js:16675:20)
at Parser$1.error (node_modules/svelte/compiler.js:16753:10)
at Parser$1.acorn_error (node_modules/svelte/compiler.js:16747:15)
at Object.read_script [as read] (node_modules/svelte/compiler.js:8799:17)
at tag (node_modules/svelte/compiler.js:15701:34)
at new Parser$1 (node_modules/svelte/compiler.js:16712:22)
at parse$I (node_modules/svelte/compiler.js:16844:21)
at node_modules/@builder.io/mitosis/dist/src/parsers/svelte/index.js:98:48
at step (node_modules/@builder.io/mitosis/dist/src/parsers/svelte/index.js:33:23)
at Object.next (node_modules/@builder.io/mitosis/dist/src/parsers/svelte/index.js:14:53)
at fulfilled (node_modules/@builder.io/mitosis/dist/src/parsers/svelte/index.js:5:58) {
functionisTypeScriptComponent(string_){constregex=createTagRegex('script','gi');// bad: use only first match/* const match = regex.exec(string_);console.log("match", match) const { lang } = parseAttributes((match?.length && match[1]) || ''); return lang === 'ts';*/// good: use all matches// https://stackoverflow.com/a/6323598/10440128varisTypeScript=false;string_.replace(regex,(...match)=>{//console.log("match:\n", match)const{ lang }=parseAttributes((match?.length&&match[1])||'');if(lang==='ts')isTypeScript=true;});returnisTypeScript;}/** Create a tag matching regexp. */functioncreateTagRegex(tagName,flags){console.log(`/<!--[^]*?-->|<${tagName}(\\s[^]*?)?(?:>([^]*?)<\\/${tagName}>|\\/>)`);returnnewRegExp(`/<!--[^]*?-->|<${tagName}(\\s[^]*?)?(?:>([^]*?)<\\/${tagName}>|\\/>)`,flags);}/** Transform an attribute string into a key-value object */functionparseAttributes(attributesString){returnattributesString.split(/\s+/).filter(Boolean).reduce((accumulator,attribute)=>{const[name,value]=attribute.split('=');// istanbul ignore nextaccumulator[name]=value ? value.replace(/["']/g,'') : true;returnaccumulator;},{});}varc=`<script> console.log("hello from javascript")</script><script lang="ts"> console.log("hello from typescript") export let name: string | null;</script>`console.log(isTypeScriptComponent(c))
ideally, the svelte parser should use my svelte.config.js
currently the svelte parser fails to parse typescript
when the first script tag is javascript
parsers/svelte/index.js:98:
const ast = parse(processedString.code);
processedString.code has unprocessed typescript in
<script lang="ts">
mitosis/packages/core/src/parsers/svelte/index.ts
Lines 52 to 73 in 8eea6e0
blame isTypeScriptComponent
mitosis/packages/core/src/parsers/svelte/typescript/index.ts
Lines 10 to 15 in 8eea6e0
const match = regex.exec(string_);
gets only the first matchfix
mitosis/packages/core/src/parsers/svelte/typescript/index.ts
ideally, the svelte parser should use my svelte.config.js
The text was updated successfully, but these errors were encountered: