diff --git a/src/index.js b/src/index.js
index 7fddb729..aec23fe9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -47,9 +47,8 @@ export default async function htmlLoader(content) {
const { html, messages } = pluginRunner(plugins).process(content);
const errors = [];
- const importedMessages = [];
- const replaceableMessages = [];
- const exportedMessages = [];
+ const imports = [];
+ const replacements = [];
for (const message of messages) {
// eslint-disable-next-line default-case
@@ -58,10 +57,10 @@ export default async function htmlLoader(content) {
errors.push(message.value);
break;
case 'import':
- importedMessages.push(message.value);
+ imports.push(message.value);
break;
- case 'replacer':
- replaceableMessages.push(message.value);
+ case 'replacement':
+ replacements.push(message.value);
break;
}
}
@@ -71,9 +70,9 @@ export default async function htmlLoader(content) {
}
const codeOptions = { ...options, loaderContext: this };
- const importCode = getImportCode(html, importedMessages, codeOptions);
- const moduleCode = getModuleCode(html, replaceableMessages, codeOptions);
- const exportCode = getExportCode(html, exportedMessages, codeOptions);
+ const importCode = getImportCode(html, imports, codeOptions);
+ const moduleCode = getModuleCode(html, replacements, codeOptions);
+ const exportCode = getExportCode(html, codeOptions);
return `${importCode}${moduleCode}${exportCode}`;
}
diff --git a/src/options.json b/src/options.json
index 8291e308..1991a355 100644
--- a/src/options.json
+++ b/src/options.json
@@ -13,7 +13,7 @@
"minLength": 1
},
"type": {
- "enum": ["src", "srcset"]
+ "enum": ["src", "srcset", "include"]
},
"filter": {
"instanceof": "Function"
diff --git a/src/plugins/source-plugin.js b/src/plugins/source-plugin.js
index 3ce08486..30be9728 100644
--- a/src/plugins/source-plugin.js
+++ b/src/plugins/source-plugin.js
@@ -201,17 +201,16 @@ export default (options) =>
return { key, name };
}
- // TODO rename
- name = `___HTML_LOADER_REPLACER_${replacements.size}___`;
+ name = `___HTML_LOADER_REPLACEMENT_${replacements.size}___`;
replacements.set(key, name);
result.messages.push({
- type: 'replacer',
+ type: 'replacement',
value: {
type: 'source',
hash,
importName: importItem.name,
- replacerName: name,
+ replacementName: name,
unquoted,
},
});
@@ -330,7 +329,7 @@ export default (options) =>
break;
}
- case 'tag': {
+ case 'include': {
let source;
try {
diff --git a/src/utils.js b/src/utils.js
index 508258bf..01f837f5 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -407,8 +407,8 @@ export function isProductionMode(loaderContext) {
return loaderContext.mode === 'production' || !loaderContext.mode;
}
-export function getImportCode(html, importedMessages, codeOptions) {
- if (importedMessages.length === 0) {
+export function getImportCode(html, imports, codeOptions) {
+ if (imports.length === 0) {
return '';
}
@@ -422,7 +422,7 @@ export function getImportCode(html, importedMessages, codeOptions) {
? `import ${GET_SOURCE_FROM_IMPORT_NAME} from ${stringifiedHelperRequest};\n`
: `var ${GET_SOURCE_FROM_IMPORT_NAME} = require(${stringifiedHelperRequest});\n`;
- for (const item of importedMessages) {
+ for (const item of imports) {
const { importName, source } = item;
const stringifiedSourceRequest = stringifyRequest(loaderContext, source);
@@ -434,7 +434,7 @@ export function getImportCode(html, importedMessages, codeOptions) {
return `// Imports\n${code}`;
}
-export function getModuleCode(html, replaceableMessages) {
+export function getModuleCode(html, replacements) {
let code = JSON.stringify(html)
// Invalid in JavaScript but valid HTML
.replace(/[\u2028\u2029]/g, (str) =>
@@ -443,8 +443,8 @@ export function getModuleCode(html, replaceableMessages) {
let replacersCode = '';
- for (const item of replaceableMessages) {
- const { importName, replacerName, unquoted, hash } = item;
+ for (const item of replacements) {
+ const { importName, replacementName, unquoted, hash } = item;
const getUrlOptions = []
.concat(hash ? [`hash: ${JSON.stringify(hash)}`] : [])
@@ -452,18 +452,18 @@ export function getModuleCode(html, replaceableMessages) {
const preparedOptions =
getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
- replacersCode += `var ${replacerName} = ${GET_SOURCE_FROM_IMPORT_NAME}(${importName}${preparedOptions});\n`;
+ replacersCode += `var ${replacementName} = ${GET_SOURCE_FROM_IMPORT_NAME}(${importName}${preparedOptions});\n`;
code = code.replace(
- new RegExp(replacerName, 'g'),
- () => `" + ${replacerName} + "`
+ new RegExp(replacementName, 'g'),
+ () => `" + ${replacementName} + "`
);
}
return `// Module\n${replacersCode}var code = ${code};\n`;
}
-export function getExportCode(html, exportedMessages, codeOptions) {
+export function getExportCode(html, codeOptions) {
if (codeOptions.esModule) {
return `// Exports\nexport default code;`;
}
diff --git a/test/__snapshots__/attributes-option.test.js.snap b/test/__snapshots__/attributes-option.test.js.snap
index 4faea77d..2d11c37f 100644
--- a/test/__snapshots__/attributes-option.test.js.snap
+++ b/test/__snapshots__/attributes-option.test.js.snap
@@ -452,8 +452,8 @@ exports[`'attributes' option should handle "src" and "srcset" tags correctly: mo
var ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ = require(\\"../../src/runtime/getUrl.js\\");
var ___HTML_LOADER_IMPORT_0___ = require(\\"./image.png\\");
// Module
-var ___HTML_LOADER_REPLACER_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
-var code = \\"\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\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\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\";
// Exports
module.exports = code;"
`;
@@ -754,17 +754,17 @@ var ___HTML_LOADER_IMPORT_7___ = require(\\"./fallback.file.js\\");
var ___HTML_LOADER_IMPORT_8___ = require(\\"./fallback.file.json\\");
var ___HTML_LOADER_IMPORT_9___ = require(\\"./preprocessor.hbs\\");
// Module
-var ___HTML_LOADER_REPLACER_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
-var ___HTML_LOADER_REPLACER_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___);
-var ___HTML_LOADER_REPLACER_2___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_2___);
-var ___HTML_LOADER_REPLACER_3___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_3___);
-var ___HTML_LOADER_REPLACER_4___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_4___);
-var ___HTML_LOADER_REPLACER_5___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_5___);
-var ___HTML_LOADER_REPLACER_6___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_6___);
-var ___HTML_LOADER_REPLACER_7___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_7___);
-var ___HTML_LOADER_REPLACER_8___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_8___);
-var ___HTML_LOADER_REPLACER_9___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_9___);
-var code = \\"\\\\n\\\\n
My First Heading
\\\\nMy first paragraph.
\\\\nAn Unordered HTML List
\\\\n\\\\n\\\\n - Coffee
\\\\n - Tea
\\\\n - Milk
\\\\n
\\\\n\\\\nAn Ordered HTML List
\\\\n\\\\n\\\\n - Coffee
\\\\n - Tea
\\\\n - Milk
\\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nFoo
\\\\n\\\\n\\\\nBAR
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n