8000 rename strictMaths to strictMath, set default to false, update strict… · browserstack/less.js@6560209 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6560209

Browse files
committed
rename strictMaths to strictMath, set default to false, update strict options to take = on | off
1 parent 91bc69a commit 6560209

File tree

14 files changed

+64
-43
lines changed

14 files changed

+64
-43
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.4.0
2+
3+
2013-05-??
4+
5+
- change strictMaths to strictMath. Enable this with --strict-math=on in lessc and strictMath:true in JavaScript.
6+
- change lessc option for strict units to --strict-units=off
7+
18
# 1.4.0 Beta 3
29

310
2013-04-30

bin/lessc

Lines changed: 22 additions & 7 deletions
< 57A0 /tr>
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var options = {
2323
rootpath: '',
2424
relativeUrls: false,
2525
ieCompat: true,
26-
strictMaths: true
26+
strictMath: false,
27+
strictUnits: false
2728
};
2829
var continueProcessing = true,
2930
currentErrorcode;
@@ -39,7 +40,17 @@ var checkArgFunc = function(arg, option) {
3940
return false;
4041
}
4142
return true;
42-
}
43+
};
44+
45+
var checkBooleanArg = function(arg) {
46+
var onOff = /^((on|t|true|y|yes)|(off|f|false|n|no))$/i.exec(arg);
47+
if (!onOff) {
48+
sys.puts(" unable to parse "+arg+" as a boolean. use one of on/t/true/y/yes/off/f/false/n/no");
49+
continueProcessing = false;
50+
return false;
51+
}
52+
return Boolean(onOff[2]);
53+
};
4354

4455
args = args.filter(function (arg) {
4556
var match;
@@ -49,7 +60,7 @@ args = args.filter(function (arg) {
4960
return false;
5061
}
5162

52-
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i)) { arg = match[1] }
63+
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]*))?$/i)) { arg = match[1] }
5364
else { return arg }
5465

5566
switch (arg) {
@@ -129,12 +140,16 @@ args = args.filter(function (arg) {
129140
options.relativeUrls = true;
130141
break;
131142
case "sm":
132-
case "strict-maths-off":
133-
options.strictMaths = false;
143+
case "strict-math":
144+
if (checkArgFunc(arg, match[2])) {
145+
options.strictMath = checkBooleanArg(match[2]);
146+
}
134147
break;
135148
case "su":
136-
case "strict-units-off":
137-
options.strictUnits = false;
149+
case "strict-units":
150+
if (checkArgFunc(arg, match[2])) {
151+
options.strictUnits = checkBooleanArg(match[2]);
152+
}
138153
break;
139154
}
140155
});

lib/less/env.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
'verbose', // whether to log more activity
5757
'compress', // whether to compress
5858
'ieCompat', // whether to enforce IE compatibility (IE8 data-uri)
59-
'strictMaths', // whether maths has to be within parenthesis
59+
'strictMath', // whether math has to be within parenthesis
6060
'strictUnits' // whether units need to evaluate correctly
6161
];
6262

@@ -77,8 +77,8 @@
7777
this.parensStack.pop();
7878
};
7979

