Skip to content

Commit 6cc958a

Browse files
fix(css): keep the calc() around a steps() count jump-none rejects bare
The math fold wrote `steps(calc(1), jump-none)` back as `steps(1,jump-none)`, which is not the same function: CSS Easing 2 §2.2 says the count must be at least 2 under `jump-none` and at least 1 under every other step position, so the literal is rejected where the `calc()` around it is clamped. WebKit honours the source and drops the printed form; Blink rejects both, which is why only the WebKit equivalence row reported it. This is the `CLAMPED_VALUE_RANGES` trade one argument in, so it is answered the same way: the generator carries the minimum per `<step-position>` — spec prose no dataset states, since the grammar says only `<integer>` — and the printer declines the bare form below it. A position the table has not met reads as the largest minimum, so an unknown spelling keeps its `calc()` rather than being guessed at. `steps(calc(2), jump-none)` still folds, as does every other position's `calc(1)`, and an omitted position is `end`, which takes one.
1 parent 381e7ff commit 6cc958a

8 files changed

Lines changed: 110 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Keep the `calc()` around a `steps()` count `jump-none` would reject bare.

‎lib/css/data.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,19 @@ const CALC_REJECTING_PROPERTIES = new Set(["overflow-clip-margin"]);
36003600
/** @type {Map<string, [string, number, number]>} */
36013601
const CLAMPED_VALUE_RANGES = new Map([["font-style", ["deg", -90, 90]]]);
36023602

