Skip to content
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

Merged
merged 6 commits into from
Jul 11, 2018

Conversation

matthew-dean
Copy link
Member

@matthew-dean matthew-dean commented Jul 7, 2018

Fixes #1880

This PR deprecates strictMath in favor of 4 math modes: always | parens-division | parens | strict | strict-legacy

In talking with @calvinjuarez, we both found the current behavior of strictMath extremely odd in cases like width: (1 + 1) + (1 + 1); which would result in the unexpected width: (1 + 1) + (1 + 1); vs. the expected width: 2 + 2;. None of the documentation seems to indicate this behavior or why it would need to evaluate in this way, since strictMath: true will evaluate width: (1 + 1) as width: 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 intuitive parens / strict option.

So, in summary, here are the math options (please see tests):

  • always (current default) - Less eagerly does math
  • parens-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 legacy strictMath: true
  • strict-legacy (deprecated) - As named, operates exactly like current strictMath: true, with the exception that width: -(1); (single dimension values in parens) will now output width: -1; vs previous behavior of width: -(1)

Note, that setting options.strictMath = true or --strict-math=on is detected and seamlessly upgraded to math: 'strict-legacy' with a warning.

@matthew-dean
Copy link
Member Author

🤔 Should parens-all just be parens ?

Copy link
Member

@calvinjuarez calvinjuarez left a 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');
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

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.

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');
Copy link
Member

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.

Copy link
Member Author

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.

ALWAYS: 0,
PARENS_DIVISION: 1,
PARENS_ALL: 2,
STRICT_LEGACY: 3
Copy link
Member

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?

Copy link
Member Author

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('./');
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

case 'parens-division':
opts.math = MATH.PARENS_DIVISION;
break;
case 'parens-all':
Copy link
Member

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.

Copy link
Member Author

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/',
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

@calvinjuarez calvinjuarez left a 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
@matthew-dean matthew-dean merged commit 8938e98 into less:master Jul 11, 2018
calvinjuarez added a commit to calvinjuarez/bootstrap-less-port that referenced this pull request Jul 16, 2018
--strict-math has been deprecated and replaced by --math.  See less/less.js#3274
calvinjuarez added a commit to calvinjuarez/bootstrap-less-port that referenced this pull request Dec 6, 2018
--strict-math has been deprecated and replaced by --math.  See less/less.js#3274
calvinjuarez added a commit to seanCodes/bootstrap-less-port that referenced this pull request Feb 26, 2019
* 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.
seanCodes pushed a commit to seanCodes/bootstrap-less-port that referenced this pull request Mar 3, 2019
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants