Debian Codegraph @

js/src/tests/non262/reflect-parse/location.js

raw
1 // |reftest| skip-if(!xulRuntime.shell)
2 function test() {
3
4 // Source location information
5 var withoutFileOrLine = Reflect.parse("42");
6 var withFile = Reflect.parse("42", {source:"foo.js"});
7 var withFileAndLine = Reflect.parse("42", {source:"foo.js", line:111});
8
9 Pattern({ source: null, start: { line: 1, column: 1 }, end: { line: 1, column: 3 } }).match(withoutFileOrLine.loc);
10 Pattern({ source: "foo.js", start: { line: 1, column: 1 }, end: { line: 1, column: 3 } }).match(withFile.loc);
11 Pattern({ source: "foo.js", start: { line: 111, column: 1 }, end: { line: 111, column: 3 } }).match(withFileAndLine.loc);
12
13 var withoutFileOrLine2 = Reflect.parse("foo +\nbar");
14 var withFile2 = Reflect.parse("foo +\nbar", {source:"foo.js"});
15 var withFileAndLine2 = Reflect.parse("foo +\nbar", {source:"foo.js", line:111});
16
17 Pattern({ source: null, start: { line: 1, column: 1 }, end: { line: 2, column: 4 } }).match(withoutFileOrLine2.loc);
18 Pattern({ source: "foo.js", start: { line: 1, column: 1 }, end: { line: 2, column: 4 } }).match(withFile2.loc);
19 Pattern({ source: "foo.js", start: { line: 111, column: 1 }, end: { line: 112, column: 4 } }).match(withFileAndLine2.loc);
20
21 var nested = Reflect.parse("(-b + sqrt(sqr(b) - 4 * a * c)) / (2 * a)", {source:"quad.js"});
22 var fourAC = nested.body[0].expression.left.right.arguments[0].right;
23
24 Pattern({ source: "quad.js", start: { line: 1, column: 21 }, end: { line: 1, column: 30 } }).match(fourAC.loc);
25
26 // No source location
27
28 assertEq("loc" in Reflect.parse("42", {loc:false}), false);
29 program([exprStmt(lit(42))]).assert(Reflect.parse("42", {loc:false}));
30
31 }
32
33 runtest(test);