Skip to content

Instantly share code, notes, and snippets.

@stormslowly
Created March 21, 2024 09:43
Show Gist options
  • Save stormslowly/05d555bd2e3bec0323826b8b11875eec to your computer and use it in GitHub Desktop.
Save stormslowly/05d555bd2e3bec0323826b8b11875eec to your computer and use it in GitHub Desktop.
swc_css_parser_memory_leak_example
use swc_core::common::{FileName, SourceMap};
use swc_core::common::input::StringInput;
use swc_core::common::sync::Lrc;
use swc_core::css::parser::{parser, lexer};
fn main() {
let cm = Lrc::<SourceMap>::default();
let fm = cm.new_source_file(
FileName::Custom("test.css".into()),
r#"
.a {
:global('.b') {
color: red;
}
}
"#.into(),
);
let config = parser::ParserConfig {
css_modules: true,
legacy_ie: true,
..Default::default()
};
let lexer = lexer::Lexer::new(StringInput::from(&*fm), None, config);
let mut parser = parser::Parser::new(lexer, config);
let parse_result = parser.parse_all();
println!("{:?}", parse_result);
}
@stormslowly
Copy link
Author

change :global('.b') -> :global(.b) , the code will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment