/* MIT License http://www.opensource.org/licenses/mit-license.php */ "use strict"; const Parser = require("../Parser"); const ConstDependency = require("../dependencies/ConstDependency"); const HtmlEntryDependency = require("../dependencies/HtmlEntryDependency"); const HtmlInlineHtmlDependency = require("../dependencies/HtmlInlineHtmlDependency"); const HtmlInlineScriptDependency = require("../dependencies/HtmlInlineScriptDependency"); const HtmlInlineStyleDependency = require("../dependencies/HtmlInlineStyleDependency"); const HtmlSourceDependency = require("../dependencies/HtmlSourceDependency"); const StaticExportsDependency = require("../dependencies/StaticExportsDependency"); const CommentCompilationWarning = require("../errors/CommentCompilationWarning"); const ModuleDependencyError = require("../errors/ModuleDependencyError"); const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning"); const WebpackError = require("../errors/WebpackError"); const ResourceHintPlugin = require("../prefetch/ResourceHintPlugin"); const parseResourceHintOptions = require("../prefetch/parseResourceHintOptions"); const LazySet = require("../util/LazySet"); const LocConverter = require("../util/LocConverter"); const createHash = require("../util/createHash"); const { contextify } = require("../util/identifier"); const { createMagicCommentContext, parseMagicComment, webpackCommentRegExp } = require("../util/magicComment"); const { NS_HTML, NS_SVG, NodeType, SVG_TAG_ADJUST, SourceProcessor, decodeEntities, escapeAttribute, escapeText, isAsciiWhitespace, parseCssUrls, parseMsapplicationTask, parseSrc, parseSrcset } = require("./syntax"); /** @typedef {import("../../declarations/WebpackOptions").HtmlParserOptions} HtmlParserOptions */ /** @typedef {import("../javascript/JavascriptParser").Range} Range */ /** @typedef {import("../Module")} Module */ /** @typedef {import("../Module").BuildInfo} BuildInfo */ /** @typedef {import("../Compilation").FileSystemDependencies} FileSystemDependencies */ /** @typedef {import("../Module").BuildMeta} BuildMeta */ /** @typedef {import("../NormalModule")} NormalModule */ /** @typedef {import("../Parser").ParserState} ParserState */ /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */ /** @typedef {import("./HtmlModule").HtmlModuleBuildInfo} HtmlModuleBuildInfo */ /** * @typedef {object} HtmlTemplateContext * @property {Module} module the html module being transformed * @property {string} resource absolute path of the module's resource * @property {(dependency: string) => void} addDependency register a file (e.g. a template partial) as a build dependency so editing it triggers a rebuild * @property {(dependency: string) => void} addContextDependency register a directory as a build dependency * @property {(dependency: string) => void} addMissingDependency register a not-yet-existing path as a build dependency so creating it triggers a rebuild * @property {(dependency: string) => void} addBuildDependency register a build dependency (e.g. a template engine config) so changing it invalidates the cache * @property {(warning: Error | string) => void} emitWarning report a non-fatal warning on the module * @property {(error: Error | string) => void} emitError report an error on the module */ /** @typedef {(source: string, context: HtmlTemplateContext) => string} HtmlTemplateFunction */ /** @typedef {import("./syntax").ParsedSource} ParsedSource */ // Cheap pre-filter for a `style="..."` attribute: only route it through the // CSS pipeline when it can hold a URL-bearing function (`url()` / `src()` / // `image()` / `image-set()`), otherwise the processed text equals the input. const STYLE_ATTR_URL_REGEXP = /url\(|src\(|image\(|image-set\(/i; // Cheap pre-filter for a `css-url` attribute value (an SVG presentation // attribute such as `fill`, `clip-path`, …): only tokenize values that can // hold a `url(...)` FuncIRI. Most are plain colors/keywords (`#fff`, `red`). const FUNC_IRI_URL_REGEXP = /url\(/i; // Cheap pre-filter for `