browser_locations.js (3563B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Covert getOriginalLocation and getGeneratedLocation functions. 7 8 add_task(async function testGetOriginalLocation() { 9 await fetchFixtureSourceMap("bundle"); 10 11 const generatedLocation = { 12 sourceId: "bundle.js", 13 line: 49, 14 }; 15 16 const originalLocation = 17 await gSourceMapLoader.getOriginalLocation(generatedLocation); 18 Assert.deepEqual( 19 originalLocation, 20 { 21 column: 0, 22 line: 3, 23 sourceId: "bundle.js/originalSource-fe2c41d3535b76c158e39ba4f3ff826a", 24 sourceUrl: "webpack:///entry.js", 25 }, 26 "Mapped a generated location" 27 ); 28 29 const originalLocation2 = 30 await gSourceMapLoader.getOriginalLocation(originalLocation); 31 Assert.deepEqual(originalLocation2, null, "No mapped location"); 32 33 gSourceMapLoader.clearSourceMaps(); 34 const originalLocation3 = 35 await gSourceMapLoader.getOriginalLocation(generatedLocation); 36 Assert.deepEqual( 37 originalLocation3, 38 null, 39 "after clearing the source maps, the same generated location no longer maps" 40 ); 41 }); 42 43 add_task(async function testGetGeneratedLocation() { 44 await fetchFixtureSourceMap("bundle"); 45 46 const originalLocation = { 47 column: 0, 48 line: 3, 49 sourceId: "bundle.js/originalSource-fe2c41d3535b76c158e39ba4f3ff826a", 50 }; 51 52 const source = { 53 url: "webpack:///entry.js", 54 id: "bundle.js/originalSource-fe2c41d3535b76c158e39ba4f3ff826a", 55 }; 56 57 const generatedLocation = await gSourceMapLoader.getGeneratedLocation( 58 originalLocation, 59 source 60 ); 61 Assert.deepEqual( 62 generatedLocation, 63 { 64 sourceId: "bundle.js", 65 line: 49, 66 column: 0, 67 }, 68 "Map an original location" 69 ); 70 71 { 72 gSourceMapLoader.clearSourceMaps(); 73 74 const secondGeneratedLocation = await gSourceMapLoader.getGeneratedLocation( 75 originalLocation, 76 source 77 ); 78 Assert.deepEqual( 79 secondGeneratedLocation, 80 null, 81 "after clearing source maps, the same location no longer maps to an original location" 82 ); 83 } 84 85 { 86 // we expect symmetric mappings, which means that if 87 // we map a generated location to an original location, 88 // and then map it back, we should get the original generated value. 89 // e.g. G[8, 0] -> O[5, 4] -> G[8, 0] 90 await fetchFixtureSourceMap("if.out"); 91 92 const genLoc1 = { 93 sourceId: "if.out.js", 94 column: 0, 95 line: 8, 96 }; 97 98 const ifSource = { 99 url: "if.js", 100 id: "if.out.js/originalSource-5ad3141023dae912c5f8833c7e03beeb", 101 }; 102 103 const oLoc = await gSourceMapLoader.getOriginalLocation(genLoc1); 104 const genLoc2 = await gSourceMapLoader.getGeneratedLocation(oLoc, ifSource); 105 106 Assert.deepEqual(genLoc2, genLoc1, "location mapping is symmetric"); 107 } 108 109 { 110 // we expect that an undefined column will be handled like a 111 // location w/ column 0. e.g. G[8, u] -> O[5, 4] -> G[8, 0] 112 await fetchFixtureSourceMap("if.out"); 113 114 const genLoc1 = { 115 sourceId: "if.out.js", 116 column: undefined, 117 line: 8, 118 }; 119 120 const ifSource = { 121 url: "if.js", 122 id: "if.out.js/originalSource-5ad3141023dae912c5f8833c7e03beeb", 123 }; 124 125 const oLoc = await gSourceMapLoader.getOriginalLocation(genLoc1); 126 const genLoc2 = await gSourceMapLoader.getGeneratedLocation(oLoc, ifSource); 127 128 Assert.deepEqual( 129 genLoc2, 130 { 131 sourceId: "if.out.js", 132 column: 0, 133 line: 8, 134 }, 135 "undefined column is handled like 0 column" 136 ); 137 } 138 });