Skip to content

Commit

Permalink
Handle negative numbers in tokenPreprocessor
Browse files Browse the repository at this point in the history
Would still fail on things like "transform-3d" if that were ever to
come up.  An actual lexer would be the real fix rather than further
regexp hackery.
  • Loading branch information
bdowning committed Apr 20, 2016
1 parent fe88b53 commit 5eb89e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/preprocessors/tokenPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createTokenPreprocessor(options = { }) {
const propsInfo = [ ];

for (let prop of props) {
const parts = state[prop].split(/\b(\d+(?:\.\d+|\.)?|\.\d+)/);
const parts = state[prop].split(/(-?\b(?:\d+(?:\.\d+|\.)?|\.\d+))/);
const values = [ ];

if (typeof easing[prop] === 'string' && easing[prop].match(/\s/)) {
Expand Down
12 changes: 12 additions & 0 deletions test/preprocessors/tokenPreprocessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ describe('tokenPreprocessor', () => {
expect(decode({ x__0: 3 }))
.toEqual({ x: 'transform3d(3.00px)' });
});

it('handles negative numbers', () => {
const tokenPreprocessor = createTokenPreprocessor();

const [ outState, outEasing, decode ] =
tokenPreprocessor({ x: 'transform3d(-2.54px)' }, { x: [ identity ] });

expect(outState).toEqual({ x__0: -2.54 });
expect(outEasing).toEqual({ x__0: identity });
expect(decode({ x__0: 3 }))
.toEqual({ x: 'transform3d(3.00px)' });
});
});

0 comments on commit 5eb89e7

Please sign in to comment.