Skip to content

Commit 0720a2f

Browse files
fix: persist formatting of source map JSON
1 parent 358e331 commit 0720a2f

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

.idea/copilotDiffState.xml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/angular/build/src/utils/debug-id.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export function injectDebugIdIntoSourceMap(json: string, id: string): string {
8585
return json;
8686
}
8787

88+
if (parsed['debugId'] === id) {
89+
return json;
90+
}
91+
8892
parsed['debugId'] = id;
8993

90-
return JSON.stringify(parsed);
94+
// Preserve existing pretty-print indentation when the source map is formatted.
95+
const indent = json.match(/^[^{]*{\r?\n([ \t]+)/)?.[1];
96+
97+
return JSON.stringify(parsed, null, indent);
9198
}

packages/angular/build/src/utils/debug-id_spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ describe('debug-id', () => {
8282
expect(updated.debugId).toBe(id);
8383
});
8484

85+
it('returns the original input when debugId already matches', () => {
86+
const map = '{\n "version": 3,\n "debugId": "11111111-2222-5333-9444-555555555555",\n "mappings": ""\n}';
87+
expect(injectDebugIdIntoSourceMap(map, id)).toBe(map);
88+
});
89+
90+
it('preserves indentation when updating a pretty-printed source map', () => {
91+
const map = '{\n\t"version": 3,\n\t"mappings": ""\n}';
92+
expect(injectDebugIdIntoSourceMap(map, id)).toBe(
93+
'{\n\t"version": 3,\n\t"mappings": "",\n\t"debugId": "11111111-2222-5333-9444-555555555555"\n}',
94+
);
95+
});
96+
8597
it('returns the original input when JSON is malformed', () => {
8698
const malformed = '{ this is not json';
8799
expect(injectDebugIdIntoSourceMap(malformed, id)).toBe(malformed);

0 commit comments

Comments
 (0)