Skip to content

Commit f85ba69

Browse files
authored
Merge pull request #67 from arethetypeswrong/bug/false-export-default
Fix false positive of FalseExportDefault
2 parents aa8698f + c8993b9 commit f85ba69

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

.changeset/gentle-cows-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": patch
3+
---
4+
5+
Fix a false positive of FalseExportDefault on packages that assign both to module.exports and module.exports.default

packages/cli/test/snapshots/[email protected]

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
$ attw [email protected] -f table-flipped
55
66
7-
❗️ The resolved types use export default where the JavaScript file appears to use module.exports =. This will cause TypeScript under the node16 module mode to think an extra .default property access is required, but that will likely fail at runtime. These types should use export = instead of export default. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseExportDefault.md
7+
No problems found 🌟
88
99
10-
┌───────┬────────┬───────────────────┬──────────────────────────────┬─────────┐
11-
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
12-
├───────┼────────┼───────────────────┼──────────────────────────────┼─────────┤
13-
│ "ajv" │ 🟢 │ 🟢 (CJS) │ ❗️ Incorrect default export │ 🟢 │
14-
└───────┴────────┴───────────────────┴──────────────────────────────┴─────────┘
10+
┌───────┬────────┬───────────────────┬───────────────────┬─────────┐
11+
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
12+
├───────┼────────┼───────────────────┼───────────────────┼─────────┤
13+
│ "ajv" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
14+
└───────┴────────┴───────────────────┴───────────────────┴─────────┘
1515
1616
1717
```
1818

19-
Exit code: 1
19+
Exit code: 0

packages/core/src/checks/entrypointResolutionProblems.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ export function getEntrypointResolutionProblems(
8282
}
8383
const jsExports = jsSourceFile?.symbol?.exports;
8484
if (typesExports && jsExports) {
85-
if (typesExports.has(ts.InternalSymbolName.Default) && jsExports.has(ts.InternalSymbolName.ExportEquals)) {
85+
if (
86+
typesExports.has(ts.InternalSymbolName.Default) &&
87+
!typesExports.has(ts.InternalSymbolName.ExportEquals) &&
88+
jsExports.has(ts.InternalSymbolName.ExportEquals) &&
89+
!jsExports.has(ts.InternalSymbolName.Default)
90+
) {
8691
// Also need to check for `default` property on `jsModule["export="]`?
8792
problems.push({
8893
kind: "FalseExportDefault",

packages/core/test/snapshots/[email protected]

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,5 @@
33
## Problems
44

55
```json
6-
[
7-
{
8-
"kind": "FalseExportDefault",
9-
"entrypoint": ".",
10-
"resolutionKind": "node16-esm"
11-
}
12-
]
6+
[]
137
```

0 commit comments

Comments
 (0)