Skip to content

Commit 5f70944

Browse files
committed
Introduce CSSStyleDeclarationBase
This should reduce DT breakage. But note that this would make `CSSPageDescriptors extends CSSStyleDeclaration` to `false`. Authors would need to use CSSStyleDeclarationBase for that.
1 parent c7e2a5c commit 5f70944

9 files changed

Lines changed: 66 additions & 18 deletions

File tree

baselines/dom.generated.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,7 +5440,7 @@ declare var CSSNumericValue: {
54405440
*
54415441
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors)
54425442
*/
5443-
interface CSSPageDescriptors extends CSSStyleDeclaration {
5443+
interface CSSPageDescriptors extends CSSStyleDeclarationBase {
54445444
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin) */
54455445
margin: string;
54465446
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin-bottom) */
@@ -5518,7 +5518,7 @@ declare var CSSPerspective: {
55185518
*
55195519
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors)
55205520
*/
5521-
interface CSSPositionTryDescriptors extends CSSStyleDeclaration {
5521+
interface CSSPositionTryDescriptors extends CSSStyleDeclarationBase {
55225522
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
55235523
"align-self": string;
55245524
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
@@ -5992,7 +5992,7 @@ declare var CSSStartingStyleRule: {
59925992
*
59935993
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSStyleDeclaration)
59945994
*/
5995-
interface CSSStyleDeclaration {
5995+
interface CSSStyleDeclarationBase {
59965996
/**
59975997
* The **`cssText`** property of the CSSStyleDeclaration interface returns or sets the text of the element's **inline** style declaration only.
59985998
*
@@ -6044,12 +6044,15 @@ interface CSSStyleDeclaration {
60446044
[index: number]: string;
60456045
}
60466046

6047+
interface CSSStyleDeclaration extends CSSStyleProperties {
6048+
}
6049+
60476050
declare var CSSStyleDeclaration: {
60486051
prototype: CSSStyleDeclaration;
60496052
new(): CSSStyleDeclaration;
60506053
};
60516054

6052-
interface CSSStyleProperties extends CSSStyleDeclaration {
6055+
interface CSSStyleProperties extends CSSStyleDeclarationBase {
60536056
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/accent-color) */
60546057
accentColor: string;
60556058
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/align-content) */

baselines/ts5.5/dom.generated.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5435,7 +5435,7 @@ declare var CSSNumericValue: {
54355435
*
54365436
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors)
54375437
*/
5438-
interface CSSPageDescriptors extends CSSStyleDeclaration {
5438+
interface CSSPageDescriptors extends CSSStyleDeclarationBase {
54395439
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin) */
54405440
margin: string;
54415441
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin-bottom) */
@@ -5512,7 +5512,7 @@ declare var CSSPerspective: {
55125512
*
55135513
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors)
55145514
*/
5515-
interface CSSPositionTryDescriptors extends CSSStyleDeclaration {
5515+
interface CSSPositionTryDescriptors extends CSSStyleDeclarationBase {
55165516
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
55175517
"align-self": string;
55185518
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
@@ -5985,7 +5985,7 @@ declare var CSSStartingStyleRule: {
59855985
*
59865986
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSStyleDeclaration)
59875987
*/
5988-
interface CSSStyleDeclaration {
5988+
interface CSSStyleDeclarationBase {
59895989
/**
59905990
* The **`cssText`** property of the CSSStyleDeclaration interface returns or sets the text of the element's **inline** style declaration only.
59915991
*
@@ -6037,12 +6037,15 @@ interface CSSStyleDeclaration {
60376037
[index: number]: string;
60386038
}
60396039

6040+
interface CSSStyleDeclaration extends CSSStyleProperties {
6041+
}
6042+
60406043
declare var CSSStyleDeclaration: {
60416044
prototype: CSSStyleDeclaration;
60426045
new(): CSSStyleDeclaration;
60436046
};
60446047

6045-
interface CSSStyleProperties extends CSSStyleDeclaration {
6048+
interface CSSStyleProperties extends CSSStyleDeclarationBase {
60466049
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/accent-color) */
60476050
accentColor: string;
60486051
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/align-content) */

baselines/ts5.6/dom.generated.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,7 +5440,7 @@ declare var CSSNumericValue: {
54405440
*
54415441
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors)
54425442
*/
5443-
interface CSSPageDescriptors extends CSSStyleDeclaration {
5443+
interface CSSPageDescriptors extends CSSStyleDeclarationBase {
54445444
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin) */
54455445
margin: string;
54465446
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPageDescriptors#margin-bottom) */
@@ -5518,7 +5518,7 @@ declare var CSSPerspective: {
55185518
*
55195519
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors)
55205520
*/
5521-
interface CSSPositionTryDescriptors extends CSSStyleDeclaration {
5521+
interface CSSPositionTryDescriptors extends CSSStyleDeclarationBase {
55225522
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
55235523
"align-self": string;
55245524
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSPositionTryDescriptors#instance_properties) */
@@ -5992,7 +5992,7 @@ declare var CSSStartingStyleRule: {
59925992
*
59935993
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSSStyleDeclaration)
59945994
*/
5995-
interface CSSStyleDeclaration {
5995+
interface CSSStyleDeclarationBase {
59965996
/**
59975997
* The **`cssText`** property of the CSSStyleDeclaration interface returns or sets the text of the element's **inline** style declaration only.
59985998
*
@@ -6044,12 +6044,15 @@ interface CSSStyleDeclaration {
60446044
[index: number]: string;
60456045
}
60466046

6047+
interface CSSStyleDeclaration extends CSSStyleProperties {
6048+
}
6049+
60476050
declare var CSSStyleDeclaration: {
60486051
prototype: CSSStyleDeclaration;
60496052
new(): CSSStyleDeclaration;
60506053
};
60516054

6052-
interface CSSStyleProperties extends CSSStyleDeclaration {
6055+
interface CSSStyleProperties extends CSSStyleDeclarationBase {
60536056
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/accent-color) */
60546057
accentColor: string;
60556058
/** [MDN Reference](https://developer.mozilla.org/docs/Web/CSS/align-content) */

inputfiles/patches/cssom.kdl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// CSSStyleDeclaration spec change broke a bunch of DT packages.
2+
// This tries to make existing usages work while still keeping the new
3+
// CSSStyleProperties.
4+
5+
interface CSSStyleDeclaration \
6+
forward=CSSStyleDeclarationBase \
7+
forwardExtends=CSSStyleProperties

src/build/emitter.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ export function emitWebIdl(
765765
}
766766

767767
function emitCallBackInterface(i: Browser.Interface) {
768-
const methods = mapToArray(i.methods.method);
768+
const methods = mapToArray(i.methods?.method);
769769
const m = methods[0];
770770
const overload = m.signature[0];
771771
const paramsString = overload.param ? paramsToString(overload.param) : "";
@@ -1284,14 +1284,21 @@ export function emitWebIdl(
12841284
return extendConflictsBaseTypes[iName] ? `${iName}Base` : iName;
12851285
}
12861286

1287+
function processExtends(iName: string) {
1288+
if (allInterfacesMap[iName]?.forward) {
1289+
return allInterfacesMap[iName].forward;
1290+
}
1291+
return processIName(iName);
1292+
}
1293+
12871294
function processMixinName(mixinName: string) {
12881295
if (allInterfacesMap[mixinName].typeParameters?.length === 1) {
12891296
return `${mixinName}<${i.name}>`;
12901297
}
12911298
return mixinName;
12921299
}
12931300

1294-
const processedIName = processIName(i.name);
1301+
const processedIName = i.forward ?? processIName(i.name);
12951302

12961303
if (processedIName !== i.name) {
12971304
printer.printLineToStack(
@@ -1311,7 +1318,7 @@ export function emitWebIdl(
13111318
const finalExtends = [i.extends || "Object"]
13121319
.concat(getImplementList(i.name).map(processMixinName))
13131320
.filter((i) => i !== "Object")
1314-
.map(processIName);
1321+
.map(processExtends);
13151322

13161323
if (finalExtends.length) {
13171324
printer.print(` extends ${assertUnique(finalExtends).join(", ")}`);
@@ -1458,6 +1465,14 @@ export function emitWebIdl(
14581465
printer.printLine("}");
14591466
printer.printLine("");
14601467

1468+
if (i.forward) {
1469+
emitInterface({
1470+
name: i.name,
1471+
extends: i.forwardExtends,
1472+
constructor: undefined,
1473+
});
1474+
}
1475+
14611476
if (!printer.stackIsEmpty()) {
14621477
printer.printStackContent();
14631478
printer.printLine("}");

src/build/patches.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ function handleMixinandInterfaces(
183183
methods: { method },
184184
...optionalMember("extends", "string", node.properties?.extends),
185185
...optionalMember("overrideThis", "string", node.properties?.overrideThis),
186+
...optionalMember("forward", "string", node.properties?.forward),
187+
...optionalMember(
188+
"forwardExtends",
189+
"string",
190+
node.properties?.forwardExtends,
191+
),
186192
...handleTypeParameters(node.properties?.typeParameters),
187193
...interfaceObject,
188194
} as DeepPartial<Interface>;

src/build/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ export interface Interface {
151151
mixin?: boolean;
152152
namespace?: boolean;
153153
extends?: string;
154+
// forward the interface members to another, while keeping the current name.
155+
forward?: string;
156+
// "extends" for the original interface, in case `forward: true`.
157+
forwardExtends?: string;
154158
comment?: string;
155159
constants?: {
156160
constant: Record<string, Constant>;
157161
};
158-
methods: {
162+
methods?: {
159163
method: Record<string, Method>;
160164
};
161165
events?: {

src/build/widlprocess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function convertInterfaceCommon(
191191
}
192192
} else if (member.type === "operation") {
193193
const operation = convertOperation(member, result.exposed);
194-
const { method } = result.methods;
194+
const { method } = result.methods!;
195195
if (!member.name) {
196196
result.anonymousMethods!.method.push(operation);
197197
} else if (method.hasOwnProperty(member.name)) {
@@ -433,7 +433,7 @@ function convertNamespace(
433433
);
434434
} else if (member.type === "operation" && member.idlType) {
435435
const operation = convertOperation(member, result.exposed);
436-
const { method } = result.methods;
436+
const { method } = result.methods!;
437437
if (method[member.name!]) {
438438
method[member.name!].signature.push(...operation.signature);
439439
} else {

unittests/files/css-style.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This should be CSSStyleProperties as of 2025,
2+
// but a decade-usage of CSSStyleDeclaration blocks it
3+
4+
const foo = { width: "10px" } as CSSStyleDeclaration;
5+
foo.height = "20px";
6+
7+
document.body.style.width = "10px";

0 commit comments

Comments
 (0)