Skip to content

Commit

Permalink
Merge pull request #152 from arethetypeswrong/bundler-missing-export-…
Browse files Browse the repository at this point in the history
…equals

Don’t run MissingExportEquals on ESM implementation files
  • Loading branch information
andrewbranch authored Feb 21, 2024
2 parents b596e74 + e38ed65 commit f95f1a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hot-gorillas-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arethetypeswrong/core": patch
---

Fix false positive MissingExportEquals that can occur when `--moduleResolution bundler` resolves to ESM JS
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineCheck({
}
const implementationSourceFile = host.getSourceFile(implementationFileName)!;
ts.bindSourceFile(implementationSourceFile, bindOptions);
if (!implementationSourceFile.symbol?.exports) {
if (!implementationSourceFile.symbol?.exports || implementationSourceFile.externalModuleIndicator) {
return;
}

Expand Down Expand Up @@ -115,6 +115,7 @@ export default defineCheck({
};
}

// TODO: does not account for export *
const typesHaveNonDefaultValueExport = Array.from(typesSourceFile.symbol.exports.values()).some((s) => {
if (s.escapedName === "default") {
return false;
Expand Down
18 changes: 18 additions & 0 deletions packages/core/test/problems/exportDefaultDisagreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,22 @@ var index_default = { a, b };`,
),
);
});

test("does not run on ESM", () => {
assert(
isOk(
`export * from 'foo';
declare const _default: { Type: string, Schema: string };
export default _default;`,
`var Type = "Type";
var Schema = "Schema";
var jsYaml = {
Type,
Schema
};
export default jsYaml;
export { Type, Schema };`,
),
);
});
});

0 comments on commit f95f1a4

Please sign in to comment.