File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable one-var */
2
2
/* eslint-disable @typescript-eslint/no-namespace */
3
+ import { createRequire } from 'module'
3
4
import { notNullish , partition } from '@antfu/utils'
4
5
import type { Program } from '@babel/types'
5
6
import type { ParserPlugin } from '@babel/parser'
@@ -82,6 +83,14 @@ const BUILD_IN_DIRECTIVES = new Set([
82
83
// 'ref',
83
84
] )
84
85
86
+ function getRequire ( ) {
87
+ return (
88
+ ( typeof require === 'function' )
89
+ ? require
90
+ : createRequire ( import . meta. url )
91
+ )
92
+ }
93
+
85
94
function getComponents ( node : TemplateChildNode ) : string [ ] {
86
95
const current
87
96
= node . type === NodeTypes . ELEMENT && node . tagType === ElementTypes . COMPONENT
@@ -367,8 +376,7 @@ export function parseSFC(
367
376
&& p . value . content === 'pug' ,
368
377
)
369
378
? baseParse (
370
- // eslint-disable-next-line @typescript-eslint/no-var-requires
371
- require ( 'pug' ) . compile (
379
+ getRequire ( ) ( 'pug' ) . compile (
372
380
templateNode . children . map ( x => x . loc . source ) . join ( '' ) ,
373
381
{
374
382
filename : id ,
You can’t perform that action at this time.
0 commit comments