0.0.3: Fixed a bug that showed up in watch mode
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -106,7 +106,8 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
}
|
||||
}
|
||||
},
|
||||
load: {
|
||||
load: { // TODO, not in the mood to fix this. Load-result is getting cached and that gives us issues. Seperate load/transform behavior and adapt to use magic string for transformations?
|
||||
// Something to figure out: its counter intuitive that rollup expects the load-callback to already return JS. It implies we already do transformations and can't really use rollup to further transform any of it. (i.e handlebars > intermediate-html > html would not be possible?)
|
||||
async handler(id: string) {
|
||||
if(virtualSources.has(id)) return virtualSources.get(id);
|
||||
if(!filter(id)) return;
|
||||
@@ -121,7 +122,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
|
||||
}) : contents;
|
||||
|
||||
// Parse document and store it (TODO: check for watch mode, we should check if it needs reparsing or not)
|
||||
const document = htmlModule.document = htmlModule.document ?? parseHtml(htmlSrc);
|
||||
const document = htmlModule.document = parseHtml(htmlSrc);
|
||||
|
||||
// Figure out which references to load from this HTML by iterating all nodes (looking for src or href attributes)
|
||||
let htmlImports: HtmlImport[] = htmlModule.imports = [];
|
||||
|
||||
@@ -49,6 +49,8 @@ export function makeInlineId(sourceId: string, node: DefaultTreeAdapterMap['chil
|
||||
export function makeLoader(mappings: NodeMapping[] = defaultMapping){
|
||||
const fn : LoadNodeCallback = async function ({node, sourceId}, load){
|
||||
for(const mapping of mappings){
|
||||
|
||||
// Test the mapping for a match
|
||||
if (mapping.tagName && mapping.tagName !== node.tagName) continue; // No match, skip
|
||||
if (mapping.match){
|
||||
if(typeof(mapping.match) === 'function'){
|
||||
@@ -67,7 +69,10 @@ export function makeLoader(mappings: NodeMapping[] = defaultMapping){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we've gotten this far its a valid mapping. (either inline or a src/href attribute)
|
||||
if((<AttributeReference>mapping).attr){
|
||||
// Mapped on attribute, resolve its src or href (or whatever was returned)
|
||||
const attr = node.attrs.find(attr=>attr.name === (<AttributeReference>mapping).attr);
|
||||
if(!attr) continue ;// No match, skip
|
||||
const placeholder = await load({
|
||||
@@ -76,6 +81,7 @@ export function makeLoader(mappings: NodeMapping[] = defaultMapping){
|
||||
});
|
||||
attr.value = placeholder;
|
||||
}else if((<BodyReference>mapping).body){
|
||||
// Mapped as body, use the contents of the DOM element
|
||||
const body = serializeHtml(node); // unlike what you' might expect, this doesn't serialize the <script>-tag itself, only its contents. Which is what we want.
|
||||
if(!body) continue; // Empty body, skip
|
||||
const placeholder = await load({
|
||||
|
||||
Reference in New Issue
Block a user