Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acorn5-object-spread

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn5-object-spread - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

8

CHANGELOG.md
# acorn5-object-spread changelog
## 3.1.0
* Support complex rest properties like `{...{a = 5, ...as}}`
* Support rest properties in arrow function arguments
* Fail if rest property is not last property or has a trailing comma
* Detect duplicate exports with rest properties
* Don't complain about duplicate property names in patterns
## 3.0.0

@@ -4,0 +12,0 @@

47

inject.js

@@ -25,5 +25,11 @@ 'use strict';

if (this.type === tt.ellipsis) {
prop = this.parseSpread()
prop.type = isPattern ? "RestElement" : "SpreadElement"
prop = isPattern ? this.parseRestBinding() : this.parseSpread(refDestructuringErrors)
node.properties.push(prop)
if (this.type === tt.comma) {
if (isPattern) {
this.raise(this.start, "Comma is not permitted after the rest element")
} else if (refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
refDestructuringErrors.trailingComma = this.start
}
}
continue

@@ -49,3 +55,3 @@ }

this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors)
this.checkPropClash(prop, propHash)
if (!isPattern) this.checkPropClash(prop, propHash)
node.properties.push(this.finishNode(prop, "Property"))

@@ -62,5 +68,4 @@ }

} else if (expr.type === "Property") {
// AssignmentProperty has type == "Property"
return this.checkLVal(expr.value, bindingType, checkClashes)
} else if (expr.type === "RestProperty") {
return this.checkLVal(expr.argument, bindingType, checkClashes)
}

@@ -72,3 +77,33 @@ return origCheckLVal.apply(this, arguments)

pp.parseObj = parseObj;
pp.checkLVal = getCheckLVal(pp.checkLVal)
instance.extend("checkLVal", getCheckLVal)
instance.extend("toAssignable", nextMethod => function(node, isBinding) {
if (this.options.ecmaVersion >= 6 && node) {
if (node.type == "ObjectExpression") {
node.type = "ObjectPattern"
for (let prop of node.properties)
this.toAssignable(prop, isBinding)
return node
} else if (node.type === "Property") {
// AssignmentProperty has type == "Property"
if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter")
return this.toAssignable(node.value, isBinding)
} else if (node.type === "SpreadElement") {
node.type = "RestElement"
return this.toAssignable(node.argument, isBinding)
}
}
return nextMethod.apply(this, arguments)
})
instance.extend("checkPatternExport", nextMethod => function(exports, pat) {
if (pat.type == "ObjectPattern") {
for (let prop of pat.properties)
this.checkPatternExport(exports, prop)
return
} else if (pat.type === "Property") {
return this.checkPatternExport(exports, pat.value)
} else if (pat.type === "RestElement") {
return this.checkPatternExport(exports, pat.argument)
}
nextMethod.apply(this, arguments)
})
};

@@ -75,0 +110,0 @@

2

package.json

@@ -20,3 +20,3 @@ {

},
"version": "3.0.0"
"version": "3.1.0"
}

@@ -30,2 +30,17 @@ # Spread and rest properties support in acorn 5

```
## Differences to acorn-object-rest-spread
[acorn-object-rest-spread](https://github.com/victor-homyakov/acorn-object-rest-spread)
is another acorn plugin implementing the same spec. There are some differences, though:
* acorn-object-rest-spread overwrites acorn`s `parseObj` with a modified copy from acorn 4,
so that an acorn instance with that plugin cannot for example parse `({async, foo})`
* acorn-object-rest-spread emits `SpreadElement`s with a
[non-standard](https://github.com/estree/estree/blob/master/es2015.md#expressions)
`value` property
* acorn-object-rest-spread emits `SpreadElement`s in arrow function argument patterns
and nested object patterns were it should emit `RestElement`s
* acorn-object-rest-spread doesn't check for invalid trailing commas in rest properties
## License

@@ -32,0 +47,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc