-
-
Notifications
You must be signed in to change notification settings - Fork 412
Closed
Description
Bug report or Feature request?
Bug report
Version (complete output of terser -V
or specific git commit)
Confirmed on 5.15.0
and current main (e062dc8)
Description
Terser stores its source map output on the input config object, under options.format.source_map
. The returned value includes a getter for a map
property, which uses options.format.source_map
. If options.format.source_map
changes between the minify
result and the use of the getter, the output may be incorrect.
In particular, a second call to minify
using the same config object will clobber source_map
.
Failing test
import {minify} from 'terser';
test('subsequent calls do not clobber previous output', async () => {
const config = {
format: {},
sourceMap: true,
};
const fooResult = await minify('"foo";', config);
const barResult = await minify('module.exports = "bar";', config);
const fooMap = fooResult.map; // Uses a getter which uses config.format.source_map, which was overwritten by the second call.
const barMap = barResult.map;
expect(barMap).toEqual(
'{"version":3,"names":["module","exports"],"sources":["0"],"mappings":"AAAAA,OAAOC,QAAU"}',
); // Succeeds - `barMap` is correct
expect(fooMap).not.toEqual(barMap); // <-- Fails - `fooMap` is `barMap`
});
Expected result
Test passes - reusing a config object should not affect previous output.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Don't mutate options object. Fixes terser#1341
metro-minify-terser: Don't mutate input options
Don't mutate options object. Fixes terser#1341
Don't mutate options object. Fixes #1341 (#1342)
metro-minify-terser: Don't mutate input options
metro-minify-terser: Don't mutate input options
metro-minify-terser: Don't mutate input options