Skip to content

Commit e8b06ff

Browse files
authored
(fix) script/style toplevel check (#693)
Handle unclosed tags #690
1 parent 6f3d4fd commit e8b06ff

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/language-server/src/lib/documents/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ function extractTags(text: string, tag: 'script' | 'style', html?: HTMLDocument)
9090
const nodes = rootNodes.slice(rootNodes.indexOf(tag));
9191
const rootContentAfterTag = nodes
9292
.map((node, idx) => {
93-
return text.substring(node.end, nodes[idx + 1]?.start);
93+
const start = node.startTagEnd ? node.end : node.start + (node.tag?.length || 0);
94+
return text.substring(start, nodes[idx + 1]?.start);
9495
})
9596
.join('');
9697

packages/language-server/test/lib/documents/utils.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ describe('document/utils', () => {
9292
});
9393
});
9494

95+
it('can extract with unclosed component after it', () => {
96+
const extracted = extractStyleTag('<style></style><C {#if asd}<p>asd</p>{/if}');
97+
assert.deepStrictEqual(extracted, {
98+
start: 7,
99+
end: 7,
100+
startPos: {
101+
character: 7,
102+
line: 0
103+
},
104+
endPos: {
105+
character: 7,
106+
line: 0
107+
},
108+
attributes: {},
109+
content: '',
110+
container: {
111+
start: 0,
112+
end: 15
113+
}
114+
});
115+
});
116+
95117
it('extracts style tag', () => {
96118
const text = `
97119
<p>bla</p>

0 commit comments

Comments
 (0)