diff --git a/README.md b/README.md index 1502463..ee5a191 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ However, there are some syntax requirements for speed and sanity reasons. ### Tags -Tag names are case sensitive. For example, this means that `P` won't be recognised as a content element +Tag names are case sensitive. For example, this means that `P` won't be recognised as a content element, `bR` won't be considered as a void tag, and `Script` won't be parsed as JavaScript. ### Entities @@ -266,7 +266,7 @@ It is an error to place whitespace between `=` and attribute names/values. It is
``` -Special handling of some attributes require case sensitive names and values. For example, `class` and `type="text/javascript"`. +Special handling of some attributes require case sensitive names and values. For example, `CLASS` won't be recognised as an attribute to minify and `type="Text/JavaScript"` on a `. - // TODO WARNING: Closing tag must not contain whitespace. // TODO Optimise while !chain!(proc.match_line_terminator().keep().matched()) { if chain!(proc.match_seq(b"").matched()) { @@ -23,10 +26,13 @@ fn parse_comment_single(proc: &mut Processor) -> ProcessingResult<()> { } fn parse_comment_multi(proc: &mut Processor) -> ProcessingResult<()> { - chain!(proc.match_seq(b"/*").expect().keep()); + if cfg!(debug_assertions) { + chain!(proc.match_seq(b"/*").expect().keep()); + } else { + proc.skip_amount_expect(2); + }; // Comment can end at closing . - // TODO WARNING: Closing tag must not contain whitespace. // TODO Optimise while !chain!(proc.match_seq(b"*/").keep().matched()) { if chain!(proc.match_seq(b"").matched()) { @@ -40,7 +46,11 @@ fn parse_comment_multi(proc: &mut Processor) -> ProcessingResult<()> { } fn parse_string(proc: &mut Processor) -> ProcessingResult<()> { - let delim = chain!(proc.match_pred(is_string_delimiter).expect().keep().char()); + let delim = if cfg!(debug_assertions) { + chain!(proc.match_pred(is_string_delimiter).expect().keep().char()) + } else { + proc.accept_expect() + }; let mut escaping = false; @@ -69,7 +79,11 @@ fn parse_string(proc: &mut Processor) -> ProcessingResult<()> { } fn parse_template(proc: &mut Processor) -> ProcessingResult<()> { - chain!(proc.match_char(b'`').expect().keep()); + if cfg!(debug_assertions) { + chain!(proc.match_char(b'`').expect().keep()); + } else { + proc.skip_expect(); + }; let mut escaping = false; diff --git a/src/unit/script/text.rs b/src/unit/script/text.rs index 59087b0..add11a4 100644 --- a/src/unit/script/text.rs +++ b/src/unit/script/text.rs @@ -14,12 +14,11 @@ pub fn process_text_script(proc: &mut Processor) -> ProcessingResult<()> { comment_has_unclosed_script = false; in_comment = false; } else if in_comment && chain!(proc.match_seq(b"').require()?.keep()); comment_has_unclosed_script = true; } else if chain!(proc.match_seq(b" bool { } fn parse_comment(proc: &mut Processor) -> ProcessingResult<()> { - chain!(proc.match_seq(b"/*").expect().keep()); + if cfg!(debug_assertions) { + chain!(proc.match_seq(b"/*").expect().keep()); + } else { + proc.skip_amount_expect(2); + }; // Unlike script tags, style comments do NOT end at closing tag. while !chain!(proc.match_seq(b"*/").keep().matched()) { @@ -20,7 +24,11 @@ fn parse_comment(proc: &mut Processor) -> ProcessingResult<()> { } fn parse_string(proc: &mut Processor) -> ProcessingResult<()> { - let delim = chain!(proc.match_pred(is_string_delimiter).expect().keep().char()); + let delim = if cfg!(debug_assertions) { + chain!(proc.match_pred(is_string_delimiter).expect().keep().char()) + } else { + proc.accept_expect() + }; let mut escaping = false; diff --git a/src/unit/tag.rs b/src/unit/tag.rs index 8f8a46b..6becbe4 100644 --- a/src/unit/tag.rs +++ b/src/unit/tag.rs @@ -42,10 +42,14 @@ enum TagType { } pub fn process_tag(proc: &mut Processor) -> ProcessingResult<()> { - // TODO Minify opening and closing tag whitespace before name and after name/last attr. + // TODO Minify opening and closing tag whitespace after name and last attr. // TODO DOC No checking if opening and closing names match. // Expect to be currently at an opening tag. - chain!(proc.match_char(b'<').expect().keep()); + if cfg!(debug_assertions) { + chain!(proc.match_char(b'<').expect().keep()); + } else { + proc.skip_expect(); + }; // May not be valid tag name at current position, so require instead of expect. let opening_name_range = chain!(proc.match_while_pred(is_valid_tag_name_char).require_with_reason("tag name")?.keep().out_range());