Skip to content

Commit

Permalink
refactor: change to object.assign polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
Grohden committed Dec 14, 2024
1 parent 237f618 commit 50ad04b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default declare(({
EMIT_DEPRECATED_DEFAULT_PROPS,
}) => {
const defaultProps = SVG_DEFAULT_PROPS_CODE
? 'var props = objectAssignShim()({}, SVG_DEFAULT_PROPS_CODE, overrides);'
? 'var props = objectAssignPolyfill()({}, SVG_DEFAULT_PROPS_CODE, overrides);'
: '';
const PROPS_NAME = SVG_DEFAULT_PROPS_CODE ? 'overrides' : 'props';

Expand Down Expand Up @@ -164,10 +164,10 @@ export default declare(({
throw new TypeError('the "filename" option is required when transforming code');
}

if (!path.scope.hasBinding('object.assign/shim')) {
if (!path.scope.hasBinding('object.assign/polyfill')) {
const assignDeclaration = t.importDeclaration([
t.importDefaultSpecifier(t.identifier('objectAssignShim')),
], t.stringLiteral('object.assign/shim'));
t.importDefaultSpecifier(t.identifier('objectAssignPolyfill')),
], t.stringLiteral('object.assign/polyfill'));

file.set('ensureObjectAssign', () => {
const [newPath] = path.unshiftContainer('body', assignDeclaration);
Expand Down
4 changes: 2 additions & 2 deletions test/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function assertMatchImport(name, matchRegex) {
const assertReactImport = assertMatchImport('React', () => /import React from ['"]react['"]/g);

const assertObjectAssignImport = assertMatchImport(
'object.assign/shim',
() => /import objectAssignShim from ['"]object.assign\/shim['"]/g,
'object.assign/polyfill',
() => /import objectAssignPolyfill from ['"]object.assign\/polyfill['"]/g,
);

function assertDefaultProps(shouldExist, result) {
Expand Down

0 comments on commit 50ad04b

Please sign in to comment.