@@ -112,10 +112,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
112
112
if (
113
113
allowConstantExport &&
114
114
init &&
115
- ( init . type === "Literal" || // 1, "foo"
116
- init . type === "UnaryExpression" || // -1
117
- init . type === "TemplateLiteral" || // `Some ${template}`
118
- init . type === "BinaryExpression" ) // 24 * 60
115
+ constantExportExpressions . has ( skipTSWrapper ( init ) . type )
119
116
) {
120
117
return ;
121
118
}
@@ -223,11 +220,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
223
220
context . report ( { messageId : "exportAll" , node } ) ;
224
221
} else if ( node . type === "ExportDefaultDeclaration" ) {
225
222
hasExports = true ;
226
- const declaration =
227
- node . declaration . type === "TSAsExpression" ||
228
- node . declaration . type === "TSSatisfiesExpression"
229
- ? node . declaration . expression
230
- : node . declaration ;
223
+ const declaration = skipTSWrapper ( node . declaration ) ;
231
224
if (
232
225
declaration . type === "VariableDeclaration" ||
233
226
declaration . type === "FunctionDeclaration" ||
@@ -301,7 +294,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
301
294
} ,
302
295
} ;
303
296
297
+ const skipTSWrapper = < T extends TSESTree . Node > ( node : T ) => {
298
+ if ( node . type === "TSAsExpression" || node . type === "TSSatisfiesExpression" ) {
299
+ return node . expression ;
300
+ }
301
+ return node ;
302
+ } ;
303
+
304
304
type ToString < T > = T extends `${infer V } ` ? V : never ;
305
+ const constantExportExpressions = new Set <
306
+ ToString < TSESTree . Expression [ "type" ] >
307
+ > ( [
308
+ "Literal" , // 1, "foo"
309
+ "UnaryExpression" , // -1
310
+ "TemplateLiteral" , // `Some ${template}`
311
+ "BinaryExpression" , // 24 * 60
312
+ ] ) ;
305
313
const notReactComponentExpression = new Set <
306
314
ToString < TSESTree . Expression [ "type" ] >
307
315
> ( [
0 commit comments