Skip to content

Commit

Permalink
Update: Expose Acorn options
Browse files Browse the repository at this point in the history
- Allow setting options for underlying Acorn parser using new acornOptions property of espree options object.
- Resolve TODO for repeated key copy as all targed versions of Node support the spread operator.
  • Loading branch information
stonegray committed Dec 11, 2020
1 parent dd0958c commit b5e051f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ const options = {

// enable implied strict mode (if ecmaVersion >= 5)
impliedStrict: false
}
},

// specify options for the internal Acorn parser
acornOptions: {}
}
```

Expand Down
10 changes: 5 additions & 5 deletions lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ module.exports = () => Parser => {
// Initialize acorn parser.
super({

// TODO: use {...options} when spread is supported(Node.js >= 8.3.0).
ecmaVersion: options.ecmaVersion,
sourceType: options.sourceType,
ranges: options.ranges,
locations: options.locations,
...options,

// Pass options directly to the underlying parser to allow
// for use of advanced options such as allowHashBang.
...opts.acornOptions,

// Truthy value is true for backward compatibility.
allowReturnOutsideFunction: Boolean(ecmaFeatures.globalReturn),
Expand Down

0 comments on commit b5e051f

Please sign in to comment.