Skip to content

Commit

Permalink
Add correct typing on getSelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice10 authored and eoghanmurray committed Mar 25, 2024
1 parent 8f6c1ef commit 53b8522
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export interface Stylesheet extends Node {
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
const commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;

export function parse(css: string, options: ParserOptions = {}) {
export function parse(css: string, options: ParserOptions = {}): Stylesheet {
/**
* Positional.
*/
Expand Down Expand Up @@ -882,7 +882,7 @@ function trim(str: string) {
* Adds non-enumerable parent node reference to each node.
*/

function addParent(obj: Stylesheet, parent?: Stylesheet) {
function addParent(obj: Stylesheet, parent?: Stylesheet): Stylesheet {
const isNode = obj && typeof obj.type === 'string';
const childParent = isNode ? obj : parent;

Expand Down
6 changes: 3 additions & 3 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from './css';
import { StyleRules, Rule, Media, parse } from './css';
import {
serializedNodeWithId,
NodeType,
Expand Down Expand Up @@ -80,15 +80,15 @@ export function adaptCssForReplay(cssText: string, cache: BuildCache): string {

const selectors: string[] = [];
const medias: string[] = [];
function getSelectors(rule: any) {
function getSelectors(rule: StyleRules | Rule | Media) {
if ('selectors' in rule) {
(rule.selectors || []).forEach((selector: string) => {
if (HOVER_SELECTOR.test(selector)) {
selectors.push(selector);
}
});
}
if ('media' in rule && MEDIA_SELECTOR.test(rule.media)) {
if ('media' in rule && rule.media && MEDIA_SELECTOR.test(rule.media)) {
medias.push(rule.media);
}
if ('rules' in rule) {
Expand Down

0 comments on commit 53b8522

Please sign in to comment.