MCPcopy
hub / github.com/webpack/webpack / reconcileScriptTypeAttr

Method reconcileScriptTypeAttr

lib/html/HtmlParser.js:928–968  ·  view source on GitHub ↗
(typeAttr, nameEnd, type, input)

Source from the content-addressed store, hash-verified

926 * @param {string} input source string
927 */
928 const reconcileScriptTypeAttr = (typeAttr, nameEnd, type, input) => {
929 if (outputModule && type === "script") {
930 // Chunk is an ES module; upgrade the tag.
931 if (typeAttr && typeAttr.valueStart !== -1) {
932 module.addPresentationalDependency(
933 new ConstDependency("module", [
934 typeAttr.valueStart,
935 typeAttr.valueEnd
936 ])
937 );
938 } else {
939 module.addPresentationalDependency(
940 new ConstDependency(' type="module"', nameEnd)
941 );
942 }
943 } else if (!outputModule && type === "script-module" && typeAttr) {
944 // Chunk is a classic IIFE; drop `type="module"` so the
945 // browser doesn't load it under module semantics.
946 let attrEnd;
947 if (typeAttr.valueStart === -1) {
948 attrEnd = typeAttr.nameEnd;
949 } else if (
950 input[typeAttr.valueEnd] === '"' ||
951 input[typeAttr.valueEnd] === "'"
952 ) {
953 attrEnd = typeAttr.valueEnd + 1;
954 } else {
955 attrEnd = typeAttr.valueEnd;
956 }
957 let attrStart = typeAttr.nameStart;
958 if (
959 attrStart > 0 &&
960 isASCIIWhitespace(input.charCodeAt(attrStart - 1))
961 ) {
962 attrStart -= 1;
963 }
964 module.addPresentationalDependency(
965 new ConstDependency("", [attrStart, attrEnd])
966 );
967 }
968 };
969
970 /**
971 * @param {string} mime mime type

Callers

nothing calls this directly

Calls 2

isASCIIWhitespaceFunction · 0.85

Tested by

no test coverage detected