]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(custom-elements): automatically respect custom elements when compiling in browser
authorEvan You <yyx990803@gmail.com>
Tue, 30 Aug 2022 03:30:52 +0000 (11:30 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 30 Aug 2022 03:30:52 +0000 (11:30 +0800)
packages/vue/src/index.ts

index 4fa3f12527017e4459c9b4d8bcb7263430becbdb..8215be7476ea1d7936d9c80129fca9edae26246d 100644 (file)
@@ -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