Unverified Commit 9342a6cc authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

feat(next-swc/auto-cjs): Detect `__esModule` (#38181)



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

---

 - Closes #38117 
parent 883a52ed
......@@ -30,4 +30,10 @@ impl Visit for CjsFinder {
e.obj.visit_with(self);
e.prop.visit_with(self);
}
fn visit_str(&mut self, s: &Str) {
if s.value.contains("__esModule") {
self.found = true;
}
}
}
......@@ -202,8 +202,9 @@ impl TransformOptions {
pub fn patch(mut self, fm: &SourceFile) -> Self {
self.swc.swcrc = false;
let should_enable_commonjs =
self.swc.config.module.is_none() && fm.src.contains("module.exports") && {
let should_enable_commonjs = self.swc.config.module.is_none()
&& (fm.src.contains("module.exports") || fm.src.contains("__esModule"))
&& {
let syntax = self.swc.config.jsc.syntax.unwrap_or_default();
let target = self.swc.config.jsc.target.unwrap_or_else(EsVersion::latest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment