Skip to content

Commit

Permalink
fix(preset-mini): fix calc handler replacement (#2133)
Browse files Browse the repository at this point in the history
Closes #2132
  • Loading branch information
chu121su12 committed Feb 1, 2023
1 parent ce75cdc commit eea51f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/preset-mini/src/_utils/handlers/handlers.ts
Expand Up @@ -145,10 +145,10 @@ function bracketWithType(str: string, requiredType?: string) {
return match
.replace(/var\((--.+?)[,)]/g, (match, g1) => {
vars.push(g1)
return match.replace(g1, '--v')
return match.replace(g1, '--un-calc')
})
.replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
.replace('--v', () => vars.shift()!)
.replace(/--un-calc/g, () => vars.shift()!)
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/handler.test.ts
Expand Up @@ -11,6 +11,8 @@ describe('value handler', () => {
expect(h.bracket('[calc(1+2)]')).eql('calc(1 + 2)')
expect(h.bracket('[calc(1/2)]')).eql('calc(1 / 2)')
expect(h.bracket('[calc(1*2)]')).eql('calc(1 * 2)')

expect(h.bracket('[calc(var(--min-width)_-_2_*_var(--col-gap))]')).eql('calc(var(--min-width) - 2 * var(--col-gap))')
})

test('bracket curly', () => {
Expand Down

0 comments on commit eea51f6

Please sign in to comment.