File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -329,6 +329,22 @@ impl ExactSizeIterator for ExportIter<'_, '_> {}
329329/// assert_eq!(analysis.exports_count(), 1);
330330/// assert_eq!(analysis.export_name(0), Some("hello"));
331331/// ```
332+ ///
333+ /// Export names borrow from the analysis handle, so leaking them past
334+ /// `analysis`'s lifetime is rejected at compile time:
335+ ///
336+ /// ```compile_fail
337+ /// use merve::parse_commonjs;
338+ ///
339+ /// fn main() {
340+ /// let src = "exports['\\u0061\\u0062'] = 1;";
341+ /// let leaked: &str = {
342+ /// let analysis = parse_commonjs(src).unwrap();
343+ /// analysis.export_name(0).unwrap()
344+ /// }; // `analysis` is dropped here.
345+ /// let _ = leaked;
346+ /// }
347+ /// ```
332348pub fn parse_commonjs ( source : & str ) -> Result < Analysis < ' _ > , LexerError > {
333349 if source. is_empty ( ) {
334350 return Err ( LexerError :: EmptySource ) ;
You can’t perform that action at this time.
0 commit comments