mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
refactor: NodeCodeTranslator - optional source to translate_cjs_to_esm (#20000)
This commit is contained in:
parent
6b74a6f0b6
commit
99daad0541
2 changed files with 3 additions and 5 deletions
|
@ -782,7 +782,7 @@ impl NpmModuleLoader {
|
||||||
// translate cjs to esm if it's cjs and inject node globals
|
// translate cjs to esm if it's cjs and inject node globals
|
||||||
self.node_code_translator.translate_cjs_to_esm(
|
self.node_code_translator.translate_cjs_to_esm(
|
||||||
specifier,
|
specifier,
|
||||||
&code,
|
Some(code.as_str()),
|
||||||
permissions,
|
permissions,
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -72,15 +72,13 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer> NodeCodeTranslator<TCjsCodeAnalyzer> {
|
||||||
pub fn translate_cjs_to_esm(
|
pub fn translate_cjs_to_esm(
|
||||||
&self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
source: &str,
|
source: Option<&str>,
|
||||||
permissions: &dyn NodePermissions,
|
permissions: &dyn NodePermissions,
|
||||||
) -> Result<String, AnyError> {
|
) -> Result<String, AnyError> {
|
||||||
let mut temp_var_count = 0;
|
let mut temp_var_count = 0;
|
||||||
let mut handled_reexports: HashSet<String> = HashSet::default();
|
let mut handled_reexports: HashSet<String> = HashSet::default();
|
||||||
|
|
||||||
let analysis = self
|
let analysis = self.cjs_code_analyzer.analyze_cjs(specifier, source)?;
|
||||||
.cjs_code_analyzer
|
|
||||||
.analyze_cjs(specifier, Some(source))?;
|
|
||||||
|
|
||||||
let mut source = vec![
|
let mut source = vec![
|
||||||
r#"import {createRequire as __internalCreateRequire} from "node:module";
|
r#"import {createRequire as __internalCreateRequire} from "node:module";
|
||||||
|
|
Loading…
Reference in a new issue