Skip to content

Commit

Permalink
fix: caller.polyfillMethod as 'false' should work
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Feb 17, 2025
1 parent 1b695de commit ce1417a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/babel-preset-anansi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ function buildPreset(api, options = {}) {
if (process.env.BABEL_MODULES) {
options.modules = process.env.BABEL_MODULES;
}
if (api.caller(caller => caller && caller.polyfillMethod)) {
if (api.caller(caller => caller && caller.polyfillMethod) !== undefined) {
options.polyfillMethod = api.caller(caller => caller.polyfillMethod);
}
if (process.env.BABEL_POLYFILL_METHOD) {
if (process.env.BABEL_POLYFILL_METHOD !== undefined) {
options.polyfillMethod = process.env.BABEL_POLYFILL_METHOD;
}
const shouldHotReload =
Expand Down
10 changes: 10 additions & 0 deletions packages/babel-preset-anansi/transform2018.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ describe('buildPreset - Babel Transform', () => {
expect(transformedCode).toMatchSnapshot();
});

it('should use @babel/runtime by default when caller sets polyfillMethod to false', () => {
api.env.mockReturnValue('development');
process.env.NODE_ENV = 'development';
api.caller.mockImplementation(cb => cb({ polyfillMethod: false }));
const code = `class MyClass { declare myThing; myProp: number = 42; }console.log(Object.hasOwn({ a: 1 }, 'a') ? 'yes' : 'no');`;
let transformedCode = transformCode(code, { loose: false });
expect(transformedCode).not.toContain('core-js');
expect(transformedCode).toContain('@babel/runtime/');
});

it('should use core-js-pure by default when caller is rollup', () => {
api.env.mockReturnValue('development');
process.env.NODE_ENV = 'development';
Expand Down

0 comments on commit ce1417a

Please sign in to comment.