Skip to content

Commit

Permalink
Merge pull request #105 from shoonia/remove-ts-extra-code
Browse files Browse the repository at this point in the history
Remove TS polyfill
  • Loading branch information
shoonia authored Oct 22, 2023
2 parents fd1897c + 01a13a6 commit 3a20a7c
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions plugins/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,41 @@ 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 = {
const maybePolyfill = {
operator: '||',
right: { type: 'FunctionExpression' },
left: {
};

/** @type {import('@babel/types').MemberExpression} */
const objectAssign = createObjectAssign();

/** @type {import('@babel/types').LogicalExpression} */
const objectAssignTs = {
type: 'LogicalExpression',
operator: '&&',
left: { type: 'ThisExpression' },
right: {
type: 'MemberExpression',
computed: false,
object: {
type: 'Identifier',
name: 'Object',
},
object: { type: 'ThisExpression' },
property: {
type: 'Identifier',
name: 'assign',
name: '__assign',
},
},
};
Expand Down Expand Up @@ -58,8 +79,13 @@ const plugin = () => {
LogicalExpression(path) {
const { node } = path;

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

Expand Down

0 comments on commit 3a20a7c

Please sign in to comment.