-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export * should allow named export overrides #1714
Comments
Another case is that star exports should not override named exports export { customRender as render } from './customRender';
// re-export everything, but keep named 'render' exported above
export * from '@testing-library/react'; |
swc_ecma_transforms_compat: - `regenerator`: Use es6 import while folding module. (#1641) - `typeof_symbol`: Handle `undefined` specially. (#1843) - `regenerator`: Do not create useless codes. (#1687) - `typeof_symbol`: Migrate to `VisitMut`. swc_ecma_transforms_module: - Add `import_hoister`. - Improve import analyzer. (#1682) - Allow overriding `export *` wth named exports. (#1714) swc_ecma_transforms_testing: - Add a hack for `regenerator-runtime`. swc: - Run import analyzer ahead of time. (#1682) misc: - Downgrade rustc to the version rust-analyzer supports.
@kdy1 This isn't quite fixed. The code as currently output still gives a runtime error if the re-export is different from the initial export (which is the case in the example above - the aim is to override In your test (https://github.com/swc-project/swc/pull/1909/files#diff-b558773d8ee3e958908d1bdf859f470eabcd8ff82aee06841982ddcdcb6b11a2) it only checks if there is an existing export of that name with the same thing being exported ( In the babel output (REPL), it also tracks the list of named exports to not override var _exportNames = {
render: true
};
Object.keys(_react).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; // <-- This check is missing in the swc output
if (key in exports && exports[key] === _react[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _react[key];
}
});
}); Without this check, at runtime you get an error from not being able to redefine the property ( |
@kdy1 Can you reopen this, or would you like a new issue? |
I prefer a new issue, would you open one? |
Raised #2101 for this |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
When you do
export * from 'x'
and override something in*
with a named export, according to the spec the named export should override the version from*
. This pattern is recommended in e.g. https://testing-library.com/docs/react-testing-library/setupInput code
Config
Expected behavior
The transpilation should respect the behaviour that the named exports can override the wildcard exports.
e.g. Babel REPL generates the
_exportNames
and then excludes those when defining the wildcard export.Other refs:
Version
The version of @swc/core: 1.2.55
Additional context
Workaround is to not depend on this behaviour
The text was updated successfully, but these errors were encountered: