Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update acorn and increase default ecmaVersion #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ build/Release
node_modules
package-lock.json

lib/*
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't seem necessary to ignore this directory, since it's not used anymore. It was only used for the plugins.

/index.js
/walk.js
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# acorn-node

[Acorn](https://github.com/acornjs/acorn) preloaded with plugins for syntax parity with recent Node versions.

It also includes versions of the plugins compiled with [Babel](https://github.com/babel/babel), so they can be run on old Node versions (0.6 and up).
[Acorn](https://github.com/acornjs/acorn) with defaults for syntax parity with recent Node versions.

[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
Expand All @@ -27,14 +25,9 @@ npm install acorn-node
var acorn = require('acorn-node')
```

The API is the same as [acorn](https://github.com/acornjs/acorn), but the following syntax features are enabled by default:

- Public and private class instance fields
- Public and private class static fields

And the following options have different defaults from acorn, to match Node modules:
The API is the same as [acorn](https://github.com/acornjs/acorn) but with different defaults, to match Node modules:

- `ecmaVersion: 2021`
- `ecmaVersion: 2022`
- `allowHashBang: true`
- `allowReturnOutsideFunction: true`

Expand All @@ -48,9 +41,3 @@ See the [acorn documentation](https://github.com/acornjs/acorn#distwalkjs) for d
## License

The files in the repo root and the ./test folder are licensed as [Apache-2.0](LICENSE.md).

The files in lib/ are generated from other packages:

- lib/class-fields: [acorn-class-fields](https://github.com/acornjs/acorn-class-fields), MIT
- lib/class-private-elements: [acorn-class-private-elements](https://github.com/acornjs/acorn-class-private-elements), MIT
- lib/static-class-features: [acorn-static-class-features](https://github.com/acornjs/acorn-static-class-features), MIT
21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"name": "acorn-node",
"description": "the acorn javascript parser, preloaded with plugins for syntax parity with recent node versions",
"description": "the acorn javascript parser, with defaults for syntax parity with recent node versions",
"version": "2.0.1",
"author": "Renée Kooi <renee@kooi.me>",
"bugs": {
"url": "https://github.com/browserify/acorn-node/issues"
},
"dependencies": {
"acorn": "^7.4.0",
"acorn-walk": "^7.2.0",
"acorn": "^8.5.0",
"acorn-walk": "^8.2.0",
"setprototypeof": "^1.2.0",
"xtend": "^4.0.2"
},
"devDependencies": {
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.1",
"@babel/preset-env": "^7.10.1",
"acorn-class-fields": "^0.3.4",
"acorn-private-class-elements": "^0.2.5",
"acorn-static-class-features": "^0.2.2",
"mkdirp": "^0.5.5",
"npm-run-all": "^4.1.5",
"standard": "^13.1.0",
"tape": "^4.13.3"
},
Expand All @@ -41,15 +37,6 @@
"lint": "standard",
"test": "node test",
"prepare": "npm run build && node test",
"build:acorn-class-fields": "babel node_modules/acorn-class-fields --out-dir lib/acorn-class-fields",
"build:acorn-static-class-features": "babel node_modules/acorn-static-class-features --out-dir lib/acorn-static-class-features",
"build:acorn-private-class-elements": "babel node_modules/acorn-private-class-elements --out-dir lib/acorn-private-class-elements",
"build:self": "babel src --out-dir .",
"build": "npm-run-all --parallel build:*"
},
"standard": {
"ignore": [
"lib/**/*"
]
"build": "babel src --out-dir ."
}
}
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
var acorn = require('acorn')

var CJSParser = acorn.Parser
// Required paths should be relative to the package root, because Babel outputs this file there.
.extend(require('./lib/acorn-class-fields'))
.extend(require('./lib/acorn-static-class-features'))
.extend(defaultOptionsPlugin)
var ESModulesParser = CJSParser

function mapOptions (opts) {
if (!opts) opts = {}
return {
ecmaVersion: 2021,
ecmaVersion: 2022,
allowHashBang: true,
allowReturnOutsideFunction: true,
...opts
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('parses object spread syntax', function (t) {

test('does not change main acorn module', function (t) {
t.throws(function () {
baseAcorn.parse('var a = 10n')
baseAcorn.parse('#!/usr/bin/env node\nconsole.log("ok")', { ecmaVersion: 2021 })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was updated to use a hashbang as an example of something the main acorn module would not support by default.

acorn requires that ecmaVersion is set (as of v8), so that had to be included.

})
t.end()
})
Expand Down