diff options
-rw-r--r-- | ext/node/analyze.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/ext/node/analyze.rs b/ext/node/analyze.rs index 4e8ee8af4..2a0324ccf 100644 --- a/ext/node/analyze.rs +++ b/ext/node/analyze.rs @@ -392,6 +392,16 @@ fn add_export( ) { fn is_valid_var_decl(name: &str) -> bool { // it's ok to be super strict here + if name.is_empty() { + return false; + } + + if let Some(first) = name.chars().next() { + if !first.is_ascii_alphabetic() && first != '_' && first != '$' { + return false; + } + } + name .chars() .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '$') @@ -479,7 +489,7 @@ mod tests { let mut temp_var_count = 0; let mut source = vec![]; - let exports = vec!["static", "server", "app", "dashed-export"]; + let exports = vec!["static", "server", "app", "dashed-export", "3d"]; for export in exports { add_export(&mut source, export, "init", &mut temp_var_count); } @@ -492,6 +502,8 @@ mod tests { "export const app = init;".to_string(), "const __deno_export_2__ = init;".to_string(), "export { __deno_export_2__ as \"dashed-export\" };".to_string(), + "const __deno_export_3__ = init;".to_string(), + "export { __deno_export_3__ as \"3d\" };".to_string(), ] ) } |