diff --git a/packages/utils/src/buildPolyfills/_createNamedExportFrom.ts b/packages/utils/src/buildPolyfills/_createNamedExportFrom.ts deleted file mode 100644 index 2193609e64f7..000000000000 --- a/packages/utils/src/buildPolyfills/_createNamedExportFrom.ts +++ /dev/null @@ -1,45 +0,0 @@ -// https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f -// -// The MIT License (MIT) -// -// Copyright (c) 2012-2018 various contributors (see AUTHORS) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -import type { GenericObject } from './types'; - -declare const exports: GenericObject; - -/** - * Copy a property from the given object into `exports`, under the given name. - * - * Adapted from Sucrase (https://github.com/alangpierce/sucrase) - * - * @param obj The object containing the property to copy. - * @param localName The name under which to export the property - * @param importedName The name under which the property lives in `obj` - */ -export function _createNamedExportFrom(obj: GenericObject, localName: string, importedName: string): void { - exports[localName] = obj[importedName]; -} - -// Sucrase version: -// function _createNamedExportFrom(obj, localName, importedName) { -// Object.defineProperty(exports, localName, {enumerable: true, get: () => obj[importedName]}); -// } diff --git a/packages/utils/src/buildPolyfills/_createStarExport.ts b/packages/utils/src/buildPolyfills/_createStarExport.ts deleted file mode 100644 index 377d51e10a84..000000000000 --- a/packages/utils/src/buildPolyfills/_createStarExport.ts +++ /dev/null @@ -1,52 +0,0 @@ -// https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f -// -// The MIT License (MIT) -// -// Copyright (c) 2012-2018 various contributors (see AUTHORS) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -import type { GenericObject } from './types'; - -declare const exports: GenericObject; - -/** - * Copy properties from an object into `exports`. - * - * Adapted from Sucrase (https://github.com/alangpierce/sucrase) - * - * @param obj The object containing the properties to copy. - */ -export function _createStarExport(obj: GenericObject): void { - Object.keys(obj) - .filter(key => key !== 'default' && key !== '__esModule' && !(key in exports)) - .forEach(key => (exports[key] = obj[key])); -} - -// Sucrase version: -// function _createStarExport(obj) { -// Object.keys(obj) -// .filter(key => key !== 'default' && key !== '__esModule') -// .forEach(key => { -// if (exports.hasOwnProperty(key)) { -// return; -// } -// Object.defineProperty(exports, key, { enumerable: true, get: () => obj[key] }); -// }); -// } diff --git a/packages/utils/src/buildPolyfills/_interopDefault.ts b/packages/utils/src/buildPolyfills/_interopDefault.ts deleted file mode 100644 index 3a8c29d1bbaf..000000000000 --- a/packages/utils/src/buildPolyfills/_interopDefault.ts +++ /dev/null @@ -1,37 +0,0 @@ -// https://github.com/rollup/rollup/tree/c2cda424e69686671ba010d628c0f70c43a563f8 -// The MIT License (MIT) -// -// Copyright (c) 2017 [these people](https://github.com/rollup/rollup/graphs/contributors) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, -// and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import type { RequireResult } from './types'; - -/** - * Unwraps a module if it has been wrapped in an object under the key `default`. - * - * Adapted from Rollup (https://github.com/rollup/rollup) - * - * @param requireResult The result of calling `require` on a module - * @returns The full module, unwrapped if necessary. - */ -export function _interopDefault(requireResult: RequireResult): RequireResult { - return requireResult.__esModule ? (requireResult.default as RequireResult) : requireResult; -} - -// Rollup version: -// function _interopDefault(e) { -// return e && e.__esModule ? e['default'] : e; -// } diff --git a/packages/utils/src/buildPolyfills/_interopNamespace.ts b/packages/utils/src/buildPolyfills/_interopNamespace.ts deleted file mode 100644 index ed596090ff73..000000000000 --- a/packages/utils/src/buildPolyfills/_interopNamespace.ts +++ /dev/null @@ -1,45 +0,0 @@ -// https://github.com/rollup/rollup/tree/c2cda424e69686671ba010d628c0f70c43a563f8 -// The MIT License (MIT) -// -// Copyright (c) 2017 [these people](https://github.com/rollup/rollup/graphs/contributors) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, -// and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import type { RequireResult } from './types'; - -/** - * Adds a self-referential `default` property to CJS modules which aren't the result of transpilation from ESM modules. - * - * Adapted from Rollup (https://github.com/rollup/rollup) - * - * @param requireResult The result of calling `require` on a module - * @returns Either `requireResult` or a copy of `requireResult` with an added self-referential `default` property - */ -export function _interopNamespace(requireResult: RequireResult): RequireResult { - return requireResult.__esModule ? requireResult : { ...requireResult, default: requireResult }; -} - -// Rollup version (with `output.externalLiveBindings` and `output.freeze` both set to false) -// function _interopNamespace(e) { -// if (e && e.__esModule) return e; -// var n = Object.create(null); -// if (e) { -// for (var k in e) { -// n[k] = e[k]; -// } -// } -// n["default"] = e; -// return n; -// } diff --git a/packages/utils/src/buildPolyfills/_interopNamespaceDefaultOnly.ts b/packages/utils/src/buildPolyfills/_interopNamespaceDefaultOnly.ts deleted file mode 100644 index a3b1de3ab3b5..000000000000 --- a/packages/utils/src/buildPolyfills/_interopNamespaceDefaultOnly.ts +++ /dev/null @@ -1,43 +0,0 @@ -// https://github.com/rollup/rollup/tree/c2cda424e69686671ba010d628c0f70c43a563f8 -// The MIT License (MIT) -// -// Copyright (c) 2017 [these people](https://github.com/rollup/rollup/graphs/contributors) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, -// and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions -// of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import type { RequireResult } from './types'; - -/** - * Wrap a module in an object, as the value under the key `default`. - * - * Adapted from Rollup (https://github.com/rollup/rollup) - * - * @param requireResult The result of calling `require` on a module - * @returns An object containing the key-value pair (`default`, `requireResult`) - */ -export function _interopNamespaceDefaultOnly(requireResult: RequireResult): RequireResult { - return { - __proto__: null, - default: requireResult, - }; -} - -// Rollup version -// function _interopNamespaceDefaultOnly(e) { -// return { -// __proto__: null, -// 'default': e -// }; -// } diff --git a/packages/utils/src/buildPolyfills/_interopRequireDefault.ts b/packages/utils/src/buildPolyfills/_interopRequireDefault.ts deleted file mode 100644 index 74122265c07e..000000000000 --- a/packages/utils/src/buildPolyfills/_interopRequireDefault.ts +++ /dev/null @@ -1,42 +0,0 @@ -// https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f -// -// The MIT License (MIT) -// -// Copyright (c) 2012-2018 various contributors (see AUTHORS) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -import type { RequireResult } from './types'; - -/** - * Wraps modules which aren't the result of transpiling an ESM module in an object under the key `default` - * - * Adapted from Sucrase (https://github.com/alangpierce/sucrase) - * - * @param requireResult The result of calling `require` on a module - * @returns `requireResult` or `requireResult` wrapped in an object, keyed as `default` - */ -export function _interopRequireDefault(requireResult: RequireResult): RequireResult { - return requireResult.__esModule ? requireResult : { default: requireResult }; -} - -// Sucrase version -// function _interopRequireDefault(obj) { -// return obj && obj.__esModule ? obj : { default: obj }; -// } diff --git a/packages/utils/src/buildPolyfills/_interopRequireWildcard.ts b/packages/utils/src/buildPolyfills/_interopRequireWildcard.ts deleted file mode 100644 index 5be829e3e48a..000000000000 --- a/packages/utils/src/buildPolyfills/_interopRequireWildcard.ts +++ /dev/null @@ -1,55 +0,0 @@ -// https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f -// -// The MIT License (MIT) -// -// Copyright (c) 2012-2018 various contributors (see AUTHORS) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -import type { RequireResult } from './types'; - -/** - * Adds a `default` property to CJS modules which aren't the result of transpilation from ESM modules. - * - * Adapted from Sucrase (https://github.com/alangpierce/sucrase) - * - * @param requireResult The result of calling `require` on a module - * @returns Either `requireResult` or a copy of `requireResult` with an added self-referential `default` property - */ -export function _interopRequireWildcard(requireResult: RequireResult): RequireResult { - return requireResult.__esModule ? requireResult : { ...requireResult, default: requireResult }; -} - -// Sucrase version -// function _interopRequireWildcard(obj) { -// if (obj && obj.__esModule) { -// return obj; -// } else { -// var newObj = {}; -// if (obj != null) { -// for (var key in obj) { -// if (Object.prototype.hasOwnProperty.call(obj, key)) { -// newObj[key] = obj[key]; -// } -// } -// } -// newObj.default = obj; -// return newObj; -// } -// } diff --git a/packages/utils/src/buildPolyfills/index.ts b/packages/utils/src/buildPolyfills/index.ts index 9717453e98fa..2017dcbd9592 100644 --- a/packages/utils/src/buildPolyfills/index.ts +++ b/packages/utils/src/buildPolyfills/index.ts @@ -1,13 +1,6 @@ export { _asyncNullishCoalesce } from './_asyncNullishCoalesce'; export { _asyncOptionalChain } from './_asyncOptionalChain'; export { _asyncOptionalChainDelete } from './_asyncOptionalChainDelete'; -export { _createNamedExportFrom } from './_createNamedExportFrom'; -export { _createStarExport } from './_createStarExport'; -export { _interopDefault } from './_interopDefault'; -export { _interopNamespace } from './_interopNamespace'; -export { _interopNamespaceDefaultOnly } from './_interopNamespaceDefaultOnly'; -export { _interopRequireDefault } from './_interopRequireDefault'; -export { _interopRequireWildcard } from './_interopRequireWildcard'; export { _nullishCoalesce } from './_nullishCoalesce'; export { _optionalChain } from './_optionalChain'; export { _optionalChainDelete } from './_optionalChainDelete'; diff --git a/packages/utils/test/buildPolyfills/interop.test.ts b/packages/utils/test/buildPolyfills/interop.test.ts deleted file mode 100644 index a53c64eb0979..000000000000 --- a/packages/utils/test/buildPolyfills/interop.test.ts +++ /dev/null @@ -1,180 +0,0 @@ -import { - _interopDefault, - _interopNamespace, - _interopNamespaceDefaultOnly, - _interopRequireDefault, - _interopRequireWildcard, -} from '../../src/buildPolyfills'; -import type { RequireResult } from '../../src/buildPolyfills/types'; -import { - _interopDefault as _interopDefaultOrig, - _interopNamespace as _interopNamespaceOrig, - _interopNamespaceDefaultOnly as _interopNamespaceDefaultOnlyOrig, - _interopRequireDefault as _interopRequireDefaultOrig, - _interopRequireWildcard as _interopRequireWildcardOrig, -} from './originals'; - -// This file tests five different functions against a range of test cases. Though the inputs are the same for each -// function's test cases, the expected output differs. The testcases for each function are therefore built from separate -// collections of expected inputs and expected outputs. Further, for readability purposes, the tests labels have also -// been split into their own object. It's also worth noting that in real life, there are some test-case/function -// pairings which would never happen, but by testing all combinations, we're guaranteed to have tested the ones which -// show up in the wild. - -const dogStr = 'dogs are great!'; -const dogFunc = () => dogStr; -const dogAdjectives = { maisey: 'silly', charlie: 'goofy' }; - -const withESModuleFlag = { __esModule: true, ...dogAdjectives }; -const withESModuleFlagAndDefault = { __esModule: true, default: dogFunc, ...dogAdjectives }; -const namedExports = { ...dogAdjectives }; -const withNonEnumerableProp = { ...dogAdjectives }; -// Properties added using `Object.defineProperty` are non-enumerable by default -Object.defineProperty(withNonEnumerableProp, 'hiddenProp', { value: 'shhhhhhhh' }); -const withDefaultExport = { default: dogFunc, ...dogAdjectives }; -const withOnlyDefaultExport = { default: dogFunc }; -const exportsEquals = dogFunc as RequireResult; -const exportsEqualsWithDefault = dogFunc as RequireResult; -exportsEqualsWithDefault.default = exportsEqualsWithDefault; - -const mockRequireResults: Record = { - withESModuleFlag, - withESModuleFlagAndDefault, - namedExports, - withNonEnumerableProp, - withDefaultExport, - withOnlyDefaultExport, - exportsEquals: exportsEquals, - exportsEqualsWithDefault: exportsEqualsWithDefault as unknown as RequireResult, -}; - -const testLabels: Record = { - withESModuleFlag: 'module with `__esModule` flag', - withESModuleFlagAndDefault: 'module with `__esModule` flag and default export', - namedExports: 'module with named exports', - withNonEnumerableProp: 'module with named exports and non-enumerable prop', - withDefaultExport: 'module with default export', - withOnlyDefaultExport: 'module with only default export', - exportsEquals: 'module using `exports =`', - exportsEqualsWithDefault: 'module using `exports =` with default export', -}; - -function makeTestCases(expectedOutputs: Record): Array<[string, RequireResult, RequireResult]> { - return Object.keys(mockRequireResults).map(key => [testLabels[key], mockRequireResults[key], expectedOutputs[key]]); -} - -describe('_interopNamespace', () => { - describe('returns the same result as the original', () => { - const expectedOutputs: Record = { - withESModuleFlag: withESModuleFlag, - withESModuleFlagAndDefault: withESModuleFlagAndDefault, - namedExports: { ...namedExports, default: namedExports }, - withNonEnumerableProp: { - ...withNonEnumerableProp, - default: withNonEnumerableProp, - }, - withDefaultExport: { ...withDefaultExport, default: withDefaultExport }, - withOnlyDefaultExport: { default: withOnlyDefaultExport }, - exportsEquals: { default: exportsEquals }, - exportsEqualsWithDefault: { default: exportsEqualsWithDefault }, - }; - - const testCases = makeTestCases(expectedOutputs); - - it.each(testCases)('%s', (_, requireResult, expectedOutput) => { - expect(_interopNamespace(requireResult)).toEqual(_interopNamespaceOrig(requireResult)); - expect(_interopNamespace(requireResult)).toEqual(expectedOutput); - }); - }); -}); - -describe('_interopNamespaceDefaultOnly', () => { - describe('returns the same result as the original', () => { - const expectedOutputs: Record = { - withESModuleFlag: { default: withESModuleFlag }, - withESModuleFlagAndDefault: { default: withESModuleFlagAndDefault }, - namedExports: { default: namedExports }, - withNonEnumerableProp: { default: withNonEnumerableProp }, - withDefaultExport: { default: withDefaultExport }, - withOnlyDefaultExport: { default: withOnlyDefaultExport }, - exportsEquals: { default: exportsEquals }, - exportsEqualsWithDefault: { default: exportsEqualsWithDefault }, - }; - - const testCases = makeTestCases(expectedOutputs); - - it.each(testCases)('%s', (_, requireResult, expectedOutput) => { - expect(_interopNamespaceDefaultOnly(requireResult)).toEqual(_interopNamespaceDefaultOnlyOrig(requireResult)); - expect(_interopNamespaceDefaultOnly(requireResult)).toEqual(expectedOutput); - }); - }); -}); - -describe('_interopRequireWildcard', () => { - describe('returns the same result as the original', () => { - const expectedOutputs: Record = { - withESModuleFlag: withESModuleFlag, - withESModuleFlagAndDefault: withESModuleFlagAndDefault, - namedExports: { ...namedExports, default: namedExports }, - withNonEnumerableProp: { - ...withNonEnumerableProp, - default: withNonEnumerableProp, - }, - withDefaultExport: { ...withDefaultExport, default: withDefaultExport }, - withOnlyDefaultExport: { default: withOnlyDefaultExport }, - exportsEquals: { default: exportsEquals }, - exportsEqualsWithDefault: { default: exportsEqualsWithDefault }, - }; - - const testCases = makeTestCases(expectedOutputs); - - it.each(testCases)('%s', (_, requireResult, expectedOutput) => { - expect(_interopRequireWildcard(requireResult)).toEqual(_interopRequireWildcardOrig(requireResult)); - expect(_interopRequireWildcard(requireResult)).toEqual(expectedOutput); - }); - }); -}); - -describe('_interopDefault', () => { - describe('returns the same result as the original', () => { - const expectedOutputs: Record = { - withESModuleFlag: undefined as unknown as RequireResult, - withESModuleFlagAndDefault: withESModuleFlagAndDefault.default as RequireResult, - namedExports: namedExports, - withNonEnumerableProp: withNonEnumerableProp, - withDefaultExport: withDefaultExport, - withOnlyDefaultExport: withOnlyDefaultExport, - exportsEquals: exportsEquals, - exportsEqualsWithDefault: exportsEqualsWithDefault, - }; - - const testCases = makeTestCases(expectedOutputs); - - it.each(testCases)('%s', (_, requireResult, expectedOutput) => { - expect(_interopDefault(requireResult)).toEqual(_interopDefaultOrig(requireResult)); - expect(_interopDefault(requireResult)).toEqual(expectedOutput); - }); - }); -}); - -describe('_interopRequireDefault', () => { - describe('returns the same result as the original', () => { - const expectedOutputs: Record = { - withESModuleFlag: withESModuleFlag, - withESModuleFlagAndDefault: withESModuleFlagAndDefault, - namedExports: { default: namedExports }, - withNonEnumerableProp: { default: withNonEnumerableProp }, - withDefaultExport: { default: withDefaultExport }, - withOnlyDefaultExport: { default: withOnlyDefaultExport }, - exportsEquals: { default: exportsEquals }, - exportsEqualsWithDefault: { default: exportsEqualsWithDefault }, - }; - - const testCases = makeTestCases(expectedOutputs); - - it.each(testCases)('%s', (_, requireResult, expectedOutput) => { - expect(_interopRequireDefault(requireResult)).toEqual(_interopRequireDefaultOrig(requireResult)); - expect(_interopRequireDefault(requireResult)).toEqual(expectedOutput); - }); - }); -}); diff --git a/packages/utils/test/buildPolyfills/originals.d.ts b/packages/utils/test/buildPolyfills/originals.d.ts index 323d6f26e93c..c2032b265476 100644 --- a/packages/utils/test/buildPolyfills/originals.d.ts +++ b/packages/utils/test/buildPolyfills/originals.d.ts @@ -8,16 +8,6 @@ export function _asyncNullishCoalesce(lhs: any, rhsFn: any): Promise; export function _asyncOptionalChain(ops: any): Promise; export function _asyncOptionalChainDelete(ops: any): Promise; -export function _createNamedExportFrom(obj: any, localName: any, importedName: any): void; -export function _createStarExport(obj: any): void; -export function _interopDefault(e: any): any; -export function _interopNamespace(e: any): any; -export function _interopNamespaceDefaultOnly(e: any): { - __proto__: any; - default: any; -}; -export function _interopRequireDefault(obj: any): any; -export function _interopRequireWildcard(obj: any): any; export function _nullishCoalesce(lhs: any, rhsFn: any): any; export function _optionalChain(ops: any): any; export function _optionalChainDelete(ops: any): any; diff --git a/packages/utils/test/buildPolyfills/originals.js b/packages/utils/test/buildPolyfills/originals.js index 969591755367..5ec688de93ac 100644 --- a/packages/utils/test/buildPolyfills/originals.js +++ b/packages/utils/test/buildPolyfills/originals.js @@ -40,73 +40,6 @@ export async function _asyncOptionalChainDelete(ops) { return result == null ? true : result; } -// From Sucrase -export function _createNamedExportFrom(obj, localName, importedName) { - Object.defineProperty(exports, localName, { enumerable: true, get: () => obj[importedName] }); -} - -// From Sucrase -export function _createStarExport(obj) { - Object.keys(obj) - .filter(key => key !== 'default' && key !== '__esModule') - .forEach(key => { - // eslint-disable-next-line no-prototype-builtins - if (exports.hasOwnProperty(key)) { - return; - } - Object.defineProperty(exports, key, { enumerable: true, get: () => obj[key] }); - }); -} - -// From Rollup -export function _interopDefault(e) { - return e && e.__esModule ? e['default'] : e; -} - -// From Rollup -export function _interopNamespace(e) { - if (e && e.__esModule) return e; - var n = Object.create(null); - if (e) { - // eslint-disable-next-line guard-for-in - for (var k in e) { - n[k] = e[k]; - } - } - n['default'] = e; - return n; -} - -export function _interopNamespaceDefaultOnly(e) { - return { - __proto__: null, - default: e, - }; -} - -// From Sucrase -export function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { default: obj }; -} - -// From Sucrase -export function _interopRequireWildcard(obj) { - if (obj && obj.__esModule) { - return obj; - } else { - var newObj = {}; - if (obj != null) { - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - newObj[key] = obj[key]; - } - } - } - newObj.default = obj; - return newObj; - } -} - // From Sucrase export function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { diff --git a/rollup/plugins/extractPolyfillsPlugin.js b/rollup/plugins/extractPolyfillsPlugin.js index e7b83b23dd35..134f39c64bdb 100644 --- a/rollup/plugins/extractPolyfillsPlugin.js +++ b/rollup/plugins/extractPolyfillsPlugin.js @@ -7,13 +7,6 @@ const POLYFILL_NAMES = new Set([ '_asyncNullishCoalesce', '_asyncOptionalChain', '_asyncOptionalChainDelete', - '_createNamedExportFrom', - '_createStarExport', - '_interopDefault', // rollup's version - '_interopNamespace', // rollup's version - '_interopNamespaceDefaultOnly', - '_interopRequireDefault', // sucrase's version - '_interopRequireWildcard', // sucrase's version '_nullishCoalesce', '_optionalChain', '_optionalChainDelete',