-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #1880 - Adds two new math modes and deprecates strictMath #3274
Conversation
# Conflicts: # lib/less/tree/declaration.js # test/index.js
🤔 Should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On parens-all
or parens
, I think parens
is probably sufficient. Otherwise, I've only really got a couple questions.
bin/lessc
Outdated
@@ -481,8 +482,17 @@ function processPluginQueue() { | |||
break; | |||
case 'sm': | |||
case 'strict-math': | |||
console.warning('Strict math is deprecated. Use --math'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning could specify --math=parens
, maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, yes. Will change it.
// TODO: deprecate and remove 'inlineJavaScript' thing - where it came from at all? | ||
options.javascriptEnabled = (options.javascriptEnabled || options.inlineJavaScript) ? true : false; | ||
|
||
options.javascriptEnabled = options.javascriptEnabled ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? true : false
isn't really necessary is it? Or is this to force Boolean? Do we have a style guide covering this case? Maybe just Boolean(options.javascriptEnabled)
would be more straightforward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should just remove this line. I was just removing the inlineJavaScript
thing, which was never used and shouldn't have gone in.
lib/less-node/lessc-helper.js
Outdated
console.log(' -m=, --math='); | ||
console.log(' always Less will eagerly perform math operations always.'); | ||
console.log(' parens-division Math performed except for division (/) operator'); | ||
console.log(' parens-all Math only performed inside parentheses'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in a separate comment, I think parens
is probably sufficient, but I don't mind either way, really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do parens
with strict
as an alias.
lib/less/math-constants.js
Outdated
ALWAYS: 0, | ||
PARENS_DIVISION: 1, | ||
PARENS_ALL: 2, | ||
STRICT_LEGACY: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of style guides, you have any strong opinion on comma dangle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comma dangles shouldn't go in, probably, for compatibility reasons.
@@ -1920,7 +1920,7 @@ var Parser = function Parser(context, imports, fileInfo) { | |||
|
|||
parserInput.save(); | |||
|
|||
op = parserInput.$char('/') || parserInput.$char('*'); | |||
op = parserInput.$char('/') || parserInput.$char('*') || parserInput.$str('./'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the ./
thing, by the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/less/utils.js
Outdated
case 'parens-division': | ||
opts.math = MATH.PARENS_DIVISION; | ||
break; | ||
case 'parens-all': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had talked about strict
as an alias of parens
/parens-all
. I don't think it's totally necessary; I'm just making sure it was a conscious choice to leave it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was, but after sleeping on it, I realized it might make the concept easier for people switching to decide which one to use.
test/index.js
Outdated
}, 'math/parens-all/'], | ||
[{ | ||
math: 'parens-division' | ||
}, 'math/parens-division/'], | ||
[{strictMath: true, strictUnits: true, javascriptEnabled: true}, 'errors/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the strictMath
option be updated here (and in other lines below) as well? Or will it not matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some in to verify that setting the legacy option worked as expected. I should make a note of it though.
- Merge branch 'master' into strict-math-division
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
# Conflicts: # test/less/functions.less
--strict-math has been deprecated and replaced by --math. See less/less.js#3274
--strict-math has been deprecated and replaced by --math. See less/less.js#3274
* package – update css-compile script to use --math --strict-math has been deprecated and replaced by --math. See less/less.js#3274 * maps – begin converting to DRs * each – use each() for loops (WIP) Still haven't updated for the grid breakpoints just yet, though some breakpoint loops have been written in anticipation of those updates. * breakpoints – fix breakpoint JS after converting to DR maps * each – replace all #each-* loop with each or #for-* There are 4 loops in mixins/_grid-framework.less that loop 'til a static number. I'm not aware of any answer for that at the moment, but a plugin could be easily written that could just leverage `each()`. * dev, meta – steal nice stuff from #12 Thanks @matthew-dean! * plugins – fix lint warnings/errors Except one in breakpoints.js: ``` 91:6 warning Variable 'nextBreakpoint' should be initialized on declaration ``` * _tables – fix .table-responsive output order See less/less.js#3340 * _navbar – fix .navbar-expand output order See less/less.js#3340 * README – update to match true min version required Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * plugins/theme-color-level – more readable code Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * README – replace the other, less easy ways of installing * _grid-framework – restore comment See #14 (comment) * README – wording edits Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * _functions – restore commented Sass * README – more wording edits Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * README – remove clone note per #14 (comment) * plugins/breakpoints – remove parseUnit(); fix nextBreakpoint ESLint issue See https://github.com/seanCodes/bootstrap-less-port/pull/14/files/94a03d156dde954caccf58130ebc8fa3adaf397e#r240023403 * rename plugin `keys` → `map-keys` Reverting the name change for now, until @calvinjuarez is able to pull in the plugin from NPM and alias it. (See [his comment](#14 (comment) sion_r241965904).) This change addresses [this PR review comment](#14 (comment) sion_r239916331). * _grid-framework – revert loop renaming Reduce the number of changes in the PR to avoid potential bugs. This change addresses [this PR review comment](#14 (comment)). * _transition – revert var renaming Match var names used in the Sass version of the mixin. This change addresses [this PR review comment](#14 (comment)). * breakpoints – put long comments on own line (instead of including at the end of a line) * restore color-function plugins Revert deletion of plugin files that add the `color()`, `gray()` and `theme-color()` functions. Even though Less’ new ruleset accessors could be used, we’re going to keep them for parity with the Sass version and for backwards compatibility. This change addresses [this PR review comment](#14). * restore usages of color functions Revert the conversion the `color()`, `gray()` and `theme-color()` functions to Less’ ruleset accessors. This change is primarily being made to keep the syntax as similar to the Sass version as possible, for easy reference/comparison. Note that keeping things similar to Sass may prove unnecessary in the future, so we may go back to accessors, but for now we’ll keep it like this. This change addresses [this PR review comment](#14). * change color functions to handle rulesets vs lists * fix bug in ruleset-to-map conversion Instead of pulling the `value` directly from each item in the ruleset, evaluate the item first to determine the true value of the item. This fixes the issue where the `value` is actually a var name and what we want is the the value of the var—not the var name itself.
* package – update css-compile script to use --math --strict-math has been deprecated and replaced by --math. See less/less.js#3274 * maps – begin converting to DRs * each – use each() for loops (WIP) Still haven't updated for the grid breakpoints just yet, though some breakpoint loops have been written in anticipation of those updates. * breakpoints – fix breakpoint JS after converting to DR maps * each – replace all #each-* loop with each or #for-* There are 4 loops in mixins/_grid-framework.less that loop 'til a static number. I'm not aware of any answer for that at the moment, but a plugin could be easily written that could just leverage `each()`. * dev, meta – steal nice stuff from #12 Thanks @matthew-dean! * plugins – fix lint warnings/errors Except one in breakpoints.js: ``` 91:6 warning Variable 'nextBreakpoint' should be initialized on declaration ``` * _tables – fix .table-responsive output order See less/less.js#3340 * _navbar – fix .navbar-expand output order See less/less.js#3340 * README – update to match true min version required Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * plugins/theme-color-level – more readable code Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * README – replace the other, less easy ways of installing * _grid-framework – restore comment See #14 (comment) * README – wording edits Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * _functions – restore commented Sass * README – more wording edits Co-Authored-By: calvinjuarez <calvin.juarez@gmail.com> * README – remove clone note per #14 (comment) * plugins/breakpoints – remove parseUnit(); fix nextBreakpoint ESLint issue See https://github.com/seanCodes/bootstrap-less-port/pull/14/files/94a03d156dde954caccf58130ebc8fa3adaf397e#r240023403 * rename plugin `keys` → `map-keys` Reverting the name change for now, until @calvinjuarez is able to pull in the plugin from NPM and alias it. (See [his comment](#14 (comment) sion_r241965904).) This change addresses [this PR review comment](#14 (comment) sion_r239916331). * _grid-framework – revert loop renaming Reduce the number of changes in the PR to avoid potential bugs. This change addresses [this PR review comment](#14 (comment)). * _transition – revert var renaming Match var names used in the Sass version of the mixin. This change addresses [this PR review comment](#14 (comment)). * breakpoints – put long comments on own line (instead of including at the end of a line) * restore color-function plugins Revert deletion of plugin files that add the `color()`, `gray()` and `theme-color()` functions. Even though Less’ new ruleset accessors could be used, we’re going to keep them for parity with the Sass version and for backwards compatibility. This change addresses [this PR review comment](#14). * restore usages of color functions Revert the conversion the `color()`, `gray()` and `theme-color()` functions to Less’ ruleset accessors. This change is primarily being made to keep the syntax as similar to the Sass version as possible, for easy reference/comparison. Note that keeping things similar to Sass may prove unnecessary in the future, so we may go back to accessors, but for now we’ll keep it like this. This change addresses [this PR review comment](#14). * change color functions to handle rulesets vs lists * fix bug in ruleset-to-map conversion Instead of pulling the `value` directly from each item in the ruleset, evaluate the item first to determine the true value of the item. This fixes the issue where the `value` is actually a var name and what we want is the the value of the var—not the var name itself.
Fixes #1880
This PR deprecates
strictMath
in favor of 4math
modes:always
|parens-division
|parens
|strict
|strict-legacy
In talking with @calvinjuarez, we both found the current behavior of
strictMath
extremely odd in cases likewidth: (1 + 1) + (1 + 1);
which would result in the unexpectedwidth: (1 + 1) + (1 + 1);
vs. the expectedwidth: 2 + 2;
. None of the documentation seems to indicate this behavior or why it would need to evaluate in this way, sincestrictMath: true
will evaluatewidth: (1 + 1)
aswidth: 2
. However, since there were many tests expecting this behavior in how Less deals with parens, we opted to leave it as "legacy" (strict-legacy
) and add a more intuitiveparens
/strict
option.So, in summary, here are the
math
options (please see tests):always
(current default) - Less eagerly does mathparens-division
(future default) - No division is performed outside of parens using/
operator (but can be "forced" outside of parens with./
operator)parens
|strict
- A more intuitive form of legacystrictMath: true
strict-legacy
(deprecated) - As named, operates exactly like currentstrictMath: true
, with the exception thatwidth: -(1);
(single dimension values in parens) will now outputwidth: -1;
vs previous behavior ofwidth: -(1)
Note, that setting
options.strictMath = true
or--strict-math=on
is detected and seamlessly upgraded tomath: 'strict-legacy'
with a warning.