-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
SASS Expected identifier: Does Not accept number and letters in same map key? #2956
Comments
Same problem here . I try to declare a mixin: @mixin 2xl {} But get the error |
yeah I googling this problem with different tricks but didn't work I wish the sass support team looking to this problem. |
Yeah let's hope. Of course there is a simple solution to rename it (e.g. 'xxl' or 'xl2), but I don't like that name-giving. On some pages I read that Sass/SCSS simply doesn't support mixins that start with an number/integer. But I dont' get it how libraries like TailwindCSS use the variable '2xl': //example of tailwind configure
screens: {
sm: '640px',
md: '768px',
lg: '1024px',
xl: '1280px',
'2xl': '1536px',
} As you can see they declare the |
yeah but it still the same problem even If I declared it as a string
|
Although they may look similar, these are two different issues. @dennisfrijlink A mixin's name needs to be a valid Sass identifier. Since @devhoussam This is supported behavior. What version of Sass are you using? Are you sure that the |
@Awjin First thanks for your anwser. So if declare the breakpoints into an array like:
I can use a Sass map function to declare a mixin for every breakpoint (even for '2xl')? |
No, dynamic mixin invocation is not yet supported. See the issue here: #626 |
Aaah okay. You maybe know an altnernative to use the name '2xl'? I use the mixins for defining the viewports so for example: // Large devices
@mixin xl {
@media (min-width: #{$screen-xl-min}) {
@content;
}
} With the variable: |
Here is A full example : Sass Version :
|
The problem is that you are using the map keys to generate a class name – and CSS does not allow class names to start with a number. If you put a prefix on the class-name (like |
@mirisuzanne is correct here. Since Sass is a superset of CSS, class names cannot start with a number. |
@devhoussam I just came across this. @use "sass:list";
@use "sass:map";
@use "sass:string";
$-number-map: (
"0": 0,
"1": 1,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9,
);
// https://mathiasbynens.be/notes/css-escapes
$-escape-chars: (
"!",
"\"",
"#",
"$",
"%",
"&",
"'",
"(",
")",
"*",
"+",
",",
"-",
".",
"/",
":",
";",
"<",
"=",
">",
"?",
"@",
"[",
"\\",
"]",
"^",
"`",
"{",
"|",
"}",
"~",
);
@function -escape-impl($str) {
$output: "";
@for $str-index from 1 through string.length($str) {
$ch: string.slice($str, $str-index, $str-index);
@if $str-index == 1 and map.has-key($-number-map, $ch) {
$output: $output + "\\3" + $ch + " ";
} @else if list.index($-escape-chars, $ch) != null {
$output: $output + "\\" + $ch;
} @else {
$output: $output + $ch;
}
}
@return $output;
}
@function escape($value) {
@return -escape-impl("" + $value);
}
.#{escape(2xl)} {
foo: bar;
}
// .\32 xl {
// foo: bar;
// } |
How can I use number and letter in same map key?
The text was updated successfully, but these errors were encountered: