Is it possible to lookup for variable that doesn't exist?
See original GitHub issueHello!
Is it possible to lookup for variables that doesn’t exist? I have a list of generated variables for every icon glyph. Some icons consist from two 2 glyphs (need for ::before
+ ::after
for 2 colors icon). I want to pass base icon name to mixin and get correct output, but i get an error of looking @@icon2
, and it doesn’t matter if i use when
or if
. Also tried to use mixin guards, but no changes.
Some code:
// generated list of icons
@icon__glyph_about_20__1: '\E00C';
@icon__glyph_about_32__1: '\E00D';
@icon__glyph_about_32__2: '\E00E';
// common mixin for icons
.nbl-icon__use(@iconName) {
@icon1: ~'icon__glyph_@{iconName}__1'; // always exists
@icon2: ~'icon__glyph_@{iconName}__2'; // sometimes doesn't exist
&::before {
content: @@icon1;
}
& when not (@@icon2 = undefined) {
&::after {
content: @@icon2;
}
}
}
.test {
.nbl-icon__use(about_20);
}
Example of error: Message: variable @icon__glyph_about_20__2 is undefined in file ...
P.S. Unfortunately i can’t generate list of vars with null
’s.
P.S.S. sry for my eng, hope u understand me
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top Results From Across the Web
JavaScript check if variable exists (is defined/initialized)
In JavaScript, a variable can be defined, but hold the value undefined , so the most common answer is not technically correct, and...
Read more >3 Ways to Check if a Variable is Defined in JavaScript
How to check if a variable is defined in JavaScript using typeof operator, try/catch blocks, or window.hasOwnProperty().
Read more >Update Lookup Field value with newly inserted object Id
variable does not exist - Update Lookup Field value with newly inserted object Id. Hi, I'm brand new to apex.
Read more >Testing if a Variable Is Defined - Python Cookbook [Book]
It is considered unusual in Python not to know whether a variable has already been defined.
Read more >Check if variable exists in workspace to plot ... - MathWorks
I am having some trouble with checking if a variable exists in the workspace. If the variable exists (which is a structure with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@theexplay The short answer is that no, there’s no current way to do this in exactly the way you mention. One workaround, though, would be to specify all the var names in a file loaded before the optional definitions, and set those values to something you would check later. In other words:
@seven-phases-max
Oh, shoot. That’s a good catch. This is one of those cases where doing a lot of Less refactoring has tricked my brain towards what Less will do vs. what Less currently does do.
It should be:
You’re right that Less currently expects something close to
===
equality, although not consistently.