Skip to content

Commit 02c7a78

Browse files
authored
fix(convertTransform): do not add redundant space between functions (#1802)
The space is optional between transform functions in the `transform` attribute and similar properties. This just omits the space as a micro-optimization. This does not add new tests is the scenario is covered adequately in existing tests. Also refactors js2transform to avoid concatenating in a loop.
1 parent 2539b9f commit 02c7a78

File tree

7 files changed

+21
-27
lines changed

7 files changed

+21
-27
lines changed

lib/svgo.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ test('encode as datauri', () => {
395395
plugins: ['convertTransform'],
396396
});
397397
expect(dataSinglePass).toMatchInlineSnapshot(
398-
`"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20transform%3D%22scale(2)%20rotate(-45%20130.898%20-126.14)%22%2F%3E%3C%2Fsvg%3E"`
398+
`"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20transform%3D%22scale(2)rotate(-45%20130.898%20-126.14)%22%2F%3E%3C%2Fsvg%3E"`
399399
);
400400
const { data: dataMultiPass } = optimize(input, {
401401
multipass: true,
402402
datauri: 'enc',
403403
plugins: ['convertTransform'],
404404
});
405405
expect(dataMultiPass).toMatchInlineSnapshot(
406-
`"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20transform%3D%22rotate(-45%20261.796%20-252.28)%20scale(2)%22%2F%3E%3C%2Fsvg%3E"`
406+
`"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20transform%3D%22rotate(-45%20261.796%20-252.28)scale(2)%22%2F%3E%3C%2Fsvg%3E"`
407407
);
408408
});

plugins/convertTransform.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,12 @@ const removeUseless = (transforms) => {
335335
* @type {(transformJS: Array<TransformItem>, params: TransformParams) => string}
336336
*/
337337
const js2transform = (transformJS, params) => {
338-
var transformString = '';
339-
340-
// collect output value string
341-
transformJS.forEach((transform) => {
342-
roundTransform(transform, params);
343-
transformString +=
344-
(transformString && ' ') +
345-
transform.name +
346-
'(' +
347-
cleanupOutData(transform.data, params) +
348-
')';
349-
});
338+
const transformString = transformJS
339+
.map((transform) => {
340+
roundTransform(transform, params);
341+
return `${transform.name}(${cleanupOutData(transform.data, params)})`;
342+
})
343+
.join('');
350344

351345
return transformString;
352346
};

test/coa/testSvg/test.1.svg

Lines changed: 1 addition & 1 deletion
Loading

test/coa/testSvg/test.svg

Lines changed: 1 addition & 1 deletion
Loading

test/plugins/convertTransform.01.svg

Lines changed: 6 additions & 6 deletions
Loading

test/plugins/convertTransform.02.svg

Lines changed: 4 additions & 4 deletions
Loading

test/plugins/convertTransform.03.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)