Skip to content
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

Fix false positive of FalseExportDefault #67

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
]
[]
```