| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,21 @@ | |||
| 1 | + ## 8.16.0 (2026-02-19) | ||
| 2 | + | ||
| 3 | + ### New features | ||
| 4 | + | ||
| 5 | + The `sourceType` option can now be set to `"commonjs"` to have the parser treat the top level scope as a function scope. | ||
| 6 | + | ||
| 7 | + Add support for Unicode 17. | ||
| 8 | + | ||
| 9 | + ### Bug fixes | ||
| 10 | + | ||
| 11 | + Don't recognize `await using` as contextual keywords when followed directly by a backslash. | ||
| 12 | + | ||
| 13 | + Fix an issue where the parser would allow `return` statements in `static` blocks when `allowReturnOutsideFunction` was enabled. | ||
| 14 | + | ||
| 15 | + Properly reject `using` declarations that appear directly in `switch` or `for` head scopes. | ||
| 16 | + | ||
| 17 | + Fix some corner case issues in the recognition of `using` syntax. | ||
| 18 | + | ||
| 1 | 19 | ## 8.15.0 (2025-06-08) | |
| 2 | 20 | ||
| 3 | 21 | ### New features | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,24 @@ git clone https://github.com/acornjs/acorn.git | |||
| 26 | 26 | cd acorn | |
| 27 | 27 | npm install | |
| 28 | 28 | ``` | |
| 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. | ||
| 29 | 47 | ||
| 30 | 48 | ## Interface | |
| 31 | 49 | ||
@@ -36,8 +54,8 @@ syntax tree object as specified by the [ESTree | |||
| 36 | 54 | spec](https://github.com/estree/estree). | |
| 37 | 55 | ||
| 38 | 56 | ```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})) | ||
| 41 | 59 | ``` | |
| 42 | 60 | ||
| 43 | 61 | When encountering a syntax error, the parser will raise a | |
@@ -61,11 +79,12 @@ required): | |||
| 61 | 79 | implemented through plugins. | |
| 62 | 80 | ||
| 63 | 81 | - **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 | ||
| 65 | 83 | and parsing of `import` and `export` declarations. | |
| 66 | 84 | ||
| 67 | 85 | **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. | ||
| 69 | 88 | ||
| 70 | 89 | - **onInsertedSemicolon**: If given a callback, that callback will be | |
| 71 | 90 | called whenever a missing semicolon is inserted by the parser. The | |
@@ -97,7 +116,7 @@ required): | |||
| 97 | 116 | for `ecmaVersion` 2022 and later, `false` for lower versions. | |
| 98 | 117 | Setting this option to `true` allows to have top-level `await` | |
| 99 | 118 | 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"`. | ||
| 101 | 120 | ||
| 102 | 121 | - **allowSuperOutsideMethod**: By default, `super` outside a method | |
| 103 | 122 | raises an error. Set this to `true` to accept such code. | |
@@ -217,7 +236,7 @@ for (let token of acorn.tokenizer(str)) { | |||
| 217 | 236 | } | |
| 218 | 237 | ||
| 219 | 238 | // transform code to array of tokens: | |
| 220 | - var tokens = [...acorn.tokenizer(str)]; | ||
| 239 | + var tokens = [...acorn.tokenizer(str)] | ||
| 221 | 240 | ``` | |
| 222 | 241 | ||
| 223 | 242 | **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, | |||
| 238 | 257 | you can use its static `extend` method. | |
| 239 | 258 | ||
| 240 | 259 | ```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}) | ||
| 245 | 264 | ``` | |
| 246 | 265 | ||
| 247 | 266 | The `extend` method takes any number of plugin values, and returns a | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -614,10 +614,10 @@ export interface Options { | |||
| 614 | 614 | ||
| 615 | 615 | /** | |
| 616 | 616 | * `sourceType` indicates the mode the code should be parsed in. | |
| 617 | - * Can be either `"script"` or `"module"`. This influences global | ||
| 617 | + * Can be either `"script"`, `"module"` or `"commonjs"`. This influences global | ||
| 618 | 618 | * strict mode and parsing of `import` and `export` declarations. | |
| 619 | 619 | */ | |
| 620 | - sourceType?: "script" | "module" | ||
| 620 | + sourceType?: "script" | "module" | "commonjs" | ||
| 621 | 621 | ||
| 622 | 622 | /** | |
| 623 | 623 | * a callback that will be called when a semicolon is automatically inserted. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -614,10 +614,10 @@ export interface Options { | |||
| 614 | 614 | ||
| 615 | 615 | /** | |
| 616 | 616 | * `sourceType` indicates the mode the code should be parsed in. | |
| 617 | - * Can be either `"script"` or `"module"`. This influences global | ||
| 617 | + * Can be either `"script"`, `"module"` or `"commonjs"`. This influences global | ||
| 618 | 618 | * strict mode and parsing of `import` and `export` declarations. | |
| 619 | 619 | */ | |
| 620 | - sourceType?: "script" | "module" | ||
| 620 | + sourceType?: "script" | "module" | "commonjs" | ||
| 621 | 621 | ||
| 622 | 622 | /** | |
| 623 | 623 | * a callback that will be called when a semicolon is automatically inserted. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ | |||
| 16 | 16 | ], | |
| 17 | 17 | "./package.json": "./package.json" | |
| 18 | 18 | }, | |
| 19 | - "version": "8.15.0", | ||
| 19 | + "version": "8.16.0", | ||
| 20 | 20 | "engines": { | |
| 21 | 21 | "node": ">=0.4.0" | |
| 22 | 22 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,5 +2,5 @@ | |||
| 2 | 2 | // Refer to tools/dep_updaters/update-acorn.sh | |
| 3 | 3 | #ifndef SRC_ACORN_VERSION_H_ | |
| 4 | 4 | #define SRC_ACORN_VERSION_H_ | |
| 5 | - #define ACORN_VERSION "8.15.0" | ||
| 5 | + #define ACORN_VERSION "8.16.0" | ||
| 6 | 6 | #endif // SRC_ACORN_VERSION_H_ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments