Skip to content

Commit b92ed21

Browse files
refactor: postpone include feature (#308)
1 parent 3584ae6 commit b92ed21

File tree

5 files changed

+50
-103
lines changed

5 files changed

+50
-103
lines changed

src/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"minLength": 1
1414
},
1515
"type": {
16-
"enum": ["src", "srcset", "include"]
16+
"enum": ["src", "srcset"]
1717
},
1818
"filter": {
1919
"instanceof": "Function"

src/plugins/source-plugin.js

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -193,52 +193,53 @@ export default (options) =>
193193

194194
break;
195195
}
196-
case 'include': {
197-
let source;
198-
199-
// eslint-disable-next-line no-underscore-dangle
200-
if (parser._tokenizer._state === 4) {
201-
return;
202-
}
203-
204-
try {
205-
source = parseSrc(value);
206-
} catch (error) {
207-
options.errors.push(
208-
new HtmlSourceError(
209-
`Bad value for attribute "${attribute}" on element "${tag}": ${error.message}`,
210-
parser.startIndex,
211-
parser.endIndex,
212-
html
213-
)
214-
);
215-
216-
return;
217-
}
218-
219-
if (!urlFilter(attribute, source.value, resourcePath)) {
220-
return;
221-
}
222-
223-
const { startIndex } = parser;
224-
const closingTag = html
225-
.slice(startIndex - 1)
226-
.match(
227-
new RegExp(`<s*${tag}[^>]*>(?:.*?)</${tag}[^<>]*>`, 's')
228-
);
229-
230-
if (!closingTag) {
231-
return;
232-
}
233-
234-
const endIndex = startIndex + closingTag[0].length;
235-
const importItem = getImportItem(source.value);
236-
const replacementItem = getReplacementItem(importItem);
237-
238-
sources.push({ replacementItem, startIndex, endIndex });
239-
240-
break;
241-
}
196+
// Need improve
197+
// case 'include': {
198+
// let source;
199+
//
200+
// // eslint-disable-next-line no-underscore-dangle
201+
// if (parser._tokenizer._state === 4) {
202+
// return;
203+
// }
204+
//
205+
// try {
206+
// source = parseSrc(value);
207+
// } catch (error) {
208+
// options.errors.push(
209+
// new HtmlSourceError(
210+
// `Bad value for attribute "${attribute}" on element "${tag}": ${error.message}`,
211+
// parser.startIndex,
212+
// parser.endIndex,
213+
// html
214+
// )
215+
// );
216+
//
217+
// return;
218+
// }
219+
//
220+
// if (!urlFilter(attribute, source.value, resourcePath)) {
221+
// return;
222+
// }
223+
//
224+
// const { startIndex } = parser;
225+
// const closingTag = html
226+
// .slice(startIndex - 1)
227+
// .match(
228+
// new RegExp(`<s*${tag}[^>]*>(?:.*?)</${tag}[^<>]*>`, 's')
229+
// );
230+
//
231+
// if (!closingTag) {
232+
// return;
233+
// }
234+
//
235+
// const endIndex = startIndex + closingTag[0].length;
236+
// const importItem = getImportItem(source.value);
237+
// const replacementItem = getReplacementItem(importItem);
238+
//
239+
// sources.push({ replacementItem, startIndex, endIndex });
240+
//
241+
// break;
242+
// }
242243
}
243244
});
244245

