@@ -11,35 +11,39 @@ import {
1111 normalizeSourceMap ,
1212} from "./utils.js" ;
1313
14- // eslint-disable-next-line jsdoc/reject-any-type
15- /** @typedef {any } EXPECTED_ANY */
14+ /** @typedef {import("webpack").LoaderContext<LoaderOptions> } LoaderContext */
15+ /** @typedef {import("schema-utils/declarations/validate").Schema } Schema */
16+ /** @typedef {import("./utils.js").LoaderOptions } LoaderOptions */
17+ /** @typedef {import("./utils.js").SassError } SassError */
1618
1719/**
1820 * The sass-loader makes dart-sass and sass-embedded available to webpack modules.
19- * @this {LoaderContext<{ string: EXPECTED_ANY } > }
21+ * @this {LoaderContext}
2022 * @param {string } content content
23+ * @returns {Promise<void> } loader result
2124 */
2225async function loader ( content ) {
23- const options = this . getOptions ( schema ) ;
26+ const options = this . getOptions ( /** @type { Schema } */ ( schema ) ) ;
2427 const callback = this . async ( ) ;
2528
2629 let implementation ;
2730
2831 try {
29- implementation = await getSassImplementation ( this , options . implementation ) ;
32+ implementation = await getSassImplementation ( options . implementation ) ;
3033 } catch ( error ) {
31- callback ( error ) ;
34+ callback ( /** @type { Error } */ ( error ) ) ;
3235
3336 return ;
3437 }
3538
3639 const useSourceMap =
37- typeof options . sourceMap === "boolean" ? options . sourceMap : this . sourceMap ;
40+ typeof options . sourceMap === "boolean"
41+ ? options . sourceMap
42+ : this . sourceMap === true ;
3843 const sassOptions = await getSassOptions (
3944 this ,
4045 options ,
4146 content ,
42- implementation ,
4347 useSourceMap ,
4448 ) ;
4549
@@ -49,18 +53,15 @@ async function loader(content) {
4953 : true ;
5054
5155 if ( shouldUseWebpackImporter ) {
52- sassOptions . importers . push (
53- // No need to pass `loadPaths`, because modern API handle them itself
54- getModernWebpackImporter ( this , implementation , [ ] ) ,
55- ) ;
56+ sassOptions . importers . push ( getModernWebpackImporter ( this ) ) ;
5657 }
5758
5859 let compile ;
5960
6061 try {
6162 compile = getCompileFn ( this , implementation , options . api ) ;
6263 } catch ( error ) {
63- callback ( error ) ;
64+ callback ( /** @type { Error } */ ( error ) ) ;
6465 return ;
6566 }
6667
@@ -69,17 +70,19 @@ async function loader(content) {
6970 try {
7071 result = await compile ( sassOptions ) ;
7172 } catch ( error ) {
73+ const sassError = /** @type {SassError } */ ( error ) ;
74+
7275 // There are situations when the `span.url` property does not exist
73- if ( error . span && typeof error . span . url !== "undefined" ) {
74- this . addDependency ( url . fileURLToPath ( error . span . url ) ) ;
76+ if ( sassError . span && typeof sassError . span . url !== "undefined" ) {
77+ this . addDependency ( url . fileURLToPath ( sassError . span . url ) ) ;
7578 }
7679
77- callback ( errorFactory ( error ) ) ;
80+ callback ( errorFactory ( sassError ) ) ;
7881
7982 return ;
8083 }
8184
82- let map = result . sourceMap || null ;
85+ let map = result . sourceMap || undefined ;
8386
8487 // Modify source paths only for webpack, otherwise we do nothing
8588 if ( map && useSourceMap ) {
@@ -99,7 +102,7 @@ async function loader(content) {
99102 }
100103 }
101104
102- callback ( null , result . css . toString ( ) , map ) ;
105+ callback ( null , result . css . toString ( ) , map || undefined ) ;
103106}
104107
105108export default loader ;
0 commit comments