File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' svelte-language-server ' : patch
3+ ---
4+
5+ fix: always treat a script tag as top-level if it's the first tag in the file
Original file line number Diff line number Diff line change @@ -72,6 +72,15 @@ function extractTags(
7272 * If that is BEFORE `{#X`, we are inside a moustache tag.
7373 */
7474 function isNotInsideControlFlowTag ( tag : Node ) {
75+ const tagIndex = rootNodes . indexOf ( tag ) ;
76+ // Quick check: if the tag has nothing before it, it can't be inside a control flow tag
77+ // This also works around a case where the tag is treated as under a control flow tag when vscode-html-languageservice parses something wrong
78+ if ( tagIndex === 0 ) {
79+ const startContent = text . substring ( 0 , tag . start ) ;
80+ if ( startContent . trim ( ) === '' ) {
81+ return true ;
82+ }
83+ }
7584 const nodes = rootNodes . slice ( rootNodes . indexOf ( tag ) ) ;
7685 const rootContentAfterTag = nodes
7786 . map ( ( node , idx ) => {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ describe('document/utils', () => {
5050 assert . deepStrictEqual ( extractStyleTag ( text ) , null ) ;
5151 } ) ;
5252
53- it ( 'is canse sensitive to style/script' , ( ) => {
53+ it ( 'is case sensitive to style/script' , ( ) => {
5454 const text = `
5555 <Style></Style>
5656 <Script></Script>
@@ -344,6 +344,20 @@ describe('document/utils', () => {
344344 container : { start : 151 , end : 181 }
345345 } ) ;
346346 } ) ;
347+
348+ it ( 'extract tag correctly if nothing is before the tag' , ( ) => {
349+ const text = `<script>let value = 2</script>
350+ {/if}` ;
351+ assert . deepStrictEqual ( extractScriptTags ( text ) ?. script , {
352+ content : 'let value = 2' ,
353+ attributes : { } ,
354+ start : 8 ,
355+ end : 21 ,
356+ startPos : Position . create ( 0 , 8 ) ,
357+ endPos : Position . create ( 0 , 21 ) ,
358+ container : { start : 0 , end : 30 }
359+ } ) ;
360+ } ) ;
347361 } ) ;
348362
349363 describe ( '#getLineAtPosition' , ( ) => {
You can’t perform that action at this time.
0 commit comments