mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-08 02:52:49 +00:00
20 lines
453 B
TypeScript
20 lines
453 B
TypeScript
import { buildParserFile } from "@lezer/generator";
|
|
import type { Plugin, Rollup } from "vite";
|
|
|
|
const fileRegex = /\.(grammar)$/;
|
|
|
|
export function lezerGrammarPlugin() {
|
|
return {
|
|
name: "lezer-grammar",
|
|
transform(code, id) {
|
|
if (fileRegex.test(id)) {
|
|
return {
|
|
code: buildParserFile(code).parser,
|
|
map: null,
|
|
} satisfies Rollup.TransformResult;
|
|
}
|
|
return null;
|
|
},
|
|
} satisfies Plugin;
|
|
}
|