Skip to content

Commit

Permalink
Rename internal PostCSS rollup plugin to hoisting plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Nov 13, 2022
1 parent c845961 commit 8bf14d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/postcss/import/rollup.js → src/postcss/import/hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
import postcssPlugin from '../../helpers/postcss_plugin'

/**
* Marpit PostCSS import rollup plugin.
* Marpit PostCSS import hoisting plugin.
*
* Rollup `@charset` and `@import` at-rule to the beginning of CSS. Marpit is
* Hoist `@charset` and `@import` at-rule to the beginning of CSS. Marpit is
* manipulating CSS with many PostCSS plugins, so sometimes a few at-rules
* cannot keep specification.
*
* This plugin takes care of rolling up invalid at-rules.
* This plugin takes care of hoisting for invalid at-rules.
*
* @function importRollup
* @function importHoisting
*/
export const importRollup = postcssPlugin(
'marpit-postcss-import-rollup',
export const importHoisting = postcssPlugin(
'marpit-postcss-import-hoisting',
() => (css) => {
const rolluped = {
const hoisted = {
charset: undefined,
imports: [],
}

css.walkAtRules((rule) => {
if (rule.name === 'charset') {
rule.remove()
if (!rolluped.charset) rolluped.charset = rule
if (!hoisted.charset) hoisted.charset = rule
} else if (rule.name === 'import') {
rolluped.imports.push(rule.remove())
hoisted.imports.push(rule.remove())
}
})

const { first } = css

// Rollup at-rules
;[rolluped.charset, ...rolluped.imports]
// Hoist at-rules
;[hoisted.charset, ...hoisted.imports]
.filter((r) => r)
.forEach((rule, idx) => {
// Strip whitespace from the beginning of first at-rule
Expand All @@ -44,4 +44,4 @@ export const importRollup = postcssPlugin(
}
)

export default importRollup
export default importHoisting
6 changes: 3 additions & 3 deletions src/theme_set.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import postcss from 'postcss'
import postcssPlugin from './helpers/postcss_plugin'
import postcssAdvancedBackground from './postcss/advanced_background'
import postcssImportHoisting from './postcss/import/hoisting'
import postcssImportReplace from './postcss/import/replace'
import postcssImportRollup from './postcss/import/rollup'
import postcssImportSuppress from './postcss/import/suppress'
import postcssPagination from './postcss/pagination'
import postcssPrintable, {
Expand Down Expand Up @@ -274,7 +274,7 @@ class ThemeSet {
postcssPlugin('marpit-pack-after', () => (css) => {
css.last.after(after)
}),
postcssImportRollup,
postcssImportHoisting,
postcssImportReplace(this),
opts.printable &&
postcssPrintable({
Expand All @@ -298,7 +298,7 @@ class ThemeSet {
postcssRootIncreasingSpecificity,
opts.printable && postcssPrintablePostProcess,
postcssRem,
postcssImportRollup,
postcssImportHoisting,
].filter((p) => p)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import dedent from 'dedent'
import postcss from 'postcss'
import { importRollup } from '../../../src/postcss/import/rollup'
import { importHoisting } from '../../../src/postcss/import/hoisting'

describe('Marpit PostCSS import rollup plugin', () => {
describe('Marpit PostCSS import hoisting plugin', () => {
const run = (input) =>
postcss([importRollup]).process(input, { from: undefined })
postcss([importHoisting]).process(input, { from: undefined })

it('rolls up invalid @import rules', () => {
const before = dedent`
Expand Down

0 comments on commit 8bf14d4

Please sign in to comment.