diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2023-07-24 15:35:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-24 15:35:13 -0400 |
| commit | 40008c73bb3b0b146b3539929ab5bd826db4c5e3 (patch) | |
| tree | 35c29811ce5d2a17ac31af05a231d57d36c47c53 /ext | |
| parent | d7a9ed9714c2a2c3a8c05ef020d495f5be03972a (diff) | |
refactor(ext/node): CjsCodeAnalyzer - analyze_cjs optionally pass source text (#19896)
Diffstat (limited to 'ext')
| -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