diff --git a/packages/peggy-loader/src/index.ts b/packages/peggy-loader/src/index.ts index 4d805d2be1..8941fe6bf6 100644 --- a/packages/peggy-loader/src/index.ts +++ b/packages/peggy-loader/src/index.ts @@ -1,33 +1,32 @@ -import type { - BuildOptionsBase, - OutputFormatAmdCommonjsEs, - OutputFormatBare, - OutputFormatGlobals, - OutputFormatUmd, - SourceOptionsBase, -} from 'peggy'; +import type { BuildOptionsBase, OutputFormatAmdCommonjsEs } from 'peggy'; import peggy from 'peggy'; import type { LoaderContext } from 'webpack'; -type Options = - | BuildOptionsBase & - ( - | Omit< - OutputFormatAmdCommonjsEs<'source'>, - keyof SourceOptionsBase<'source'> - > - | Omit, keyof SourceOptionsBase<'source'>> - | Omit, keyof SourceOptionsBase<'source'>> - | Omit, keyof SourceOptionsBase<'source'>> - ); +type Options = Partial>; function peggyLoader( this: LoaderContext, grammarContent: string ): string { + const dependenciesKeyValue = this.resourceQuery + ? [...new URLSearchParams(this.resourceQuery).entries()] + : []; + + const fromEntries = (entries: (readonly [string, string])[]) => { + const obj: Record = {}; + for (const [key, value] of entries) { + obj[key] = value; + } + return obj; + }; + + const { dependencies } = this.getOptions(); const options: Options = { format: 'commonjs', ...this.getOptions(), + ...(dependenciesKeyValue.length && { + dependencies: { ...fromEntries(dependenciesKeyValue), ...dependencies }, + }), }; return peggy.generate(grammarContent, { diff --git a/packages/peggy-loader/tsconfig.json b/packages/peggy-loader/tsconfig.json index 9d2804b026..cb8b1309f9 100644 --- a/packages/peggy-loader/tsconfig.json +++ b/packages/peggy-loader/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "module": "ESNext", "declaration": true, "declarationMap": true,