Skip to content

Commit 217a09d

Browse files
committed
fix: πŸ› self-closing templates with external source
βœ… Closes: #235
1 parent f18ca79 commit 217a09d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Diff for: β€Žsrc/modules/tagInfo.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ export const getTagInfo = async ({
2727
content,
2828
}: PreprocessorArgs) => {
2929
const dependencies = [];
30+
// catches empty content and self-closing tags
31+
const isEmptyContent = content == null || content.trim().length === 0;
3032

3133
/** only include src file if content of tag is empty */
32-
if (attributes.src && content.trim().length === 0) {
34+
if (attributes.src && isEmptyContent) {
3335
// istanbul ignore if
3436
if (typeof attributes.src !== 'string') {
3537
throw new Error('src attribute must be string');

Diff for: β€Žtest/autoProcess/externalFiles.test.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { resolve } from 'path';
22

33
import sveltePreprocess from '../../src';
4-
import { Processed } from '../../src/types';
54
import {
65
preprocess,
76
getFixtureContent,
@@ -24,12 +23,8 @@ const REMOTE_JS = [
2423
];
2524

2625
describe('external files', () => {
27-
let markup: Processed;
28-
let script: Processed;
29-
let style: Processed;
30-
31-
beforeAll(async () => {
32-
[markup, script, style] = [
26+
it('should insert external file content and add as deps', async () => {
27+
const [markup, script, style] = [
3328
await markupProcessor({
3429
content: `<template src="./fixtures/template.html"></template>
3530
<style src="./fixtures/style.css"></style>
@@ -47,20 +42,24 @@ describe('external files', () => {
4742
attributes: { src: `./fixtures/style.css` },
4843
}),
4944
];
50-
});
5145

52-
it('should insert external file content', async () => {
5346
expect(markup.code).toContain(getFixtureContent('template.html'));
5447
expect(script.code).toContain(getFixtureContent('script.js'));
5548
expect(style.code).toContain(getFixtureContent('style.css'));
56-
});
57-
58-
it('should add a external file as a dependency', async () => {
5949
expect(markup.dependencies).toContain(getFixturePath('template.html'));
6050
expect(script.dependencies).toContain(getFixturePath('script.js'));
6151
expect(style.dependencies).toContain(getFixturePath('style.css'));
6252
});
6353

54+
it('should support self-closing tags', async () => {
55+
const markup = await markupProcessor({
56+
content: `<template src="./fixtures/template.html"/>`,
57+
filename: resolve(__dirname, '..', 'App.svelte'),
58+
});
59+
60+
expect(markup.code).toContain(getFixtureContent('template.html'));
61+
});
62+
6463
REMOTE_JS.forEach((url) => {
6564
it(`should not attempt to locally resolve ${url}`, async () => {
6665
const input = `<div></div><script src="${url}"></script>`;

0 commit comments

Comments
Β (0)