sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.97k stars 360 forks source link

Unable to use meta.get-mixin to pass mixin as a value to another mixin, then use it in its content. #2154

Closed curlykay closed 10 months ago

curlykay commented 10 months ago

Bug report

I get a compilation error when I use the following SCSS code snippet in the project.

@use "sass:meta";

@mixin theme-style($mixin) {
  :root {
    @include meta.apply($mixin);
  }
}

@mixin light() {
    --text-color: #000;
}

@include theme-style(meta.get-mixin("light"));

In fact, this SCSS snippet runs correctly on the SCSS playground. After the issue, @alexander-akait asked me to come here for help. https://github.com/webpack-contrib/sass-loader/issues/1174#issuecomment-1871167294

https://sass-lang.com/playground/#eJxNjcEKwyAQRO9+xWJ70IPFXPXir0i6JILGEDeQEPLvbZem9DYMb950XVgbgmyxNVeQovRChJK2NAGNWNA02jOqO1caDgHgllqJE0BIU5/XJ8Jn+4jznPeL9W/gFOdPl9MwktLfoTGEG5m+5ro4uFlrPbOX7/+c3QOSYZGSbJJa+xdXFTwC

image

PS: This is the smallest complete SCSS snippet I have simplified for verification purposes. If you need the SCSS code from my project, please let me know.

Actual Behavior

print error:

Bad state: Can't access __parent outside of a module.
image

Expected Behavior

Generating CSS Output Correctly:

:root {
  --text-color: #000;
}

How Do We Reproduce?

You can reproduce it just by importing this SCSS snippet into any Webpack project that uses sass-loader.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System: OS: macOS 13.4.1 CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz Memory: 12.07 MB / 8.00 GB Binaries: Node: 18.18.2 - ~/Library/pnpm/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.4.1 - /usr/local/bin/npm Browsers: Chrome: 120.0.6099.129 Edge: 120.0.2210.91 Safari: 16.5.1 Packages: sass: ^1.69.5 => 1.69.5 css-loader: ^6.8.1 => 6.8.1 sass-loader: ^13.3.3 => 13.3.3 style-loader: ^3.3.3 => 3.3.3 webpack: ^5.89.0 => 5.89.0 webpack-cli: ^5.1.4 => 5.1.4

ntkme commented 10 months ago

This should have been fixed in 1.69.6 released just an hour ago.

curlykay commented 10 months ago

Incredible efficiency, thank you for your efforts.

nex3 commented 10 months ago

Thanks to you for the thorough and reproducible bug report!