browser_dbg_parser-function-defaults.js 998 B

12345678910111213141516171819202122232425262728293031
  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 function default arguments are correctly processed.
  6. */
  7. "use strict";
  8. function test() {
  9. let { Parser, ParserHelpers, SyntaxTreeVisitor } =
  10. Cu.import("resource://devtools/shared/Parser.jsm", {});
  11. function verify(source, predicate, string) {
  12. let ast = Parser.reflectionAPI.parse(source);
  13. let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
  14. let info = ParserHelpers.getIdentifierEvalString(node);
  15. is(info, string, "The identifier evaluation string is correct.");
  16. }
  17. // FunctionDeclaration
  18. verify("function foo(a, b='b') {}", e => e.type == "Literal", "\"b\"");
  19. // FunctionExpression
  20. verify("let foo=function(a, b='b') {}", e => e.type == "Literal", "\"b\"");
  21. // ArrowFunctionExpression
  22. verify("let foo=(a, b='b')=> {}", e => e.type == "Literal", "\"b\"");
  23. finish();
  24. }