Skip to content

Commit

Permalink
adjust HAS_IMPORT regex (#1062)
Browse files Browse the repository at this point in the history
fix #1060 

match RegExp `HAS_IMPORT` with `fileMayBeTailwindRelated()`

---

```js
let HAS_IMPORT = /@import\s*('[^']+'|"[^"]+");/
let HAS_IMPORT = /@import\s*['"]/ // from fileMayBeTailwindRelated()
```

It seemed like the regex only accepted `@import '~~~';`, so `@import
'~~~' layer(xxx);` did not match.
Therefore, I loosened the regex of `HAS_IMPORT` a bit so that it would
match the other parts.

<sub>translated from japanese</sub>
  • Loading branch information
manmen-mi authored Sep 30, 2024
1 parent 6c3409a commit 83cccdb
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/tailwindcss-language-server/src/project-locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ testFixture('v4/auto-content', [
},
])

testFixture('v4/auto-content-split', [
//
{
config: 'src/app.css',
content: [
'{URL}/package.json',
'{URL}/src/index.html',
'{URL}/src/components/example.html',
'{URL}/src/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
],
},
])

testFixture('v4/custom-source', [
//
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class FileEntry {
isMaybeTailwindRelated(): boolean {
if (!this.content) return false

let HAS_IMPORT = /@import\s*('[^']+'|"[^"]+");/
let HAS_IMPORT = /@import\s*['"]/
let HAS_TAILWIND = /@tailwind\s*[^;]+;/
let HAS_DIRECTIVE = /@(theme|plugin|config|utility|variant|apply)\s*[^;{]+[;{]/

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"tailwindcss": "^4.0.0-alpha.25",
"@tailwindcss/oxide": "^4.0.0-alpha.25"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "tailwindcss/preflight" layer(base);
@import "tailwindcss/theme" layer(theme);
@import "tailwindcss/utilities" layer(utilities);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="underline">Test</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="flex">Test</div>

0 comments on commit 83cccdb

Please sign in to comment.