diff --git a/packages/tailwindcss-language-server/tests/env/v4.test.js b/packages/tailwindcss-language-server/tests/env/v4.test.js index 76de7f15..3a7780af 100644 --- a/packages/tailwindcss-language-server/tests/env/v4.test.js +++ b/packages/tailwindcss-language-server/tests/env/v4.test.js @@ -791,3 +791,51 @@ defineTest({ }) }, }) + +defineTest({ + options: { only: true }, + name: 'regex literals do not break language boundaries', + fs: { + 'app.css': css` + @import 'tailwindcss'; + `, + }, + prepare: async ({ root }) => ({ client: await createClient({ root }) }), + handle: async ({ client }) => { + let doc = await client.open({ + lang: 'javascriptreact', + text: js` + export default function Page() { + let styles = "str".match(/ +
+ + `, + }) + + let boundaries = getLanguageBoundaries(file.state, file.doc) + + expect(boundaries).toEqual([ + { + type: 'html', + range: { + start: { line: 0, character: 0 }, + end: { line: 1, character: 2 }, + }, + }, + { + type: 'css', + range: { + start: { line: 1, character: 2 }, + end: { line: 5, character: 2 }, + }, + }, + { + type: 'html', + range: { + start: { line: 5, character: 2 }, + end: { line: 7, character: 6 }, + }, + }, + ]) +}) + +test('script tags in HTML are treated as a separate boundary', ({ expect }) => { + let file = createDocument({ + name: 'file.html', + lang: 'html', + content: html` +
+ +
+
+ `, + }) + + let boundaries = getLanguageBoundaries(file.state, file.doc) + + expect(boundaries).toEqual([ + { + type: 'html', + range: { + start: { line: 0, character: 0 }, + end: { line: 1, character: 2 }, + }, + }, + { + type: 'js', + range: { + start: { line: 1, character: 2 }, + end: { line: 5, character: 2 }, + }, + }, + { + type: 'html', + range: { + start: { line: 5, character: 2 }, + end: { line: 7, character: 6 }, + }, + }, + ]) +}) + +test('Vue files detect