Skip to content

Commit 4752553

Browse files
committed
Test
1 parent e6e8cb4 commit 4752553

File tree

8 files changed

+70
-1
lines changed

8 files changed

+70
-1
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function getLoaderConfig (ctx) {
106106
function hoistUseRule (content) {
107107
const list = []
108108

109-
const cleared = content.replace(/@use [^;];/g, (match) => {
109+
const cleared = content.replace(/@use [^;]*;/g, (match) => {
110110
if (!list.includes(match)) {
111111
list.push(match)
112112
}

test/fixtures/use-rule/expect.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
header {
2+
background: #ccc;
3+
}
4+
5+
header {
6+
width: 1px;
7+
}
8+
9+
header {
10+
height: 1px;
11+
}

test/fixtures/use-rule/index.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@import "without-use.scss";
2+
@import "with-use.scss";
3+
@import "second-with-use.scss";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use "sass:math";
2+
3+
header {
4+
height: math.div(6px, 6);
5+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const path = require('path')
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5+
const loader = require.resolve('../../..')
6+
const cssLoader = require.resolve('css-loader')
7+
8+
module.exports = {
9+
context: path.join(__dirname),
10+
entry: {
11+
index: './index.scss'
12+
},
13+
output: {
14+
path: path.join(__dirname, '../../runtime/use-rule'),
15+
filename: '[name].js'
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.(scss|sass)$/,
21+
use: ExtractTextPlugin.extract({
22+
use: [
23+
cssLoader,
24+
loader
25+
]
26+
})
27+
},
28+
{
29+
test: /\.png$/,
30+
loader: 'file-loader?name=[path][name].[ext]'
31+
}
32+
]
33+
},
34+
plugins: [
35+
new ExtractTextPlugin('[name].css')
36+
]
37+
}

test/fixtures/use-rule/with-use.scss

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use "sass:math";
2+
3+
header {
4+
width: math.div(5px, 5);
5+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
header {
2+
background: #ccc;
3+
}

test/index.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ describe('test sass-loader', function() {
148148
runSimpleTest(done, 'data-import-issue')
149149
})
150150

151+
152+
it('should be able to hoist @use rule usage in merged content', function(done) {
153+
runSimpleTest(done, 'use-rule')
154+
})
155+
151156
it('should pass options to sass.render (#53)', function(done) {
152157
runSimpleTest(done, 'pass-output-style')
153158
})

0 commit comments

Comments
 (0)