From 9f8f07ed38b2e003f308875fe3a3e4c0d5477b32 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 30 Aug 2022 11:30:52 +0800 Subject: [PATCH] feat(custom-elements): automatically respect custom elements when compiling in browser --- packages/vue/src/index.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 4fa3f125270..8215be7476e 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -44,18 +44,21 @@ function compileToFunction( template = el ? el.innerHTML : `` } - const { code } = compile( - template, - extend( - { - hoistStatic: true, - onError: __DEV__ ? onError : undefined, - onWarn: __DEV__ ? e => onError(e, true) : NOOP - } as CompilerOptions, - options - ) + const opts = extend( + { + hoistStatic: true, + onError: __DEV__ ? onError : undefined, + onWarn: __DEV__ ? e => onError(e, true) : NOOP + } as CompilerOptions, + options ) + if (!opts.isCustomElement && typeof customElements !== 'undefined') { + opts.isCustomElement = tag => !!customElements.get(tag) + } + + const { code } = compile(template, opts) + function onError(err: CompilerError, asWarning = false) { const message = asWarning ? err.message