Skip to content

Commit

Permalink
Merge pull request #67 from arethetypeswrong/bug/false-export-default
Browse files Browse the repository at this point in the history
Fix false positive of FalseExportDefault
  • Loading branch information
andrewbranch authored Jul 15, 2023
2 parents aa8698f + c8993b9 commit f85ba69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-cows-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arethetypeswrong/core": patch
---

Fix a false positive of FalseExportDefault on packages that assign both to module.exports and module.exports.default
14 changes: 7 additions & 7 deletions packages/cli/test/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
$ attw [email protected] -f table-flipped
❗️ 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
No problems found 🌟
┌───────┬────────┬───────────────────┬──────────────────────────────┬─────────┐
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
├───────┼────────┼───────────────────┼──────────────────────────────┼─────────┤
│ "ajv" │ 🟢 │ 🟢 (CJS) │ ❗️ Incorrect default export │ 🟢 │
└───────┴────────┴───────────────────┴──────────────────────────────┴─────────┘
┌───────┬────────┬───────────────────┬───────────────────┬─────────┐
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
├───────┼────────┼───────────────────┼───────────────────┼─────────┤
│ "ajv" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │
└───────┴────────┴───────────────────┴───────────────────┴─────────┘
```

Exit code: 1
Exit code: 0
7 changes: 6 additions & 1 deletion packages/core/src/checks/entrypointResolutionProblems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ export function getEntrypointResolutionProblems(
}
const jsExports = jsSourceFile?.symbol?.exports;
if (typesExports && jsExports) {
if (typesExports.has(ts.InternalSymbolName.Default) && jsExports.has(ts.InternalSymbolName.ExportEquals)) {
if (
typesExports.has(ts.InternalSymbolName.Default) &&
!typesExports.has(ts.InternalSymbolName.ExportEquals) &&
jsExports.has(ts.InternalSymbolName.ExportEquals) &&
!jsExports.has(ts.InternalSymbolName.Default)
) {
// Also need to check for `default` property on `jsModule["export="]`?
problems.push({
kind: "FalseExportDefault",
Expand Down
8 changes: 1 addition & 7 deletions packages/core/test/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
## Problems

```json
[
{
"kind": "FalseExportDefault",
"entrypoint": ".",
"resolutionKind": "node16-esm"
}
]
[]
```

0 comments on commit f85ba69

Please sign in to comment.