babel-plugin-transform-builtin-extend icon indicating copy to clipboard operation
babel-plugin-transform-builtin-extend copied to clipboard

Added support for extending HTMLElement

Open oravecz opened this issue 8 years ago • 1 comments

Added a third parameter to Reflect.construct() which was preventing the plugin from working with classes that extend HTMLElement

I would like to contribute a test, but that would be a lot of work considering the tests do not currently support a browser environment. If someone wants to add that plumbing, they can use this test. It will have to be run in Chrome unless polyfills are provided. Not sure if Phantom supports it or not.

    describe('HTMLElement', function(){
        class MyHTMLElement extends HTMLElement {
            constructor(){
                super();
                this.attr = null;
            }

            static get observedAttributes() {
                return [ 'supports' ]
            }

            attributeChangedCallback( name, oldValue, newValue ) {
                if (name === 'supports') {
                    this.attr = newValue;
                }
            }
        }

        it('should behave properly', function(){
            const a = new MyHTMLElement();
            a.setAttribute('supports', 'HTMLElement');

            expect(a instanceof MyHTMLElement).to.be.true;
            expect(a instanceof HTMLElement).to.be.true;

            expect(a).to.have.ownProperty('offsetLeft');
            expect(a).to.have.ownProperty('attr');

            expect(a.attr).to.eql('HTMLElement');
        });
    });

oravecz avatar Jan 05 '17 02:01 oravecz

@loganfsmyth this would be 👍 wonderful

aaronshaf avatar Jan 07 '17 20:01 aaronshaf