Skip to content

Commit

Permalink
Forward slash switched to backslash for division
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Feb 10, 2018
1 parent c185461 commit 509d34f
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 69 deletions.
24 changes: 12 additions & 12 deletions lib/less/parser/parser.js
Expand Up @@ -369,12 +369,14 @@ var Parser = function Parser(context, imports, fileInfo) {
},

//
// A catch-all word, such as:
// A catch-all word, such as
// - catches escaped values
//
// black border-collapse
// black border-collapse auto\9 \20AC\20AC
//
keyword: function () {
var k = parserInput.$char("%") || parserInput.$re(/^\[?[_A-Za-z-][_A-Za-z0-9-]*\]?/);
var k = parserInput.$char("%")
|| parserInput.$re(/^\[?[_A-Za-z-\\][_A-Za-z0-9-\\]*\]?/);
if (k) {
return tree.Color.fromKeyword(k) || new(tree.Keyword)(k);
}
Expand Down Expand Up @@ -1348,7 +1350,7 @@ var Parser = function Parser(context, imports, fileInfo) {
},
anonymousValue: function () {
var index = parserInput.i;
var match = parserInput.$re(/^([^@\$+\/'"*`(;{}-]*);/);
var match = parserInput.$re(/^([^@\$+\\'"*`(;{}-]*);/);
if (match) {
return new(tree.Anonymous)(match[1], index);
}
Expand Down Expand Up @@ -1697,13 +1699,13 @@ var Parser = function Parser(context, imports, fileInfo) {
if (m) {
isSpaced = parserInput.isWhitespace(-1);
while (true) {
if (parserInput.peek(/^\/[*\/]/)) {
if (parserInput.peek(/^\/[*\\]/)) {
break;
}

parserInput.save();

op = parserInput.$char('/') || parserInput.$char('*');
op = parserInput.$char('\\') || parserInput.$char('*');

if (!op) { parserInput.forget(); break; }

Expand Down Expand Up @@ -1941,12 +1943,10 @@ var Parser = function Parser(context, imports, fileInfo) {
e = this.addition() || this.entity();
if (e) {
entities.push(e);
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
if (!parserInput.peek(/^\/[\/*]/)) {
delim = parserInput.$char('/');
if (delim) {
entities.push(new(tree.Anonymous)(delim, index));
}
// slash separator in CSS expression
delim = parserInput.$re(/^[\/\\]/);
if (delim) {
entities.push(new(tree.Anonymous)(delim, index));
}
}
} while (e);
Expand Down
2 changes: 1 addition & 1 deletion lib/less/tree/dimension.js
Expand Up @@ -87,7 +87,7 @@ Dimension.prototype.operate = function (context, op, other) {
unit.numerator = unit.numerator.concat(other.unit.numerator).sort();
unit.denominator = unit.denominator.concat(other.unit.denominator).sort();
unit.cancel();
} else if (op === '/') {
} else if (op === '\\') {
unit.numerator = unit.numerator.concat(other.unit.denominator).sort();
unit.denominator = unit.denominator.concat(other.unit.numerator).sort();
unit.cancel();
Expand Down
4 changes: 2 additions & 2 deletions lib/less/tree/node.js
Expand Up @@ -53,12 +53,12 @@ Node.prototype.accept = function (visitor) {
this.value = visitor.visit(this.value);
};
Node.prototype.eval = function () { return this; };
Node.prototype._operate = function (context, op, a, b) {
Node.prototype._operate = function (context, op, a, b) {
switch (op) {
case '+': return a + b;
case '-': return a - b;
case '*': return a * b;
case '/': return a / b;
case '\\': return a / b;
}
};
Node.prototype.fround = function(context, value) {
Expand Down
3 changes: 3 additions & 0 deletions test/css/css-escapes.css
Expand Up @@ -22,3 +22,6 @@
ng\:form {
display: none;
}
textarea {
font-family: 'helvetica neue', 'wenquanyi micro hei', \5FAE\8F6F\96C5\9ED1, \5B8B\4F53, sans-serif;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion test/css/operations.css
Expand Up @@ -16,7 +16,7 @@
size: 1cm;
}
.with-functions {
color: #646464;
color: #1c0d0d;
color: #ff8080;
color: #c94a4a;
}
Expand Down
4 changes: 2 additions & 2 deletions test/css/strict-math/mixins-args.css
Expand Up @@ -73,8 +73,8 @@ body {
width: "{";
}
.slash-vs-math {
border-radius: 2px/5px;
border-radius: 5px/10px;
border-radius: 2px / 5px;
border-radius: 5px / 10px;
border-radius: 6px;
}
.comma-vs-semi-colon {
Expand Down
8 changes: 4 additions & 4 deletions test/css/strict-math/parens.css
Expand Up @@ -12,11 +12,11 @@
height-keep: (7 * 7) + (8 * 8);
height-all: 113;
height-parts: 49 + 64;
margin-keep: (4 * (5 + 5) / 2) - (4 * 2);
margin-keep: (4 * (5 + 5) \ 2) - (4 * 2);
margin-parts: 20 - 8;
margin-all: 12;
border-radius-keep: 4px * (1 + 1) / 4 + 3px;
border-radius-parts: 8px / 7px;
border-radius-keep: 4px * (1 + 1) \ 4 + 3px;
border-radius-parts: 8px \ 7px;
border-radius-all: 5px;
}
.negative {
Expand All @@ -25,7 +25,7 @@
}
.nested-parens {
width: 2 * (4 * (2 + (1 + 6))) - 1;
height: ((2 + 3) * (2 + 3) / (9 - 4)) + 1;
height: ((2 + 3) * (2 + 3) \ (9 - 4)) + 1;
}
.mixed-units {
margin: 2px 4em 1 5pc;
Expand Down
16 changes: 8 additions & 8 deletions test/less-test.js
Expand Up @@ -296,15 +296,15 @@ module.exports = function() {
}
if (err) {
fail("ERROR: " + (err && err.message));
if (isVerbose) {
process.stdout.write("\n");
if (err.stack) {
process.stdout.write(err.stack + "\n");
} else {
// this sometimes happen - show the whole error object
console.log(err);
}
// if (isVerbose) {
process.stdout.write("\n");
if (err.stack) {
process.stdout.write(err.stack + "\n");
} else {
// this sometimes happen - show the whole error object
console.log(err);
}
// }
release();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/less/calc.less
@@ -1,5 +1,5 @@
.no-math {
@var: 50vh/2;
@var: 50vh\2;
width: calc(50% + (@var - 20px));
foo: 1 + 2 calc(3 + 4) 5 + 6;
@floor: floor(1 + .1);
Expand Down
4 changes: 4 additions & 0 deletions test/less/css-escapes.less
Expand Up @@ -31,3 +31,7 @@
ng\:form {
display: none;
}

textarea {
font-family: 'helvetica neue','wenquanyi micro hei',\5FAE\8F6F\96C5\9ED1, \5B8B\4F53, sans-serif;
}
2 changes: 1 addition & 1 deletion test/less/errors/divide-mixed-units.less
@@ -1,3 +1,3 @@
.a {
error: (1px / 3em);
error: (1px \ 3em);
}
2 changes: 1 addition & 1 deletion test/less/errors/divide-mixed-units.txt
@@ -1,4 +1,4 @@
SyntaxError: Multiple units in dimension. Correct the units or use the unit function. Bad unit: px/em in {path}divide-mixed-units.less on line 2, column 3:
1 .a {
2 error: (1px / 3em);
2 error: (1px \ 3em);
3 }
2 changes: 1 addition & 1 deletion test/less/errors/unit-function.less
@@ -1,3 +1,3 @@
.a {
font-size: unit(80/16,rem);
font-size: unit(80\16,rem);
}
2 changes: 1 addition & 1 deletion test/less/errors/unit-function.txt
@@ -1,4 +1,4 @@
ArgumentError: error evaluating function `unit`: the first argument to unit must be a number. Have you forgotten parenthesis? in {path}unit-function.less on line 2, column 14:
1 .a {
2 font-size: unit(80/16,rem);
2 font-size: unit(80\16,rem);
3 }
10 changes: 5 additions & 5 deletions test/less/functions.less
Expand Up @@ -92,10 +92,10 @@
red: red(#f00);
green: green(#0f0);
blue: blue(#00f);
rounded: round((@r/3));
rounded-two: round((@r/3), 2);
roundedpx: round((10px / 3));
roundedpx-three: round((10px / 3), 3);
rounded: round((@r\3));
rounded-two: round((@r\3), 2);
roundedpx: round((10px \ 3));
roundedpx-three: round((10px \ 3), 3);
rounded-percentage: round(10.2%);
ceil: ceil(10.1px);
floor: floor(12.9px);
Expand All @@ -118,7 +118,7 @@
min: min(1cm, 3mm);
max: max(1, 3);
max: max(3em, 1em, 2em, 5em);
percentage: percentage((10px / 50));
percentage: percentage((10px \ 50));
color-quoted-digit: color("#dda0dd");
color-quoted-keyword: color("plum");
color-color: color(#dda0dd);
Expand Down
14 changes: 7 additions & 7 deletions test/less/legacy/legacy.less
@@ -1,17 +1,17 @@
@media (-o-min-device-pixel-ratio: 2) {
.test-math-and-units {
font: ignores 0/0 rules;
test-division: 4 / 2 + 5em;
test-division: 4 \ 2 + 5em;
simple: 1px + 1px;
}
}
#units {
t1: (2em/1em) + 20;
t2: 20 + (2em/1em);
t3: 2em/1em;
t4: (2em/1px) + 20;
t5: 20 + (2em/1px);
t6: 2em/1px;
t1: (2em\1em) + 20;
t2: 20 + (2em\1em);
t3: 2em\1em;
t4: (2em\1px) + 20;
t5: 20 + (2em\1px);
t6: 2em\1px;
t7: (2em*1em) + 20;
t8: 20 + (2em*1em);
t9: 2em*1em;
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions test/less/operations.less
@@ -1,14 +1,14 @@
#operations {
color: (#110000 + #000011 + #001100); // #111111
color-2: (yellow - #070707);
height: (10px / 2px + 6px - 1px * 2); // 9px
height: (10px \ 2px + 6px - 1px * 2); // 9px
width: (2 * 4 - 5em); // 3em
.spacing {
height: (10px / 2px+6px-1px*2);
height: (10px \ 2px+6px-1px*2);
width: (2 * 4-5em);
}
subtraction: (20 - 10 - 5 - 5); // 0
division: (20 / 5 / 4); // 1
division: (20 \ 5 \ 4); // 1
}

@x: 4;
Expand All @@ -21,7 +21,7 @@
}

.with-functions {
color: (rgb(200, 200, 200) / 2);
color: (rgb(56, 25, 25) \ 2);
color: (2 * hsl(0, 50%, 50%));
color: (rgb(10, 10, 10) + hsl(0, 50%, 50%));
}
Expand All @@ -38,7 +38,7 @@
}

.rem-dimensions {
font-size: (20rem / 5 + 1.5rem); // 5.5rem
font-size: (20rem \ 5 + 1.5rem); // 5.5rem
}

.colors {
Expand All @@ -47,7 +47,7 @@
background-color: (#222222 - #fff); // #000000
.other {
color: (2 * #111); // #222222
border-color: (#333333 / 3 + #111); // #222222
border-color: (#333333 \ 3 + #111); // #222222
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/less/property-accessors.less
Expand Up @@ -4,7 +4,7 @@
background-color: $color;
@width: 50px;
width: @width;
height: ($width / 2);
height: $width \ 2;
@color: red;
border: 1px solid lighten($color, 10%);
&:hover {
Expand Down
14 changes: 7 additions & 7 deletions test/less/strict-math/parens.less
Expand Up @@ -15,12 +15,12 @@
height-keep: (7 * 7) + (8 * 8);
height-all: ((7 * 7) + (8 * 8));
height-parts: ((7 * 7)) + ((8 * 8));
margin-keep: (4 * (5 + 5) / 2) - (@var * 2);
margin-parts: ((4 * (5 + 5) / 2)) - ((@var * 2));
margin-all: ((4 * (5 + 5) / 2) + (-(@var * 2)));
border-radius-keep: 4px * (1 + 1) / @var + 3px;
border-radius-parts: ((4px * (1 + 1))) / ((@var + 3px));
border-radius-all: (4px * (1 + 1) / @var + 3px);
margin-keep: (4 * (5 + 5) \ 2) - (@var * 2);
margin-parts: ((4 * (5 + 5) \ 2)) - ((@var * 2));
margin-all: ((4 * (5 + 5) \ 2) + (-(@var * 2)));
border-radius-keep: 4px * (1 + 1) \ @var + 3px;
border-radius-parts: ((4px * (1 + 1))) \ ((@var + 3px));
border-radius-all: (4px * (1 + 1) \ @var + 3px);
//margin: (6 * 6)px;
}

Expand All @@ -32,7 +32,7 @@

.nested-parens {
width: 2 * (4 * (2 + (1 + 6))) - 1;
height: ((2 + 3) * (2 + 3) / (9 - 4)) + 1;
height: ((2 + 3) * (2 + 3) \ (9 - 4)) + 1;
}

.mixed-units {
Expand Down
4 changes: 2 additions & 2 deletions test/less/strict-units/strict-units.less
@@ -1,4 +1,4 @@
.units {
cancels-to-nothing: (1px / 1px);
cancels: ((((10px / 5em) / 1px) * 3em) * 1px);
cancels-to-nothing: (1px \ 1px);
cancels: ((((10px \ 5em) \ 1px) * 3em) * 1px);
}
12 changes: 6 additions & 6 deletions test/less/variables.less
Expand Up @@ -87,24 +87,24 @@

.units {
width: @onePixel;
same-unit-as-previously: (@onePixel / @onePixel);
square-pixel-divided: (@onePixel * @onePixel / @onePixel);
odd-unit: unit((@onePixel * 4em / 2cm));
same-unit-as-previously: (@onePixel \ @onePixel);
square-pixel-divided: (@onePixel * @onePixel \ @onePixel);
odd-unit: unit((@onePixel * 4em \ 2cm));
percentage: (10 * 50%);
pixels: (50px * 10);
conversion-metric-a: (20mm + 1cm);
conversion-metric-b: (1cm + 20mm);
conversion-imperial: (1in + 72pt + 6pc);
custom-unit: (42octocats * 10);
custom-unit-cancelling: (8cats * 9dogs / 4cats);
custom-unit-cancelling: (8cats * 9dogs \ 4cats);
mix-units: (1px + 1em);
invalid-units: (1px * 1px);
.fallback {
@px: 14px;
@em: 1.4em;
@cm: 10cm;
div-px-1: (@px / @em);
div-px-2: ((@px / @em) / @cm);
div-px-1: (@px \ @em);
div-px-2: ((@px \ @em) \ @cm);
sub-px-1: (@px - @em);
sub-cm-1: (@cm - (@px - @em));
mul-px-1: (@px * @em);
Expand Down

0 comments on commit 509d34f

Please sign in to comment.