From 9600308108daa60c142a5a6fddc9c6ef94c12b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 15 Nov 2022 17:05:43 +0900 Subject: [PATCH] feat(css/parser): Add `parse_string_input` (#6441) --- crates/swc_css_parser/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/swc_css_parser/src/lib.rs b/crates/swc_css_parser/src/lib.rs index e6ac6451e75d..c026f2302b73 100644 --- a/crates/swc_css_parser/src/lib.rs +++ b/crates/swc_css_parser/src/lib.rs @@ -49,7 +49,22 @@ pub fn parse_file<'a, T>( where Parser>>: Parse, { - let lexer = Lexer::new(StringInput::from(fm), config); + parse_string_input(StringInput::from(fm), config, errors) +} + +/// Parse a given [StringInput] as `T`. +/// +/// If there are syntax errors but if it was recoverable, it will be appended +/// to `errors`. +pub fn parse_string_input<'a, T>( + input: StringInput<'a>, + config: ParserConfig, + errors: &mut Vec, +) -> PResult +where + Parser>>: Parse, +{ + let lexer = Lexer::new(input, config); let mut parser = Parser::new(lexer, config); let res = parser.parse();