@@ -61,15 +61,18 @@ def resolve_module_exports_from_url(url: str, max_depth: int) -> Set[str]:
61
61
def resolve_module_exports_from_source (content : str ) -> Tuple [Set [str ], Set [str ]]:
62
62
names : Set [str ] = set ()
63
63
references : Set [str ] = set ()
64
- for export in _JS_EXPORT_PATTERN .findall (content ):
64
+
65
+ if _JS_DEFAULT_EXPORT_PATTERN .search (content ):
66
+ names .add ("default" )
67
+
68
+ # Exporting functions and classes
69
+ names .update (_JS_FUNC_OR_CLS_EXPORT_PATTERN .findall (content ))
70
+
71
+ for export in _JS_GENERAL_EXPORT_PATTERN .findall (content ):
65
72
export = export .rstrip (";" ).strip ()
66
73
# Exporting individual features
67
74
if export .startswith ("let " ):
68
75
names .update (let .split ("=" , 1 )[0 ] for let in export [4 :].split ("," ))
69
- elif export .startswith ("function " ):
70
- names .add (export [9 :].split ("(" , 1 )[0 ])
71
- elif export .startswith ("class " ):
72
- names .add (export [6 :].split ("{" , 1 )[0 ])
73
76
# Renaming exports and export list
74
77
elif export .startswith ("{" ) and export .endswith ("}" ):
75
78
names .update (
@@ -119,4 +122,12 @@ def _resolve_relative_url(base_url: str, rel_url: str) -> str:
119
122
return f"{ base_url } /{ rel_url } "
120
123
121
124
122
- _JS_EXPORT_PATTERN = re .compile (r";?\s*export(?=\s+|{)(.*?(?:;|}\s*))" , re .MULTILINE )
125
+ _JS_DEFAULT_EXPORT_PATTERN = re .compile (
126
+ rf";?\s*export\s+default\s" ,
127
+ )
128
+ _JS_FUNC_OR_CLS_EXPORT_PATTERN = re .compile (
129
+ rf";?\s*export\s+(?:function|class)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)"
130
+ )
131
+ _JS_GENERAL_EXPORT_PATTERN = re .compile (
132
+ r";?\s*export(?=\s+|{)(.*?)(?:;|$)" , re .MULTILINE
133
+ )
0 commit comments