test/__snapshots__/attributes-option.test.js.snap

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,60 +1862,6 @@ or
18621862
18631863
exports[`'attributes' option should handle attributes with a "boolean" notation equals "true": warnings 1`] = `Array []`;
18641864
1865-
exports[`'attributes' option should handle the "include" tags: errors 1`] = `Array []`;
1866-
1867-
exports[`'attributes' option should handle the "include" tags: module 1`] = `
1868-
"// Imports
1869-
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
1870-
var ___HTML_LOADER_IMPORT_0___ = require(\\"./include-header.html\\");
1871-
var ___HTML_LOADER_IMPORT_1___ = require(\\"./include-footer.html\\");
1872-
var ___HTML_LOADER_IMPORT_2___ = require(\\"./include-content.html\\");
1873-
// Module
1874-
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
1875-
var ___HTML_LOADER_REPLACEMENT_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___);
1876-
var ___HTML_LOADER_REPLACEMENT_2___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_2___);
1877-
var code = \\"<div>\\\\n <article>\\\\n BeforeHeaderText\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"AfterHeaderText\\\\n <ol>\\\\n <li>Grow a long, majestic beard.</li>\\\\n <li>Wear a tall, pointed hat.</li>\\\\n <li>Have I mentioned the beard?</li>\\\\n </ol>\\\\n BeforeFooterText\\" + ___HTML_LOADER_REPLACEMENT_1___ + \\"AfterFooterText\\\\n TextBeforeOpenDiv<div>TextAfterOpenDiv\\" + ___HTML_LOADER_REPLACEMENT_2___ + \\"TextBeforeCloseDiv</div>TextAfterCloseDiv\\\\n </article>\\\\n</div>\\\\n\\\\n<!-- Future improvements -->\\\\nBEFORE\\\\n\\" + ___HTML_LOADER_REPLACEMENT_2___ + \\"\\\\nAFTER\\\\n\\\\n<div>TEXT</div>\\\\n<div>\\\\n \\" + ___HTML_LOADER_REPLACEMENT_2___ + \\"\\\\n</div>\\\\n<div>TEXT</div>\\\\n\\\\n<!-- WRONG -->\\\\n<div><include src=\\\\\\"./include-conten\\" + ___HTML_LOADER_REPLACEMENT_2___ + \\"\\\\n</include>\\\\n\\";
1878-
// Exports
1879-
module.exports = code;"
1880-
`;
1881-
1882-
exports[`'attributes' option should handle the "include" tags: result 1`] = `
1883-
"<div>
1884-
<article>
1885-
BeforeHeaderText<header>
1886-
<h1>How to be a wizard</h1>
1887-
</header>AfterHeaderText
1888-
<ol>
1889-
<li>Grow a long, majestic beard.</li>
1890-
<li>Wear a tall, pointed hat.</li>
1891-
<li>Have I mentioned the beard?</li>
1892-
</ol>
1893-
BeforeFooterText<footer>
1894-
<p>© 2018 Gandalf</p>
1895-
</footer>AfterFooterText
1896-
TextBeforeOpenDiv<div>TextAfterOpenDiv<span>Text</span>TextBeforeCloseDiv</div>TextAfterCloseDiv
1897-
</article>
1898-
</div>
1899-
1900-
<!-- Future improvements -->
1901-
BEFORE
1902-
<span>Text</span>
1903-
AFTER
1904-
1905-
<div>TEXT</div>
1906-
<div>
1907-
<span>Text</span>
1908-
</div>
1909-
<div>TEXT</div>
1910-
1911-
<!-- WRONG -->
1912-
<div><include src=\\"./include-conten<span>Text</span>
1913-
</include>
1914-
"
1915-
`;
1916-
1917-
exports[`'attributes' option should handle the "include" tags: warnings 1`] = `Array []`;
1918-
19191865
exports[`'attributes' option should not handle attributes with a "boolean" notation equals "false": errors 1`] = `Array []`;
19201866
19211867
exports[`'attributes' option should not handle attributes with a "boolean" notation equals "false": module 1`] = `

test/__snapshots__/validate-options.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exports[`validate options should throw an error on the "attributes" option with
3333
exports[`validate options should throw an error on the "attributes" option with "{"list":[{"tag":"img","attribute":"src"}]}" value 1`] = `
3434
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
3535
- options.attributes.list[0] misses the property 'type'. Should be:
36-
\\"src\\" | \\"srcset\\" | \\"include\\""
36+
\\"src\\" | \\"srcset\\""
3737
`;
3838
3939
exports[`validate options should throw an error on the "attributes" option with "{"root":false}" value 1`] = `

test/attributes-option.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("'attributes' option", () => {
3535
expect(getErrors(stats)).toMatchSnapshot('errors');
3636
});
3737

38-
it('should handle the "include" tags', async () => {
38+
it.skip('should handle the "include" tags', async () => {
3939
const compiler = getCompiler('include.js', {
4040
attributes: {
4141
list: [

0 commit comments

Comments
 (0)