Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.document not referring to the module document, but rather the script #14

Open
aaronmars opened this issue May 2, 2019 · 2 comments

Comments

@aaronmars
Copy link

The transform for import.meta.document in html-module-transform.ts generates a selector for the script element that the expression appears in, like:
'script[data-inline-module-script="0"]'

According to the explanation in the MS explainer, import.meta.document is supposed to refer to the HTML Module document, not a the inner <script> element.

I think the fix would be as simple as adding parentElement at the end.

Here's an example source illustrating the issue:

<template id="header">
    <div>HTML Modules</div>
</template>
<script type="module">
    let importDoc = import.meta.document;

    // Shouldn't need this line since `import.meta.document` is supposed to refer to this whole
    //  HTML document. The 
    importDoc = importDoc.parentElement;
    class Component extends HTMLElement {
        constructor() {
            super();
            const shadowRoot = this.attachShadow({ mode: 'open' });
            const template = importDoc.querySelector('#header');
            shadowRoot.appendChild(template.content.cloneNode(true));
        }
    }
    customElements.define('my-component', Component);
</script>
@cdata
Copy link
Contributor

cdata commented May 2, 2019

Thanks for reporting @aaronmars

As you can probably tell, this project predated the latest proposals for HTML Modules, and hasn't received a lot of attention since Microsoft starting pushing for them.

PRs are welcome if you or anyone else wants to help us bring these transforms up to date with the latest proposals! 🙏

@aaronmars
Copy link
Author

Cool! I'll see if I can find anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants