Skip to content

Tests for fix to crash when mixin @import and @use #2060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ X. Exit testing.

[implementation-specific expectations]: #implementation-specific-expectations

Any option can also be applied to all future occurences of that type of failure
Any option can also be applied to all future occurrences of that type of failure
by adding `!` after it. For example, if you want to mark *all* failing specs as
`:todo` for the current implementation you'd type `I!`.

Expand Down
20 changes: 20 additions & 0 deletions spec/core_functions/meta/load_css/error/load.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,23 @@ Error: Module loop: input.scss is already being loaded.
'
_other.scss 2:1 load-css()
input.scss 2:1 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/input.scss
@use "sass:meta";
@include meta.load-css("upstream");

<===> top_level_include_declaration/_upstream.scss
@mixin a { b: c }
@include a;

<===> top_level_include_declaration/error
Error: Declarations may only be used within style rules.
,
1 | @mixin a { b: c }
| ^^^^^
'
_upstream.scss 1:12 a()
_upstream.scss 2:1 load-css()
input.scss 2:1 root stylesheet
61 changes: 61 additions & 0 deletions spec/core_functions/meta/load_css/extend.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,64 @@ a {
.target, .extender {
a: b;
}

<===>
================================================================================
<===> nested/README.md
These are regression tests for https://github.com/sass/dart-sass/issues/2588.

<===>
================================================================================
<===> nested/without_use/input.scss
@use 'sass:meta';
.a {
@include meta.load-css('upstream');
}

<===> nested/without_use/_upstream.scss
@mixin b { c: d }
@include b;

<===> nested/without_use/output.css
.a {
c: d;
}

<===> nested/without_use/warning
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.
More info and automated migrator: https://sass-lang.com/d/import
,
2 | @import 'upstream';
| ^^^^^^^^^^
'
input.scss 2:11 root stylesheet

<===>
================================================================================
<===> nested/with_use/input.scss
@use 'sass:meta';
.a {
@include meta.load-css('midstream');
}

<===> nested/with_use/_midstream.scss
@use 'upstream';
@mixin b { c: d }
@include b;

<===> nested/with_use/_upstream.scss
// Intentionally empty.

<===> nested/with_use/output.css
.a {
c: d;
}

<===> nested/with_use/warning
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.
More info and automated migrator: https://sass-lang.com/d/import
,
2 | @import 'upstream';
| ^^^^^^^^^^
'
input.scss 2:11 root stylesheet
114 changes: 110 additions & 4 deletions spec/directives/import/nested.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ More info and automated migrator: https://sass-lang.com/d/import
/* Y */

<===> with_comment/_b.scss
@import 'a'
@import 'a';

<===> with_comment/_c.scss
@import 'a'
@import 'a';

<===> with_comment/output.css
/* Y */
Expand Down Expand Up @@ -246,7 +246,7 @@ DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be remo
More info and automated migrator: https://sass-lang.com/d/import

,
1 | @import 'a'
1 | @import 'a';
| ^^^
'
_b.scss 1:9 @import
Expand All @@ -257,8 +257,114 @@ DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be remo
More info and automated migrator: https://sass-lang.com/d/import

,
1 | @import 'a'
1 | @import 'a';
| ^^^
'
_c.scss 1:9 @import
input.scss 2:9 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/README.md
These are regression tests for https://github.com/sass/dart-sass/issues/2588.

<===>
================================================================================
<===> top_level_include_declaration/without_use/input.scss
.a {
@import 'upstream';
}

<===> top_level_include_declaration/without_use/_upstream.scss
@mixin b { c: d }
@include b;

<===> top_level_include_declaration/without_use/output.css
.a {
c: d;
}

<===> top_level_include_declaration/without_use/warning
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.
More info and automated migrator: https://sass-lang.com/d/import
,
2 | @import 'upstream';
| ^^^^^^^^^^
'
input.scss 2:11 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/with_use/input.scss
.a {
@import 'midstream';
}

<===> top_level_include_declaration/with_use/_midstream.scss
@use 'upstream';
@mixin b { c: d }
@include b;

<===> top_level_include_declaration/with_use/_upstream.scss
// Intentionally empty.

<===> top_level_include_declaration/with_use/output.css
.a {
c: d;
}

<===> top_level_include_declaration/with_use/warning
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import

,
2 | @import 'midstream';
| ^^^^^^^^^^^
'
input.scss 2:11 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/with_use_two_levels_deep/input.scss
.a {
@import 'midstream1';
}

<===> top_level_include_declaration/with_use_two_levels_deep/_midstream1.scss
@import 'midstream2';

<===> top_level_include_declaration/with_use_two_levels_deep/_midstream2.scss
@use 'upstream';
@mixin b { c: d }
@include b;

<===> top_level_include_declaration/with_use_two_levels_deep/_upstream.scss
// Intentionally empty.

<===> top_level_include_declaration/with_use_two_levels_deep/output.css
.a {
c: d;
}

<===> top_level_include_declaration/with_use_two_levels_deep/warning
DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import

,
2 | @import 'midstream1';
| ^^^^^^^^^^^^
'
input.scss 2:11 root stylesheet

DEPRECATION WARNING [import]: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import

,
1 | @import 'midstream2';
| ^^^^^^^^^^^^
'
_midstream1.scss 1:9 @import
input.scss 2:11 root stylesheet
37 changes: 37 additions & 0 deletions spec/directives/use/error/load.hrx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's also worth testing the meta.load-css() equivalent to the nested import case, since that should produce an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that:

.foo {
  @include meta.load-css('upstream');
}

Should throw an error, when this does not?

.foo {
  @import 'upstream';
}

Because it actually throws an error, but I don't think it should 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if it should, then we're all set :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should. meta.load-css() loads the module as a module, which means that its CSS is generated context-independently and only afterwards injected into the document. A stylesheet loaded as a module shouldn't allow top-level declarations, because that's not valid CSS.

Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,40 @@ Error: There's already a module with namespace "other".
| ^^^^^^^^^^^^^^^^^^^^^^ new @use
'
input.scss 2:1 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/upstream_mixin/input.scss
@use "upstream";
@include upstream.a;

<===> top_level_include_declaration/upstream_mixin/_upstream.scss
@mixin a { b: c }

<===> top_level_include_declaration/upstream_mixin/error
Error: Declarations may only be used within style rules.
,
1 | @mixin a { b: c }
| ^^^^^
'
_upstream.scss 1:12 a()
input.scss 2:1 root stylesheet

<===>
================================================================================
<===> top_level_include_declaration/input_mixin/input.scss
@use 'upstream';
@mixin a { b: c }
@include a;

<===> top_level_include_declaration/input_mixin/_upstream.scss
// Intentionally empty.

<===> top_level_include_declaration/input_mixin/error
Error: Declarations may only be used within style rules.
,
2 | @mixin a { b: c }
| ^^^^^
'
input.scss 2:12 a()
input.scss 3:1 root stylesheet
Loading