refactor: NodeCodeTranslator - optional source to translate_cjs_to_esm (#20000)

This commit is contained in:
David Sherret 2023-07-31 13:46:58 -04:00 committed by GitHub
parent 6b74a6f0b6
commit 99daad0541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View file

@ -782,7 +782,7 @@ impl NpmModuleLoader {
// translate cjs to esm if it's cjs and inject node globals
self.node_code_translator.translate_cjs_to_esm(
specifier,
&code,
Some(code.as_str()),
permissions,
)?
} else {

View file

@ -72,15 +72,13 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer> NodeCodeTranslator<TCjsCodeAnalyzer> {
pub fn translate_cjs_to_esm(
&self,
specifier: &ModuleSpecifier,
source: &str,
source: Option<&str>,
permissions: &dyn NodePermissions,
) -> Result<String, AnyError> {
let mut temp_var_count = 0;
let mut handled_reexports: HashSet<String> = HashSet::default();
let analysis = self
.cjs_code_analyzer
.analyze_cjs(specifier, Some(source))?;
let analysis = self.cjs_code_analyzer.analyze_cjs(specifier, source)?;
let mut source = vec![
r#"import {createRequire as __internalCreateRequire} from "node:module";