Skip to content

Commit 4ffaf7b

Browse files
committed
fix: check if filename exists before processing
1 parent 34cd869 commit 4ffaf7b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ let pluginOptions: PluginOptions;
3535
* @returns the preprocessor markup
3636
*/
3737
const markup: MarkupPreprocessor = async ({ content, filename }) => {
38-
const isIncluded = filename ? isFileIncluded(pluginOptions.includePaths, filename) : false;
39-
40-
if (!isIncluded || (!pluginOptions.parseStyleTag && !pluginOptions.parseExternalStylesheet)) {
38+
if (
39+
!filename ||
40+
!isFileIncluded(pluginOptions.includePaths, filename) ||
41+
(!pluginOptions.parseStyleTag && !pluginOptions.parseExternalStylesheet)
42+
) {
4143
return { code: content };
4244
}
45+
4346
let ast: Ast;
4447
try {
4548
ast = parse(content, { filename });
@@ -61,7 +64,7 @@ const markup: MarkupPreprocessor = async ({ content, filename }) => {
6164
let { mode, hashSeeder } = pluginOptions;
6265

6366
if (pluginOptions.parseStyleTag && hasModuleAttribute(ast)) {
64-
const moduleAttribute = ast.css.attributes.find((item) => item.name === 'module');
67+
const moduleAttribute = ast.css?.attributes.find((item) => item.name === 'module');
6568
mode = moduleAttribute.value !== true ? moduleAttribute.value[0].data : mode;
6669
}
6770

0 commit comments

Comments
 (0)