Skip to content

Commit

Permalink
Breaking: remove experimentalObjectRestSpread option
Browse files Browse the repository at this point in the history
Users who want to use object rest/spread should enable `ecmaVersion: 2018` instead. As discussed in eslint/eslint#9990, ESLint 5 will translate the `experimentalObjectRestSpread` option to `ecmaVersion: 2018` and emit a deprecation warning.
  • Loading branch information
not-an-aardvark committed Mar 29, 2018
1 parent 0df063f commit 513d93f
Show file tree
Hide file tree
Showing 29 changed files with 2 additions and 7,005 deletions.
113 changes: 0 additions & 113 deletions espree.js
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
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
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
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"]
};

0 comments on commit 513d93f

Please sign in to comment.