|
|
|
@ -58,38 +58,9 @@ export default function dom(
|
|
|
|
|
const expectedProperties = Array.from(component.expectedProperties);
|
|
|
|
|
const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
|
|
|
|
|
|
|
|
|
|
if (component.customElement) {
|
|
|
|
|
// TODO use `export` to determine this
|
|
|
|
|
const props = Array.from(component.expectedProperties);
|
|
|
|
|
|
|
|
|
|
builder.addBlock(deindent`
|
|
|
|
|
class ${name} extends HTMLElement {
|
|
|
|
|
constructor(options = {}) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get observedAttributes() {
|
|
|
|
|
return ${JSON.stringify(props)};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
${renderer.slots.size && deindent`
|
|
|
|
|
connectedCallback() {
|
|
|
|
|
Object.keys(this.$$.slotted).forEach(key => {
|
|
|
|
|
this.appendChild(this.$$.slotted[key]);
|
|
|
|
|
});
|
|
|
|
|
}`}
|
|
|
|
|
|
|
|
|
|
attributeChangedCallback(attr, oldValue, newValue) {
|
|
|
|
|
this[attr] = newValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customElements.define("${component.customElement.tag}", ${name});
|
|
|
|
|
`);
|
|
|
|
|
} else {
|
|
|
|
|
const refs = Array.from(component.refs);
|
|
|
|
|
|
|
|
|
|
const superclass = component.alias(options.dev ? '$$ComponentDev' : '$$Component');
|
|
|
|
|
const superclass = component.alias(options.dev ? 'SvelteComponentDev' : 'SvelteComponent');
|
|
|
|
|
|
|
|
|
|
if (options.dev && !options.hydratable) {
|
|
|
|
|
block.builders.claim.addLine(
|
|
|
|
@ -135,25 +106,6 @@ export default function dom(
|
|
|
|
|
const not_equal = component.options.immutable ? `@not_equal` : `@safe_not_equal`;
|
|
|
|
|
let dev_props_check;
|
|
|
|
|
|
|
|
|
|
if (component.options.dev) {
|
|
|
|
|
// TODO check no uunexpected props were passed, as well as
|
|
|
|
|
// checking that expected ones were passed
|
|
|
|
|
const expected = component.exports
|
|
|
|
|
.map(x => x.name)
|
|
|
|
|
.filter(name => !component.initialised_declarations.has(name));
|
|
|
|
|
|
|
|
|
|
if (expected.length) {
|
|
|
|
|
dev_props_check = deindent`
|
|
|
|
|
const state = this.$$.get();
|
|
|
|
|
${expected.map(name => deindent`
|
|
|
|
|
|
|
|
|
|
if (state.${name} === undefined) {
|
|
|
|
|
console.warn("${debug_name} was created without expected data property '${name}'");
|
|
|
|
|
}`)}
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component.exports.forEach(x => {
|
|
|
|
|
body.push(deindent`
|
|
|
|
|
get ${x.as}() {
|
|
|
|
@ -177,6 +129,25 @@ export default function dom(
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (component.options.dev) {
|
|
|
|
|
// TODO check no uunexpected props were passed, as well as
|
|
|
|
|
// checking that expected ones were passed
|
|
|
|
|
const expected = component.exports
|
|
|
|
|
.map(x => x.name)
|
|
|
|
|
.filter(name => !component.initialised_declarations.has(name));
|
|
|
|
|
|
|
|
|
|
if (expected.length) {
|
|
|
|
|
dev_props_check = deindent`
|
|
|
|
|
const state = this.$$.get();
|
|
|
|
|
${expected.map(name => deindent`
|
|
|
|
|
|
|
|
|
|
if (state.${name} === undefined) {
|
|
|
|
|
console.warn("${debug_name} was created without expected data property '${name}'");
|
|
|
|
|
}`)}
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.addBlock(deindent`
|
|
|
|
|
function create_fragment(${component.alias('component')}, ctx) {
|
|
|
|
|
${block.getContents()}
|
|
|
|
@ -201,7 +172,29 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
${inject_refs && `$$self.$$.inject_refs = ${inject_refs};`}
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
if (component.customElement) {
|
|
|
|
|
// TODO observedAttributes
|
|
|
|
|
|
|
|
|
|
builder.addBlock(deindent`
|
|
|
|
|
class ${name} extends @SvelteElement {
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
@init(this, { target: this.shadowRoot }, define, create_fragment, ${not_equal});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get observedAttributes() {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
${body.join('\n\n')}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customElements.define("${component.customElement.tag}", ${name});
|
|
|
|
|
`);
|
|
|
|
|
} else {
|
|
|
|
|
builder.addBlock(deindent`
|
|
|
|
|
class ${name} extends ${superclass} {
|
|
|
|
|
constructor(options) {
|
|
|
|
|
super(${options.dev && `options`});
|
|
|
|
|