@staticbolt/core 1.0.0-beta.5 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/plugins/index.mjs +17 -20
- package/lib/plugins/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/plugins/index.mjs
CHANGED
|
@@ -5105,7 +5105,10 @@ function parseHtmlSources(ast) {
|
|
|
5105
5105
|
//#endregion
|
|
5106
5106
|
//#region src/parsers/html-parser.ts
|
|
5107
5107
|
function parseHtmlUnsafe(html, options = {}) {
|
|
5108
|
-
return parse(html,
|
|
5108
|
+
return parse(html, {
|
|
5109
|
+
comment: true,
|
|
5110
|
+
...options
|
|
5111
|
+
});
|
|
5109
5112
|
}
|
|
5110
5113
|
/** Parse HTML string and return the root node */
|
|
5111
5114
|
const parseHtml = valueOrError(parseHtmlUnsafe);
|
|
@@ -5208,24 +5211,25 @@ function coreHtmlPlugin(options = {}) {
|
|
|
5208
5211
|
const nodeIdMap = /* @__PURE__ */ new Map();
|
|
5209
5212
|
const scriptsAndStyles = metadata.ast.querySelectorAll("script,style");
|
|
5210
5213
|
for (const node of scriptsAndStyles) {
|
|
5211
|
-
const
|
|
5212
|
-
|
|
5213
|
-
const id = node.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5214
|
-
if (!id) continue;
|
|
5215
|
-
nodeIdMap.set(node, id);
|
|
5216
|
-
node.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5214
|
+
const hasMinifyAttribute = node.hasAttribute(minifyAttribute);
|
|
5215
|
+
const shouldMinify = minify || hasMinifyAttribute;
|
|
5217
5216
|
const isScript = node.tagName === "SCRIPT";
|
|
5217
|
+
node.removeAttribute(minifyAttribute);
|
|
5218
5218
|
const scriptType = node.getAttribute("type");
|
|
5219
5219
|
if (isScript && !isScriptType(scriptType)) continue;
|
|
5220
|
-
const
|
|
5220
|
+
const metadataID = node.getAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5221
|
+
if (!metadataID) continue;
|
|
5222
|
+
nodeIdMap.set(node, metadataID);
|
|
5223
|
+
node.removeAttribute(CUSTOM_ATTRIBUTES.MetadataID);
|
|
5224
|
+
const tagMetadata = metadata[isScript ? "scriptsMetadataList" : "stylesMetadataList"].get(metadataID);
|
|
5221
5225
|
if (!tagMetadata) continue;
|
|
5222
5226
|
const code = await this.stringify(tagMetadata, {
|
|
5223
|
-
format: format && !
|
|
5224
|
-
minify:
|
|
5227
|
+
format: format && !shouldMinify,
|
|
5228
|
+
minify: shouldMinify
|
|
5225
5229
|
});
|
|
5226
5230
|
if (!code) continue;
|
|
5227
5231
|
node.textContent = code;
|
|
5228
|
-
if (format &&
|
|
5232
|
+
if (format && hasMinifyAttribute) node.replaceWith(ignoreFormatComment + node.outerHTML);
|
|
5229
5233
|
}
|
|
5230
5234
|
const code = metadata.ast.toString();
|
|
5231
5235
|
for (const [node, metadataID] of nodeIdMap) node.setAttribute(CUSTOM_ATTRIBUTES.MetadataID, metadataID);
|
|
@@ -5390,12 +5394,8 @@ function coreMarkdownPlugin(options = {}) {
|
|
|
5390
5394
|
|
|
5391
5395
|
//#endregion
|
|
5392
5396
|
//#region src/ast-utilities/babel-utils/parse-script-srouces.ts
|
|
5393
|
-
function parseScriptSources({ ast
|
|
5397
|
+
function parseScriptSources({ ast }) {
|
|
5394
5398
|
const result = [];
|
|
5395
|
-
const printFmtError = PrintFormattedError.create({
|
|
5396
|
-
function: parseScriptSources,
|
|
5397
|
-
filePath
|
|
5398
|
-
});
|
|
5399
5399
|
t.traverseFast(ast, (node) => {
|
|
5400
5400
|
if (t.isImportDeclaration(node)) {
|
|
5401
5401
|
if (!t.isStringLiteral(node.source)) return;
|
|
@@ -5469,10 +5469,7 @@ function parseScriptSources({ ast, filePath }) {
|
|
|
5469
5469
|
if (t.isNewExpression(node)) {
|
|
5470
5470
|
if (!t.isIdentifier(node.callee, { name: "URL" })) return;
|
|
5471
5471
|
const firstArgument = node.arguments[0];
|
|
5472
|
-
if (!t.isStringLiteral(firstArgument))
|
|
5473
|
-
printFmtError("The first argument of `URL` should be a string", { node });
|
|
5474
|
-
return;
|
|
5475
|
-
}
|
|
5472
|
+
if (!t.isStringLiteral(firstArgument)) return;
|
|
5476
5473
|
const setSource = (newValue) => {
|
|
5477
5474
|
node.arguments[0] = t.stringLiteral(newValue);
|
|
5478
5475
|
};
|