Skip to content

Commit 12c3af3

Browse files
committed
fix: πŸ› scss with empty content
βœ… Closes: Closes #166
1 parent 6759bee commit 12c3af3

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

β€Žsrc/transformers/globalRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const globalifyRulePlugin = (root: any) => {
1919
const transformer: Transformer<never> = async ({ content, filename }) => {
2020
const { css, map: newMap } = await postcss()
2121
.use(globalifyRulePlugin)
22-
.process(content, { from: filename, map: true });
22+
.process(content, { from: filename, map: false });
2323

2424
return { code: css, map: newMap };
2525
};

β€Žsrc/transformers/globalStyle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const globalifyPlugin = (root: any) => {
2222
const transformer: Transformer<never> = async ({ content, filename }) => {
2323
const { css, map: newMap } = await postcss()
2424
.use(globalifyPlugin)
25-
.process(content, { from: filename, map: true });
25+
.process(content, { from: filename, map: false });
2626

2727
return { code: css, map: newMap };
2828
};

β€Žsrc/transformers/scss.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const transformer: Transformer<Options.Sass> = async ({
4545

4646
// scss errors if passed an empty string
4747
if (sassOptions.data.length === 0) {
48-
return { code: options.data };
48+
return { code: '' };
4949
}
5050

5151
if (renderSync) {

β€Žtest/autoProcess/style.test.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ const STYLE_LANGS: Array<[string, string]> = [
1515

1616
STYLE_LANGS.forEach(([lang, ext]) => {
1717
describe(`style - preprocessor - ${lang}`, () => {
18-
const template = `<div></div><style lang="${lang}">${getFixtureContent(
19-
`style.${ext}`,
20-
)}</style>`;
21-
const templateExternal = `<div></div><style src="./fixtures/style.${ext}"></style>`;
22-
2318
it(`should throw parsing ${lang} when { ${lang}: false }`, async () => {
19+
const template = `<div></div><style lang="${lang}">${getFixtureContent(
20+
`style.${ext}`,
21+
)}</style>`;
22+
2423
const opts = getAutoPreprocess({
2524
[lang]: false,
2625
});
@@ -29,17 +28,40 @@ STYLE_LANGS.forEach(([lang, ext]) => {
2928
});
3029

3130
it(`should parse ${lang}`, async () => {
31+
const template = `<div></div><style lang="${lang}">${getFixtureContent(
32+
`style.${ext}`,
33+
)}</style>`;
34+
3235
const opts = getAutoPreprocess();
3336
const preprocessed = await preprocess(template, opts);
3437

3538
expect(preprocessed.toString()).toMatch(CSS_PATTERN);
3639
});
3740

3841
it(`should parse external ${lang}`, async () => {
42+
const templateExternal = `<div></div><style src="./fixtures/style.${ext}"></style>`;
43+
const opts = getAutoPreprocess();
44+
const preprocessed = await preprocess(templateExternal, opts);
45+
46+
expect(preprocessed.toString()).toMatch(CSS_PATTERN);
47+
});
48+
49+
it(`should parse external ${lang}`, async () => {
50+
const templateExternal = `<div></div><style src="./fixtures/style.${ext}"></style>`;
3951
const opts = getAutoPreprocess();
4052
const preprocessed = await preprocess(templateExternal, opts);
4153

4254
expect(preprocessed.toString()).toMatch(CSS_PATTERN);
4355
});
56+
57+
it(`should return empty if content is empty`, async () => {
58+
const templateExternal = `<div></div><style src="./potato/style.${ext}"></style>`;
59+
const opts = getAutoPreprocess({
60+
[lang]: { sourceMap: false, sourcemap: false, map: false },
61+
});
62+
const preprocessed = await preprocess(templateExternal, opts);
63+
64+
expect(preprocessed.toString()).toMatch(templateExternal);
65+
});
4466
});
4567
});

0 commit comments

Comments
Β (0)