Skip to content

Commit

Permalink
Copy strictMath flag in temporary env for mixin definitions
Browse files Browse the repository at this point in the history
Fixes an unreleased regression from fe66a9a (If4a0a7ce05),
which broke the elliptical corner feature of CSS border-radius,
which includes a literal slash (not meant as math).

https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius

The upstream handles creating new environment by calling
context.Eval() which calls copyFromOriginal() function.
This function preserves set of properties, including
`strictMath` param.

Whe we initialize the temporary env, we should preserve
at least the `strictMath`, the best approach is to
utilize the copyEvalEnv() method from Environment that
would create a copy of Environemnt with preserved
`strictMath` param.

The upstream tests run with `{strictMath: true}`, therefore
we should run tests in the same way. This allows us to remove
some overrides.

Bug: T362343
Change-Id: I1b2ec0ae206a49bf4fdf01f2acd47534343f3ba1
  • Loading branch information
polishdeveloper authored and Krinkle committed Apr 29, 2024
1 parent 6edad32 commit 9c38475
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 274 deletions.
1 change: 1 addition & 0 deletions lib/Less/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function isFileParsed( $file ) {
public function copyEvalEnv( $frames = [] ) {
$new_env = new self();
$new_env->frames = $frames;
$new_env->strictMath = $this->strictMath;
return $new_env;
}

Expand Down
31 changes: 20 additions & 11 deletions lib/Less/Tree/Mixin/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function toCSS() {
}

/**
* @param Less_Environment $env
* @see less-2.5.3.js#Definition.prototype.evalParams
*/
public function compileParams( $env, $mixinFrames, $args = [], &$evaldArguments = [] ) {
Expand Down Expand Up @@ -104,8 +105,7 @@ public function compileParams( $env, $mixinFrames, $args = [], &$evaldArguments
} elseif ( isset( $param['value'] ) ) {

if ( !$mixinEnv ) {
$mixinEnv = new Less_Environment();
$mixinEnv->frames = array_merge( [ $frame ], $mixinFrames );
$mixinEnv = $env->copyEvalEnv( array_merge( [ $frame ], $mixinFrames ) );
}

$val = $param['value']->compile( $mixinEnv );
Expand Down Expand Up @@ -140,6 +140,12 @@ public function compile( $env ) {
return new self( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $env->frames );
}

/**
* @param Less_Environment $env
* @param array|null $args
* @param bool|null $important
* @return Less_Tree_Ruleset
*/
public function evalCall( $env, $args = null, $important = null ) {
Less_Environment::$mixin_stack++;

Expand All @@ -159,8 +165,7 @@ public function evalCall( $env, $args = null, $important = null ) {
$ruleset = new Less_Tree_Ruleset( null, $this->rules );
$ruleset->originalRuleset = $this->ruleset_id;

$ruleSetEnv = new Less_Environment();
$ruleSetEnv->frames = array_merge( [ $this, $frame ], $mixinFrames );
$ruleSetEnv = $env->copyEvalEnv( array_merge( [ $this, $frame ], $mixinFrames ) );
$ruleset = $ruleset->compile( $ruleSetEnv );

if ( $important ) {
Expand All @@ -172,7 +177,11 @@ public function evalCall( $env, $args = null, $important = null ) {
return $ruleset;
}

/** @return bool */
/**
* @param array $args
* @param Less_Environment $env
* @return bool
*/
public function matchCondition( $args, $env ) {
if ( !$this->condition ) {
return true;
Expand All @@ -185,13 +194,13 @@ public function matchCondition( $args, $env ) {

$frame = $this->compileParams( $env, array_merge( $this->frames, $env->frames ), $args );

$compile_env = new Less_Environment();
$compile_env->frames = array_merge(
$compile_env = $env->copyEvalEnv(
array_merge(
[ $frame ], // the parameter variables
$this->frames, // the parent namespace/mixin frames
$env->frames // the current environment frames
);

$this->frames, // the parent namespace/mixin frames
$env->frames // the current environment frames
)
);
$compile_env->functions = $env->functions;

return (bool)$this->condition->compile( $compile_env );
Expand Down
12 changes: 0 additions & 12 deletions test/Fixtures/lessjs-2.5.3/override/comments2.css

This file was deleted.

163 changes: 0 additions & 163 deletions test/Fixtures/lessjs-2.5.3/override/mixins-args.css

This file was deleted.

87 changes: 0 additions & 87 deletions test/Fixtures/lessjs-2.5.3/override/urls.css

This file was deleted.

3 changes: 3 additions & 0 deletions test/fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
'javascript',
'plugin',
],
'options' => [
'strictMath' => true
]
],
'lessjs-2.5.3/compression' => [
'lessDir' => "$fixtureDir/lessjs-2.5.3/less/compression",
Expand Down
1 change: 0 additions & 1 deletion test/phpunit/FixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
'parens' => true,

// Temporary disabled
'css' => true, // T352911 & T352866
'mixins-guards' => true, // T352867
'urls' => true, // T353147
'variables' => true, // T352830, T352866
Expand Down

0 comments on commit 9c38475

Please sign in to comment.