From 1c0e0d40ca6f6e52d860e3c1e646687cf60dae23 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Sun, 25 Feb 2024 10:53:59 -0700 Subject: [PATCH 1/3] Throw errors when imports are used in unsupported formats. Fixes #490 --- docs/documentation.html | 12 ++++++-- docs/js/benchmark-bundle.min.js | 2 +- docs/js/test-bundle.min.js | 2 +- docs/vendor/peggy/peggy.min.js | 2 +- lib/compiler/passes/generate-js.js | 30 +++++++++++++------ test/cli/run.spec.ts | 47 ++++++++++++++++++++++++++++-- 6 files changed, 79 insertions(+), 16 deletions(-) diff --git a/docs/documentation.html b/docs/documentation.html index 5eddcdbf..eaa3affd 100644 --- a/docs/documentation.html +++ b/docs/documentation.html @@ -746,8 +746,16 @@

Importing External Rules

grammar, NOT the source. Grammars MUST be compiled by a version that supports imports in order to be imported. Only rules that are allowed start rules are valid. It can be useful to specify - --allowed-start-rules \* in library grammars. All of the - following are valid:

+ --allowed-start-rules \* in library grammars. Imports are + only valid in output formats "es" and "commonjs". If you + use imports, you should use { output: "source" }; the default + output of "parser" will call `eval` on the source which fails immediately + for some formats (e.g. "es") and will not find modules in the expected + places for others (e.g. "commonjs"). The + ["from-mem"](https://github.com/peggyjs/from-mem/) project is used by + the Peggy CLI to resolve these issues, but note well its relatively severe + limitations.

+

All of the following are valid: