Skip to content

Commit da182f4

Browse files
committed
fix lint
1 parent c489e06 commit da182f4

File tree

2 files changed

+108
-89
lines changed

2 files changed

+108
-89
lines changed

src/css.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,11 @@ export function parse(css: string, options: ParserOptions = {}) {
440440
* http://ostermiller.org/findcomment.html */
441441
return trim(m[0])
442442
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
443-
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, m => {
443+
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, (m) => {
444444
return m.replace(/,/g, '\u200C');
445445
})
446446
.split(/\s*(?![^(]*\)),\s*/)
447-
.map(s => {
447+
.map((s) => {
448448
return s.replace(/\u200C/g, ',');
449449
});
450450
}
@@ -888,7 +888,7 @@ function addParent(obj: Stylesheet, parent?: Stylesheet) {
888888
for (const k of Object.keys(obj)) {
889889
const value = obj[k as keyof Stylesheet];
890890
if (Array.isArray(value)) {
891-
value.forEach(v => {
891+
value.forEach((v) => {
892892
addParent(v, childParent);
893893
});
894894
} else if (value && typeof value === 'object') {

src/snapshot.ts

Lines changed: 105 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function getValidTagName(tagName: string): string {
3434
function getCssRulesString(s: CSSStyleSheet): string | null {
3535
try {
3636
const rules = s.rules || s.cssRules;
37-
return rules
38-
? Array.from(rules).map(getCssRuleString).join('')
39-
: null;
37+
return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
4038
} catch (error) {
4139
return null;
4240
}
@@ -74,18 +72,20 @@ export function absoluteToStylesheet(
7472
URL_IN_CSS_REF,
7573
(origin, quote1, path1, quote2, path2, path3) => {
7674
const filePath = path1 || path2 || path3;
77-
const maybe_quote = quote1 || quote2 || '';
75+
const maybeQuote = quote1 || quote2 || '';
7876
if (!filePath) {
7977
return origin;
8078
}
8179
if (!RELATIVE_PATH.test(filePath)) {
82-
return `url(${maybe_quote}${filePath}${maybe_quote})`;
80+
return `url(${maybeQuote}${filePath}${maybeQuote})`;
8381
}
8482
if (DATA_URI.test(filePath)) {
85-
return `url(${maybe_quote}${filePath}${maybe_quote})`;
83+
return `url(${maybeQuote}${filePath}${maybeQuote})`;
8684
}
8785
if (filePath[0] === '/') {
88-
return `url(${maybe_quote}${extractOrigin(href) + filePath}${maybe_quote})`;
86+
return `url(${maybeQuote}${
87+
extractOrigin(href) + filePath
88+
}${maybeQuote})`;
8989
}
9090
const stack = href.split('/');
9191
const parts = filePath.split('/');
@@ -99,7 +99,7 @@ export function absoluteToStylesheet(
9999
stack.push(part);
100100
}
101101
}
102-
return `url(${maybe_quote}${stack.join('/')}${maybe_quote})`;
102+
return `url(${maybeQuote}${stack.join('/')}${maybeQuote})`;
103103
},
104104
);
105105
}
@@ -179,7 +179,7 @@ export function _isBlockedElement(
179179
});
180180
}
181181
if (blockSelector) {
182-
return element.matches(blockSelector)
182+
return element.matches(blockSelector);
183183
}
184184

185185
return false;
@@ -208,7 +208,11 @@ function serializeNode(
208208
systemId: (n as DocumentType).systemId,
209209
};
210210
case n.ELEMENT_NODE:
211-
const needBlock = _isBlockedElement(n as HTMLElement, blockClass, blockSelector);
211+
const needBlock = _isBlockedElement(
212+
n as HTMLElement,
213+
blockClass,
214+
blockSelector,
215+
);
212216
const tagName = getValidTagName((n as HTMLElement).tagName);
213217
let attributes: attributes = {};
214218
for (const { name, value } of Array.from((n as HTMLElement).attributes)) {
@@ -339,76 +343,91 @@ function serializeNode(
339343
}
340344
}
341345

342-
function lowerIfExists(maybeAttr : string | number | boolean) : string {
346+
function lowerIfExists(maybeAttr: string | number | boolean): string {
343347
if (maybeAttr === undefined) {
344348
return '';
345349
} else {
346350
return (maybeAttr as string).toLowerCase();
347351
}
348352
}
349353

350-
function slimDOMExcluded(sn: serializedNode, slimDOMOptions: SlimDOMOptions): boolean {
354+
function slimDOMExcluded(
355+
sn: serializedNode,
356+
slimDOMOptions: SlimDOMOptions,
357+
): boolean {
351358
if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
352359
// TODO: convert IE conditional comments to real nodes
353360
return true;
354361
} else if (sn.type === NodeType.Element) {
355-
if (slimDOMOptions.script &&
356-
(sn.tagName === 'script' ||
357-
(sn.tagName === 'link' && sn.attributes.rel === 'preload' && sn.attributes['as'] === 'script')
358-
)) {
362+
if (
363+
slimDOMOptions.script &&
364+
(sn.tagName === 'script' ||
365+
(sn.tagName === 'link' &&
366+
sn.attributes.rel === 'preload' &&
367+
sn.attributes.as === 'script'))
368+
) {
359369
return true;
360-
} else if (slimDOMOptions.headFavicon && (
361-
(sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon')
362-
|| (sn.tagName === 'meta' && (
363-
lowerIfExists(sn.attributes['name']).match(/^msapplication-tile(image|color)$/)
364-
|| lowerIfExists(sn.attributes['name']) === 'application-name'
365-
|| lowerIfExists(sn.attributes['rel']) === 'icon'
366-
|| lowerIfExists(sn.attributes['rel']) === 'apple-touch-icon'
367-
|| lowerIfExists(sn.attributes['rel']) === 'shortcut icon'
368-
)))) {
370+
} else if (
371+
slimDOMOptions.headFavicon &&
372+
((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
373+
(sn.tagName === 'meta' &&
374+
(lowerIfExists(sn.attributes.name).match(
375+
/^msapplication-tile(image|color)$/,
376+
) ||
377+
lowerIfExists(sn.attributes.name) === 'application-name' ||
378+
lowerIfExists(sn.attributes.rel) === 'icon' ||
379+
lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
380+
lowerIfExists(sn.attributes.rel) === 'shortcut icon')))
381+
) {
369382
return true;
370383
} else if (sn.tagName === 'meta') {
371-
if (slimDOMOptions.headMetaDescKeywords && (
372-
lowerIfExists(sn.attributes['name']).match(/^description|keywords$/)
373-
)) {
384+
if (
385+
slimDOMOptions.headMetaDescKeywords &&
386+
lowerIfExists(sn.attributes.name).match(/^description|keywords$/)
387+
) {
374388
return true;
375-
} else if (slimDOMOptions.headMetaSocial && (
376-
lowerIfExists(sn.attributes['property']).match(/^(og|twitter|fb):/) // og = opengraph (facebook)
377-
|| lowerIfExists(sn.attributes['name']).match(/^(og|twitter):/)
378-
|| lowerIfExists(sn.attributes['name']) === 'pinterest'
379-
)) {
389+
} else if (
390+
slimDOMOptions.headMetaSocial &&
391+
(lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) || // og = opengraph (facebook)
392+
lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
393+
lowerIfExists(sn.attributes.name) === 'pinterest')
394+
) {
380395
return true;
381-
} else if (slimDOMOptions.headMetaRobots && (
382-
lowerIfExists(sn.attributes['name']) === 'robots'
383-
|| lowerIfExists(sn.attributes['name']) === 'googlebot'
384-
|| lowerIfExists(sn.attributes['name']) === 'bingbot'
385-
)) {
396+
} else if (
397+
slimDOMOptions.headMetaRobots &&
398+
(lowerIfExists(sn.attributes.name) === 'robots' ||
399+
lowerIfExists(sn.attributes.name) === 'googlebot' ||
400+
lowerIfExists(sn.attributes.name) === 'bingbot')
401+
) {
386402
return true;
387-
} else if (slimDOMOptions.headMetaHttpEquiv && (
403+
} else if (
404+
slimDOMOptions.headMetaHttpEquiv &&
388405
sn.attributes['http-equiv'] !== undefined
389-
)) {
406+
) {
390407
// e.g. X-UA-Compatible, Content-Type, Content-Language,
391408
// cache-control, X-Translated-By
392409
return true;
393-
} else if (slimDOMOptions.headMetaAuthorship && (
394-
lowerIfExists(sn.attributes['name']) === 'author'
395-
|| lowerIfExists(sn.attributes['name']) === 'generator'
396-
|| lowerIfExists(sn.attributes['name']) === 'framework'
397-
|| lowerIfExists(sn.attributes['name']) === 'publisher'
398-
|| lowerIfExists(sn.attributes['name']) === 'progid'
399-
|| lowerIfExists(sn.attributes['property']).match(/^article:/)
400-
|| lowerIfExists(sn.attributes['property']).match(/^product:/)
401-
)) {
410+
} else if (
411+
slimDOMOptions.headMetaAuthorship &&
412+
(lowerIfExists(sn.attributes.name) === 'author' ||
413+
lowerIfExists(sn.attributes.name) === 'generator' ||
414+
lowerIfExists(sn.attributes.name) === 'framework' ||
415+
lowerIfExists(sn.attributes.name) === 'publisher' ||
416+
lowerIfExists(sn.attributes.name) === 'progid' ||
417+
lowerIfExists(sn.attributes.property).match(/^article:/) ||
418+
lowerIfExists(sn.attributes.property).match(/^product:/))
419+
) {
402420
return true;
403-
} else if (slimDOMOptions.headMetaVerification && (
404-
lowerIfExists(sn.attributes['name']) === 'google-site-verification'
405-
|| lowerIfExists(sn.attributes['name']) === 'yandex-verification'
406-
|| lowerIfExists(sn.attributes['name']) === 'csrf-token'
407-
|| lowerIfExists(sn.attributes['name']) === 'p:domain_verify'
408-
|| lowerIfExists(sn.attributes['name']) === 'verify-v1'
409-
|| lowerIfExists(sn.attributes['name']) === 'verification'
410-
|| lowerIfExists(sn.attributes['name']) === 'shopify-checkout-api-token'
411-
)) {
421+
} else if (
422+
slimDOMOptions.headMetaVerification &&
423+
(lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
424+
lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
425+
lowerIfExists(sn.attributes.name) === 'csrf-token' ||
426+
lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
427+
lowerIfExists(sn.attributes.name) === 'verify-v1' ||
428+
lowerIfExists(sn.attributes.name) === 'verification' ||
429+
lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')
430+
) {
412431
return true;
413432
}
414433
}
@@ -448,20 +467,21 @@ export function serializeNodeWithId(
448467
// Try to reuse the previous id
449468
if ('__sn' in n) {
450469
id = n.__sn.id;
451-
} else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
452-
(!preserveWhiteSpace &&
453-
_serializedNode.type === NodeType.Text &&
454-
!_serializedNode.isStyle &&
455-
!_serializedNode.textContent.replace(/^\s+|\s+$/gm,'').length
456-
)) {
470+
} else if (
471+
slimDOMExcluded(_serializedNode, slimDOMOptions) ||
472+
(!preserveWhiteSpace &&
473+
_serializedNode.type === NodeType.Text &&
474+
!_serializedNode.isStyle &&
475+
!_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)
476+
) {
457477
id = IGNORED_NODE;
458478
} else {
459479
id = genId();
460480
}
461481
const serializedNode = Object.assign(_serializedNode, { id });
462482
(n as INode).__sn = serializedNode;
463483
if (id === IGNORED_NODE) {
464-
return null; // slimDOM
484+
return null; // slimDOM
465485
}
466486
map[id] = n as INode;
467487
let recordChild = !skipChild;
@@ -476,9 +496,9 @@ export function serializeNodeWithId(
476496
recordChild
477497
) {
478498
if (
479-
(slimDOMOptions.headWhitespace &&
480-
_serializedNode.type === NodeType.Element &&
481-
_serializedNode.tagName == 'head')
499+
slimDOMOptions.headWhitespace &&
500+
_serializedNode.type === NodeType.Element &&
501+
_serializedNode.tagName === 'head'
482502
// would impede performance: || getComputedStyle(n)['white-space'] === 'normal'
483503
) {
484504
preserveWhiteSpace = false;
@@ -538,24 +558,23 @@ function snapshot(
538558
? {}
539559
: maskAllInputsOrOptions;
540560
const slimDOMOptions: SlimDOMOptions =
541-
(slimDOMSensibleOrOptions === true ||
542-
slimDOMSensibleOrOptions === 'all')
543-
// if true: set of sensible options that should not throw away any information
544-
? {
545-
script: true,
546-
comment: true,
547-
headFavicon: true,
548-
headWhitespace: true,
549-
headMetaDescKeywords: slimDOMSensibleOrOptions === 'all', // destructive
550-
headMetaSocial: true,
551-
headMetaRobots: true,
552-
headMetaHttpEquiv: true,
553-
headMetaAuthorship: true,
554-
headMetaVerification: true,
555-
}
556-
: slimDOMSensibleOrOptions === false
557-
? {}
558-
: slimDOMSensibleOrOptions;
561+
slimDOMSensibleOrOptions === true || slimDOMSensibleOrOptions === 'all'
562+
? // if true: set of sensible options that should not throw away any information
563+
{
564+
script: true,
565+
comment: true,
566+
headFavicon: true,
567+
headWhitespace: true,
568+
headMetaDescKeywords: slimDOMSensibleOrOptions === 'all', // destructive
569+
headMetaSocial: true,
570+
headMetaRobots: true,
571+
headMetaHttpEquiv: true,
572+
headMetaAuthorship: true,
573+
headMetaVerification: true,
574+
}
575+
: slimDOMSensibleOrOptions === false
576+
? {}
577+
: slimDOMSensibleOrOptions;
559578
return [
560579
serializeNodeWithId(
561580
n,

0 commit comments

Comments
 (0)