From badf2c9789728a81617beda88e91e8ceb2535f89 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Tue, 23 Jul 2024 15:30:00 +0200 Subject: [PATCH] fixup! Merge branch 'main' into feat/migrate-to-webidl --- lib/CSSStyleDeclaration-impl.js | 40 +++++++++++++-------------- lib/CSSStyleDeclaration.test.js | 4 +-- lib/parsers.js | 2 +- scripts/convert-idl.js | 8 +++--- scripts/download_latest_properties.js | 6 +++- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/CSSStyleDeclaration-impl.js b/lib/CSSStyleDeclaration-impl.js index 530a19fc..428e29ef 100644 --- a/lib/CSSStyleDeclaration-impl.js +++ b/lib/CSSStyleDeclaration-impl.js @@ -3,12 +3,11 @@ * https://github.com/NV/CSSOM ********************************************************************/ 'use strict'; -var CSSOM = require('rrweb-cssom'); -var allProperties = require('./allProperties'); -var allExtraProperties = require('./allExtraProperties'); -var implementedProperties = require('./implementedProperties'); -var { dashedToCamelCase } = require('./parsers'); -var getBasicPropertyDescriptor = require('./utils/getBasicPropertyDescriptor'); +const CSSOM = require('rrweb-cssom'); +const allProperties = require('./allProperties'); +const allExtraProperties = require('./allExtraProperties'); +const implementedProperties = require('./implementedProperties'); +const idlUtils = require('./utils.js'); class CSSStyleDeclarationImpl { /** @@ -70,13 +69,15 @@ class CSSStyleDeclarationImpl { ); } this._setInProgress = false; - this._onChange?.(this.cssText); + if (this._onChange) { + this._onChange(this.cssText); + } } /** * @see https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-length */ - get length () { + get length() { return this._list.length; } @@ -85,7 +86,7 @@ class CSSStyleDeclarationImpl { * length. If the new length is more, it does nothing, the new indices * will be undefined until set. **/ - set length (value) { + set length(value) { this._list.length = value; } @@ -96,11 +97,8 @@ class CSSStyleDeclarationImpl { * @return {string} the value of the property if it has been explicitly set for this declaration block. * Returns the empty string if the property has not been set. */ - getPropertyValue (name) { - if (!this._values.hasOwnProperty(name)) { - return ''; - } - return this._values[name].toString(); + getPropertyValue(name) { + return this._values[name] || ''; } /** @@ -110,7 +108,7 @@ class CSSStyleDeclarationImpl { * @param {string} [priority=""] "important" or "" * @see https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty */ - setProperty (name, value, priority = '') { + setProperty(name, value, priority = '') { if (value === '') { this.removeProperty(name); return; @@ -139,7 +137,7 @@ class CSSStyleDeclarationImpl { * @param {string | null} value * @param {string} [priority=""] */ - _setProperty (name, value, priority = '') { + _setProperty(name, value, priority = '') { // FIXME: A good chunk of the implemented properties call this method // with `value = undefined`, expecting it to do nothing: if (value === undefined) { @@ -178,7 +176,7 @@ class CSSStyleDeclarationImpl { * @return {string} the value of the property if it has been explicitly set for this declaration block. * Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property. */ - removeProperty (name) { + removeProperty(name) { if (!idlUtils.hasOwn(this._values, name)) { return ''; } @@ -198,7 +196,9 @@ class CSSStyleDeclarationImpl { // That's what Firefox does //this._list[index] = '' - this._onChange?.(this.cssText); + if (this._onChange) { + this._onChange(this.cssText); + } return prevValue; } @@ -207,14 +207,14 @@ class CSSStyleDeclarationImpl { * @param {String} name * @see https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority */ - getPropertyPriority (name) { + getPropertyPriority(name) { return this._importants[name] || ''; } /** * @see https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-item */ - item (index) { + item(index) { const { _list } = this; if (index < 0 || index >= _list.length) { return ''; diff --git a/lib/CSSStyleDeclaration.test.js b/lib/CSSStyleDeclaration.test.js index 2bb30289..e2641090 100644 --- a/lib/CSSStyleDeclaration.test.js +++ b/lib/CSSStyleDeclaration.test.js @@ -8,8 +8,8 @@ var implementedProperties = require('./implementedProperties'); var { cssPropertyToIDLAttribute } = require('./parsers'); var dashedProperties = [...allProperties, ...allExtraProperties]; -var allowedProperties = ['cssFloat', ...dashedProperties.map(p => cssPropertyToIDLAttribute(p))]; -implementedProperties = Array.from(implementedProperties, p => cssPropertyToIDLAttribute(p)); +var allowedProperties = ['cssFloat', ...dashedProperties.map((p) => cssPropertyToIDLAttribute(p))]; +implementedProperties = Array.from(implementedProperties, (p) => cssPropertyToIDLAttribute(p)); var invalidProperties = implementedProperties.filter((prop) => !allowedProperties.includes(prop)); describe('CSSStyleDeclaration', () => { diff --git a/lib/parsers.js b/lib/parsers.js index 4c184c63..00700251 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -455,7 +455,7 @@ exports.parseKeyword = function parseKeyword(val, valid_keywords) { * @param {boolean} [lowercaseFirst] * @see https://drafts.csswg.org/cssom/#css-property-to-idl-attribute */ -function cssPropertyToIDLAttribute (property, lowercaseFirst = false) { +function cssPropertyToIDLAttribute(property, lowercaseFirst = false) { let output = ''; let uppercaseNext = false; diff --git a/scripts/convert-idl.js b/scripts/convert-idl.js index f719cb35..068cb713 100644 --- a/scripts/convert-idl.js +++ b/scripts/convert-idl.js @@ -15,7 +15,7 @@ const outputDir = implDir; const propertyNames = [ ...allProperties, - ...Array.from(allExtraProperties).filter(prop => { + ...Array.from(allExtraProperties).filter((prop) => { return !allProperties.has(prop); }), ].sort(); @@ -86,7 +86,7 @@ const transformer = new Transformer({ implSuffix: '-impl', // TODO: Add support for `[CEReactions]` processReflect(idl, implName) { - const reflectStyle = idl.extAttrs.find(extAttr => extAttr.name === 'ReflectStyle'); + const reflectStyle = idl.extAttrs.find((extAttr) => extAttr.name === 'ReflectStyle'); if (!reflectStyle || !reflectStyle.rhs || reflectStyle.rhs.type !== 'string') { throw new Error(`Internal error: Invalid [ReflectStyle] for attribute ${idl.name}`); } @@ -99,9 +99,9 @@ const transformer = new Transformer({ }); transformer.addSource(srcDir, implDir); -new Promise(resolve => genIDL.on('finish', resolve)) +new Promise((resolve) => genIDL.on('finish', resolve)) .then(() => transformer.generate(outputDir)) - .catch(err => { + .catch((err) => { console.error(err.stack); process.exit(1); }); diff --git a/scripts/download_latest_properties.js b/scripts/download_latest_properties.js index 7f3331c7..c33f594b 100644 --- a/scripts/download_latest_properties.js +++ b/scripts/download_latest_properties.js @@ -71,7 +71,11 @@ async function main() { out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n'); out_file.write( 'module.exports = new Set(' + - JSON.stringify(CSSpropertyNames.map((p) => idlAttributeToCSSProperty(p)), null, 2) + + JSON.stringify( + CSSpropertyNames.map((p) => idlAttributeToCSSProperty(p)), + null, + 2 + ) + ');\n' );