Skip to content

Commit 78f987f

Browse files
committed
Support type assertion on default export (fixes #48) [publish]
1 parent f6dbb3a commit 78f987f

6 files changed

+455
-420
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## Unreleased
3+
## 4.0.12
44

5+
- Support type assertion on default export (fixes #48)
56
- Add default export to fix usage with jiti (fixes #50)
67

78
## 0.4.11

bun.lockb

1.23 KB
Binary file not shown.

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
"scripts": {
77
"build": "scripts/bundle.ts",
88
"test": "bun test",
9-
"lint": "bun lint-ci --fix --cache",
10-
"lint-ci": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
9+
"lint": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1110
"prettier": "bun prettier-ci --write",
1211
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
13-
"ci": "tsc && bun lint-ci && bun prettier-ci && bun test && bun run build"
12+
"ci": "tsc && bun lint && bun prettier-ci && bun test && bun run build"
1413
},
14+
"prettier": {},
1515
"peerDependencies": {
1616
"eslint": ">=7"
1717
},
1818
"devDependencies": {
19-
"@arnaud-barre/eslint-config": "^4.0.0",
19+
"@arnaud-barre/eslint-config": "^4.1.1",
2020
"@arnaud-barre/tnode": "^0.19.2",
2121
"@types/eslint": "^8.44.8",
2222
"@types/node": "^20.10.2",
23-
"@typescript-eslint/parser": "^6.13.1",
24-
"@typescript-eslint/utils": "^6.13.1",
25-
"bun-types": "^1.0.15",
26-
"eslint": "^8.55.0",
23+
"@typescript-eslint/parser": "^7.18.0",
24+
"@typescript-eslint/utils": "^7.18.0",
25+
"bun-types": "^1.1.27",
26+
"eslint": "^8.57.0",
2727
"prettier": "3.0.3",
28-
"typescript": "~5.3"
28+
"typescript": "~5.4"
2929
}
3030
}

src/only-export-components.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ const valid = [
109109
name: "export default React.memo function declaration",
110110
code: "function Foo() {}; export default React.memo(Foo);",
111111
},
112+
{
113+
name: "export default React.memo function declaration with type assertion",
114+
code: "function Foo() {}; export default React.memo(Foo) as typeof Foo;",
115+
},
112116
{
113117
name: "export type *",
114118
code: "export type * from './module';",

src/only-export-components.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
200200
context.report({ messageId: "exportAll", node });
201201
} else if (node.type === "ExportDefaultDeclaration") {
202202
hasExports = true;
203+
const declaration =
204+
node.declaration.type === "TSAsExpression" ||
205+
node.declaration.type === "TSSatisfiesExpression"
206+
? node.declaration.expression
207+
: node.declaration;
203208
if (
204-
node.declaration.type === "VariableDeclaration" ||
205-
node.declaration.type === "FunctionDeclaration" ||
206-
node.declaration.type === "CallExpression"
209+
declaration.type === "VariableDeclaration" ||
210+
declaration.type === "FunctionDeclaration" ||
211+
declaration.type === "CallExpression"
207212
) {
208-
handleExportDeclaration(node.declaration);
213+
handleExportDeclaration(declaration);
209214
}
210-
if (node.declaration.type === "Identifier") {
211-
handleExportIdentifier(node.declaration);
215+
if (declaration.type === "Identifier") {
216+
handleExportIdentifier(declaration);
212217
}
213-
if (node.declaration.type === "ArrowFunctionExpression") {
218+
if (declaration.type === "ArrowFunctionExpression") {
214219
context.report({ messageId: "anonymousExport", node });
215220
}
216221
} else if (node.type === "ExportNamedDeclaration") {

0 commit comments

Comments
 (0)