browser_dbg_parser-spread-expression.js 988 B

1234567891011121314151617181920212223242526272829303132
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. /**
  5. * Test that spread expressions work both in arrays and function calls.
  6. */
  7. "use strict";
  8. function test() {
  9. let { Parser, SyntaxTreeVisitor } =
  10. Cu.import("resource://devtools/shared/Parser.jsm", {});
  11. const SCRIPTS = ["[...a]", "foo(...a)"];
  12. for (let script of SCRIPTS) {
  13. info(`Testing spread expression in '${script}'`);
  14. let ast = Parser.reflectionAPI.parse(script);
  15. let nodes = SyntaxTreeVisitor.filter(ast,
  16. e => e.type == "SpreadExpression");
  17. ok(nodes && nodes.length === 1, "Found the SpreadExpression node");
  18. let expr = nodes[0].expression;
  19. ok(expr, "The SpreadExpression node has the sub-expression");
  20. is(expr.type, "Identifier", "The sub-expression is an Identifier");
  21. is(expr.name, "a", "The sub-expression identifier has a correct name");
  22. }
  23. finish();
  24. }