Skip to content

Commit b9c3c1b

Browse files
committed
Declarations of multiple font feature value map cascade together
1 parent 66cd34b commit b9c3c1b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/cssom/CSSFontFeatureValuesRule-impl.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ export default class CSSFontFeatureValuesRuleImpl extends CSSRuleImpl {
3737
declarations.forEach(declaration =>
3838
this[toIDLAttribute(declaration.name)] = serializeValue(declaration))
3939
features.forEach(({ name }) => {
40-
const rule = rules.findLast(rule => rule._definition.name === name)
41-
?? CSSFontFeatureValuesMap.createImpl(globalObject, args, {
40+
const [
41+
rule = CSSFontFeatureValuesMap.createImpl(globalObject, args, {
4242
name: name.slice(1),
4343
parentRule: this,
4444
parentStyleSheet,
45-
})
45+
}),
46+
...tail
47+
] = rules.filter(rule => rule._definition.name === name)
48+
tail.forEach(sibling => {
49+
for (const [name, value] of sibling) {
50+
rule.set(name, value)
51+
}
52+
})
4653
this[toIDLAttribute(name.slice(1))] = rule
4754
})
4855
}

test/stylesheet.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,14 @@ describe('CSSFontFeatureValuesRule, CSSFontFeatureValuesMap', () => {
534534

535535
const styleSheet = createStyleSheet(`
536536
@font-feature-values name {
537-
@annotation { name: 1 }
538-
@annotation { name: 2 }
537+
@annotation { a: 1; b: 1 }
538+
@annotation { a: 2 }
539539
font-display: block;
540540
}`)
541541
const rule = styleSheet.cssRules[0]
542542

543543
// CSSRule
544-
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { name: 2; } }')
544+
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { a: 2; b: 1; } }')
545545
assert.equal(rule.parentRule, null)
546546
assert.equal(rule.parentStyleSheet, styleSheet)
547547

@@ -551,12 +551,12 @@ describe('CSSFontFeatureValuesRule, CSSFontFeatureValuesMap', () => {
551551
// CSSFontFeatureValuesMap
552552
rule.styleset.set('double-W', 0)
553553
assert.deepEqual(rule.styleset.get('double-W'), [0])
554-
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { name: 2; } @styleset { double-W: 0; } }')
554+
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { a: 2; b: 1; } @styleset { double-W: 0; } }')
555555
rule.styleset.set('double-W', [0, 1])
556556
assert.deepEqual(rule.styleset.get('double-W'), [0, 1])
557-
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { name: 2; } @styleset { double-W: 0 1; } }')
557+
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { a: 2; b: 1; } @styleset { double-W: 0 1; } }')
558558
rule.styleset.delete('double-W')
559-
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { name: 2; } }')
559+
assert.equal(rule.cssText, '@font-feature-values name { font-display: block; @annotation { a: 2; b: 1; } }')
560560
assert.throws(() => rule.annotation.set('boxed', [0, 1]), INVALID_FONT_FEATURE_VALUE_ERROR)
561561
assert.throws(() => rule.annotation.set('boxed', [-1]), INVALID_FONT_FEATURE_VALUE_ERROR)
562562
assert.throws(() => rule.characterVariant.set('alpha-2', [0, 1, 2]), INVALID_FONT_FEATURE_VALUE_ERROR)

0 commit comments

Comments
 (0)