Skip to content

Commit

Permalink
fix: properly handle nested add and sub expression inside sub express…
Browse files Browse the repository at this point in the history
…ion (#70)
  • Loading branch information
evilebottnawi authored Apr 3, 2019
1 parent 153d0f2 commit b5bb24e
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 288 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"prepublish": "npm run build",
"build": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist --ignore src/__tests__/**/*.js && jison src/parser.jison -o dist/parser.js",
"pretest": "eslint src && npm run build",
"pretest": "npm run build && eslint src",
"test": "ava"
},
"author": "Andy Jansson",
Expand Down
105 changes: 105 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,108 @@ test(
'CALC( (1EM - CALC( 10PX + 1EM)) / 2)',
'-5PX',
);

test(
'should handle nested calc function (#1)',
testValue,
'calc(calc(var(--foo) + var(--bar)) + var(--baz))',
'calc(var(--foo) + var(--bar) + var(--baz))',
);

test(
'should handle nested calc function (#2)',
testValue,
'calc(var(--foo) + calc(var(--bar) + var(--baz)))',
'calc(var(--foo) + var(--bar) + var(--baz))',
);

test(
'should handle nested calc function (#3)',
testValue,
'calc(calc(var(--foo) - var(--bar)) - var(--baz))',
'calc(var(--foo) - var(--bar) - var(--baz))',
);

test(
'should handle nested calc function (#4)',
testValue,
'calc(var(--foo) - calc(var(--bar) - var(--baz)))',
'calc(var(--foo) - var(--bar) + var(--baz))',
);

test(
'should handle nested calc function (#5)',
testValue,
'calc(calc(var(--foo) + var(--bar)) - var(--baz))',
'calc(var(--foo) + var(--bar) - var(--baz))',
);

test(
'should handle nested calc function (#6)',
testValue,
'calc(var(--foo) + calc(var(--bar) - var(--baz)))',
'calc(var(--foo) + var(--bar) - var(--baz))',
);

test(
'should handle nested calc function (#7)',
testValue,
'calc(calc(var(--foo) - var(--bar)) + var(--baz))',
'calc(var(--foo) - var(--bar) + var(--baz))',
);

test(
'should handle nested calc function (#8)',
testValue,
'calc(var(--foo) - calc(var(--bar) + var(--baz)))',
'calc(var(--foo) - var(--bar) - var(--baz))',
);

test(
'should handle nested calc function (#9)',
testValue,
'calc(calc(var(--foo) + var(--bar)) * var(--baz))',
'calc((var(--foo) + var(--bar))*var(--baz))',
);

test(
'should handle nested calc function (#10)',
testValue,
'calc(var(--foo) * calc(var(--bar) + var(--baz)))',
'calc(var(--foo)*(var(--bar) + var(--baz)))',
);

test(
'should handle nested calc function (#11)',
testValue,
'calc(calc(var(--foo) + var(--bar)) / var(--baz))',
'calc((var(--foo) + var(--bar))/var(--baz))',
);

test(
'should handle nested calc function (#12)',
testValue,
'calc(var(--foo) / calc(var(--bar) + var(--baz)))',
'calc(var(--foo)/(var(--bar) + var(--baz)))',
);

test(
'should handle nested calc function (#13)',
testValue,
'calc(100vh - 5rem - calc(10rem + 100px))',
'calc(100vh - 5rem - 10rem - 100px)',
);

test(
'should handle nested calc function (#14)',
testValue,
'calc(100% - calc(10px + 2vw))',
'calc(100% - 10px - 2vw)',
);

test(
'should handle nested calc function (#15)',
testValue,
'calc(100% - calc(10px - 2vw))',
'calc(100% - 10px + 2vw)',
);
Loading

0 comments on commit b5bb24e

Please sign in to comment.