diff options
Diffstat (limited to 'ext/node/analyze.rs')
| -rw-r--r-- | ext/node/analyze.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/ext/node/analyze.rs b/ext/node/analyze.rs index d811122d5..cf292d82f 100644 --- a/ext/node/analyze.rs +++ b/ext/node/analyze.rs @@ -29,10 +29,15 @@ pub struct CjsAnalysis { pub trait CjsCodeAnalyzer { /// Analyzes CommonJs code for exports and reexports, which is /// then used to determine the wrapper ESM module exports. + /// + /// Note that the source is provided by the caller when the caller + /// already has it. If the source is needed by the implementation, + /// then it can use the provided source, or otherwise load it if + /// necessary. fn analyze_cjs( &self, specifier: &ModuleSpecifier, - source: &str, + maybe_source: Option<&str>, ) -> Result<CjsAnalysis, AnyError>; } @@ -73,7 +78,9 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer> NodeCodeTranslator<TCjsCodeAnalyzer> { let mut temp_var_count = 0; let mut handled_reexports: HashSet<String> = HashSet::default(); - let analysis = self.cjs_code_analyzer.analyze_cjs(specifier, source)?; + let analysis = self + .cjs_code_analyzer + .analyze_cjs(specifier, Some(source))?; let mut source = vec