From f2eb092f8e7601273992f3d482e7ef393e05067f Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 4 Jul 2019 06:26:09 -0400 Subject: [PATCH] docs(@babel/parser): Document allowUndeclaredExports option. (#2047) * docs(@babel/parser): Document allowUndeclaredExports option. Documents the changes from https://github.com/babel/babel/pull/9864 implemented by @nicolo-ribaudo. * Clarify when allowUndeclaredExports is intended to be used. --- docs/parser.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/parser.md b/docs/parser.md index 5731716525..ea5cd66647 100644 --- a/docs/parser.md +++ b/docs/parser.md @@ -46,6 +46,14 @@ mind. When in doubt, use `.parse()`. outside of class and object methods. Set this to `true` to accept such code. +- **allowUndeclaredExports**: By default, exporting an identifier that was + not declared in the current module scope will raise an error. While this + behavior is required by the ECMAScript modules specification, Babel's + parser cannot anticipate transforms later in the plugin pipeline that + might insert the appropriate declarations, so it is sometimes important + to set this option to `true` to prevent the parser from prematurely + complaining about undeclared exports that will be added later. + - **sourceType**: Indicate the mode the code should be parsed in. Can be one of `"script"`, `"module"`, or `"unambiguous"`. Defaults to `"script"`. `"unambiguous"` will make @babel/parser attempt to _guess_, based on the presence of ES6 `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`.