Skip to content

Commit 06b4703

Browse files
committed
element namespace should be resolved at runtime for render function / jsx usage
1 parent f20b1a8 commit 06b4703

File tree

7 files changed

+27
-28
lines changed

7 files changed

+27
-28
lines changed

src/compiler/codegen.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ function genElement (el: ASTElement): string {
6565
? genChildren(el, !el.ns && !isPlatformReservedTag(el.tag) /* asThunk */)
6666
: null
6767
code = `_h('${el.tag}'${
68-
data ? `,${data}` : (children || el.ns) ? ',void 0' : '' // data
68+
data ? `,${data}` : children ? ',void 0' : '' // data
6969
}${
7070
children ? `,${children}` : '' // children
71-
}${
72-
el.ns ? `,'${el.ns}'` : '' // namespace
7371
})`
7472
}
7573
// module transforms

src/core/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { no } from 'shared/util'
3+
import { no, noop } from 'shared/util'
44

55
export type Config = {
66
// user
@@ -13,6 +13,7 @@ export type Config = {
1313
// platform
1414
isReservedTag: (x?: string) => boolean,
1515
isUnknownElement: (x?: string) => boolean,
16+
getTagNamespace: (x?: string) => string | void,
1617
mustUseProp: (x?: string) => boolean,
1718
// internal
1819
_assetTypes: Array<string>,
@@ -64,6 +65,11 @@ const config: Config = {
6465
*/
6566
isUnknownElement: no,
6667

68+
/**
69+
* Get the namespace of an element
70+
*/
71+
getTagNamespace: noop,
72+
6773
/**
6874
* Check if an attribute must be bound using property, e.g. value
6975
* Platform-dependent.

src/core/vdom/create-element.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { warn, resolveAsset } from '../util/index'
1010
export function createElement (
1111
tag?: string | Class<Component> | Function | Object,
1212
data?: VNodeData,
13-
children?: VNodeChildren | void,
14-
namespace?: string
13+
children?: VNodeChildren | void
1514
): VNode | Array<VNode> | void {
1615
// make sure to expose real self instead of proxy
1716
const context: Component = this._self
@@ -29,10 +28,11 @@ export function createElement (
2928
return emptyVNode()
3029
}
3130
if (typeof tag === 'string') {
31+
const namespace = config.getTagNamespace(tag)
3232
let Ctor
3333
if (config.isReservedTag(tag)) {
3434
return new VNode(
35-
tag, data, normalizeChildren(children),
35+
tag, data, normalizeChildren(children, namespace),
3636
undefined, undefined,
3737
namespace, context, host
3838
)
@@ -53,7 +53,7 @@ export function createElement (
5353
}
5454
}
5555
return new VNode(
56-
tag, data, normalizeChildren(children),
56+
tag, data, normalizeChildren(children, namespace),
5757
undefined, undefined,
5858
namespace, context, host
5959
)

src/core/vdom/helpers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import { isPrimitive } from '../util/index'
44
import VNode from './vnode'
55

6-
export function normalizeChildren (children: any): Array<VNode> | void {
6+
export function normalizeChildren (
7+
children: any,
8+
ns: string | void
9+
): Array<VNode> | void {
710
// invoke children thunks.
811
// components always receive their children as thunks so that they
912
// can perform the actual render inside their own dependency collection cycle.
@@ -32,6 +35,8 @@ export function normalizeChildren (children: any): Array<VNode> | void {
3235
if (c.text && last && last.text) {
3336
last.text += c.text
3437
} else {
38+
// inherit parent namespace
39+
if (ns && c.tag) c.ns = ns
3540
res.push(c)
3641
}
3742
}

src/core/vdom/vnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class VNode {
2121
children?: Array<VNode> | void,
2222
text?: string,
2323
elm?: Node,
24-
ns?: string,
24+
ns?: string | void,
2525
context?: Component,
2626
host?: ?Component,
2727
componentOptions?: VNodeComponentOptions

src/entries/web-runtime.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ import { devtools, inBrowser } from 'core/util/index'
77
import { patch } from 'web/runtime/patch'
88
import platformDirectives from 'web/runtime/directives/index'
99
import platformComponents from 'web/runtime/components/index'
10-
import { query, isUnknownElement, isReservedTag, mustUseProp } from 'web/util/index'
10+
import {
11+
query,
12+
isUnknownElement,
13+
isReservedTag,
14+
getTagNamespace,
15+
mustUseProp
16+
} from 'web/util/index'
1117

1218
// install platform specific utils
1319
Vue.config.isUnknownElement = isUnknownElement
1420
Vue.config.isReservedTag = isReservedTag
21+
Vue.config.getTagNamespace = getTagNamespace
1522
Vue.config.mustUseProp = mustUseProp
1623

1724
// install platform runtime directives & components

test/unit/modules/compiler/codegen.spec.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,6 @@ describe('codegen', () => {
9696
)
9797
})
9898

99-
it('generate svg tag', () => {
100-
assertCodegen(
101-
'<svg><text>hello world</text></svg>',
102-
`with(this){return _h('svg',void 0,[_h('text',void 0,["hello world"],'svg')],'svg')}`
103-
)
104-
})
105-
106-
it('generate MathML tag', () => {
107-
assertCodegen(
108-
`<math>
109-
<matrix>
110-
</matrix>
111-
</math>`,
112-
`with(this){return _h('math',void 0,[_h('matrix',void 0,'math')],'math')}`
113-
)
114-
})
115-
11699
it('generate single slot', () => {
117100
assertCodegen(
118101
'<slot></slot>',

0 commit comments

Comments
 (0)