Skip to content

Commit

Permalink
fix(math): Time units and IE11
Browse files Browse the repository at this point in the history
Fixes two bugs with `math`. Time units (and angles) are now supported. Also properly works in IE11
(doesn't support Object.values).

fix #405 #407
  • Loading branch information
bhough committed Mar 1, 2019
1 parent f901055 commit 95c8e35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "lib/index.js",
"module": "dist/polished.es.js",
"types": "lib/index.d.ts",
"version": "3.0.0",
"version": "3.0.1",
"scripts": {
"build": "yarn build:lib && yarn build:dist && yarn build:flow && yarn build:docs && yarn build:typescript",
"prebuild:lib": "shx rm -rf lib/*",
Expand Down
2 changes: 1 addition & 1 deletion src/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import defaultSymbolMap from './defaultMathSymbols'
import PolishedError from '../internalHelpers/_errors'

const unitRegExp = /((?!\w)a|na|hc|mc|me[r]?|xe|ni(?![a-zA-Z])|mm|cp|tp|xp|q(?!s)|hv|xamv|nimv|wv)/g
const unitRegExp = /((?!\w)a|na|hc|mc|dg|me[r]?|xe|ni(?![a-zA-Z])|mm|cp|tp|xp|q(?!s)|hv|xamv|nimv|wv|sm|(?<![a-zA-Z])s|ged|darg?|nrut)/g

This comment has been minimized.

Copy link
@znarf

znarf Mar 1, 2019

I have an error on this line in 3.0.1. SyntaxError: invalid regexp group. In Firefox at least.

This comment has been minimized.

Copy link
@znarf

znarf Mar 1, 2019

It was working in 3.0.0.

This comment has been minimized.

Copy link
@bhough

bhough Mar 1, 2019

Author Contributor

@znarf this should be good in 3.0.2. I moved too quickly to fix another bug and used a negative lookbehind that FF doesn't support. Sorry about that!

This comment has been minimized.

Copy link
@znarf

znarf Mar 4, 2019

@bhough That works! Thank you.


// Merges additional math functionality into the defaults.
function mergeSymbolMaps(additionalSymbols?: Object): Object {
Expand Down
9 changes: 9 additions & 0 deletions src/math/test/math.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import math from '../math'

describe('math', () => {
it('should handle non-length units', () => {
expect(math('1ms + 2ms')).toEqual(`${1 + 2}ms`)
expect(math('1s + 2s')).toEqual(`${1 + 2}s`)
expect(math('1deg + 2deg')).toEqual(`${1 + 2}deg`)
expect(math('1grad + 2grad')).toEqual(`${1 + 2}grad`)
expect(math('1rad + 2rad')).toEqual(`${1 + 2}rad`)
expect(math('1turn + 2turn')).toEqual(`${1 + 2}turn`)
})

it('should be able to do simple addition', () => {
expect(math('1rem + 2rem')).toEqual(`${1 + 2}rem`)
expect(math('1rem + 2')).toEqual(`${1 + 2}rem`)
Expand Down

0 comments on commit 95c8e35

Please sign in to comment.