Skip to content

Commit dbb2604

Browse files
authored
fix(css): don't transform sass function calls with namespace (#18414)
1 parent ddee0ad commit dbb2604

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

packages/vite/src/node/plugins/css.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const commonjsProxyRE = /\?commonjs-proxy/
197197
const inlineRE = /[?&]inline\b/
198198
const inlineCSSRE = /[?&]inline-css\b/
199199
const styleAttrRE = /[?&]style-attr\b/
200-
const functionCallRE = /^[A-Z_][\w-]*\(/i
200+
const functionCallRE = /^[A-Z_][.\w-]*\(/i
201201
const transformOnlyRE = /[?&]transform-only\b/
202202
const nonEscapedDoubleQuoteRe = /(?<!\\)"/g
203203

playground/css-sourcemap/__tests__/css-sourcemap.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ describe.runIf(isServe)('serve', () => {
145145
"/root/imported-nested.sass",
146146
],
147147
"sourcesContent": [
148-
"@import "/imported-nested.sass"
148+
"@use "/imported-nested.sass"
149149
150150
.imported
151151
&-sass
152-
color: $primary
152+
color: imported-nested.$primary
153153
",
154154
"$primary: red
155155
",
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@import "/imported-nested.sass"
1+
@use "/imported-nested.sass"
22

33
.imported
44
&-sass
5-
color: $primary
5+
color: imported-nested.$primary

playground/css-sourcemap/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineConfig({
3232
},
3333
},
3434
sass: {
35-
silenceDeprecations: ['legacy-js-api'],
35+
silenceDeprecations: ['legacy-js-api', 'import'],
3636
},
3737
},
3838
},

playground/css/nested/_index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ $var: '/ok.png';
2020

2121
$var2: '/OK.PNG';
2222
.sass-url-starts-with-function-call {
23-
background: url(to-lower-case($var2));
23+
background: url(string.to-lower-case($var2));
2424
background-position: center;
2525
}

playground/css/sass.scss

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
@import '=/nested'; // alias + custom index resolving -> /nested/_index.scss
2-
@import '=/nested/partial'; // sass convention: omitting leading _ for partials
3-
@import '@vitejs/test-css-dep'; // package w/ sass entry points
4-
@import '@vitejs/test-css-dep-exports'; // package with a sass export mapping
5-
@import '@vitejs/test-scss-proxy-dep'; // package with a sass proxy import
6-
@import 'virtual-dep'; // virtual file added through importer
7-
@import '=/pkg-dep'; // package w/out sass field
8-
@import '=/weapp.wxss'; // wxss file
9-
@import 'virtual-file-absolute';
10-
@import '=/scss-dir/main.scss'; // "./dir" reference from vite custom importer
1+
@use '=/nested'; // alias + custom index resolving -> /nested/_index.scss
2+
@use '=/nested/partial'; // sass convention: omitting leading _ for partials
3+
@use '@vitejs/test-css-dep'; // package w/ sass entry points
4+
@use '@vitejs/test-css-dep-exports'; // package with a sass export mapping
5+
@use '@vitejs/test-scss-proxy-dep'; // package with a sass proxy import
6+
@use 'virtual-dep'; // virtual file added through importer
7+
@use '=/pkg-dep'; // package w/out sass field
8+
@use '=/weapp.wxss'; // wxss file
9+
@use 'virtual-file-absolute';
10+
@use '=/scss-dir/main.scss'; // "./dir" reference from vite custom importer
1111

1212
.sass {
1313
/* injected via vite.config.js */

playground/css/scss-dir/main.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@import './dir';
1+
@use './dir';
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@import '@vitejs/test-scss-proxy-dep-nested/index.css';
1+
@use '@vitejs/test-scss-proxy-dep-nested/index.css';

playground/css/vite.config-sass-modern.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineConfig({
3434
},
3535
load() {
3636
return {
37-
contents: `@import "${pathToFileURL(path.join(import.meta.dirname, 'file-absolute.scss')).href}"`,
37+
contents: `@use "${pathToFileURL(path.join(import.meta.dirname, 'file-absolute.scss')).href}"`,
3838
syntax: 'scss',
3939
}
4040
},

playground/css/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ export default defineConfig({
6969
function (url) {
7070
return url === 'virtual-file-absolute'
7171
? {
72-
contents: `@import "${pathToFileURL(path.join(import.meta.dirname, 'file-absolute.scss')).href}"`,
72+
contents: `@use "${pathToFileURL(path.join(import.meta.dirname, 'file-absolute.scss')).href}"`,
7373
}
7474
: null
7575
},
7676
function (url) {
7777
return url.endsWith('.wxss') ? { contents: '' } : null
7878
},
7979
],
80-
silenceDeprecations: ['legacy-js-api'],
80+
silenceDeprecations: ['legacy-js-api', 'import'],
8181
},
8282
styl: {
8383
additionalData: `$injectedColor ?= orange`,

0 commit comments

Comments
 (0)