import.meta.document not referring to the module document, but rather the script #14
Open
Description
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>
Metadata
Assignees
Labels
No labels