Skip to content

Commit

Permalink
refactor: add missing await and remove redundant async keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Oct 30, 2024
1 parent d4ea1a3 commit da88ff0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/beasties/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ export default class Beasties {
const document = createDocument(html)

if (this.options.additionalStylesheets.length > 0) {
this.embedAdditionalStylesheet(document)
await this.embedAdditionalStylesheet(document)
}

// `external:false` skips processing of external sheets
if (this.options.external !== false) {
const externalSheets = ([] as ChildNode[]).slice.call(
document.querySelectorAll('link[rel="stylesheet"]'),
)
const externalSheets = [...document.querySelectorAll('link[rel="stylesheet"]')] as ChildNode[]

await Promise.all(
externalSheets.map(link => this.embedLinkedStylesheet(link, document)),
Expand All @@ -92,13 +90,12 @@ export default class Beasties {

// go through all the style tags in the document and reduce them to only critical CSS
const styles = this.getAffectedStyleTags(document)

await Promise.all(
styles.map(style => this.processStyle(style, document)),
)
for (const style of styles) {
this.processStyle(style, document)
}

if (this.options.mergeStylesheets !== false && styles.length !== 0) {
await this.mergeStylesheets(document)
this.mergeStylesheets(document)
}

// serialize the document back to HTML and we're done
Expand All @@ -121,7 +118,7 @@ export default class Beasties {
return styles
}

async mergeStylesheets(document: HTMLDocument) {
mergeStylesheets(document: HTMLDocument) {
const styles = this.getAffectedStyleTags(document)
if (styles.length === 0) {
this.logger.warn?.(
Expand Down Expand Up @@ -375,7 +372,7 @@ export default class Beasties {
/**
* Parse the stylesheet within a <style> element, then reduce it to contain only rules used by the document.
*/
async processStyle(style: Node, document: HTMLDocument) {
processStyle(style: Node, document: HTMLDocument) {
if (style.$$reduce === false)
return

Expand Down

0 comments on commit da88ff0

Please sign in to comment.