Registry / testing / acorn-object-rest-spread

acorn-object-rest-spread

JSON →
library1.1.0jsnpmunverified

Acorn plugin that adds support for the Object Rest/Spread Properties proposal (e.g., `let { x, y, ...z } = obj`) to Acorn 5. Version 1.1.0 is the latest and only stable release. It is a lightweight, single-purpose plugin that must be injected into an Acorn instance via `require('acorn-object-rest-spread/inject')`. Compared to other parsers like Babel, this plugin keeps Acorn minimal and fast. No updates since 2017; compatible with Acorn 5.x only.

npm install acorn-object-rest-spread
INSTALL
IMPORT
SIG · ACORN-OBJECT-REST-
A
acorn-object-rest-spread
testingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

acorn (pre-injected)
var acorn = require('acorn-object-rest-spread')
var acorn = require('acorn')
The default export is an Acorn instance with the plugin already injected.
inject function
var inject = require('acorn-object-rest-spread/inject')
var inject = require('acorn-object-rest-spread').inject
The inject function is a separate file; it must be required from '/inject'.
parse call with plugin
acorn.parse(code, { plugins: { objectRestSpread: true } })
acorn.parse(code, { objectRestSpread: true })
The plugin option must be nested under `plugins`; using it at the top level won't enable the plugin.

Parses a string with object rest/spread properties and logs the AST.

var acorn = require('acorn-object-rest-spread'); var ast = acorn.parse('let { x, y, ...rest } = obj;', { ecmaVersion: 2018, plugins: { objectRestSpread: true } }); console.log(JSON.stringify(ast, null, 2));
Debug
Known issues
gotchaOnly compatible with Acorn 5.x; will fail with Acorn 6+.
fix
Downgrade to Acorn 5 or switch to a newer parser.
affects: >=1.0.0
gotchaPlugin must be enabled via `plugins: {objectRestSpread: true}` in parse options.
fix
Add the plugin option in the parse call.
affects: >=1.0.0
gotchaCannot inject the same plugin multiple times; will throw an error.
fix
Inject plugin only once.
affects: >=1.0.0
deprecatedPlugin is unmaintained; use acorn@6+ built-in support for rest/spread.
fix
Upgrade to Acorn 6 or later and remove the plugin.
affects: >=1.0.0
Errors
Common errors & fixes
Error: acorn-object-rest-spread/acorn is not a function
Using `require('acorn-object-rest-spread')()` incorrectly; the export is already an Acorn instance.
fix
var acorn = require('acorn-object-rest-spread'); acorn.parse(...);
TypeError: Cannot read property 'objectRestSpread' of undefined
`plugins` option is missing or not an object.
fix
Include `plugins: { objectRestSpread: true }` in parse options.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
acornrequiredpeer dependency: requires Acorn 5.x to be installed
Agent activity
46 hits · last 30 days
node
36
Amazon
1
OpenAI (training)
1
Resources
acorn-object-rest-spread — npm install acorn-object-rest-spread · libregistry