Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export type FireObject = {

const SHOW_ELEMENT = 1;
const SHOW_COMMENT = 128;
const ELEMENT_NODE = 1;
const COMMENT_NODE = 8;
const MARKO_SCRIPT_REG = /\b\$MC\b|\bM\._\b|\("M"\)\("_"\)/;

export function normalize<T extends DocumentFragment | Element>(container: T) {
const idMap: Map<string, number> = new Map();
Expand All @@ -52,7 +54,7 @@ export function normalize<T extends DocumentFragment | Element>(container: T) {
let nextNode = commentAndElementWalker.nextNode();
while ((node = nextNode as Comment | Element)) {
nextNode = commentAndElementWalker.nextNode();
if (isComment(node)) {
if (isComment(node) || isMarkoScript(node)) {
node.remove();
} else {
const { id, attributes } = node;
Expand Down Expand Up @@ -184,3 +186,16 @@ function waitForBatchedUpdates() {
function isComment(node: Node): node is Comment {
return node.nodeType === COMMENT_NODE;
}

function isElement(node: Node): node is HTMLElement {
return node.nodeType === ELEMENT_NODE;
}

function isMarkoScript(node: Node): node is HTMLScriptElement {
return (
isElement(node) &&
node.tagName === "SCRIPT" &&
!(node as HTMLScriptElement).src &&
MARKO_SCRIPT_REG.test(node.textContent || "")
);
}