browser/devtools/debugger/test/browser_dbg_parser-09.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Test that inferring anonymous function information is done correctly
     6  * from arrow expressions.
     7  */
     9 function test() {
    10   let { Parser, ParserHelpers, SyntaxTreeVisitor } =
    11     Cu.import("resource:///modules/devtools/Parser.jsm", {});
    13   function verify(source, predicate, details) {
    14     let { name, chain } = details;
    15     let [[sline, scol], [eline, ecol]] = details.loc;
    16     let ast = Parser.reflectionAPI.parse(source);
    17     let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
    18     let info = ParserHelpers.inferFunctionExpressionInfo(node);
    20     is(info.name, name,
    21       "The function expression assignment property name is correct.");
    22     is(chain ? info.chain.toSource() : info.chain, chain ? chain.toSource() : chain,
    23       "The function expression assignment property chain is correct.");
    24     is(info.loc.start.toSource(), { line: sline, column: scol }.toSource(),
    25       "The start location was correct for the identifier in: '" + source + "'.");
    26     is(info.loc.end.toSource(), { line: eline, column: ecol }.toSource(),
    27       "The end location was correct for the identifier in: '" + source + "'.");
    28   }
    30   // VariableDeclarator
    32   verify("var foo=()=>{}", e => e.type == "ArrowExpression", {
    33     name: "foo",
    34     chain: null,
    35     loc: [[1, 4], [1, 7]]
    36   });
    37   verify("\nvar\nfoo\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression", {
    38     name: "foo",
    39     chain: null,
    40     loc: [[3, 0], [3, 3]]
    41   });
    43   // AssignmentExpression
    45   verify("foo=()=>{}", e => e.type == "ArrowExpression",
    46     { name: "foo", chain: [], loc: [[1, 0], [1, 3]] });
    48   verify("\nfoo\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression",
    49     { name: "foo", chain: [], loc: [[2, 0], [2, 3]] });
    51   verify("foo.bar=()=>{}", e => e.type == "ArrowExpression",
    52     { name: "bar", chain: ["foo"], loc: [[1, 0], [1, 7]] });
    54   verify("\nfoo.bar\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression",
    55     { name: "bar", chain: ["foo"], loc: [[2, 0], [2, 7]] });
    57   verify("this.foo=()=>{}", e => e.type == "ArrowExpression",
    58     { name: "foo", chain: ["this"], loc: [[1, 0], [1, 8]] });
    60   verify("\nthis.foo\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression",
    61     { name: "foo", chain: ["this"], loc: [[2, 0], [2, 8]] });
    63   verify("this.foo.bar=()=>{}", e => e.type == "ArrowExpression",
    64     { name: "bar", chain: ["this", "foo"], loc: [[1, 0], [1, 12]] });
    66   verify("\nthis.foo.bar\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression",
    67     { name: "bar", chain: ["this", "foo"], loc: [[2, 0], [2, 12]] });
    69   verify("foo.this.bar=()=>{}", e => e.type == "ArrowExpression",
    70     { name: "bar", chain: ["foo", "this"], loc: [[1, 0], [1, 12]] });
    72   verify("\nfoo.this.bar\n=\n(\n)\n=>\n{\n}\n", e => e.type == "ArrowExpression",
    73     { name: "bar", chain: ["foo", "this"], loc: [[2, 0], [2, 12]] });
    75   // ObjectExpression
    77   verify("({foo:()=>{}})", e => e.type == "ArrowExpression",
    78     { name: "foo", chain: [], loc: [[1, 2], [1, 5]] });
    80   verify("(\n{\nfoo\n:\n(\n)\n=>\n{\n}\n}\n)", e => e.type == "ArrowExpression",
    81     { name: "foo", chain: [], loc: [[3, 0], [3, 3]] });
    83   verify("({foo:{bar:()=>{}}})", e => e.type == "ArrowExpression",
    84     { name: "bar", chain: ["foo"], loc: [[1, 7], [1, 10]] });
    86   verify("(\n{\nfoo\n:\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n}\n)", e => e.type == "ArrowExpression",
    87     { name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
    89   // AssignmentExpression + ObjectExpression
    91   verify("foo={bar:()=>{}}", e => e.type == "ArrowExpression",
    92     { name: "bar", chain: ["foo"], loc: [[1, 5], [1, 8]] });
    94   verify("\nfoo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
    95     { name: "bar", chain: ["foo"], loc: [[5, 0], [5, 3]] });
    97   verify("foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
    98     { name: "baz", chain: ["foo", "bar"], loc: [[1, 10], [1, 13]] });
   100   verify("\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   101     { name: "baz", chain: ["foo", "bar"], loc: [[8, 0], [8, 3]] });
   103   verify("nested.foo={bar:()=>{}}", e => e.type == "ArrowExpression",
   104     { name: "bar", chain: ["nested", "foo"], loc: [[1, 12], [1, 15]] });
   106   verify("\nnested.foo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
   107     { name: "bar", chain: ["nested", "foo"], loc: [[5, 0], [5, 3]] });
   109   verify("nested.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
   110     { name: "baz", chain: ["nested", "foo", "bar"], loc: [[1, 17], [1, 20]] });
   112   verify("\nnested.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   113     { name: "baz", chain: ["nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
   115   verify("this.foo={bar:()=>{}}", e => e.type == "ArrowExpression",
   116     { name: "bar", chain: ["this", "foo"], loc: [[1, 10], [1, 13]] });
   118   verify("\nthis.foo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
   119     { name: "bar", chain: ["this", "foo"], loc: [[5, 0], [5, 3]] });
   121   verify("this.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
   122     { name: "baz", chain: ["this", "foo", "bar"], loc: [[1, 15], [1, 18]] });
   124   verify("\nthis.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   125     { name: "baz", chain: ["this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
   127   verify("this.nested.foo={bar:()=>{}}", e => e.type == "ArrowExpression",
   128     { name: "bar", chain: ["this", "nested", "foo"], loc: [[1, 17], [1, 20]] });
   130   verify("\nthis.nested.foo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
   131     { name: "bar", chain: ["this", "nested", "foo"], loc: [[5, 0], [5, 3]] });
   133   verify("this.nested.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
   134     { name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[1, 22], [1, 25]] });
   136   verify("\nthis.nested.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   137     { name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
   139   verify("nested.this.foo={bar:()=>{}}", e => e.type == "ArrowExpression",
   140     { name: "bar", chain: ["nested", "this", "foo"], loc: [[1, 17], [1, 20]] });
   142   verify("\nnested.this.foo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
   143     { name: "bar", chain: ["nested", "this", "foo"], loc: [[5, 0], [5, 3]] });
   145   verify("nested.this.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
   146     { name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[1, 22], [1, 25]] });
   148   verify("\nnested.this.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   149     { name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
   151   // VariableDeclarator + AssignmentExpression + ObjectExpression
   153   verify("let foo={bar:()=>{}}", e => e.type == "ArrowExpression",
   154     { name: "bar", chain: ["foo"], loc: [[1, 9], [1, 12]] });
   156   verify("\nlet\nfoo\n=\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n", e => e.type == "ArrowExpression",
   157     { name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
   159   verify("let foo={bar:{baz:()=>{}}}", e => e.type == "ArrowExpression",
   160     { name: "baz", chain: ["foo", "bar"], loc: [[1, 14], [1, 17]] });
   162   verify("\nlet\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n", e => e.type == "ArrowExpression",
   163     { name: "baz", chain: ["foo", "bar"], loc: [[9, 0], [9, 3]] });
   165   // New/CallExpression + AssignmentExpression + ObjectExpression
   167   verify("foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   168     { name: "bar", chain: [], loc: [[1, 5], [1, 8]] });
   170   verify("\nfoo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   171     { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
   173   verify("foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   174     { name: "baz", chain: ["bar"], loc: [[1, 10], [1, 13]] });
   176   verify("\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   177     { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
   179   verify("nested.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   180     { name: "bar", chain: [], loc: [[1, 12], [1, 15]] });
   182   verify("\nnested.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   183     { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
   185   verify("nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   186     { name: "baz", chain: ["bar"], loc: [[1, 17], [1, 20]] });
   188   verify("\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   189     { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
   191   verify("this.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   192     { name: "bar", chain: [], loc: [[1, 10], [1, 13]] });
   194   verify("\nthis.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   195     { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
   197   verify("this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   198     { name: "baz", chain: ["bar"], loc: [[1, 15], [1, 18]] });
   200   verify("\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   201     { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
   203   verify("this.nested.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   204     { name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
   206   verify("\nthis.nested.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   207     { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
   209   verify("this.nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   210     { name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
   212   verify("\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   213     { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
   215   verify("nested.this.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   216     { name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
   218   verify("\nnested.this.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   219     { name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
   221   verify("nested.this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   222     { name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
   224   verify("\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   225     { name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
   227   // New/CallExpression + VariableDeclarator + AssignmentExpression + ObjectExpression
   229   verify("let target=foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   230     { name: "bar", chain: ["target"], loc: [[1, 16], [1, 19]] });
   232   verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   233     { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
   235   verify("let target=foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   236     { name: "baz", chain: ["target", "bar"], loc: [[1, 21], [1, 24]] });
   238   verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   239     { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
   241   verify("let target=nested.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   242     { name: "bar", chain: ["target"], loc: [[1, 23], [1, 26]] });
   244   verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   245     { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
   247   verify("let target=nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   248     { name: "baz", chain: ["target", "bar"], loc: [[1, 28], [1, 31]] });
   250   verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   251     { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
   253   verify("let target=this.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   254     { name: "bar", chain: ["target"], loc: [[1, 21], [1, 24]] });
   256   verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   257     { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
   259   verify("let target=this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   260     { name: "baz", chain: ["target", "bar"], loc: [[1, 26], [1, 29]] });
   262   verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   263     { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
   265   verify("let target=this.nested.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   266     { name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
   268   verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   269     { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
   271   verify("let target=this.nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   272     { name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
   274   verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   275     { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
   277   verify("let target=nested.this.foo({bar:()=>{}})", e => e.type == "ArrowExpression",
   278     { name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
   280   verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n(\n)\n=>\n{\n}\n}\n)\n", e => e.type == "ArrowExpression",
   281     { name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
   283   verify("let target=nested.this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowExpression",
   284     { name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
   286   verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)\n=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowExpression",
   287     { name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
   289   finish();
   290 }

mercurial