Skip to content

Commit

Permalink
fixup! Merge branch 'main' into feat/migrate-to-webidl
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Jul 23, 2024
1 parent d077e92 commit badf2c9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
40 changes: 20 additions & 20 deletions lib/CSSStyleDeclaration-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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] || '';
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 '';
}
Expand All @@ -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;
}

Expand All @@ -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 '';
Expand Down
4 changes: 2 additions & 2 deletions lib/CSSStyleDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions scripts/convert-idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}`);
}
Expand All @@ -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);
});
6 changes: 5 additions & 1 deletion scripts/download_latest_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down

0 comments on commit badf2c9

Please sign in to comment.