browser_dbg_parser-computed-name.js 1.0 KB

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 template strings are correctly processed.
  6. */
  7. "use strict";
  8. function test() {
  9. let { Parser, SyntaxTreeVisitor } =
  10. Cu.import("resource://devtools/shared/Parser.jsm", {});
  11. let ast = Parser.reflectionAPI.parse("({ [i]: 1 })");
  12. let nodes = SyntaxTreeVisitor.filter(ast, e => e.type == "ComputedName");
  13. ok(nodes && nodes.length === 1, "Found the ComputedName node");
  14. let name = nodes[0].name;
  15. ok(name, "The ComputedName node has a name property");
  16. is(name.type, "Identifier", "The name has a correct type");
  17. is(name.name, "i", "The name has a correct name");
  18. let identNodes = SyntaxTreeVisitor.filter(ast, e => e.type == "Identifier");
  19. ok(identNodes && identNodes.length === 1, "Found the Identifier node");
  20. is(identNodes[0].type, "Identifier", "The identifier has a correct type");
  21. is(identNodes[0].name, "i", "The identifier has a correct name");
  22. finish();
  23. }