Commit 077d70f0 authored by nikolaos's avatar nikolaos Committed by Commit bot

Avoid multiple rewriting of object key expressions

NonPatternRewrite was called more than once for the same AST
in the case of (computed) key expressions present in object
literals.  As an example, in:

   var x = { [[...42]]: 17 };

the array containing the spread would be desugared first and
then the resulting do-expression would again be desugared.

This could be problematic if a computed key expression contains
large nested array/object literals.

R=rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1645023002

Cr-Commit-Position: refs/heads/master@{#33632}
parent a17bd3f3
......@@ -5561,6 +5561,12 @@ class NonPatternRewriter : public AstExpressionRewriter {
return false;
}
void VisitObjectLiteralProperty(ObjectLiteralProperty* property) override {
if (property == nullptr) return;
// Do not rewrite (computed) key expressions
AST_REWRITE_PROPERTY(Expression, property, value);
}
Parser* parser_;
};
......@@ -5581,8 +5587,7 @@ ObjectLiteralProperty* Parser::RewriteNonPatternObjectLiteralProperty(
ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
bool* ok) {
if (property != nullptr) {
Expression* key = RewriteNonPattern(property->key(), classifier, ok);
property->set_key(key);
// Do not rewrite (computed) key expressions
Expression* value = RewriteNonPattern(property->value(), classifier, ok);
property->set_value(value);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment