})
})
+ test('custom element', () => {
+ const ast = parse('<div></div><comp></comp>', {
+ isNativeTag: tag => tag === 'div',
+ isCustomElement: tag => tag === 'comp'
+ })
+
+ expect(ast.children[0]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'div',
+ tagType: ElementTypes.ELEMENT
+ })
+
+ expect(ast.children[1]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'comp',
+ tagType: ElementTypes.ELEMENT
+ })
+ })
+
test('attribute with no value', () => {
const ast = parse('<div id></div>')
const element = ast.children[0] as ElementNode
export interface ParserOptions {
isVoidTag?: (tag: string) => boolean // e.g. img, br, hr
isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex
+ isCustomElement?: (tag: string) => boolean
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
getTextMode?: (tag: string, ns: Namespace) => TextModes
delimiters?: [string, string] // ['{{', '}}']
getNamespace: () => Namespaces.HTML,
getTextMode: () => TextModes.DATA,
isVoidTag: NO,
+ isCustomElement: NO,
namedCharacterReferences: {
'gt;': '>',
'lt;': '<',
}
let tagType = ElementTypes.ELEMENT
- if (!context.inPre) {
+ if (!context.inPre && !context.options.isCustomElement(tag)) {
if (context.options.isNativeTag) {
if (!context.options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
} else {
devtools: boolean
performance: boolean
readonly isNativeTag?: (tag: string) => boolean
+ isCustomElement?: (tag: string) => boolean
errorHandler?: (
err: Error,
instance: ComponentPublicInstance | null,
devtools: true,
performance: false,
isNativeTag: NO,
+ isCustomElement: NO,
errorHandler: undefined,
warnHandler: undefined
},
if (__RUNTIME_COMPILE__ && Component.template && !Component.render) {
if (compile) {
Component.render = compile(Component.template, {
+ isCustomElement: instance.appContext.config.isCustomElement || NO,
onError(err: CompilerError) {
if (__DEV__) {
const message = `Template compilation error: ${err.message}`
expect(classes.contains('test')).toBe(true)
expect(classes.contains('test2')).toBe(false)
})
+
+it('should support custom element', () => {
+ const app = createApp()
+ const container = document.createElement('div')
+ const App = {
+ template: '<custom></custom>'
+ }
+ app.config.isCustomElement = tag => tag === 'custom'
+ app.mount(App, container)
+ expect(container.innerHTML).toBe('<custom></custom>')
+})