-
Notifications
You must be signed in to change notification settings - Fork 33
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
fix: improve support for each #103
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ export default function transformEachAtrule(rule, opts) { | |
// return the @each statement options (@each NAME in LIST, @each NAME ITERATOR in LIST) | ||
const getEachOpts = (node, opts) => { | ||
const params = node.params.split(matchInOperator); | ||
const args = (params[0] || '').trim().split(' '); | ||
const args = (params[0] || '').trim().split(/[\s,]+/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
support for sass syntax -> comma |
||
const varname = args[0].trim().slice(1); | ||
const incname = args.length > 1 && args[1].trim().slice(1); | ||
const rawlist = getValueAsObject( | ||
|
@@ -67,6 +67,11 @@ const getEachOpts = (node, opts) => { | |
); | ||
const list = 'string' === typeof rawlist ? [rawlist] : rawlist; | ||
|
||
const reverseParams = incname && !Array.isArray(list) | ||
if (reverseParams) { | ||
return { incname: varname, varname: incname, list }; | ||
} | ||
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case of object if 2 arguments are passed, its |
||
|
||
return { varname, incname, list }; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* arrayTest: $value */ | ||
.one-arrayTest { | ||
content: one; | ||
} | ||
.two-arrayTest { | ||
content: two; | ||
} | ||
|
||
/* arrayTest: $value, $key */ | ||
.0-arrayTest { | ||
content: one; | ||
} | ||
.1-arrayTest { | ||
content: two; | ||
} | ||
|
||
/* objectTest: $value */ | ||
."1"-arrayTest { | ||
content: "1"; | ||
} | ||
."2"-arrayTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this idffers from sass, as sass removes "', not sure if you want me to remove it to removal of quotes is only present if string is |
||
content: "2"; | ||
} | ||
|
||
/* objectTest: $key, $value */ | ||
.one-arrayTest { | ||
content: "1"; | ||
} | ||
.two-arrayTest { | ||
content: "2"; | ||
} | ||
|
||
/* objectStringTest: $key, $value */ | ||
.one-arrayTest { | ||
content: "1"; | ||
} | ||
.two-arrayTest { | ||
content: "2"; | ||
} | ||
|
||
/* objectStringTestMultiLine: $key, $value */ | ||
.one-arrayTest { | ||
content: "1"; | ||
} | ||
.two-arrayTest { | ||
content: "2"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
$arrayTest: (one, two); | ||
|
||
$objectTest: (one: "1", two: "2"); | ||
$objectStringTest: ("one": "1", "two": "2"); | ||
|
||
$objectStringTestMultiLine: ( | ||
"one": "1", | ||
"two": "2" | ||
); | ||
|
||
/* arrayTest: $value */ | ||
@each $value in $arrayTest { | ||
.#{$value}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} | ||
|
||
/* arrayTest: $value, $key */ | ||
@each $value, $key in $arrayTest { | ||
.#{$key}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} | ||
|
||
/* objectTest: $value */ | ||
@each $value in $objectTest { | ||
.#{$value}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} | ||
|
||
/* objectTest: $key, $value */ | ||
@each $key, $value in $objectTest { | ||
.#{$key}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} | ||
|
||
/* objectStringTest: $key, $value */ | ||
@each $key, $value in $objectStringTest { | ||
.#{$key}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} | ||
|
||
/* objectStringTestMultiLine: $key, $value */ | ||
@each $key, $value in $objectStringTestMultiLine { | ||
.#{$key}-arrayTest { | ||
content: #{$value}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quoted keys where not supported