Skip to content

Commit

Permalink
Change rules to be non optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice10 authored and jxiwang committed Jun 21, 2024
1 parent a5343b5 commit 60c8a1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 7 additions & 9 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rule | Comment | AtRule>;
rules: Array<Rule | Comment | AtRule>;
}

export interface Rule extends Node {
Expand Down Expand Up @@ -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. */
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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<Rule | Comment | AtRule>;
/** Array of Errors. Errors collected during parsing when option silent is true. */
parsingErrors?: ParserError[];
}
Expand Down
6 changes: 2 additions & 4 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleRules, Rule, Media, NodeWithOptionalRules, parse } from './css';
import { Rule, Media, NodeWithRules, parse } from './css';
import {
serializedNodeWithId,
NodeType,
Expand Down Expand Up @@ -81,9 +81,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)) {
Expand Down

0 comments on commit 60c8a1e

Please sign in to comment.