Merge pull request #2251 from sveltejs/gh-2025-alt

make customElement a boolean option
pull/2258/head
Rich Harris 7 years ago committed by GitHub
commit 106b88d240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -118,15 +118,14 @@ export default class Component {
this.componentOptions = process_component_options(this, this.ast.html.children); this.componentOptions = process_component_options(this, this.ast.html.children);
this.namespace = namespaces[this.componentOptions.namespace] || this.componentOptions.namespace; this.namespace = namespaces[this.componentOptions.namespace] || this.componentOptions.namespace;
if (compileOptions.customElement === true && !this.componentOptions.tag) { if (compileOptions.customElement) {
throw new Error(`No tag name specified`); // TODO better error 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 <svelte:options>`);
}
} 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_module_js();
this.walk_instance_js_pre_template(); this.walk_instance_js_pre_template();

@ -21,6 +21,7 @@ const valid_options = [
'hydratable', 'hydratable',
'legacy', 'legacy',
'customElement', 'customElement',
'tag',
'css', 'css',
'preserveComments' 'preserveComments'
]; ];

@ -53,7 +53,8 @@ export interface CompileOptions {
immutable?: boolean; immutable?: boolean;
hydratable?: boolean; hydratable?: boolean;
legacy?: boolean; legacy?: boolean;
customElement?: CustomElementOptions | true; customElement?: boolean;
tag?: string;
css?: boolean; css?: boolean;
preserveComments?: boolean | false; preserveComments?: boolean | false;
@ -64,11 +65,6 @@ export interface Visitor {
leave?: (node: Node) => void; leave?: (node: Node) => void;
} }
export interface CustomElementOptions {
tag?: string;
props?: string[];
}
export interface AppendTarget { export interface AppendTarget {
slots: Record<string, string>; slots: Record<string, string>;
slotStack: string[] slotStack: string[]

@ -3,13 +3,13 @@ import fragment from './state/fragment';
import { whitespace } from '../utils/patterns'; import { whitespace } from '../utils/patterns';
import reservedNames from '../utils/reservedNames'; import reservedNames from '../utils/reservedNames';
import fullCharCodeAt from '../utils/fullCharCodeAt'; import fullCharCodeAt from '../utils/fullCharCodeAt';
import { Node, Ast, CustomElementOptions } from '../interfaces'; import { Node, Ast } from '../interfaces';
import error from '../utils/error'; import error from '../utils/error';
interface ParserOptions { interface ParserOptions {
filename?: string; filename?: string;
bind?: boolean; bind?: boolean;
customElement?: CustomElementOptions | true; customElement?: boolean;
} }
type ParserState = (parser: Parser) => (ParserState | void); type ParserState = (parser: Parser) => (ParserState | void);
@ -17,7 +17,7 @@ type ParserState = (parser: Parser) => (ParserState | void);
export class Parser { export class Parser {
readonly template: string; readonly template: string;
readonly filename?: string; readonly filename?: string;
readonly customElement: CustomElementOptions | true; readonly customElement: boolean;
index = 0; index = 0;
stack: Array<Node> = []; stack: Array<Node> = [];

Loading…
Cancel
Save