80-
tree.evalEnv.prototype.isMathsOn = function () {
81-
return this.strictMaths === false ? true : (this.parensStack && this.parensStack.length);
80+
tree.evalEnv.prototype.isMathOn = function () {
81+
return this.strictMath ? (this.parensStack && this.parensStack.length) : true;
8282
};
8383

8484
tree.evalEnv.prototype.isPathRelative = function (path) {

lib/less/lessc_helper.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ var lessc_helper = {
5454
sys.puts(" -rp, --rootpath=URL Set rootpath for url rewriting in relative imports and urls.");
5555
sys.puts(" Works with or without the relative-urls option.");
5656
sys.puts(" -ru, --relative-urls re-write relative urls to the base less file.");
57-
sys.puts(" -sm, --strict-maths-off Make maths not require brackets, which is similar behaviour");
58-
sys.puts(" to before 1.4. This option is for compatability and may be");
59-
sys.puts(" removed in the future.");
60-
sys.puts(" -su, --strict-units-off Allow mixed units, e.g. 1px+1em or 1px*1px which have units");
61-
sys.puts(" that cannot be represented. This option is for compatability");
62-
sys.puts(" and may be removed in the future.");
57+
sys.puts(" -sm=on|off Turn on or off strict math, where in strict mode, math");
58+
sys.puts(" --strict-math=on|off requires brackets. This option may default to on and then");
59+
sys.puts(" be removed in the future.");
60+
sys.puts(" -su=on|off Allow mixed units, e.g. 1px+1em or 1px*1px which have units");
61+
sys.puts(" --strict-units=on|off that cannot be represented.");
6362
sys.puts("");
6463
sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
6564
sys.puts("Home page: <http://lesscss.org/>");

lib/less/tree/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tree.Expression.prototype = {
2828
if (inParenthesis) {
2929
env.outOfParenthesis();
3030
}
31-
if (this.parens && this.parensInOp && !(env.isMathsOn()) && !doubleParen) {
31+
if (this.parens && this.parensInOp && !(env.isMathOn()) && !doubleParen) {
3232
returnValue = new(tree.Paren)(returnValue);
3333
}
3434
return returnValue;

lib/less/tree/media.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ tree.Media.prototype = {
3131
this.ruleset.debugInfo = this.debugInfo;
3232
media.debugInfo = this.debugInfo;
3333
}
34-
var strictMathsBypass = false;
35-
if (env.strictMaths === false) {
36-
strictMathsBypass = true;
37-
env.strictMaths = true;
34+
var strictMathBypass = false;
35+
if (!env.strictMath) {
36+
strictMathBypass = true;
37+
env.strictMath = true;
3838
}
3939
try {
4040
media.features = this.features.eval(env);
4141
}
4242
finally {
43-
if (strictMathsBypass) {
44-
env.strictMaths = false;
43+
if (strictMathBypass) {
44+
env.strictMath = false;
4545
}
4646
}
4747

lib/less/tree/negative.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tree.Negative.prototype = {
1212
return '-' + this.value.toCSS(env);
1313
},
1414
eval: function (env) {
15-
if (env.isMathsOn()) {
15+
if (env.isMathOn()) {
1616
return (new(tree.Operation)('*', [new(tree.Dimension)(-1), this.value])).eval(env);
1717
}
1818
return new(tree.Negative)(this.value.eval(env));

lib/less/tree/operation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tree.Operation.prototype = {
1515
b = this.operands[1].eval(env),
1616
temp;
1717

18-
if (env.isMathsOn()) {
18+
if (env.isMathOn()) {
1919
if (a instanceof tree.Dimension && b instanceof tree.Color) {
2020
if (this.op === '*' || this.op === '+') {
2121
temp = b, b = a, a = temp;

lib/less/tree/rule.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ tree.Rule.prototype = {
3434
}
3535
},
3636
eval: function (env) {
37-
var strictMathsBypass = false;
38-
if (this.name === "font" && env.strictMaths === false) {
39-
strictMathsBypass = true;
40-
env.strictMaths = true;
37+
var strictMathBypass = false;
38+
if (this.name === "font" && env.strictMath === false) {
39+
strictMathBypass = true;
40+
env.strictMath = true;
4141
}
4242
try {
4343
return new(tree.Rule)(this.name,
@@ -46,8 +46,8 @@ tree.Rule.prototype = {
4646
this.index, this.currentFileInfo, this.inline);
4747
}
4848
finally {
49-
if (strictMathsBypass) {
50-
env.strictMaths = false;
49+
if (strictMathBypass) {
50+
env.strictMath = false;
5151
}
5252
}
5353
},

test/browser/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*if not async then phantomjs fails to run the webserver and the test concurrently*/
2-
var less = { async: true };
2+
var less = { async: true, strictMath: true };
33

44
/* record log messages for testing */
55
var logMessages = [],

test/browser/runner-legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
less.strictMaths = false;
1+
less.strictMath = false;
22
less.strictUnits = false;
33

44
describe("less.js legacy tests", function() {

test/css/legacy/legacy.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@media (-o-min-device-pixel-ratio: 2/1) {
2-
.test-maths-and-units {
2+
.test-math-and-units {
33
font: ignores 0/0 rules;
44
test-division: 7em;
55
simple: 2px;

test/less-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ less.tree.functions._color = function (str) {
2323

2424
sys.puts("\n" + stylize("LESS", 'underline') + "\n");
2525

26-
runTestSet({relativeUrls: true, silent: true});
26+
runTestSet({strictMath: true, relativeUrls: true, silent: true});
2727

28-
runTestSet({strictUnits: true}, "errors/", function(name, err, compiledLess, doReplacements) {
28+
runTestSet({strictMath: true, strictUnits: true}, "errors/", function(name, err, compiledLess, doReplacements) {
2929
fs.readFile(path.join('test/less/', name) + '.txt', 'utf8', function (e, expectedErr) {
3030
sys.print("- " + name + ": ");
3131
expectedErr = doReplacements(expectedErr, 'test/less/errors/');
@@ -53,15 +53,15 @@ runTestSet({strictUnits: true}, "errors/", function(name, err, compiledLess, doR
5353
.replace(/\r\n/g, '\n');
5454
});
5555

56-
runTestSet({dumpLineNumbers: 'comments'}, "debug/", null,
56+
runTestSet({strictMath: true, dumpLineNumbers: 'comments'}, "debug/", null,
5757
function(name) { return name + '-comments'; });
58-
runTestSet({dumpLineNumbers: 'mediaquery'}, "debug/", null,
58+
runTestSet({strictMath: true, dumpLineNumbers: 'mediaquery'}, "debug/", null,
5959
function(name) { return name + '-mediaquery'; });
60-
runTestSet({dumpLineNumbers: 'all'}, "debug/", null,
60+
runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
6161
function(name) { return name + '-all'; });
62-
runTestSet({relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
63-
runTestSet({compress: true}, "compression/");
64-
runTestSet({strictMaths: false}, "legacy/");
62+
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
63+
runTestSet({strictMath: true, compress: true}, "compression/");
64+
runTestSet({strictMath: false}, "legacy/");
6565

6666
function globalReplacements(input, directory) {
6767
var p = path.join(process.cwd(), directory),

test/less/legacy/legacy.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@media (-o-min-device-pixel-ratio: 2/1) {
2-
.test-maths-and-units {
2+
.test-math-and-units {
33
font: ignores 0/0 rules;
44
test-division: 4 / 2 + 5em;
55
simple: 1px + 1px;

0 commit comments

Comments
 (0)
0