diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 61f9186e8b..14d02730e8 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -1,5 +1,5 @@ import deindent from '../../utils/deindent'; -import { stringify } from '../../utils/stringify'; +import { stringify, escape } from '../../utils/stringify'; import CodeBuilder from '../../utils/CodeBuilder'; import globalWhitelist from '../../utils/globalWhitelist'; import Component from '../Component'; @@ -175,17 +175,29 @@ export default function dom( `); if (component.customElement) { - // TODO observedAttributes - builder.addBlock(deindent` class ${name} extends @SvelteElement { - constructor() { + constructor(options) { super(); + + ${css.code && `this.shadowRoot.innerHTML = \`\`;`} + @init(this, { target: this.shadowRoot }, define, create_fragment, ${not_equal}); + + if (options) { + if (options.target) { + @insert(options.target, this, options.anchor); + } + + if (options.props) { + this.$set(options.props); + @flush(); + } + } } static get observedAttributes() { - return []; + return ${JSON.stringify(component.exports.map(x => x.as))}; } ${body.join('\n\n')} diff --git a/test/custom-elements/samples/html/test.js b/test/custom-elements/samples/html/test.js index 9f0a925b43..732d79f009 100644 --- a/test/custom-elements/samples/html/test.js +++ b/test/custom-elements/samples/html/test.js @@ -5,7 +5,7 @@ export default function (target) { target.innerHTML = ''; const el = target.querySelector('custom-element'); - assert.equal(el.get().name, 'world'); + assert.equal(el.name, 'world'); const h1 = el.shadowRoot.querySelector('h1'); assert.equal(h1.textContent, 'Hello world!'); diff --git a/test/custom-elements/samples/new/test.js b/test/custom-elements/samples/new/test.js index ff27f52130..f37f4301fb 100644 --- a/test/custom-elements/samples/new/test.js +++ b/test/custom-elements/samples/new/test.js @@ -4,7 +4,7 @@ import CustomElement from './main.html'; export default function (target) { new CustomElement({ target, - data: { + props: { name: 'world' } });