Apply one attribute to the parse decision. Returns false when the * attribute rules the block out of inline extraction: * src= always names an external program, so nothing inline is extracted, * even for malformed mixed markup; * lang= selects the JavaScript or TypeScript grammar; any other language * has no parser here; * type= plain HTML routinely carri
| 2033 | * current use pass — absent or empty, module, text/javascript, |
| 2034 | * application/javascript — and the rest bail. */ |
| 2035 | static bool apply_script_attribute(CBMExtractCtx *ctx, TSNode attribute, CBMLanguage *language) { |
| 2036 | if (ts_node_named_child_count(attribute) == 0) { |
| 2037 | return false; |
| 2038 | } |
| 2039 | const char *name = cbm_node_text(ctx->arena, ts_node_named_child(attribute, 0), ctx->source); |
| 2040 | if (ascii_trimmed_equals(name, "src")) { |
| 2041 | return false; |
| 2042 | } |
| 2043 | if (ascii_trimmed_equals(name, "lang")) { |
| 2044 | const char *value = script_attribute_value(ctx, attribute); |
| 2045 | if (ascii_trimmed_equals(value, "js") || ascii_trimmed_equals(value, "javascript")) { |
| 2046 | *language = CBM_LANG_JAVASCRIPT; |
| 2047 | return true; |
| 2048 | } |
| 2049 | if (ascii_trimmed_equals(value, "ts") || ascii_trimmed_equals(value, "typescript")) { |
| 2050 | *language = CBM_LANG_TYPESCRIPT; |
| 2051 | return true; |
| 2052 | } |
| 2053 | return false; |
| 2054 | } |
| 2055 | if (ascii_trimmed_equals(name, "type")) { |
| 2056 | const char *value = script_attribute_value(ctx, attribute); |
| 2057 | return ascii_trimmed_equals(value, "") || ascii_trimmed_equals(value, "module") || |
| 2058 | ascii_trimmed_equals(value, "text/javascript") || |
| 2059 | ascii_trimmed_equals(value, "application/javascript"); |
| 2060 | } |
| 2061 | return true; |
| 2062 | } |
| 2063 | |
| 2064 | /* Markup hosts (Vue, Svelte, HTML, Astro) hang the attributes that decide |
| 2065 | * whether and how an inline program is parsed off the <script> start tag. |
no test coverage detected