diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 02e1712280..27380a04df 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -118,16 +118,15 @@ export default class Component { this.componentOptions = process_component_options(this, this.ast.html.children); this.namespace = namespaces[this.componentOptions.namespace] || this.componentOptions.namespace; - if (compileOptions.customElement === true && !this.componentOptions.tag) { - throw new Error(`No tag name specified`); // TODO better error + if (compileOptions.customElement) { + this.tag = this.componentOptions.tag || compileOptions.tag; + if (!this.tag) { + throw new Error(`Cannot compile to a custom element without specifying a tag name via options.tag or `); + } + } else { + this.tag = this.name; } - this.tag = compileOptions.customElement - ? compileOptions.customElement === true - ? this.componentOptions.tag - : compileOptions.customElement as string - : this.name; - this.walk_module_js(); this.walk_instance_js_pre_template(); diff --git a/src/compile/index.ts b/src/compile/index.ts index aee72fcd9e..35816fdc7a 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -21,6 +21,7 @@ const valid_options = [ 'hydratable', 'legacy', 'customElement', + 'tag', 'css', 'preserveComments' ]; diff --git a/src/interfaces.ts b/src/interfaces.ts index bc2a672c47..1fe7673fc6 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -53,7 +53,8 @@ export interface CompileOptions { immutable?: boolean; hydratable?: boolean; legacy?: boolean; - customElement?: CustomElementOptions | true; + customElement?: boolean; + tag?: string; css?: boolean; preserveComments?: boolean | false; @@ -64,11 +65,6 @@ export interface Visitor { leave?: (node: Node) => void; } -export interface CustomElementOptions { - tag?: string; - props?: string[]; -} - export interface AppendTarget { slots: Record; slotStack: string[] diff --git a/src/parse/index.ts b/src/parse/index.ts index 4b1e0a225c..a28cf8a707 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -3,13 +3,13 @@ import fragment from './state/fragment'; import { whitespace } from '../utils/patterns'; import reservedNames from '../utils/reservedNames'; import fullCharCodeAt from '../utils/fullCharCodeAt'; -import { Node, Ast, CustomElementOptions } from '../interfaces'; +import { Node, Ast } from '../interfaces'; import error from '../utils/error'; interface ParserOptions { filename?: string; bind?: boolean; - customElement?: CustomElementOptions | true; + customElement?: boolean; } type ParserState = (parser: Parser) => (ParserState | void); @@ -17,7 +17,7 @@ type ParserState = (parser: Parser) => (ParserState | void); export class Parser { readonly template: string; readonly filename?: string; - readonly customElement: CustomElementOptions | true; + readonly customElement: boolean; index = 0; stack: Array = [];