Performance: sass:list module
Using the sass:list module affects CSS compilation speed and the size of the generated CSS, impacting initial page load and render time.
@use 'sass:list'; .selector { color: list.nth(1, 2, 3, 1); }
@function get-first($list) { @return nth($list, 1); } .selector { color: get-first(1, 2, 3); }
| Pattern | Sass Compile Time | CSS Size | Browser Parse Cost | Verdict |
|---|---|---|---|---|
| Custom list functions | High (linear with list size) | Larger | Higher due to verbose CSS | [X] Bad |
| sass:list module functions | Low (optimized native) | Smaller | Lower due to concise CSS | [OK] Good |
What is the main purpose of the sass:list module in Sass?
Which of the following is the correct way to import the sass:list module in your Sass file?
@use to import modules, not @import which is deprecated.@use "sass:list"; which is the correct way to import the list module.Given the Sass code below, what will be the output of list.length($colors)?
@use "sass:list";
$colors: red, green, blue;
.result {
length: list.length($colors);
}$colors contains three items: red, green, and blue.list.length() function returns the number of items in the list, which is 3 here.Identify the error in the following Sass code using sass:list module:
@use "sass:list";
$items: 1 2 3;
$new-items: list.push($items, 4);
.result {
content: $new-items;
}$items is written as 1 2 3 without commas, which is valid space-separated list.sass:list module has list.append() to add items, but no list.push().list.push(), causing a compilation error. Change to list.append().You want to combine two lists $list1: 1, 2, 3; and $list2: 4, 5; into one list using sass:list functions. Which code snippet correctly joins these lists?
@use "sass:list";
// Options:
// A
$combined: list.length($list1) + list.length($list2);
// B
$combined: list.append($list1, $list2);
// C
$combined: list.insert($list1, $list2, 1);
// D
$combined: list.join($list1, $list2, comma);
list.join() function combines two lists into one, with a separator (comma or space).list.join($list1, $list2, comma) to join lists with commas.Pass the test and this pattern moves unknown