acorn5-object-spread
Advanced tools
Comparing version 3.0.0 to 3.1.0
# 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 @@ |
@@ -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 @@ |
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8170
103
50