(text: js_data)
| 118 | |
| 119 | |
| 120 | def json_parser(text: js_data): |
| 121 | output = "" |
| 122 | reg_other = "[0-9a-zA-Z\s" + re.escape("!?$_.{}&=") + "]" |
| 123 | for data in text.children: |
| 124 | if type(data) is js_data: |
| 125 | json = json_parser(data) |
| 126 | else: |
| 127 | data = ( |
| 128 | data.replace("null==t?void 0:", "{optional}") |
| 129 | .replace("?void 0:", "{void}") |
| 130 | .replace('"private"', "{private}") |
| 131 | .replace('"none"', "{none}") |
| 132 | ) |
| 133 | placeholder = parentheses_placeholder(data) |
| 134 | json_child = "" |
| 135 | json = re.sub( |
| 136 | f"(,|^)(\.\.\.{reg_other}+)(,|$)", |
| 137 | r'\1"\2":"_"\3', |
| 138 | placeholder.text, |
| 139 | ) |
| 140 | while json_child != json: |
| 141 | json_child = json |
| 142 | json = re.sub( |
| 143 | f"(,|^)(\.\.\.{reg_other}+)(,|$)", |
| 144 | r'\1"\2":"_"\3', |
| 145 | json_child, |
| 146 | ) |
| 147 | json = re.sub( |
| 148 | f"(,|^)({reg_other}+)(:|$)", |
| 149 | r'\1"\2"\3', |
| 150 | json, |
| 151 | ) |
| 152 | json = re.sub( |
| 153 | f"(:|^)({reg_other}+)(,|$)", |
| 154 | r'\1"\2"\3', |
| 155 | json, |
| 156 | ) |
| 157 | args = [ |
| 158 | "(" + parsed.replace('"', '\\"') + ")" for parsed in placeholder.list |
| 159 | ] |
| 160 | json = json.format( |
| 161 | *args, |
| 162 | optional="(optional) ", |
| 163 | void="?void 0:", |
| 164 | private="private", |
| 165 | none="none", |
| 166 | ) |
| 167 | output += json |
| 168 | output = output.replace(':"_"{', ":{") |
| 169 | return "{" + output + "}" |
| 170 | |
| 171 | |
| 172 | def parentheses_placeholder(text: str): |
no test coverage detected