feat(custom-elements): automatically respect custom elements when compiling in browser

This commit is contained in:
Evan You 2022-08-30 11:30:52 +08:00
parent c3465c1e88
commit 9f8f07ed38

View File

@ -44,18 +44,21 @@ function compileToFunction(
template = el ? el.innerHTML : `` template = el ? el.innerHTML : ``
} }
const { code } = compile( const opts = extend(
template, {
extend( hoistStatic: true,
{ onError: __DEV__ ? onError : undefined,
hoistStatic: true, onWarn: __DEV__ ? e => onError(e, true) : NOOP
onError: __DEV__ ? onError : undefined, } as CompilerOptions,
onWarn: __DEV__ ? e => onError(e, true) : NOOP options
} 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) { function onError(err: CompilerError, asWarning = false) {
const message = asWarning const message = asWarning
? err.message ? err.message