From 681342f3abd750732544370bc8724ceb691e9b89 Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Mon, 25 Mar 2024 15:08:23 +0100 Subject: [PATCH] Change `rules` to be non optional --- packages/rrweb-snapshot/src/css.ts | 16 +++++++--------- packages/rrweb-snapshot/src/rebuild.ts | 6 ++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/rrweb-snapshot/src/css.ts b/packages/rrweb-snapshot/src/css.ts index 29e96593b4..522e257daf 100644 --- a/packages/rrweb-snapshot/src/css.ts +++ b/packages/rrweb-snapshot/src/css.ts @@ -56,9 +56,9 @@ export interface Node { }; } -export interface NodeWithOptionalRules extends Node { +export interface NodeWithRules extends Node { /** Array of nodes with the types rule, comment and any of the at-rule types. */ - rules?: Array; + rules: Array; } export interface Rule extends Node { @@ -103,7 +103,7 @@ export interface CustomMedia extends Node { /** * The @document at-rule. */ -export interface Document extends NodeWithOptionalRules { +export interface Document extends NodeWithRules { /** The part following @document. */ document?: string; /** The vendor prefix in @document, or undefined if there is none. */ @@ -121,7 +121,7 @@ export interface FontFace extends Node { /** * The @host at-rule. */ -export type Host = NodeWithOptionalRules; +export type Host = NodeWithRules; /** * The @import at-rule. @@ -153,7 +153,7 @@ export interface KeyFrame extends Node { /** * The @media at-rule. */ -export interface Media extends NodeWithOptionalRules { +export interface Media extends NodeWithRules { /** The part following @media. */ media?: string; } @@ -179,7 +179,7 @@ export interface Page extends Node { /** * The @supports at-rule. */ -export interface Supports extends NodeWithOptionalRules { +export interface Supports extends NodeWithRules { /** The part following @supports. */ supports?: string; } @@ -201,10 +201,8 @@ export type AtRule = /** * A collection of rules */ -export interface StyleRules { +export interface StyleRules extends NodeWithRules { source?: string; - /** Array of nodes with the types rule, comment and any of the at-rule types. */ - rules: Array; /** Array of Errors. Errors collected during parsing when option silent is true. */ parsingErrors?: ParserError[]; } diff --git a/packages/rrweb-snapshot/src/rebuild.ts b/packages/rrweb-snapshot/src/rebuild.ts index 98a1ad8f06..dc9b6c3b9f 100644 --- a/packages/rrweb-snapshot/src/rebuild.ts +++ b/packages/rrweb-snapshot/src/rebuild.ts @@ -1,4 +1,4 @@ -import { StyleRules, Rule, Media, NodeWithOptionalRules, parse } from './css'; +import { Rule, Media, NodeWithRules, parse } from './css'; import { serializedNodeWithId, NodeType, @@ -80,9 +80,7 @@ export function adaptCssForReplay(cssText: string, cache: BuildCache): string { const selectors: string[] = []; const medias: string[] = []; - function getSelectors( - rule: StyleRules | Rule | Media | NodeWithOptionalRules, - ) { + function getSelectors(rule: Rule | Media | NodeWithRules) { if ('selectors' in rule && rule.selectors) { rule.selectors.forEach((selector: string) => { if (HOVER_SELECTOR.test(selector)) {