Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shoonia committed Oct 22, 2023
1 parent fd1897c commit 7049d90
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions plugins/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ const components = new Set([
'ModalPortal',
]);

/** @returns {import('@babel/types').MemberExpression} */
const createObjectAssign = () => ({
type: 'MemberExpression',
computed: false,
object: {
type: 'Identifier',
name: 'Object',
},
property: {
type: 'Identifier',
name: 'assign',
},
});

/** @type {import('@babel/types').LogicalExpression} */
const objectAssign = {
operator: '||',
right: { type: 'FunctionExpression' },
left: {
type: 'MemberExpression',
computed: false,
object: {
type: 'Identifier',
name: 'Object',
},
property: {
type: 'Identifier',
name: 'assign',
},
},
left: createObjectAssign(),
};

/** @type {import('@babel/types').AssignmentExpression} */
Expand Down Expand Up @@ -59,7 +62,7 @@ const plugin = () => {
const { node } = path;

if (deepMatch(node, objectAssign)) {
path.replaceWith(node.left);
path.replaceWith(createObjectAssign());
}
},

Expand Down

0 comments on commit 7049d90

Please sign in to comment.