File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -582,13 +582,24 @@ function genProps(props: any[]) {
582582 } , { } )
583583}
584584
585+ // 移除JavaScript/TypeScript代码中的注释
586+ export function removeComments ( code : string ) : string {
587+ // 移除单行注释
588+ code = code . replace ( / \/ \/ .* $ / gm, '' )
589+ // 移除多行注释
590+ code = code . replace ( / \/ \* [ \s \S ] * ?\* \/ / g, '' )
591+ return code
592+ }
593+
585594// read page config from a sfc file instead of the regular config file
586595function readSFCPageConfig ( configPath : string ) {
587596 if ( ! fs . existsSync ( configPath ) ) return { }
588597
589598 const sfcSource = fs . readFileSync ( configPath , 'utf8' )
599+ // 先移除注释,再应用正则表达式
600+ const codeWithoutComments = removeComments ( sfcSource )
590601 const dpcReg = / d e f i n e P a g e C o n f i g \( \{ [ \w \W ] + ?\} \) / g
591- const matches = sfcSource . match ( dpcReg )
602+ const matches = codeWithoutComments . match ( dpcReg )
592603
593604 let result : any = { }
594605
You can’t perform that action at this time.
0 commit comments