mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
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
This commit is contained in:
parent
e212e1fc35
commit
040fdeec0b
1 changed files with 13 additions and 1 deletions
|
@ -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(),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue