build: remove main function from `.jison` files

When converting a `.jison` file into a CommonJS module,
jison by default adds a main() function that calls `require("fs");`

Even though the main function is never used in the browser,
because `fs` is a Node.JS only module, this causes some esbuild issues.

To disable this, we can just set an empty main to the jison generator.
This commit is contained in:
Alois Klink 2022-09-10 02:22:03 +01:00
parent 5148acb20f
commit 48a899f7a9
No known key found for this signature in database
GPG Key ID: 4482AA96E51ADF71
1 changed files with 3 additions and 1 deletions

View File

@ -61,7 +61,9 @@ const jisonPlugin = {
build.onLoad({ filter: /\.jison$/ }, async (args) => {
// Load the file from the file system
const source = await fs.promises.readFile(args.path, 'utf8');
const contents = new Generator(source, { 'token-stack': true }).generate();
const contents = new Generator(source, { 'token-stack': true }).generate({
moduleMain: '() => {}', // disable moduleMain (default one requires Node.JS modules)
});
return { contents, warnings: [] };
});
},