Skip to content

feat: supports starting value from middle #4

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 1 commit into
base: master
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
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ module.exports = () => {

case decl.variable && decl.value.startsWith('z-stack('): {
const explicitValue = decl.value.match(REGEXP_STACK).groups.value
if (explicitValue && stackedVariable) {
throw decl.error('z-stack with starting value should be first')
}
const startingZ = explicitValue || '1'
decl.value = stackedVariable ? `calc(var(${stackedVariable}) + 1)` : startingZ
decl.value = stackedVariable ? (
explicitValue !== '' ? explicitValue : `calc(var(${stackedVariable}) + 1)`
) : startingZ
stackedVariable = decl.prop
return
}
Expand Down
12 changes: 10 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('postcss-easy-z', () => {
await run(input, output)
})

it('fails if starting value is not first', async () => {
it('works if starting value is not first', async () => {
const input = `
:root {
--z-content: z-stack();
Expand All @@ -91,7 +91,15 @@ describe('postcss-easy-z', () => {
}
`

await expect(process(input)).rejects.toThrow('z-stack with starting value should be first')
const output = `
:root {
--z-content: 1;
--z-header: 10;
--z-popup: calc(var(--z-header) + 1);
}
`

await run(input, output)
})
})

Expand Down