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

Breaking: remove experimentalObjectRestSpread option #374

Merged
merged 2 commits into from
Mar 30, 2018
Merged
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ var ast = espree.parse(code, {
globalReturn: false,

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

// allow experimental object rest/spread
experimentalObjectRestSpread: false
impliedStrict: false
}
});
```
Expand Down
113 changes: 0 additions & 113 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ function normalizeEcmaVersion(ecmaVersion) {
* @private
*/
function isValidNode(node) {
var ecma = extra.ecmaFeatures;

switch (node.type) {
case "ExperimentalSpreadProperty":
case "ExperimentalRestProperty":
return ecma.experimentalObjectRestSpread;

case "ImportDeclaration":
case "ExportNamedDeclaration":
case "ExportDefaultDeclaration":
Expand Down Expand Up @@ -289,24 +283,6 @@ acorn.plugins.espree = function(instance) {
};
});

// needed for experimental object rest/spread
instance.extend("checkLVal", function(checkLVal) {

return /** @this acorn.Parser */ function(expr, isBinding, checkClashes) {

if (extra.ecmaFeatures.experimentalObjectRestSpread && expr.type === "ObjectPattern") {
for (var i = 0; i < expr.properties.length; i++) {
if (expr.properties[i].type.indexOf("Experimental") === -1) {
this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
}
}
return undefined;
}

return checkLVal.call(this, expr, isBinding, checkClashes);
};
});

instance.extend("parseTopLevel", function(parseTopLevel) {
return /** @this acorn.Parser */ function(node) {
if (extra.ecmaFeatures.impliedStrict && this.options.ecmaVersion >= 5) {
Expand All @@ -316,95 +292,6 @@ acorn.plugins.espree = function(instance) {
};
});

instance.extend("toAssignable", function(toAssignable) {

return /** @this acorn.Parser */ function(node, isBinding, refDestructuringErrors) {

if (extra.ecmaFeatures.experimentalObjectRestSpread &&
node.type === "ObjectExpression"
) {
node.type = "ObjectPattern";

for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];

if (prop.type === "ExperimentalSpreadProperty") {
prop.type = "ExperimentalRestProperty";
} else if (prop.kind !== "init") {
this.raise(prop.key.start, "Object pattern can't contain getter or setter");
} else {
this.toAssignable(prop.value, isBinding);
}
}

return node;
} else {
return toAssignable.call(this, node, isBinding, refDestructuringErrors);
}
};

});

/**
* Method to parse an object rest or object spread.
* @returns {ASTNode} The node representing object rest or object spread.
* @this acorn.Parser
*/
instance.parseObjectRest = function() {
var node = this.startNode();
this.next();
node.argument = this.parseIdent();

if (this.type === tt.comma) {
this.raise(this.start, "Unexpected trailing comma after rest property");
}

return this.finishNode(node, "ExperimentalRestProperty");
};

instance.extend("parseProperty", function(parseProperty) {
/**
* Override `parseProperty` method to parse rest/spread properties.
* @param {boolean} isPattern True if the object is a destructuring pattern.
* @param {Object} refDestructuringErrors ?
* @returns {ASTNode} The node representing a rest/spread property.
* @this acorn.Parser
*/
return function(isPattern, refDestructuringErrors) {
if (extra.ecmaFeatures.experimentalObjectRestSpread && this.type === tt.ellipsis) {
var prop;

if (isPattern) {
prop = this.parseObjectRest();
} else {
prop = this.parseSpread();
prop.type = "ExperimentalSpreadProperty";
}

return prop;
}

return parseProperty.call(this, isPattern, refDestructuringErrors);
};
});

instance.extend("checkPropClash", function(checkPropClash) {
/**
* Override `checkPropClash` method to avoid clash on rest/spread properties.
* @param {ASTNode} prop A property node to check.
* @param {Object} propHash Names map.
* @param {Object} refDestructuringErrors Destructuring error information.
* @returns {void}
* @this acorn.Parser
*/
return function(prop, propHash, refDestructuringErrors) {
if (prop.type === "ExperimentalRestProperty" || prop.type === "ExperimentalSpreadProperty") {
return;
}
checkPropClash.call(this, prop, propHash, refDestructuringErrors);
};
});

/**
* Overwrites the default raise method to throw Esprima-style errors.
* @param {int} pos The position of the error.
Expand Down
2 changes: 0 additions & 2 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ module.exports = {
DoWhileStatement: "DoWhileStatement",
DebuggerStatement: "DebuggerStatement",
EmptyStatement: "EmptyStatement",
ExperimentalRestProperty: "ExperimentalRestProperty",
ExperimentalSpreadProperty: "ExperimentalSpreadProperty",
ExpressionStatement: "ExpressionStatement",
ForStatement: "ForStatement",
ForInStatement: "ForInStatement",
Expand Down
5 changes: 1 addition & 4 deletions lib/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ module.exports = {
globalReturn: false,

// allow implied strict mode
impliedStrict: false,

// allow experimental object rest/spread
experimentalObjectRestSpread: false
impliedStrict: false
};
6 changes: 1 addition & 5 deletions lib/visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,5 @@ module.exports = {
JSXOpeningElement: ["name", "attributes"],
JSXAttribute: ["name", "value"],
JSXText: null,
JSXSpreadAttribute: ["argument"],

// Experimental features
ExperimentalRestProperty: ["argument"],
ExperimentalSpreadProperty: ["argument"]
JSXSpreadAttribute: ["argument"]
};
Loading