Skip to content

Commit 6bddc8f

Browse files
committed
fix export pattern matching
1 parent a170397 commit 6bddc8f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/idom/web/utils.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ def resolve_module_exports_from_url(url: str, max_depth: int) -> Set[str]:
6161
def resolve_module_exports_from_source(content: str) -> Tuple[Set[str], Set[str]]:
6262
names: Set[str] = set()
6363
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):
6572
export = export.rstrip(";").strip()
6673
# Exporting individual features
6774
if export.startswith("let "):
6875
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])
7376
# Renaming exports and export list
7477
elif export.startswith("{") and export.endswith("}"):
7578
names.update(
@@ -119,4 +122,12 @@ def _resolve_relative_url(base_url: str, rel_url: str) -> str:
119122
return f"{base_url}/{rel_url}"
120123

121124

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

Comments
 (0)