mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
updated comment explaining the regex
This commit is contained in:
parent
f3fc45f119
commit
5c730e8b95
@ -466,11 +466,20 @@ function convertHtmlToReact(node, context) {
|
||||
* @throws {String} the part of the string that failed to parse
|
||||
*/
|
||||
function parseScopeSyntax(text) {
|
||||
// in plain english, this regex scans for:
|
||||
// any character + one or more space + "as" + one or more space + JavaScript identifier +
|
||||
// zero or more space + semicolon or end of line + zero or more space
|
||||
// it captures "any character" as the scope expression, "JavaScript identifier" as the identifier
|
||||
const regex = RegExp('([\\s\\S]*?)(?: )+as(?: )+([$_a-zA-Z]+[$_a-zA-Z0-9]*)(?: )*(?:;|$)(?: )*', 'g');
|
||||
// the regex below was built using the following pseudo-code:
|
||||
// double_quoted_string = `"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"`
|
||||
// single_quoted_string = `'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'`
|
||||
// text_out_of_quotes = `[^"']*?`
|
||||
// expr_parts = double_quoted_string + "|" + single_quoted_string + "|" + text_out_of_quotes
|
||||
// expression = zeroOrMore(nonCapture(expr_parts)) + "?"
|
||||
// id = "[$_a-zA-Z]+[$_a-zA-Z0-9]*"
|
||||
// as = " as" + OneOrMore(" ")
|
||||
// optional_spaces = zeroOrMore(" ")
|
||||
// semicolon = nonCapture(or(text(";"), "$"))
|
||||
//
|
||||
// regex = capture(expression) + as + capture(id) + optional_spaces + semicolon + optional_spaces
|
||||
|
||||
const regex = RegExp("((?:(?:\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|[^\"']*?))*?) as(?: )+([$_a-zA-Z]+[$_a-zA-Z0-9]*)(?: )*(?:;|$)(?: )*", 'g');
|
||||
const res = [];
|
||||
do {
|
||||
const idx = regex.lastIndex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user