deps: update acorn to 8.16.0 · nodejs/node@f53a32a
@@ -26,6 +26,24 @@ git clone https://github.com/acornjs/acorn.git
2626cd acorn
2727npm install
2828```
29+## Importing acorn
30+31+ESM as well as CommonJS is supported for all 3: `acorn`, `acorn-walk` and `acorn-loose`.
32+33+ESM example for `acorn`:
34+35+```js
36+import * as acorn from "acorn"
37+```
38+39+CommonJS example for `acorn`:
40+41+```js
42+let acorn = require("acorn")
43+```
44+45+ESM is preferred, as it allows better editor auto-completions by offering TypeScript support.
46+For this reason, following examples will use ESM imports.
29473048## Interface
3149@@ -36,8 +54,8 @@ syntax tree object as specified by the [ESTree
3654spec](https://github.com/estree/estree).
37553856```javascript
39-let acorn = require("acorn");
40-console.log(acorn.parse("1 + 1", {ecmaVersion: 2020}));
57+import * as acorn from "acorn"
58+console.log(acorn.parse("1 + 1", {ecmaVersion: 2020}))
4159```
42604361When encountering a syntax error, the parser will raise a
@@ -61,11 +79,12 @@ required):
6179 implemented through plugins.
62806381- **sourceType**: Indicate the mode the code should be parsed in. Can be
64- either `"script"` or `"module"`. This influences global strict mode
82+ either `"script"`, `"module"` or `"commonjs"`. This influences global strict mode
6583 and parsing of `import` and `export` declarations.
66846785**NOTE**: If set to `"module"`, then static `import` / `export` syntax
68- will be valid, even if `ecmaVersion` is less than 6.
86+ will be valid, even if `ecmaVersion` is less than 6. If set to `"commonjs"`,
87+ it is the same as `"script"` except that the top-level scope behaves like a function.
69887089- **onInsertedSemicolon**: If given a callback, that callback will be
7190 called whenever a missing semicolon is inserted by the parser. The
@@ -97,7 +116,7 @@ required):
97116 for `ecmaVersion` 2022 and later, `false` for lower versions.
98117 Setting this option to `true` allows to have top-level `await`
99118 expressions. They are still not allowed in non-`async` functions,
100- though.
119+ though. Setting this option to `true` is not allowed when `sourceType: "commonjs"`.
101120102121- **allowSuperOutsideMethod**: By default, `super` outside a method
103122 raises an error. Set this to `true` to accept such code.
@@ -217,7 +236,7 @@ for (let token of acorn.tokenizer(str)) {
217236}
218237219238// transform code to array of tokens:
220-var tokens = [...acorn.tokenizer(str)];
239+var tokens = [...acorn.tokenizer(str)]
221240```
222241223242**tokTypes** holds an object mapping names to the token type objects
@@ -238,10 +257,10 @@ on the extended version of the class. To extend a parser with plugins,
238257you can use its static `extend` method.
239258240259```javascript
241-var acorn = require("acorn");
242-var jsx = require("acorn-jsx");
243-var JSXParser = acorn.Parser.extend(jsx());
244-JSXParser.parse("foo(<bar/>)", {ecmaVersion: 2020});
260+var acorn = require("acorn")
261+var jsx = require("acorn-jsx")
262+var JSXParser = acorn.Parser.extend(jsx())
263+JSXParser.parse("foo(<bar/>)", {ecmaVersion: 2020})
245264```
246265247266The `extend` method takes any number of plugin values, and returns a