summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-01-08 18:50:52 +0100
committerGitHub <noreply@github.com>2024-01-08 17:50:52 +0000
commit040fdeec0bada9883e0d87bb6bb95651dda1769f (patch)
tree9a9b17e5a5b894dc1acd74eebf026749329bffbf
parente212e1fc35ddae63f457f0f2a2e95154e008941f (diff)
fix: cjs export rewritten to invalid identifier (#21853)
<!-- Before submitting a PR, please read https://deno.com/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> Fixes https://github.com/denoland/deno/issues/21836
-rw-r--r--ext/node/analyze.rs14
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(),
]
)
}