@atlaspack/core 2.33.1 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/dist/AssetGraph.js +4 -72
- package/dist/BundleGraph.js +34 -0
- package/dist/PackagerRunner.js +13 -88
- package/dist/RequestTracker.js +17 -80
- package/dist/TargetDescriptor.schema.js +3 -0
- package/dist/UncommittedAsset.js +0 -5
- package/dist/applyRuntimes.js +2 -1
- package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
- package/dist/requests/AssetGraphRequest.js +6 -15
- package/dist/requests/AssetGraphRequestRust.js +119 -22
- package/dist/requests/AtlaspackBuildRequest.js +8 -2
- package/dist/requests/BundleGraphRequest.js +9 -15
- package/dist/requests/BundleGraphRequestRust.js +1 -2
- package/dist/requests/PackageRequest.js +1 -1
- package/dist/requests/TargetRequest.js +5 -0
- package/dist/requests/WriteBundleRequest.js +129 -12
- package/dist/requests/WriteBundlesRequest.js +15 -9
- package/dist/resolveOptions.js +2 -4
- package/lib/AssetGraph.js +3 -62
- package/lib/BundleGraph.js +38 -0
- package/lib/PackagerRunner.js +13 -77
- package/lib/RequestTracker.js +15 -69
- package/lib/TargetDescriptor.schema.js +3 -0
- package/lib/UncommittedAsset.js +0 -11
- package/lib/applyRuntimes.js +1 -1
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
- package/lib/requests/AssetGraphRequest.js +4 -18
- package/lib/requests/AssetGraphRequestRust.js +88 -23
- package/lib/requests/AtlaspackBuildRequest.js +8 -2
- package/lib/requests/BundleGraphRequest.js +12 -16
- package/lib/requests/BundleGraphRequestRust.js +2 -3
- package/lib/requests/PackageRequest.js +3 -1
- package/lib/requests/TargetRequest.js +5 -0
- package/lib/requests/WriteBundleRequest.js +131 -8
- package/lib/requests/WriteBundlesRequest.js +12 -5
- package/lib/resolveOptions.js +2 -4
- package/lib/types/AssetGraph.d.ts +2 -27
- package/lib/types/BundleGraph.d.ts +5 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
- package/lib/types/requests/BundleGraphRequest.d.ts +1 -1
- package/lib/types/requests/WriteBundleRequest.d.ts +20 -1
- package/lib/types/types.d.ts +1 -0
- package/package.json +15 -15
- package/src/AssetGraph.ts +4 -72
- package/src/BundleGraph.ts +39 -0
- package/src/PackagerRunner.ts +15 -101
- package/src/RequestTracker.ts +24 -110
- package/src/TargetDescriptor.schema.ts +3 -0
- package/src/UncommittedAsset.ts +1 -11
- package/src/applyRuntimes.ts +3 -1
- package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
- package/src/requests/AssetGraphRequest.ts +8 -20
- package/src/requests/AssetGraphRequestRust.ts +96 -23
- package/src/requests/AtlaspackBuildRequest.ts +16 -8
- package/src/requests/BundleGraphRequest.ts +12 -30
- package/src/requests/BundleGraphRequestRust.ts +1 -2
- package/src/requests/PackageRequest.ts +1 -1
- package/src/requests/TargetRequest.ts +5 -0
- package/src/requests/WriteBundleRequest.ts +177 -13
- package/src/requests/WriteBundlesRequest.ts +25 -13
- package/src/resolveOptions.ts +2 -4
- package/src/types.ts +1 -0
- package/test/AssetGraph.test.ts +0 -32
- package/test/RequestTracker.test.ts +0 -165
- package/test/TargetRequest.test.ts +25 -0
- package/test/requests/WriteBundleRequest.test.ts +239 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -122,6 +122,7 @@ describe('TargetResolver', () => {
|
|
|
122
122
|
{
|
|
123
123
|
name: 'customA',
|
|
124
124
|
publicUrl: '/',
|
|
125
|
+
inlineRequires: false,
|
|
125
126
|
distDir: normalizeSeparators(path.resolve('customA')),
|
|
126
127
|
env: createEnvironment({
|
|
127
128
|
context: 'browser',
|
|
@@ -142,6 +143,7 @@ describe('TargetResolver', () => {
|
|
|
142
143
|
{
|
|
143
144
|
name: 'customB',
|
|
144
145
|
publicUrl: '/',
|
|
146
|
+
inlineRequires: false,
|
|
145
147
|
distEntry: 'b.js',
|
|
146
148
|
distDir: normalizeSeparators(path.resolve('customB')),
|
|
147
149
|
env: createEnvironment({
|
|
@@ -175,6 +177,7 @@ describe('TargetResolver', () => {
|
|
|
175
177
|
distDir: 'fixtures/common-targets/dist/main',
|
|
176
178
|
distEntry: 'index.js',
|
|
177
179
|
publicUrl: '/',
|
|
180
|
+
inlineRequires: false,
|
|
178
181
|
env: createEnvironment({
|
|
179
182
|
context: 'node',
|
|
180
183
|
engines: {
|
|
@@ -209,6 +212,7 @@ describe('TargetResolver', () => {
|
|
|
209
212
|
distDir: 'fixtures/common-targets/dist/module',
|
|
210
213
|
distEntry: 'index.js',
|
|
211
214
|
publicUrl: '/',
|
|
215
|
+
inlineRequires: false,
|
|
212
216
|
env: createEnvironment({
|
|
213
217
|
context: 'browser',
|
|
214
218
|
engines: {
|
|
@@ -245,6 +249,7 @@ describe('TargetResolver', () => {
|
|
|
245
249
|
distDir: 'fixtures/common-targets/dist/browser',
|
|
246
250
|
distEntry: 'index.js',
|
|
247
251
|
publicUrl: '/assets',
|
|
252
|
+
inlineRequires: false,
|
|
248
253
|
env: createEnvironment({
|
|
249
254
|
context: 'browser',
|
|
250
255
|
engines: {
|
|
@@ -291,6 +296,7 @@ describe('TargetResolver', () => {
|
|
|
291
296
|
),
|
|
292
297
|
distEntry: 'index.js',
|
|
293
298
|
publicUrl: '/',
|
|
299
|
+
inlineRequires: false,
|
|
294
300
|
env: createEnvironment({
|
|
295
301
|
context: 'node',
|
|
296
302
|
engines: {
|
|
@@ -334,6 +340,7 @@ describe('TargetResolver', () => {
|
|
|
334
340
|
distDir: 'fixtures/custom-targets/dist/main',
|
|
335
341
|
distEntry: 'index.js',
|
|
336
342
|
publicUrl: '/',
|
|
343
|
+
inlineRequires: false,
|
|
337
344
|
env: createEnvironment({
|
|
338
345
|
context: 'node',
|
|
339
346
|
engines: {
|
|
@@ -368,6 +375,7 @@ describe('TargetResolver', () => {
|
|
|
368
375
|
distDir: 'fixtures/custom-targets/dist/browserModern',
|
|
369
376
|
distEntry: 'index.js',
|
|
370
377
|
publicUrl: '/',
|
|
378
|
+
inlineRequires: false,
|
|
371
379
|
env: createEnvironment({
|
|
372
380
|
context: 'browser',
|
|
373
381
|
engines: {
|
|
@@ -405,6 +413,7 @@ describe('TargetResolver', () => {
|
|
|
405
413
|
distDir: 'fixtures/custom-targets/dist/browserLegacy',
|
|
406
414
|
distEntry: 'index.js',
|
|
407
415
|
publicUrl: '/',
|
|
416
|
+
inlineRequires: false,
|
|
408
417
|
env: createEnvironment({
|
|
409
418
|
context: 'browser',
|
|
410
419
|
engines: {
|
|
@@ -459,6 +468,7 @@ describe('TargetResolver', () => {
|
|
|
459
468
|
distDir: 'fixtures/custom-targets/dist/main',
|
|
460
469
|
distEntry: 'index.js',
|
|
461
470
|
publicUrl: '/',
|
|
471
|
+
inlineRequires: false,
|
|
462
472
|
env: createEnvironment({
|
|
463
473
|
context: 'node',
|
|
464
474
|
engines: {
|
|
@@ -493,6 +503,7 @@ describe('TargetResolver', () => {
|
|
|
493
503
|
distDir: 'fixtures/custom-targets/dist/browserModern',
|
|
494
504
|
distEntry: 'index.js',
|
|
495
505
|
publicUrl: '/',
|
|
506
|
+
inlineRequires: false,
|
|
496
507
|
env: createEnvironment({
|
|
497
508
|
context: 'browser',
|
|
498
509
|
engines: {
|
|
@@ -530,6 +541,7 @@ describe('TargetResolver', () => {
|
|
|
530
541
|
distDir: 'fixtures/custom-targets/dist/browserLegacy',
|
|
531
542
|
distEntry: 'index.js',
|
|
532
543
|
publicUrl: '/',
|
|
544
|
+
inlineRequires: false,
|
|
533
545
|
env: createEnvironment({
|
|
534
546
|
context: 'browser',
|
|
535
547
|
engines: {
|
|
@@ -576,6 +588,7 @@ describe('TargetResolver', () => {
|
|
|
576
588
|
distDir: 'fixtures/custom-targets-distdir/www',
|
|
577
589
|
distEntry: undefined,
|
|
578
590
|
publicUrl: 'www',
|
|
591
|
+
inlineRequires: false,
|
|
579
592
|
env: createEnvironment({
|
|
580
593
|
context: 'browser',
|
|
581
594
|
engines: {
|
|
@@ -631,6 +644,7 @@ describe('TargetResolver', () => {
|
|
|
631
644
|
name: 'customB',
|
|
632
645
|
distDir: normalizeSeparators(path.resolve('customB')),
|
|
633
646
|
publicUrl: '/',
|
|
647
|
+
inlineRequires: false,
|
|
634
648
|
env: createEnvironment({
|
|
635
649
|
context: 'browser',
|
|
636
650
|
engines: {
|
|
@@ -673,6 +687,7 @@ describe('TargetResolver', () => {
|
|
|
673
687
|
name: 'customA',
|
|
674
688
|
distDir: normalizeSeparators(path.resolve('customA')),
|
|
675
689
|
publicUrl: '/',
|
|
690
|
+
inlineRequires: false,
|
|
676
691
|
env: createEnvironment({
|
|
677
692
|
context: 'browser',
|
|
678
693
|
engines: {
|
|
@@ -702,6 +717,7 @@ describe('TargetResolver', () => {
|
|
|
702
717
|
distDir: 'fixtures/context/dist/main',
|
|
703
718
|
distEntry: 'index.js',
|
|
704
719
|
publicUrl: '/',
|
|
720
|
+
inlineRequires: false,
|
|
705
721
|
env: createEnvironment({
|
|
706
722
|
context: 'node',
|
|
707
723
|
engines: {
|
|
@@ -1073,6 +1089,7 @@ describe('TargetResolver', () => {
|
|
|
1073
1089
|
distDir: relative(path.join(fixture, 'dist')),
|
|
1074
1090
|
distEntry: 'index.mjs',
|
|
1075
1091
|
publicUrl: '/',
|
|
1092
|
+
inlineRequires: false,
|
|
1076
1093
|
env: createEnvironment({
|
|
1077
1094
|
context: 'browser',
|
|
1078
1095
|
engines: {
|
|
@@ -1118,6 +1135,7 @@ describe('TargetResolver', () => {
|
|
|
1118
1135
|
distDir: relative(path.join(fixture, 'dist')),
|
|
1119
1136
|
distEntry: 'index.js',
|
|
1120
1137
|
publicUrl: '/',
|
|
1138
|
+
inlineRequires: false,
|
|
1121
1139
|
env: createEnvironment({
|
|
1122
1140
|
context: 'browser',
|
|
1123
1141
|
engines: {
|
|
@@ -1167,6 +1185,7 @@ describe('TargetResolver', () => {
|
|
|
1167
1185
|
distDir: 'fixtures/common-targets/dist/main',
|
|
1168
1186
|
distEntry: 'index.js',
|
|
1169
1187
|
publicUrl: '/',
|
|
1188
|
+
inlineRequires: false,
|
|
1170
1189
|
env: createEnvironment({
|
|
1171
1190
|
context: 'node',
|
|
1172
1191
|
engines: {
|
|
@@ -1201,6 +1220,7 @@ describe('TargetResolver', () => {
|
|
|
1201
1220
|
distDir: 'fixtures/common-targets/dist/browser',
|
|
1202
1221
|
distEntry: 'index.js',
|
|
1203
1222
|
publicUrl: '/assets',
|
|
1223
|
+
inlineRequires: false,
|
|
1204
1224
|
env: createEnvironment({
|
|
1205
1225
|
context: 'browser',
|
|
1206
1226
|
engines: {
|
|
@@ -1249,6 +1269,7 @@ describe('TargetResolver', () => {
|
|
|
1249
1269
|
name: 'default',
|
|
1250
1270
|
distDir: serveDistDir,
|
|
1251
1271
|
publicUrl: '/',
|
|
1272
|
+
inlineRequires: false,
|
|
1252
1273
|
env: createEnvironment({
|
|
1253
1274
|
context: 'browser',
|
|
1254
1275
|
engines: {
|
|
@@ -1286,6 +1307,7 @@ describe('TargetResolver', () => {
|
|
|
1286
1307
|
path.join(DEFAULT_DISTPATH_FIXTURE_PATHS.none, 'dist'),
|
|
1287
1308
|
),
|
|
1288
1309
|
publicUrl: '/',
|
|
1310
|
+
inlineRequires: false,
|
|
1289
1311
|
env: createEnvironment({
|
|
1290
1312
|
context: 'browser',
|
|
1291
1313
|
engines: {
|
|
@@ -1319,6 +1341,7 @@ describe('TargetResolver', () => {
|
|
|
1319
1341
|
),
|
|
1320
1342
|
distEntry: undefined,
|
|
1321
1343
|
publicUrl: '/',
|
|
1344
|
+
inlineRequires: false,
|
|
1322
1345
|
env: createEnvironment({
|
|
1323
1346
|
context: 'browser',
|
|
1324
1347
|
engines: {
|
|
@@ -1369,6 +1392,7 @@ describe('TargetResolver', () => {
|
|
|
1369
1392
|
),
|
|
1370
1393
|
distEntry: undefined,
|
|
1371
1394
|
publicUrl: '/',
|
|
1395
|
+
inlineRequires: false,
|
|
1372
1396
|
env: createEnvironment({
|
|
1373
1397
|
context: 'browser',
|
|
1374
1398
|
engines: {
|
|
@@ -1409,6 +1433,7 @@ describe('TargetResolver', () => {
|
|
|
1409
1433
|
),
|
|
1410
1434
|
distEntry: undefined,
|
|
1411
1435
|
publicUrl: '/',
|
|
1436
|
+
inlineRequires: false,
|
|
1412
1437
|
env: createEnvironment({
|
|
1413
1438
|
context: 'browser',
|
|
1414
1439
|
engines: {
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import SourceMap from '@atlaspack/source-map';
|
|
3
|
+
import {
|
|
4
|
+
applyReplacementsToSourceMap,
|
|
5
|
+
type HashRefReplacement,
|
|
6
|
+
} from '../../src/requests/WriteBundleRequest';
|
|
7
|
+
|
|
8
|
+
const HASH_REF = 'HASH_REF_0123456789abcdef'; // 25 chars
|
|
9
|
+
const HASH_REPLACEMENT = 'a1b2c3d4'; // 8 chars
|
|
10
|
+
const HASH_REF_LEN = HASH_REF.length; // 25
|
|
11
|
+
const REPLACEMENT_LEN = HASH_REPLACEMENT.length; // 8
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build a single-line code string with HASH_REF placeholders at known positions.
|
|
15
|
+
* Returns original code, replaced code, correct replacement coordinates, and
|
|
16
|
+
* identifier position tracking in both coordinate spaces.
|
|
17
|
+
*/
|
|
18
|
+
function buildCodeWithHashRefs(
|
|
19
|
+
segments: Array<{type: 'code'; text: string} | {type: 'hashref'}>,
|
|
20
|
+
) {
|
|
21
|
+
let code = '';
|
|
22
|
+
const hashPositions: Array<{column: number}> = [];
|
|
23
|
+
const identifierPositions = new Map<string, number>();
|
|
24
|
+
|
|
25
|
+
for (const seg of segments) {
|
|
26
|
+
if (seg.type === 'hashref') {
|
|
27
|
+
hashPositions.push({column: code.length});
|
|
28
|
+
code += HASH_REF;
|
|
29
|
+
} else {
|
|
30
|
+
const regex = /[A-Z][A-Z_0-9]{3,}/g;
|
|
31
|
+
let match;
|
|
32
|
+
while ((match = regex.exec(seg.text)) !== null) {
|
|
33
|
+
identifierPositions.set(match[0], code.length + match.index);
|
|
34
|
+
}
|
|
35
|
+
code += seg.text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Build replaced code and compute CORRECT replacement coordinates
|
|
40
|
+
let replacedCode = '';
|
|
41
|
+
const correctReplacements: HashRefReplacement[] = [];
|
|
42
|
+
let srcIdx = 0;
|
|
43
|
+
for (const hp of hashPositions) {
|
|
44
|
+
replacedCode += code.slice(srcIdx, hp.column);
|
|
45
|
+
correctReplacements.push({
|
|
46
|
+
line: 0,
|
|
47
|
+
column: replacedCode.length,
|
|
48
|
+
originalLength: HASH_REF_LEN,
|
|
49
|
+
newLength: REPLACEMENT_LEN,
|
|
50
|
+
});
|
|
51
|
+
replacedCode += HASH_REPLACEMENT;
|
|
52
|
+
srcIdx = hp.column + HASH_REF_LEN;
|
|
53
|
+
}
|
|
54
|
+
replacedCode += code.slice(srcIdx);
|
|
55
|
+
|
|
56
|
+
// Track where identifiers end up in the replaced code
|
|
57
|
+
const replacedIdentifierPositions = new Map<string, number>();
|
|
58
|
+
for (const [name] of identifierPositions) {
|
|
59
|
+
const idx = replacedCode.indexOf(name);
|
|
60
|
+
if (idx >= 0) replacedIdentifierPositions.set(name, idx);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
originalCode: code,
|
|
65
|
+
replacedCode,
|
|
66
|
+
correctReplacements,
|
|
67
|
+
identifierPositions,
|
|
68
|
+
replacedIdentifierPositions,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('applyReplacementsToSourceMap', () => {
|
|
73
|
+
describe('with correct replacement coordinates', () => {
|
|
74
|
+
it('should correctly adjust a single HASH_REF replacement', () => {
|
|
75
|
+
const {
|
|
76
|
+
correctReplacements,
|
|
77
|
+
identifierPositions,
|
|
78
|
+
replacedIdentifierPositions,
|
|
79
|
+
} = buildCodeWithHashRefs([
|
|
80
|
+
{type: 'hashref'},
|
|
81
|
+
{type: 'code', text: ';var x=SOME_IDENT;'},
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
const origCol = identifierPositions.get('SOME_IDENT')!;
|
|
85
|
+
const expectedCol = replacedIdentifierPositions.get('SOME_IDENT')!;
|
|
86
|
+
|
|
87
|
+
const sm = new SourceMap('/');
|
|
88
|
+
sm.addIndexedMapping({
|
|
89
|
+
generated: {line: 1, column: origCol},
|
|
90
|
+
original: {line: 10, column: 5},
|
|
91
|
+
source: 'test.js',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
applyReplacementsToSourceMap(sm, correctReplacements);
|
|
95
|
+
|
|
96
|
+
const mappings = sm.getMap().mappings;
|
|
97
|
+
const mapping = mappings.find(
|
|
98
|
+
(m) => m.original?.line === 10 && m.original?.column === 5,
|
|
99
|
+
);
|
|
100
|
+
assert.ok(mapping, 'Mapping should exist');
|
|
101
|
+
assert.strictEqual(mapping!.generated.column, expectedCol);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should correctly adjust multiple HASH_REF replacements on the same line', () => {
|
|
105
|
+
const {
|
|
106
|
+
correctReplacements,
|
|
107
|
+
identifierPositions,
|
|
108
|
+
replacedIdentifierPositions,
|
|
109
|
+
} = buildCodeWithHashRefs([
|
|
110
|
+
{type: 'hashref'},
|
|
111
|
+
{type: 'code', text: ';var a=IDENT_ALPHA;require("'},
|
|
112
|
+
{type: 'hashref'},
|
|
113
|
+
{type: 'code', text: '");var b=IDENT_BETA;require("'},
|
|
114
|
+
{type: 'hashref'},
|
|
115
|
+
{type: 'code', text: '");var c=IDENT_GAMMA;'},
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
const sm = new SourceMap('/');
|
|
119
|
+
sm.addIndexedMapping({
|
|
120
|
+
generated: {line: 1, column: identifierPositions.get('IDENT_ALPHA')!},
|
|
121
|
+
original: {line: 10, column: 0},
|
|
122
|
+
source: 'test.js',
|
|
123
|
+
});
|
|
124
|
+
sm.addIndexedMapping({
|
|
125
|
+
generated: {line: 1, column: identifierPositions.get('IDENT_BETA')!},
|
|
126
|
+
original: {line: 20, column: 0},
|
|
127
|
+
source: 'test.js',
|
|
128
|
+
});
|
|
129
|
+
sm.addIndexedMapping({
|
|
130
|
+
generated: {line: 1, column: identifierPositions.get('IDENT_GAMMA')!},
|
|
131
|
+
original: {line: 30, column: 0},
|
|
132
|
+
source: 'test.js',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
applyReplacementsToSourceMap(sm, correctReplacements);
|
|
136
|
+
|
|
137
|
+
const mappings = sm.getMap().mappings;
|
|
138
|
+
for (const [name, origLine] of [
|
|
139
|
+
['IDENT_ALPHA', 10],
|
|
140
|
+
['IDENT_BETA', 20],
|
|
141
|
+
['IDENT_GAMMA', 30],
|
|
142
|
+
] as const) {
|
|
143
|
+
const mapping = mappings.find((m) => m.original?.line === origLine);
|
|
144
|
+
const expectedCol = replacedIdentifierPositions.get(name)!;
|
|
145
|
+
assert.ok(mapping, `${name} mapping should exist`);
|
|
146
|
+
assert.strictEqual(
|
|
147
|
+
mapping!.generated.column,
|
|
148
|
+
expectedCol,
|
|
149
|
+
`${name}: expected col ${expectedCol}, got ${mapping!.generated.column}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should handle 10 replacements on the same line', () => {
|
|
155
|
+
const segments: Array<{type: 'code'; text: string} | {type: 'hashref'}> =
|
|
156
|
+
[];
|
|
157
|
+
for (let i = 0; i < 10; i++) {
|
|
158
|
+
segments.push({type: 'hashref'});
|
|
159
|
+
segments.push({
|
|
160
|
+
type: 'code',
|
|
161
|
+
text: `;var x${i}=TARGET_${String(i).padStart(2, '0')};require("`,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
segments.push({type: 'code', text: '");'});
|
|
165
|
+
|
|
166
|
+
const {
|
|
167
|
+
correctReplacements,
|
|
168
|
+
identifierPositions,
|
|
169
|
+
replacedIdentifierPositions,
|
|
170
|
+
} = buildCodeWithHashRefs(segments);
|
|
171
|
+
|
|
172
|
+
const sm = new SourceMap('/');
|
|
173
|
+
for (let i = 0; i < 10; i++) {
|
|
174
|
+
const name = `TARGET_${String(i).padStart(2, '0')}`;
|
|
175
|
+
sm.addIndexedMapping({
|
|
176
|
+
generated: {line: 1, column: identifierPositions.get(name)!},
|
|
177
|
+
original: {line: (i + 1) * 10, column: 0},
|
|
178
|
+
source: 'test.js',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
applyReplacementsToSourceMap(sm, correctReplacements);
|
|
183
|
+
|
|
184
|
+
const mappings = sm.getMap().mappings;
|
|
185
|
+
for (let i = 0; i < 10; i++) {
|
|
186
|
+
const name = `TARGET_${String(i).padStart(2, '0')}`;
|
|
187
|
+
const mapping = mappings.find((m) => m.original?.line === (i + 1) * 10);
|
|
188
|
+
const expectedCol = replacedIdentifierPositions.get(name)!;
|
|
189
|
+
assert.ok(mapping, `${name} mapping should exist`);
|
|
190
|
+
assert.strictEqual(
|
|
191
|
+
mapping!.generated.column,
|
|
192
|
+
expectedCol,
|
|
193
|
+
`${name}: expected col ${expectedCol}, got ${mapping!.generated.column}`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should not affect mappings before the first HASH_REF', () => {
|
|
199
|
+
const {
|
|
200
|
+
correctReplacements,
|
|
201
|
+
identifierPositions,
|
|
202
|
+
replacedIdentifierPositions,
|
|
203
|
+
} = buildCodeWithHashRefs([
|
|
204
|
+
{type: 'code', text: 'var BEFORE_HASH=1;'},
|
|
205
|
+
{type: 'hashref'},
|
|
206
|
+
{type: 'code', text: ';var AFTER_HASH=2;'},
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
const sm = new SourceMap('/');
|
|
210
|
+
sm.addIndexedMapping({
|
|
211
|
+
generated: {line: 1, column: identifierPositions.get('BEFORE_HASH')!},
|
|
212
|
+
original: {line: 1, column: 0},
|
|
213
|
+
source: 'test.js',
|
|
214
|
+
});
|
|
215
|
+
sm.addIndexedMapping({
|
|
216
|
+
generated: {line: 1, column: identifierPositions.get('AFTER_HASH')!},
|
|
217
|
+
original: {line: 2, column: 0},
|
|
218
|
+
source: 'test.js',
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
applyReplacementsToSourceMap(sm, correctReplacements);
|
|
222
|
+
|
|
223
|
+
const mappings = sm.getMap().mappings;
|
|
224
|
+
const beforeMapping = mappings.find((m) => m.original?.line === 1);
|
|
225
|
+
assert.ok(beforeMapping);
|
|
226
|
+
assert.strictEqual(
|
|
227
|
+
beforeMapping!.generated.column,
|
|
228
|
+
replacedIdentifierPositions.get('BEFORE_HASH'),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const afterMapping = mappings.find((m) => m.original?.line === 2);
|
|
232
|
+
assert.ok(afterMapping);
|
|
233
|
+
assert.strictEqual(
|
|
234
|
+
afterMapping!.generated.column,
|
|
235
|
+
replacedIdentifierPositions.get('AFTER_HASH'),
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|