3603+
// The smallest count `steps()` takes as a literal, keyed by its
3604+
// `<step-position>`. A position missing here is one the table has not met, so
3605+
// it reads as the largest and the fold declines rather than guesses.
3606+
/** @type {Map<string, number>} */
3607+
const STEP_POSITION_MINIMUM_COUNTS = new Map([
3608+
["jump-start", 1],
3609+
["jump-end", 1],
3610+
["jump-both", 1],
3611+
["jump-none", 2],
3612+
["start", 1],
3613+
["end", 1]
3614+
]);
3615+
36033616
// At-rules whose empty block is inert, so dropping it changes nothing.
36043617
const DROPPABLE_WHEN_EMPTY_AT_RULES = new Set([
36053618
"media",
@@ -7957,6 +7970,7 @@ module.exports.SLASH_BOX_SHORTHANDS = SLASH_BOX_SHORTHANDS;
79577970
module.exports.SLASH_LONGHANDS = SLASH_LONGHANDS;
79587971
module.exports.SRGB_SPACE = SRGB_SPACE;
79597972
module.exports.STEPPED_FUNCTIONS = STEPPED_FUNCTIONS;
7973+
module.exports.STEP_POSITION_MINIMUM_COUNTS = STEP_POSITION_MINIMUM_COUNTS;
79607974
module.exports.SUBSTITUTION_FUNCTIONS = SUBSTITUTION_FUNCTIONS;
79617975
module.exports.SUPPORTED_FROM = SUPPORTED_FROM;
79627976
module.exports.SUPPORT_BROWSERS = SUPPORT_BROWSERS;

‎lib/css/syntax.js‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const {
127127
SLASH_LONGHANDS,
128128
SRGB_SPACE,
129129
STEPPED_FUNCTIONS,
130+
STEP_POSITION_MINIMUM_COUNTS,
130131
SUBSTITUTION_FUNCTIONS,
131132
SUPPORTED_FROM,
132133
SUPPORT_BROWSERS,
@@ -7494,6 +7495,50 @@ const _foldLosesClamp = (term) => {
74947495
return match === null || _losesClamp(property, match[1], match[2]);
74957496
};
74967497

7498+
// A folded term that is a plain count, which is the only shape a step count
7499+
// takes — anything else is not the argument this guard judges.
7500+
const _INTEGER_TERM_RE = /^\d+$/;
7501+
7502+
/**
7503+
* Whether writing a folded term bare would take `steps()` under the count its
7504+
* `<step-position>` needs. CSS Easing 2 puts that at two under `jump-none` and
7505+
* one under every other position, and a count below it rejects the function
7506+
* where the `calc()` around the same value is clamped instead.
7507+
* @param {string} term the folded term
7508+
* @param {CssPath} path the accessor positioned on the math function
7509+
* @returns {boolean} true when the `calc()` has to stay
7510+
*/
7511+
const _foldBelowStepCount = (term, path) => {
7512+
// WHY: Folding `steps(calc(1), jump-none)` to `steps(1,jump-none)` printed a
7513+
// function the source did not name. Measured over three engines: WebKit reads
7514+
// the source and drops the printed form, while Blink rejects both — which is
7515+
// why one engine alone could not see it.
7516+
const parent = path.parent;
7517+
if (
7518+
parent === null ||
7519+
path.type(parent) !== T_FUNCTION ||
7520+
!_INTEGER_TERM_RE.test(term) ||
7521+
asciiLowerCaseName(path.name(parent)) !== "steps"
7522+
) {
7523+
return false;
7524+
}
7525+
// An omitted position is `end`, whose minimum is the one every position but
7526+
// `jump-none` takes; a spelling the table has not met reads as the largest,
7527+
// so the fold declines rather than guessing at its grammar.
7528+
let minimum = 1;
7529+
const count = path.childCount(parent);
7530+
for (let at = 0; at < count; at++) {
7531+
const child = path.childAt(parent, at);
7532+
if (path.type(child) !== T_IDENT) continue;
7533+
const named = STEP_POSITION_MINIMUM_COUNTS.get(
7534+
asciiLowerCaseName(path.value(child))
7535+
);
7536+
minimum = named === undefined ? 2 : named;
7537+
break;
7538+
}
7539+
return Number(term) < minimum;
7540+
};
7541+
74977542
/**
74987543
* Put back the fraction that keeps a number a `<number>` token, in the spelling
74997544
* the rest of the printer uses — one fractional digit, and no leading zero.
@@ -17219,7 +17264,8 @@ const printer = (path, writer) => {
1721917264
const folded =
1722017265
shape.test(term) &&
1722117266
!_inCalcRejectingProperty() &&
17222-
!_foldLosesClamp(term)
17267+
!_foldLosesClamp(term) &&
17268+
!_foldBelowStepCount(term, path)
1722317269
? term
1722417270
: `calc(${term})`;
1722517271
// A division can land on a value needing every digit of a double, which

‎test/configCases/css/minimize-timing-functions/__snapshots__/ConfigCacheTest.snap‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ Array [
4343
"/*! webpack: a custom property's easing function is opaque, bar its spacing */.t39{--easing:cubic-bezier(0.25,0.1,0.25,1)}",
4444
"/*! webpack: a signed argument still resolves to the keyword */.t40{animation-timing-function:ease-in-out}",
4545
"/*! webpack: a non-integer step count keeps the function */.t41{animation-timing-function:steps(1.5,end)}",
46+
"/*! webpack: jump-none takes two intervals, so a calc() holding one has to stay */.t42{animation-timing-function:steps(calc(1),jump-none)}",
47+
"/*! webpack: the same count is folded where jump-none can hold it */.t43{animation-timing-function:steps(2,jump-none)}",
48+
"/*! webpack: every other position takes one, so its calc() folds */.t44{animation-timing-function:steps(1,jump-both)}",
49+
"/*! webpack: an omitted position is end, which takes one */.t45{animation-timing-function:steps(1)}",
50+
"/*! webpack: a position no grammar here states keeps its calc() */.t46{animation-timing-function:steps(calc(1),jump-sideways)}",
4651
]
4752
`;

‎test/configCases/css/minimize-timing-functions/__snapshots__/ConfigTest.snap‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ Array [
4343
"/*! webpack: a custom property's easing function is opaque, bar its spacing */.t39{--easing:cubic-bezier(0.25,0.1,0.25,1)}",
4444
"/*! webpack: a signed argument still resolves to the keyword */.t40{animation-timing-function:ease-in-out}",
4545
"/*! webpack: a non-integer step count keeps the function */.t41{animation-timing-function:steps(1.5,end)}",
46+
"/*! webpack: jump-none takes two intervals, so a calc() holding one has to stay */.t42{animation-timing-function:steps(calc(1),jump-none)}",
47+
"/*! webpack: the same count is folded where jump-none can hold it */.t43{animation-timing-function:steps(2,jump-none)}",
48+
"/*! webpack: every other position takes one, so its calc() folds */.t44{animation-timing-function:steps(1,jump-both)}",
49+
"/*! webpack: an omitted position is end, which takes one */.t45{animation-timing-function:steps(1)}",
50+
"/*! webpack: a position no grammar here states keeps its calc() */.t46{animation-timing-function:steps(calc(1),jump-sideways)}",
4651
]
4752
`;

‎test/configCases/css/minimize-timing-functions/style.css‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@
8686
.t40 { animation-timing-function: cubic-bezier(+0.42, -0, 0.58, 1) }
8787
/*! webpack: a non-integer step count keeps the function */
8888
.t41 { animation-timing-function: steps(1.5, end) }
89+
90+
/*! webpack: jump-none takes two intervals, so a calc() holding one has to stay */
91+
.t42 { animation-timing-function: steps(calc(1), jump-none) }
92+
/*! webpack: the same count is folded where jump-none can hold it */
93+
.t43 { animation-timing-function: steps(calc(2), jump-none) }
94+
/*! webpack: every other position takes one, so its calc() folds */
95+
.t44 { animation-timing-function: steps(calc(1), jump-both) }
96+
/*! webpack: an omitted position is end, which takes one */
97+
.t45 { animation-timing-function: steps(calc(1)) }
98+
/*! webpack: a position no grammar here states keeps its calc() */
99+
.t46 { animation-timing-function: steps(calc(1), jump-sideways) }

‎test/specCases/syntaxEquivalence.spectest.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ const FILED_WPT_VALUE_DEFECTS = new Map([
259259
"background-image:paint(mypaint ",
260260
"webkit only: the unimplemented `paint()` again \u2014 see `paint( mypaint`"
261261
],
262-
[
263-
"animation-timing-function:steps(calc(1), jump-none)",
264-
"webkit only: a printer defect, not yet decided \u2014 WebKit reads the step count through a `calc()` where the printed form drops it. Measured in the first WebKit run"
265-
],
266262
[
267263
"font-family:\"New Century Schoolbook\", serif",
268264
"firefox only: not a printer defect — Gecko carries the source's quoting into the computed family where Blink drops it, so unquoting a name neither engine reads differently still reads as a difference there"

‎tooling/generate-css-data.js‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,7 +3777,7 @@ const eighthTurnEntries = (values) => {
37773777
// Spec prose no dataset states: an equivalence between two spellings, or a
37783778
// judgement about what a construct still does. Each carries the reason it has to
37793779
// be written out rather than derived.
3780-
/** @type {{ cssWideKeywords: string[], cubicBezierKeywords: [string, string][], flexKeywords: [string, string][], fontWeightNumbers: [string, string][], fontStretchPercentages: [string, string][], filterFunctionOmitted: [string, string][], positionKeywordPercentages: [string, string][], legacyPseudoElements: string[], compoundContinuations: string[], featurelessPseudoClasses: string[], initialValueKeywords: [string, string][], initialKeywordsAnEngineReadsApart: string[], unmergeableSlotKeywords: [string, string][], zeroUnitKeepingProperties: string[], calcRejectingProperties: string[], clampedValueRanges: [string, string, number, number][], autoSecondValueProperties: string[], defaultGradientDirections: string[], xAxisTransforms: [string, string][], negativeAcceptingProperties: string[], placeShorthands: string[], oneValuePairShorthands: string[], familyShorthands: string[], orderedShorthands: string[], omittableInitialKeywords: string[], pairLonghandOverrides: [string, string[]][], droppableWhenEmptyAtRules: string[], replacedByNameAtRules: string[], classSpellings: [string, string[]][], absoluteUnitScale: [string, string, number][], unitConversionTargets: string[], angleUnits: string[], colorSpacePrimitives: [string, string][], oklabMatrices: number[][], systemUiStack: string[], colorTransfers: [string, string][], predefinedColorSpaces: [string, string, string, string][], colorPrimaries: [string, number[]][], colorWhitePoints: [string, number[]][], enginesDisagreeOnTransfer: string[], calcConstantValues: [string, string][], quarterTurnAngle: [string, number][], eighthTurnSine: (number | null)[], eighthTurnTangent: (number | null)[], mathFunctionFold: [string, string, string, string, string | null, boolean][], mathPrimitives: [string, string][], predefinedCounterStyles: string[], predefinedCounterNames: string[], cssModulesKeywordSupplement: [string, string, number][] }} */
3780+
/** @type {{ cssWideKeywords: string[], cubicBezierKeywords: [string, string][], flexKeywords: [string, string][], fontWeightNumbers: [string, string][], fontStretchPercentages: [string, string][], filterFunctionOmitted: [string, string][], positionKeywordPercentages: [string, string][], legacyPseudoElements: string[], compoundContinuations: string[], featurelessPseudoClasses: string[], initialValueKeywords: [string, string][], initialKeywordsAnEngineReadsApart: string[], unmergeableSlotKeywords: [string, string][], zeroUnitKeepingProperties: string[], calcRejectingProperties: string[], clampedValueRanges: [string, string, number, number][], stepPositionMinimumCounts: [string, number][], autoSecondValueProperties: string[], defaultGradientDirections: string[], xAxisTransforms: [string, string][], negativeAcceptingProperties: string[], placeShorthands: string[], oneValuePairShorthands: string[], familyShorthands: string[], orderedShorthands: string[], omittableInitialKeywords: string[], pairLonghandOverrides: [string, string[]][], droppableWhenEmptyAtRules: string[], replacedByNameAtRules: string[], classSpellings: [string, string[]][], absoluteUnitScale: [string, string, number][], unitConversionTargets: string[], angleUnits: string[], colorSpacePrimitives: [string, string][], oklabMatrices: number[][], systemUiStack: string[], colorTransfers: [string, string][], predefinedColorSpaces: [string, string, string, string][], colorPrimaries: [string, number[]][], colorWhitePoints: [string, number[]][], enginesDisagreeOnTransfer: string[], calcConstantValues: [string, string][], quarterTurnAngle: [string, number][], eighthTurnSine: (number | null)[], eighthTurnTangent: (number | null)[], mathFunctionFold: [string, string, string, string, string | null, boolean][], mathPrimitives: [string, string][], predefinedCounterStyles: string[], predefinedCounterNames: string[], cssModulesKeywordSupplement: [string, string, number][] }} */
37813781

37823782
const SUPPLEMENT = {
37833783
// CSS Values 4's list. `mdn-data` has no `css-wide-keyword` production.
@@ -3899,6 +3899,19 @@ const SUPPLEMENT = {
38993899
// declaration off. CSS Fonts 4 §2.3 bounds `oblique` at ±90deg; `mdn-data`
39003900
// states `oblique <angle>` with no range, and no dataset carries the clamp.
39013901
clampedValueRanges: [["font-style", "deg", -90, 90]],
3902+
// WHY: The same trade one argument in: `steps()` clamps a count below its
3903+
// minimum inside a `calc()` and rejects the bare literal, so folding one to
3904+
// the value it equals switches the easing off. CSS Easing 2 §2.2 states the
3905+
// minimum as prose — `jump-none` holds neither end, so it takes two intervals
3906+
// to have any — and the grammar `mdn-data` carries says only `<integer>`.
3907+
stepPositionMinimumCounts: [
3908+
["jump-start", 1],
3909+
["jump-end", 1],
3910+
["jump-both", 1],
3911+
["jump-none", 2],
3912+
["start", 1],
3913+
["end", 1]
3914+
],
39023915
// CSS Backgrounds 3 §3.9 / CSS Masking 1 §4.5: these spell an omitted second
39033916
// value `auto`, not the first repeated. Their shared grammar cannot say so.
39043917
autoSecondValueProperties: ["background-size", "mask-size"],
@@ -7224,6 +7237,14 @@ const CLAMPED_VALUE_RANGES = new Map([${SUPPLEMENT.clampedValueRanges
72247237
.map(([name, unit, min, max]) => `["${name}", ["${unit}", ${min}, ${max}]]`)
72257238
.join(", ")}]);
72267239
7240+
// The smallest count \`steps()\` takes as a literal, keyed by its
7241+
// \`<step-position>\`. A position missing here is one the table has not met, so
7242+
// it reads as the largest and the fold declines rather than guesses.
7243+
/** @type {Map<string, number>} */
7244+
const STEP_POSITION_MINIMUM_COUNTS = new Map([${SUPPLEMENT.stepPositionMinimumCounts
7245+
.map(([name, min]) => `["${name}", ${min}]`)
7246+
.join(", ")}]);
7247+
72277248
// At-rules whose empty block is inert, so dropping it changes nothing.
72287249
const DROPPABLE_WHEN_EMPTY_AT_RULES = ${setLiteral(
72297250
SUPPLEMENT.droppableWhenEmptyAtRules
@@ -7599,7 +7620,7 @@ module.exports.PREFIX_WINDOWS = PREFIX_WINDOWS;\nmodule.exports.PREFIX_WINDOW_ST
75997620
module.exports.QUARTER_TURN_ANGLE = QUARTER_TURN_ANGLE;
76007621
module.exports.RATIO_PROPERTIES = RATIO_PROPERTIES;\nmodule.exports.REPEAT_STYLE_KEYWORDS = REPEAT_STYLE_KEYWORDS;\nmodule.exports.REPEAT_STYLE_PROPERTIES = REPEAT_STYLE_PROPERTIES;\nmodule.exports.RGB_TO_NAME = RGB_TO_NAME;
76017622
module.exports.SELECTOR_FUNCTIONS = SELECTOR_FUNCTIONS;\nmodule.exports.SELECTOR_SUPPORTED_FROM = SELECTOR_SUPPORTED_FROM;\nmodule.exports.SHADOW_PROPERTIES = SHADOW_PROPERTIES;\nmodule.exports.SHORTHAND_INITIAL_KEYWORDS = SHORTHAND_INITIAL_KEYWORDS;\nmodule.exports.SHORTHAND_LONGHANDS = SHORTHAND_LONGHANDS;\nmodule.exports.SLASH_BOX_SHORTHANDS = SLASH_BOX_SHORTHANDS;\nmodule.exports.SLASH_LONGHANDS = SLASH_LONGHANDS;\nmodule.exports.SRGB_SPACE = SRGB_SPACE;
7602-
module.exports.STEPPED_FUNCTIONS = STEPPED_FUNCTIONS;
7623+
module.exports.STEPPED_FUNCTIONS = STEPPED_FUNCTIONS;\nmodule.exports.STEP_POSITION_MINIMUM_COUNTS = STEP_POSITION_MINIMUM_COUNTS;
76037624
module.exports.SUBSTITUTION_FUNCTIONS = SUBSTITUTION_FUNCTIONS;\nmodule.exports.SUPPORTED_FROM = SUPPORTED_FROM;\nmodule.exports.SUPPORT_BROWSERS = SUPPORT_BROWSERS;\nmodule.exports.SUPPORT_PROFILES = SUPPORT_PROFILES;\nmodule.exports.SYSTEM_UI_STACK = SYSTEM_UI_STACK;\nmodule.exports.THROUGH_MATRIX = THROUGH_MATRIX;\nmodule.exports.THROUGH_TRANSFER = THROUGH_TRANSFER;\nmodule.exports.TRANSITION_BEHAVIORS = TRANSITION_BEHAVIORS;
76047625
module.exports.UNIT_CONVERSION_TARGETS = UNIT_CONVERSION_TARGETS;
76057626
module.exports.UNIT_GROUP_BASE = UNIT_GROUP_BASE;\nmodule.exports.UNSHARED_LONGHAND_KEYWORDS = UNSHARED_LONGHAND_KEYWORDS;\nmodule.exports.VALUE_SUPPORT_PACKED = VALUE_SUPPORT_PACKED;\nmodule.exports.X_AXIS_TRANSFORMS = X_AXIS_TRANSFORMS;

0 commit comments

Comments
 (0)