Skip to content

Commit 9a2d5b1

Browse files
Christopher QuadfliegShinigami92
Christopher Quadflieg
authored andcommitted
wip: parse pug content
1 parent 6c9c1fa commit 9a2d5b1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/html/parser.ts

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import {
5151
getScriptParser,
5252
getParserLangFromSFC,
5353
} from "../common/parser-options"
54+
// import type { Token } from "pug-lexer";
55+
import lex from "pug-lexer";
5456

5557
const DIRECTIVE_NAME = /^(?:v-|[.:@#]).*[^.:@#]$/u
5658
const DT_DD = /^d[dt]$/u
@@ -300,6 +302,14 @@ export class Parser {
300302
}
301303
this.postProcessesForScript = []
302304

305+
// Process pug
306+
const match = /<template\s+lang="pug">(?<content>.*)<\/template>/isu.exec(this.text)
307+
if (match && match.groups && match.groups.content) {
308+
const pugTokens = lex(match.groups.content)
309+
console.log(pugTokens);
310+
311+
}
312+
303313
return doc
304314
}
305315

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export function parseForESLint(
106106
template != null && (templateLang === "html" || templateLang === "pug")
107107
? Object.assign(template, concreteInfo)
108108
: undefined
109+
// if (templateLang === "pug")
110+
// console.log(templateBody)
109111

110112
const scriptParser = getScriptParser(options.parser, () =>
111113
getParserLangFromSFC(rootAST),

test/fixtures/ast/pug/source.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<template lang="pug">
2-
Hello!
2+
p {{ greeting }} World!
33
</template>

0 commit comments

Comments
 (0)