From 8bf14d469856bf80b39ba67130162b06653b86d1 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Sun, 13 Nov 2022 22:00:29 +0900 Subject: [PATCH] Rename internal PostCSS rollup plugin to hoisting plugin --- src/postcss/import/{rollup.js => hoisting.js} | 24 +++++++++---------- src/theme_set.js | 6 ++--- .../postcss/import/{rollup.js => hoisting.js} | 6 ++--- 3 files changed, 18 insertions(+), 18 deletions(-) rename src/postcss/import/{rollup.js => hoisting.js} (58%) rename test/postcss/import/{rollup.js => hoisting.js} (82%) diff --git a/src/postcss/import/rollup.js b/src/postcss/import/hoisting.js similarity index 58% rename from src/postcss/import/rollup.js rename to src/postcss/import/hoisting.js index 571bb58..dc403f0 100644 --- a/src/postcss/import/rollup.js +++ b/src/postcss/import/hoisting.js @@ -2,20 +2,20 @@ 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: [], } @@ -23,16 +23,16 @@ export const importRollup = postcssPlugin( 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 @@ -44,4 +44,4 @@ export const importRollup = postcssPlugin( } ) -export default importRollup +export default importHoisting diff --git a/src/theme_set.js b/src/theme_set.js index 2a0e2c7..dbaa97f 100644 --- a/src/theme_set.js +++ b/src/theme_set.js @@ -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, { @@ -274,7 +274,7 @@ class ThemeSet { postcssPlugin('marpit-pack-after', () => (css) => { css.last.after(after) }), - postcssImportRollup, + postcssImportHoisting, postcssImportReplace(this), opts.printable && postcssPrintable({ @@ -298,7 +298,7 @@ class ThemeSet { postcssRootIncreasingSpecificity, opts.printable && postcssPrintablePostProcess, postcssRem, - postcssImportRollup, + postcssImportHoisting, ].filter((p) => p) ) diff --git a/test/postcss/import/rollup.js b/test/postcss/import/hoisting.js similarity index 82% rename from test/postcss/import/rollup.js rename to test/postcss/import/hoisting.js index 6816944..3151f60 100644 --- a/test/postcss/import/rollup.js +++ b/test/postcss/import/hoisting.js @@ -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`