@@ -49,34 +49,34 @@ const factory = (isEnabled: boolean, _options: never, context: {fix: boolean}) =
49
49
50
50
/** Extracts the namespace of an `@use` rule from its parameters. */
51
51
function extractNamespaceFromUseStatement ( params : string ) : string | null {
52
- const closeQuoteIndex = Math . max ( params . lastIndexOf ( `"` ) , params . lastIndexOf ( `'` ) ) ;
52
+ const openQuoteIndex = Math . max ( params . indexOf ( `"` ) , params . indexOf ( `'` ) ) ;
53
+ const closeQuoteIndex =
54
+ Math . max ( params . indexOf ( `"` , openQuoteIndex + 1 ) , params . indexOf ( `'` , openQuoteIndex + 1 ) ) ;
53
55
54
56
if ( closeQuoteIndex > - 1 ) {
55
57
const asExpression = 'as ' ;
56
58
const asIndex = params . indexOf ( asExpression , closeQuoteIndex ) ;
59
+ const withIndex = params . indexOf ( ' with' , asIndex ) ;
57
60
58
61
// If we found an ` as ` expression, we consider the rest of the text as the namespace.
59
62
if ( asIndex > - 1 ) {
60
- return params . slice ( asIndex + asExpression . length ) . trim ( ) ;
63
+ return withIndex == - 1 ?
64
+ params . slice ( asIndex + asExpression . length ) . trim ( ) :
65
+ params . slice ( asIndex + asExpression . length , withIndex ) . trim ( ) ;
61
66
}
62
67
63
- const openQuoteIndex = Math . max ( params . lastIndexOf ( `"` , closeQuoteIndex - 1 ) ,
64
- params . lastIndexOf ( `'` , closeQuoteIndex - 1 ) ) ;
68
+ const importPath = params . slice ( openQuoteIndex + 1 , closeQuoteIndex )
69
+ // Sass allows for leading underscores to be omitted and it technically supports .scss.
70
+ . replace ( / ^ _ | ( \. i m p o r t ) ? \. s c s s $ | \. i m p o r t $ / g, '' ) ;
65
71
66
- if ( openQuoteIndex > - 1 ) {
67
- const importPath = params . slice ( openQuoteIndex + 1 , closeQuoteIndex )
68
- // Sass allows for leading underscores to be omitted and it technically supports .scss.
69
- . replace ( / ^ _ | ( \. i m p o r t ) ? \. s c s s $ | \. i m p o r t $ / g, '' ) ;
70
-
71
- // Built-in Sass imports look like `sass:map`.
72
- if ( importPath . startsWith ( 'sass:' ) ) {
73
- return importPath . split ( 'sass:' ) [ 1 ] ;
74
- }
75
-
76
- // Sass ignores `/index` and infers the namespace as the next segment in the path.
77
- const fileName = basename ( importPath ) ;
78
- return fileName === 'index' ? basename ( join ( fileName , '..' ) ) : fileName ;
72
+ // Built-in Sass imports look like `sass:map`.
73
+ if ( importPath . startsWith ( 'sass:' ) ) {
74
+ return importPath . split ( 'sass:' ) [ 1 ] ;
79
75
}
76
+
77
+ // Sass ignores `/index` and infers the namespace as the next segment in the path.
78
+ const fileName = basename ( importPath ) ;
79
+ return fileName === 'index' ? basename ( join ( fileName , '..' ) ) : fileName ;
80
80
}
81
81
82
82
return null ;
0 commit comments