export function genTemplates(
templates: string[],
rootIndex: number | undefined,
- { helper }: CodegenContext,
+ { helper, ir: { templateNS } }: CodegenContext,
): string {
return templates
- .map(
- (template, i) =>
- `const t${i} = ${helper('template')}(${JSON.stringify(
- template,
- )}${i === rootIndex ? ', true' : ''})\n`,
- )
+ .map((template, i) => {
+ const ns = templateNS.get(template)
+ return `const t${i} = ${helper('template')}(${JSON.stringify(
+ template,
+ )}${i === rootIndex ? ', true' : ns ? ', false' : ''}${ns ? `, ${ns}` : ''})\n`
+ })
.join('')
}
node: RootNode
source: string
template: string[]
+ templateNS: Map<string, number>
rootTemplateIndex?: number
component: Set<string>
directive: Set<string>
type ElementNode,
ElementTypes,
NodeTypes,
+ type PlainElementNode,
type RootNode,
type SimpleExpressionNode,
type TemplateChildNode,
>
template: string = ''
+ templateNS: Map<string, number> = new Map<string, number>()
childrenTemplate: (string | null)[] = []
dynamic: IRDynamicInfo = this.ir.block.dynamic
}
enterBlock(ir: BlockIRNode, isVFor: boolean = false): () => void {
- const { block, template, dynamic, childrenTemplate, slots } = this
+ const { block, template, templateNS, dynamic, childrenTemplate, slots } =
+ this
this.block = ir
this.dynamic = ir.dynamic
this.template = ''
+ this.templateNS = new Map<string, number>()
this.childrenTemplate = []
this.slots = []
isVFor && this.inVFor++
this.registerTemplate()
this.block = block
this.template = template
+ this.templateNS = templateNS
this.dynamic = dynamic
this.childrenTemplate = childrenTemplate
this.slots = slots
)
if (existing !== -1) return existing
this.ir.template.push(content)
+ this.ir.templateNS.set(content, (this.node as PlainElementNode).ns)
return this.ir.template.length - 1
}
registerTemplate(): number {
node,
source: node.source,
template: [],
+ templateNS: new Map<string, number>(),
component: new Set(),
directive: new Set(),
block: newBlock(node),
vModelSelectInit,
vModelSetSelected,
} from './directives/vModel'
+/**
+ * @internal
+ */
+export { svgNS, mathmlNS } from './nodeOps'
+import { mathmlNS, svgNS } from '@vue/runtime-dom'
import { adoptTemplate, currentHydrationNode, isHydrating } from './hydration'
import { child, createTextNode } from './node'
let t: HTMLTemplateElement
+let st: HTMLTemplateElement
+let mt: HTMLTemplateElement
/*! #__NO_SIDE_EFFECTS__ */
-export function template(html: string, root?: boolean) {
+export function template(html: string, root?: boolean, ns?: number) {
let node: Node
return (): Node & { $root?: true } => {
if (isHydrating) {
return createTextNode(html)
}
if (!node) {
- t = t || document.createElement('template')
- t.innerHTML = html
- node = child(t.content)
+ if (!ns) {
+ t = t || document.createElement('template')
+ t.innerHTML = html
+ node = child(t.content)
+ } else if (ns === 1) {
+ st = st || document.createElementNS(svgNS, 'template')
+ st.innerHTML = html
+ node = child(st)
+ } else {
+ mt = mt || document.createElementNS(mathmlNS, 'template')
+ mt.innerHTML = html
+ node = child(mt)
+ }
}
const ret = node.cloneNode(true)
if (root) (ret as any).$root = true