Created
March 21, 2024 09:43
-
-
Save stormslowly/05d555bd2e3bec0323826b8b11875eec to your computer and use it in GitHub Desktop.
swc_css_parser_memory_leak_example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change :global('.b') -> :global(.b) , the code will work