Skip to content

Commit

Permalink
Remove TS polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
shoonia committed Oct 22, 2023
1 parent 7049d90 commit 01a13a6
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions plugins/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ const createObjectAssign = () => ({
});

/** @type {import('@babel/types').LogicalExpression} */
const objectAssign = {
const maybePolyfill = {
operator: '||',
right: { type: 'FunctionExpression' },
left: createObjectAssign(),
};

/** @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: 'ThisExpression' },
property: {
type: 'Identifier',
name: '__assign',
},
},
};

/** @type {import('@babel/types').AssignmentExpression} */
Expand All @@ -61,8 +79,13 @@ const plugin = () => {
LogicalExpression(path) {
const { node } = path;

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

Expand Down

0 comments on commit 01a13a6

Please sign in to comment.