|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +const DependencyTemplates = require("../lib/DependencyTemplates"); |
3 | 4 | const { |
4 | 5 | addScopesToSourceMap, |
5 | 6 | collectSourceScopes, |
6 | | - encodeScopes |
| 7 | + enableImportBindingScopes, |
| 8 | + encodeScopes, |
| 9 | + isImportBindingScopesEnabled |
7 | 10 | } = require("../lib/util/sourceMapScopes"); |
8 | 11 |
|
9 | 12 | describe("sourceMapScopes", () => { |
@@ -44,6 +47,22 @@ describe("sourceMapScopes", () => { |
44 | 47 | expect(scopes[0].rangeEnds[0]).toEqual({ line: 1, column: 0 }); |
45 | 48 | }); |
46 | 49 |
|
| 50 | + it("opens no run for a source-less segment before any mapped one", () => { |
| 51 | + /* cspell:disable-next-line */ |
| 52 | + const scopes = collectSourceScopes("A;AAAA", 1); |
| 53 | + |
| 54 | + expect(scopes).toHaveLength(1); |
| 55 | + expect(scopes[0].rangeStarts).toEqual([{ line: 1, column: 0 }]); |
| 56 | + }); |
| 57 | + |
| 58 | + it("survives source-less segments in a row", () => { |
| 59 | + /* cspell:disable-next-line */ |
| 60 | + const scopes = collectSourceScopes("AAAA;A;A", 1); |
| 61 | + |
| 62 | + expect(scopes).toHaveLength(1); |
| 63 | + expect(scopes[0].rangeEnds).toEqual([{ line: 1, column: 0 }]); |
| 64 | + }); |
| 65 | + |
47 | 66 | it("stops at a digit outside the alphabet rather than misplacing the rest", () => { |
48 | 67 | expect(collectSourceScopes("AAAA;!!!", 1)).toHaveLength(1); |
49 | 68 | }); |
@@ -122,6 +141,22 @@ describe("sourceMapScopes", () => { |
122 | 141 | }); |
123 | 142 | }); |
124 | 143 |
|
| 144 | + describe("enableImportBindingScopes", () => { |
| 145 | + it("moves the code generation cache key, so a build without scopes is not reused", () => { |
| 146 | + const dependencyTemplates = new DependencyTemplates(); |
| 147 | + const before = dependencyTemplates.getHash(); |
| 148 | + const compilation = |
| 149 | + /** @type {import("../lib/Compilation")} */ |
| 150 | + (/** @type {unknown} */ ({ moduleGraph: {}, dependencyTemplates })); |
| 151 | + |
| 152 | + expect(isImportBindingScopesEnabled(compilation.moduleGraph)).toBe(false); |
| 153 | + enableImportBindingScopes(compilation); |
| 154 | + |
| 155 | + expect(isImportBindingScopesEnabled(compilation.moduleGraph)).toBe(true); |
| 156 | + expect(dependencyTemplates.getHash()).not.toBe(before); |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
125 | 160 | describe("addScopesToSourceMap", () => { |
126 | 161 | /** |
127 | 162 | * @returns {import("../lib/util/sourceMapScopes").ScopedSourceMap} a two-source map |
|
0 commit comments