mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 890913 - Parser.jsm: support SpreadExpression r=vporof
This commit is contained in:
parent
fe9ec4e232
commit
e6efccfea4
@ -337,6 +337,7 @@ skip-if = e10s && debug
|
||||
skip-if = e10s && debug
|
||||
[browser_dbg_parser-11.js]
|
||||
[browser_dbg_parser-function-defaults.js]
|
||||
[browser_dbg_parser-spread-expression.js]
|
||||
[browser_dbg_parser-template-strings.js]
|
||||
skip-if = e10s && debug
|
||||
[browser_dbg_pause-exceptions-01.js]
|
||||
|
@ -0,0 +1,32 @@
|
||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Test that spread expressions work both in arrays and function calls.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
function test() {
|
||||
let { Parser, SyntaxTreeVisitor } =
|
||||
Cu.import("resource://devtools/shared/Parser.jsm", {});
|
||||
|
||||
const SCRIPTS = ["[...a]", "foo(...a)"];
|
||||
|
||||
for (let script of SCRIPTS) {
|
||||
info(`Testing spread expression in '${script}'`);
|
||||
let ast = Parser.reflectionAPI.parse(script);
|
||||
let nodes = SyntaxTreeVisitor.filter(ast,
|
||||
e => e.type == "SpreadExpression");
|
||||
ok(nodes && nodes.length === 1, "Found the SpreadExpression node");
|
||||
|
||||
let expr = nodes[0].expression;
|
||||
ok(expr, "The SpreadExpression node has the sub-expression");
|
||||
is(expr.type, "Identifier", "The sub-expression is an Identifier");
|
||||
is(expr.name, "a", "The sub-expression identifier has a correct name");
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Console.jsm");
|
||||
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
|
||||
@ -1558,14 +1559,37 @@ var SyntaxTreeVisitor = {
|
||||
callbacks.onArrayExpression(node);
|
||||
}
|
||||
for (let element of node.elements) {
|
||||
// TODO: remove the typeof check when support for SpreadExpression is
|
||||
// added (bug 890913).
|
||||
if (element && typeof this[element.type] == "function") {
|
||||
if (element) {
|
||||
this[element.type](element, node, callbacks);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* A spread expression.
|
||||
*
|
||||
* interface SpreadExpression <: Expression {
|
||||
* type: "SpreadExpression";
|
||||
* expression: Expression;
|
||||
* }
|
||||
*/
|
||||
SpreadExpression: function(node, parent, callbacks) {
|
||||
node._parent = parent;
|
||||
|
||||
if (this.break) {
|
||||
return;
|
||||
}
|
||||
if (callbacks.onNode) {
|
||||
if (callbacks.onNode(node, parent) === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (callbacks.onSpreadExpression) {
|
||||
callbacks.onSpreadExpression(node);
|
||||
}
|
||||
this[node.expression.type](node.expression, node, callbacks);
|
||||
},
|
||||
|
||||
/**
|
||||
* An object expression. A literal property in an object expression can have
|
||||
* either a string or number as its value. Ordinary property initializers
|
||||
@ -1936,6 +1960,9 @@ var SyntaxTreeVisitor = {
|
||||
this[node.callee.type](node.callee, node, callbacks);
|
||||
for (let argument of node.arguments) {
|
||||
if (argument) {
|
||||
if (!this[argument.type]) {
|
||||
console.error("Unknown parser object:", argument.type);
|
||||
}
|
||||
this[argument.type](argument, node, callbacks);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user