html-minifier-next 8.4.1 → 8.4.3
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/README.md +1 -1
- package/cli.js +4 -3
- package/dist/types/htmlminifier.d.ts.map +1 -1
- package/dist/types/lib/constants.d.ts +2 -1
- package/dist/types/lib/constants.d.ts.map +1 -1
- package/dist/types/lib/options.d.ts.map +1 -1
- package/dist/types/lib/utils.d.ts +12 -1
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/dist/types/lib/whitespace.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/htmlminifier.js +17 -7
- package/src/lib/constants.js +5 -0
- package/src/lib/file-pool.js +2 -1
- package/src/lib/file-write.js +87 -0
- package/src/lib/options.js +32 -5
- package/src/lib/utils.js +24 -1
- package/src/lib/whitespace.js +133 -91
package/README.md
CHANGED
|
@@ -241,7 +241,7 @@ Where the modifiers disagree, the preserving one wins—`conservativeCollapse` a
|
|
|
241
241
|
|
|
242
242
|
### Sorting attributes and style classes
|
|
243
243
|
|
|
244
|
-
Minifier options like `sortAttributes` and `sortClassNames` won’t impact the plain-text size of the output. However,
|
|
244
|
+
Minifier options like `sortAttributes` and `sortClassNames` won’t impact the plain-text size of the output. However, `sortAttributes` (but not `sortClassNames`) improves the compression ratio for Gzip and Brotli used over HTTP.
|
|
245
245
|
|
|
246
246
|
### CSS minification
|
|
247
247
|
|
package/cli.js
CHANGED
|
@@ -53,6 +53,7 @@ const commanderOptionKey = (key) => {
|
|
|
53
53
|
import { getPreset, getPresetNames } from './src/presets.js';
|
|
54
54
|
import { paramCase, parseRegExp } from './src/lib/utils.js';
|
|
55
55
|
import { optionDefinitions } from './src/lib/option-definitions.js';
|
|
56
|
+
import { writeFileAtomic } from './src/lib/file-write.js';
|
|
56
57
|
|
|
57
58
|
const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
58
59
|
|
|
@@ -681,7 +682,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
681
682
|
return { originalSize: stats.originalSize, minifiedSize: stats.minifiedSize, saved: stats.saved };
|
|
682
683
|
}
|
|
683
684
|
|
|
684
|
-
await
|
|
685
|
+
await writeFileAtomic(outputFile, minified).catch(err => {
|
|
685
686
|
fatal('Cannot write ' + outputFile + '\n' + err.message);
|
|
686
687
|
});
|
|
687
688
|
|
|
@@ -1000,7 +1001,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
1000
1001
|
if (programOptions.output) {
|
|
1001
1002
|
try {
|
|
1002
1003
|
await fs.promises.mkdir(path.dirname(programOptions.output), { recursive: true });
|
|
1003
|
-
await
|
|
1004
|
+
await writeFileAtomic(programOptions.output, minified);
|
|
1004
1005
|
} catch (err) {
|
|
1005
1006
|
fatal('Cannot write ' + programOptions.output + '\n' + errorMessage(err));
|
|
1006
1007
|
}
|
|
@@ -1188,7 +1189,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
1188
1189
|
if (programOptions.output) {
|
|
1189
1190
|
try {
|
|
1190
1191
|
await fs.promises.mkdir(path.dirname(programOptions.output), { recursive: true });
|
|
1191
|
-
await
|
|
1192
|
+
await writeFileAtomic(programOptions.output, minifiedCombined);
|
|
1192
1193
|
} catch (err) {
|
|
1193
1194
|
fatal('Cannot write ' + programOptions.output + '\n' + errorMessage(err));
|
|
1194
1195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAuE/D,YAAkB,aAAa,GAI/B;IAAe,IAAI,EAA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,EACL,OAAO,EACP,SAAS,EACT,cAAc,EACf,CAAC"}
|
|
@@ -106,5 +106,6 @@ declare const genericRawTextElements: Set<string>;
|
|
|
106
106
|
declare const endlessRawTextElements: Set<string>;
|
|
107
107
|
declare const escapableRawTextElements: Set<string>;
|
|
108
108
|
declare const rawTextElements: Set<string>;
|
|
109
|
-
|
|
109
|
+
declare const MISSING_DEPENDENCY = "HMN_MISSING_DEPENDENCY";
|
|
110
|
+
export { RE_WS_START, RE_WS_END, RE_WS_ONLY, RE_WS_NBSP_END, RE_ALL_WS_NBSP, RE_NBSP_LEADING_GROUP, RE_NBSP_LEAD_GROUP, RE_NBSP_TRAILING_GROUP, RE_NBSP_TRAILING_STRIP, RE_EVENT_ATTR_DEFAULT, RE_CAN_REMOVE_ATTR_QUOTES, RE_TRAILING_SEMICOLON, RE_AMP_ENTITY, RE_LEGACY_ENTITIES, RE_ESCAPE_LT, RE_ESCAPE_LT_RAW_TEXT, RE_HTML_ENCODING, RE_ATTR_WS_CHECK, RE_ATTR_WS_COLLAPSE, RE_ATTR_WS_TRIM, RE_STYLE_ELEMENT, RE_EMPTY_ATTRIBUTE, inlineElementsToKeepWhitespaceAround, inlineElementsToKeepWhitespaceWithin, inlineElementsToKeepWhitespace, formControlElements, generalDefaults, tagDefaults, executableScriptsMimetypes, keepScriptsMimetypes, jsonScriptTypes, isSimpleBoolean, isBooleanValue, collapsibleValues, srcsetElements, MISSING_DEPENDENCY, optionalStartTags, optionalEndTags, headerElements, descriptionElements, pBlockElements, pInlineElements, rubyEndTagOmission, rubyRtcEndTagOmission, optionElements, tableContentElements, tableSectionElements, cellElements, topLevelElements, compactElements, looseElements, trailingElements, htmlElements, specialContentElements, genericRawTextElements, endlessRawTextElements, escapableRawTextElements, rawTextElements };
|
|
110
111
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/constants.js"],"names":[],"mappings":"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,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAkB;AA5CtB,2EAA2E;AAI3E;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,wCAAwC;AACxC,iBAAS,qBAAqB,CAAC,OAAO,EAD1B,gBAC0B,WAUrC;AA+CE,YAAkB,gBAAgB,GAM3B,gBAAgB,EAAE,CAAC;AAZ7B;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,kBAAkB;;;;;;;;eAYT,kCAAkC,QAAvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;IAI5C,CAAC;AAuCF;;;;GAIG;AACH,QAAA,MAAM,cAAc,iBAJT,eAAe,mGACf;IAAC,eAAe,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,WAAW,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IAAC,aAAa,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,GAAG,GAAG,SAAS,CAAA;CAAC,KAC5O,gBAkjBZ,CAAC;AAIF,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACf,CAAC"}
|
|
@@ -98,5 +98,16 @@ declare function describeQuantifierRisk(pattern: RegExp | string): string | null
|
|
|
98
98
|
* @returns {number} Index of the closing `>`, or -1 if not found
|
|
99
99
|
*/
|
|
100
100
|
declare function findTagEnd(html: string, pos: number, limit?: number): number;
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
|
+
* A package that resolves but fails to load—e.g., a native binding built for
|
|
103
|
+
* another platform—is not one another `npm install` fixes, so name what happened
|
|
104
|
+
* rather than the install command
|
|
105
|
+
*
|
|
106
|
+
* @param {string} label - Minifier name as it should read in the message
|
|
107
|
+
* @param {string} specifier - Package that failed to load
|
|
108
|
+
* @param {unknown} cause - Error the import rejected with
|
|
109
|
+
* @returns {string} Message describing the failure
|
|
110
|
+
*/
|
|
111
|
+
declare function describeDependencyFailure(label: string, specifier: string, cause: unknown): string;
|
|
112
|
+
export { stableStringify, findTagEnd, LRU, MAX_CACHE_ENTRY_SIZE, hashContent, uniqueId, identity, isThenable, lowercase, paramCase, replaceAsync, parseRegExp, embedSource, lostFlag, describeQuantifierRisk, describeDependencyFailure };
|
|
102
113
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,iBAAS,eAAe,CAAC,GAAG,EAHjB,OAGiB,GAFf,MAAM,CAYlB;AAID,cAAM,GAAG;IAEA,KAAK;IACL,IAAI;IACJ,IAAI;IACT,mCAAmC;IAC9B,GAAG,EADG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAJjC,YAAY,KAAK,SAAM,EAMtB;IACD,0BAA0B;IAC1B,GAAG,CAAC,GAAG,EADK,MACL,WAUN;IACD;;;OAGG;IACH,GAAG,CAAC,GAAG,EAHI,MAGJ,EAAE,KAAK,EAFH,OAEG,QAOb;IACD,0BAA0B;IAC1B,MAAM,CAAC,GAAG,EADE,MACF,QAA2B;IACrC,6EAA6E;IAC7E,KAAK,IADS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAGxE;CACF;AAKD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AS,EACT,YAAY,EACZ,WAAW,EACX,WAAW,EACX,QAAQ,EACR,sBAAsB,EACtB,yBAAyB,EAC1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whitespace.d.ts","sourceRoot":"","sources":["../../../src/lib/whitespace.js"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"whitespace.d.ts","sourceRoot":"","sources":["../../../src/lib/whitespace.js"],"names":[],"mappings":"AAAA;;GAEG;AAqBH,0BAA0B;AAC1B,QAAA,MAAM,cAAc,QADR,MAAM,WAQjB,CAAC;AAuBF,0BAA0B;AAC1B,iBAAS,qBAAqB,CAAC,GAAG,EADtB,MACsB,UAOjC;AAeD;;;;;;GAMG;AACH,iBAAS,kBAAkB,CAAC,GAAG,EANpB,MAMoB,EAAE,OAAO,EAL7B;IAAC,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAKxD,EAAE,QAAQ,EAJvC,OAIuC,EAAE,SAAS,EAHlD,OAGkD,EAAE,WAAW,AAFvE,CAA8B,EAAtB,OAEuE,UAcjF;AAsHD;;;;;;;;;GASG;AACH,iBAAS,uBAAuB,CAAC,GAAG,EATzB,MASyB,EAAE,OAAO,EARlC,MAQkC,EAAE,OAAO,EAP3C,MAO2C,EAAE,SAAS,EANtD,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAMkB,EAAE,SAAS,EALjE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAK6B,EAAE,OAAO,EAJ1E;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAAC,2BAA2B,CAAC,EAAE,OAAO,CAAA;CAI1B,EAAE,cAAc,EAH1F,GAAG,CAAC,MAAM,CAGgF,EAAE,aAAa,EAFzG,GAAG,CAAC,MAAM,CAE+F,UA6DnH;AAcD,0BAA0B;AAC1B,iBAAS,qBAAqB,CAAC,GAAG,EADtB,MACsB,WAEjC;AAED,0BAA0B;AAC1B,iBAAS,iBAAiB,CAAC,GAAG,EADlB,MACkB,WAE7B;AAID,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@commitlint/cli": "^21.2.2",
|
|
18
18
|
"@eslint/js": "^10.0.1",
|
|
19
19
|
"@swc/core": "^1.16.2",
|
|
20
|
-
"@types/node": "^26.5.
|
|
20
|
+
"@types/node": "^26.5.1",
|
|
21
21
|
"eslint": "^10.10.0",
|
|
22
22
|
"globals": "^17.12.0",
|
|
23
23
|
"typescript": "^7.0.2",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
},
|
|
96
96
|
"type": "module",
|
|
97
97
|
"types": "dist/types/htmlminifier.d.ts",
|
|
98
|
-
"version": "8.4.
|
|
98
|
+
"version": "8.4.3"
|
|
99
99
|
}
|
package/src/htmlminifier.js
CHANGED
|
@@ -2,7 +2,7 @@ import { HTMLParser, endTag } from './htmlparser.js';
|
|
|
2
2
|
import TokenChain from './tokenchain.js';
|
|
3
3
|
import { presets, getPreset, getPresetNames } from './presets.js';
|
|
4
4
|
|
|
5
|
-
import { LRU, findTagEnd, identity, isThenable, lowercase, uniqueId } from './lib/utils.js';
|
|
5
|
+
import { LRU, describeDependencyFailure, findTagEnd, identity, isThenable, lowercase, uniqueId } from './lib/utils.js';
|
|
6
6
|
import { collectUsedSymbols } from './lib/unused-css.js';
|
|
7
7
|
|
|
8
8
|
import {
|
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
compactElements,
|
|
27
27
|
looseElements,
|
|
28
28
|
trailingElements,
|
|
29
|
-
pInlineElements
|
|
29
|
+
pInlineElements,
|
|
30
|
+
MISSING_DEPENDENCY
|
|
30
31
|
} from './lib/constants.js';
|
|
31
32
|
|
|
32
33
|
import {
|
|
@@ -516,17 +517,26 @@ async function getTerser() {
|
|
|
516
517
|
return terserPromise;
|
|
517
518
|
}
|
|
518
519
|
|
|
520
|
+
/**
|
|
521
|
+
* @param {string} label - Minifier name as it should read in the message
|
|
522
|
+
* @param {string} specifier - Package that failed to load
|
|
523
|
+
* @param {unknown} cause - Error the import rejected with
|
|
524
|
+
* @returns {Error} Error marked as an unavailable dependency
|
|
525
|
+
*/
|
|
526
|
+
function unavailableDependency(label, specifier, cause) {
|
|
527
|
+
const err = new Error(describeDependencyFailure(label, specifier, cause), { cause });
|
|
528
|
+
/** @type {any} */ (err).code = MISSING_DEPENDENCY;
|
|
529
|
+
return err;
|
|
530
|
+
}
|
|
531
|
+
|
|
519
532
|
/** @type {Promise<any> | undefined} */
|
|
520
533
|
let swcPromise;
|
|
521
534
|
async function getSwc() {
|
|
522
535
|
if (!swcPromise) {
|
|
523
536
|
swcPromise = import('@swc/core')
|
|
524
537
|
.then(m => m.default || m)
|
|
525
|
-
.catch(
|
|
526
|
-
throw
|
|
527
|
-
'The swc minifier requires @swc/core to be installed.\n' +
|
|
528
|
-
'Install it with: npm install @swc/core'
|
|
529
|
-
);
|
|
538
|
+
.catch(err => {
|
|
539
|
+
throw unavailableDependency('swc', '@swc/core', err);
|
|
530
540
|
});
|
|
531
541
|
}
|
|
532
542
|
return swcPromise;
|
package/src/lib/constants.js
CHANGED
|
@@ -207,6 +207,10 @@ const escapableRawTextElements = new Set(['textarea', 'title']);
|
|
|
207
207
|
// of `textarea` and `title`, where they are resolved as they are anywhere else
|
|
208
208
|
const rawTextElements = new Set([...specialContentElements, ...genericRawTextElements]);
|
|
209
209
|
|
|
210
|
+
// Marks the error for a minifier that was asked for but isn’t available—a
|
|
211
|
+
// configuration error, and so not one that `continueOnMinifyError` waves through
|
|
212
|
+
const MISSING_DEPENDENCY = 'HMN_MISSING_DEPENDENCY';
|
|
213
|
+
|
|
210
214
|
// Exports
|
|
211
215
|
|
|
212
216
|
export {
|
|
@@ -256,6 +260,7 @@ export {
|
|
|
256
260
|
|
|
257
261
|
// Misc
|
|
258
262
|
srcsetElements,
|
|
263
|
+
MISSING_DEPENDENCY,
|
|
259
264
|
|
|
260
265
|
// Tag omission rules
|
|
261
266
|
optionalStartTags,
|
package/src/lib/file-pool.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import fs from 'node:fs';
|
|
23
23
|
import { isMainThread, parentPort, workerData, Worker } from 'node:worker_threads';
|
|
24
|
+
import { writeFileAtomic } from './file-write.js';
|
|
24
25
|
|
|
25
26
|
// This module is its own worker entry point: The pool spawns it by URL and the branch
|
|
26
27
|
// below runs in the spawned copy. Keeping both halves in one file keeps the message
|
|
@@ -61,7 +62,7 @@ if (!isMainThread && parentPort) {
|
|
|
61
62
|
const minified = await minify(data, taskOptions);
|
|
62
63
|
if (!task.dryRun) {
|
|
63
64
|
stage = 'write';
|
|
64
|
-
await
|
|
65
|
+
await writeFileAtomic(task.outputFile, minified);
|
|
65
66
|
}
|
|
66
67
|
port.postMessage({
|
|
67
68
|
id: task.id,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output writing for the CLI, shared by in-process runs and the worker pool
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import crypto from 'node:crypto';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
// A random name is taken by chance only, so a few attempts are plenty
|
|
10
|
+
const ATTEMPTS_MAX = 10;
|
|
11
|
+
// As many links as a system commonly follows before reporting a loop
|
|
12
|
+
const LINKS_MAX = 40;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The file a write replaces: the output itself or, for a symlink, the file it
|
|
16
|
+
* points to—followed by hand where that file does not exist yet, which
|
|
17
|
+
* `realpath` cannot resolve
|
|
18
|
+
* @param {string} outputFile
|
|
19
|
+
* @returns {Promise<string>}
|
|
20
|
+
*/
|
|
21
|
+
async function resolveTarget(outputFile) {
|
|
22
|
+
let file = outputFile;
|
|
23
|
+
for (let i = 0; i < LINKS_MAX; i++) {
|
|
24
|
+
try {
|
|
25
|
+
return await fs.promises.realpath(file);
|
|
26
|
+
} catch {
|
|
27
|
+
const link = await fs.promises.readlink(file).catch(() => undefined);
|
|
28
|
+
if (link === undefined) return file;
|
|
29
|
+
// A relative link is read from the real location of its folder
|
|
30
|
+
const dir = await fs.promises.realpath(path.dirname(file)).catch(() => path.dirname(file));
|
|
31
|
+
file = path.resolve(dir, link);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// A loop, which writing through would not resolve, either—refused so the rename cannot replace the link
|
|
35
|
+
throw Object.assign(new Error(`ELOOP: Too many symbolic links encountered, '${outputFile}'`), { code: 'ELOOP', path: outputFile });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a temporary file next to the target under a random name, exclusively,
|
|
40
|
+
* so that it can neither be predicted nor write through a file or link already there
|
|
41
|
+
* @param {string} targetFile
|
|
42
|
+
* @param {number | undefined} mode
|
|
43
|
+
*/
|
|
44
|
+
async function openTempFile(targetFile, mode) {
|
|
45
|
+
for (let attempt = 1; ; attempt++) {
|
|
46
|
+
const tempFile = path.join(path.dirname(targetFile), `.${path.basename(targetFile)}.${crypto.randomBytes(8).toString('hex')}.tmp`);
|
|
47
|
+
try {
|
|
48
|
+
return { tempFile, handle: await fs.promises.open(tempFile, 'wx', mode) };
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (/** @type {any} */ (err).code !== 'EEXIST' || attempt >= ATTEMPTS_MAX) throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Write a file by way of a temporary file in the same folder, so that an exit
|
|
57
|
+
* that leaves no chance to clean up—a native crash in a minifier, an OOM
|
|
58
|
+
* kill—cannot leave a half-written file where the output belongs
|
|
59
|
+
* @param {string} outputFile
|
|
60
|
+
* @param {string} data
|
|
61
|
+
*/
|
|
62
|
+
export async function writeFileAtomic(outputFile, data) {
|
|
63
|
+
// A rename would replace a symlink itself, so work on the file it points to
|
|
64
|
+
const targetFile = await resolveTarget(outputFile);
|
|
65
|
+
// The rename replaces the output rather than writing through it, so a mode set on the output has to be carried over
|
|
66
|
+
const stats = await fs.promises.stat(targetFile).catch(() => undefined);
|
|
67
|
+
const mode = stats ? stats.mode & 0o7777 : undefined;
|
|
68
|
+
|
|
69
|
+
// Outside the `try`, so that only a file this write created is ever removed
|
|
70
|
+
const { tempFile, handle } = await openTempFile(targetFile, mode);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
try {
|
|
74
|
+
await handle.writeFile(data, 'utf8');
|
|
75
|
+
} finally {
|
|
76
|
+
await handle.close();
|
|
77
|
+
}
|
|
78
|
+
// `mode` on creation is subject to the umask, so the exact bits have to be set separately
|
|
79
|
+
if (mode !== undefined) {
|
|
80
|
+
await fs.promises.chmod(tempFile, mode);
|
|
81
|
+
}
|
|
82
|
+
await fs.promises.rename(tempFile, targetFile);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
await fs.promises.rm(tempFile, { force: true });
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/lib/options.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { createUrlMinifier } from './urls.js';
|
|
6
6
|
import { LRU, MAX_CACHE_ENTRY_SIZE, stableStringify, hashContent, identity, lowercase, paramCase, replaceAsync, parseRegExp, describeQuantifierRisk, lostFlag } from './utils.js';
|
|
7
|
-
import { RE_TRAILING_SEMICOLON } from './constants.js';
|
|
7
|
+
import { RE_TRAILING_SEMICOLON, MISSING_DEPENDENCY } from './constants.js';
|
|
8
8
|
import { canCollapseWhitespace, canTrimWhitespace } from './whitespace.js';
|
|
9
9
|
import { wrapCSS, unwrapCSS } from './content.js';
|
|
10
10
|
import { findUnusedSymbols, normalizeUnusedCSSOptions } from './unused-css.js';
|
|
@@ -152,6 +152,33 @@ function isRequested(value) {
|
|
|
152
152
|
return Array.isArray(value) ? value.length > 0 : Boolean(value);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/** @param {unknown} err - Error raised while minifying */
|
|
156
|
+
function isMissingDependency(err) {
|
|
157
|
+
return Boolean(err) && /** @type {any} */ (err).code === MISSING_DEPENDENCY;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// An unset (falsy) engine takes the fallback and names match lowercase; anything else
|
|
161
|
+
// passes through untouched so that validation reports it instead of a type error
|
|
162
|
+
/**
|
|
163
|
+
* @param {unknown} engine - Configured engine name
|
|
164
|
+
* @param {string} fallback - Engine to use when none is configured
|
|
165
|
+
*/
|
|
166
|
+
function normalizeEngine(engine, fallback) {
|
|
167
|
+
if (!engine) return fallback;
|
|
168
|
+
return typeof engine === 'string' ? engine.toLowerCase() : engine;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** @param {unknown} engine - Engine name as it should read in an error message */
|
|
172
|
+
function describeEngine(engine) {
|
|
173
|
+
if (typeof engine === 'string') return engine;
|
|
174
|
+
try {
|
|
175
|
+
return JSON.stringify(engine) ?? String(engine);
|
|
176
|
+
} catch {
|
|
177
|
+
// BigInt and cyclic values do not serialize
|
|
178
|
+
return String(engine);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
155
182
|
// Main options processor
|
|
156
183
|
|
|
157
184
|
/**
|
|
@@ -433,12 +460,12 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
|
|
|
433
460
|
|
|
434
461
|
// Parse configuration
|
|
435
462
|
const config = typeof option === 'object' ? option : {};
|
|
436
|
-
const engine = (config.engine
|
|
463
|
+
const engine = normalizeEngine(config.engine, 'terser');
|
|
437
464
|
|
|
438
465
|
// Validate engine
|
|
439
466
|
const supportedEngines = ['terser', 'swc'];
|
|
440
|
-
if (!supportedEngines.includes(engine)) {
|
|
441
|
-
throw new Error(`Unsupported JS minifier engine:
|
|
467
|
+
if (!supportedEngines.includes(/** @type {string} */ (engine))) {
|
|
468
|
+
throw new Error(`Unsupported JS minifier engine: \`${describeEngine(engine)}\`. Supported engines: ${supportedEngines.join(', ')}`);
|
|
442
469
|
}
|
|
443
470
|
|
|
444
471
|
// Extract engine-specific options (excluding `engine` field itself)
|
|
@@ -530,7 +557,7 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
|
|
|
530
557
|
return resolved;
|
|
531
558
|
} catch (err) {
|
|
532
559
|
if (jsKey !== undefined) jsCache.delete(jsKey);
|
|
533
|
-
if (!options.continueOnMinifyError) {
|
|
560
|
+
if (!options.continueOnMinifyError || isMissingDependency(err)) {
|
|
534
561
|
throw err;
|
|
535
562
|
}
|
|
536
563
|
options.log && options.log(err);
|
package/src/lib/utils.js
CHANGED
|
@@ -840,6 +840,28 @@ function findTagEnd(html, pos, limit = html.length) {
|
|
|
840
840
|
return -1;
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
+
/**
|
|
844
|
+
* A package that resolves but fails to load—e.g., a native binding built for
|
|
845
|
+
* another platform—is not one another `npm install` fixes, so name what happened
|
|
846
|
+
* rather than the install command
|
|
847
|
+
*
|
|
848
|
+
* @param {string} label - Minifier name as it should read in the message
|
|
849
|
+
* @param {string} specifier - Package that failed to load
|
|
850
|
+
* @param {unknown} cause - Error the import rejected with
|
|
851
|
+
* @returns {string} Message describing the failure
|
|
852
|
+
*/
|
|
853
|
+
function describeDependencyFailure(label, specifier, cause) {
|
|
854
|
+
const err = /** @type {any} */ (cause);
|
|
855
|
+
const notInstalled =
|
|
856
|
+
err?.code === 'ERR_MODULE_NOT_FOUND' && String(err?.message).includes(`'${specifier}'`);
|
|
857
|
+
if (notInstalled) {
|
|
858
|
+
return `The ${label} minifier requires ${specifier} to be installed.\n` +
|
|
859
|
+
`Install it with: npm install ${specifier}`;
|
|
860
|
+
}
|
|
861
|
+
return `The ${label} minifier could not load ${specifier}: ` +
|
|
862
|
+
(cause instanceof Error ? cause.message : String(cause));
|
|
863
|
+
}
|
|
864
|
+
|
|
843
865
|
// Exports
|
|
844
866
|
|
|
845
867
|
export {
|
|
@@ -857,5 +879,6 @@ export {
|
|
|
857
879
|
parseRegExp,
|
|
858
880
|
embedSource,
|
|
859
881
|
lostFlag,
|
|
860
|
-
describeQuantifierRisk
|
|
882
|
+
describeQuantifierRisk,
|
|
883
|
+
describeDependencyFailure
|
|
861
884
|
};
|
package/src/lib/whitespace.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
RE_WS_START,
|
|
7
|
-
RE_WS_END,
|
|
8
6
|
RE_ALL_WS_NBSP,
|
|
9
7
|
RE_NBSP_LEADING_GROUP,
|
|
10
8
|
RE_NBSP_LEAD_GROUP,
|
|
@@ -15,37 +13,64 @@ import {
|
|
|
15
13
|
formControlElements
|
|
16
14
|
} from './constants.js';
|
|
17
15
|
|
|
16
|
+
const RE_ANY_WS_NBSP = /[ \n\r\t\f\xA0]/;
|
|
17
|
+
const RE_TAB_NBSP = /[\t\xA0]/;
|
|
18
|
+
const RE_ASCII_WS_RUN = /[ \n\r\f]+/g;
|
|
19
|
+
const RE_NEEDS_COLLAPSE = /[\n\r\f]| {2}/;
|
|
20
|
+
const RE_NON_WS = /\S/;
|
|
21
|
+
|
|
18
22
|
// Trim whitespace
|
|
19
23
|
|
|
20
24
|
/** @param {string} str */
|
|
21
25
|
const trimWhitespace = str => {
|
|
22
26
|
if (!str) return str;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return str.
|
|
27
|
+
let start = 0;
|
|
28
|
+
let end = str.length;
|
|
29
|
+
while (start < end && isAsciiWs(str.charCodeAt(start))) start++;
|
|
30
|
+
while (end > start && isAsciiWs(str.charCodeAt(end - 1))) end--;
|
|
31
|
+
return start === 0 && end === str.length ? str : str.slice(start, end);
|
|
28
32
|
};
|
|
29
33
|
|
|
34
|
+
/** @param {number} code */
|
|
35
|
+
function isAsciiWs(code) {
|
|
36
|
+
return code === 32 || code === 10 || code === 13 || code === 9 || code === 12;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {number} code */
|
|
40
|
+
function isWsOrNbsp(code) {
|
|
41
|
+
return code === 32 || code === 10 || code === 13 || code === 9 || code === 12 || code === 160;
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
// Collapse all whitespace
|
|
31
45
|
|
|
46
|
+
// Module scope so the hot path doesn’t allocate a closure per call
|
|
47
|
+
/** @param {string} spaces */
|
|
48
|
+
function collapseRun(spaces) {
|
|
49
|
+
// Preserve standalone tabs
|
|
50
|
+
if (spaces === '\t') return '\t';
|
|
51
|
+
if (spaces.indexOf('\xA0') === -1) return ' ';
|
|
52
|
+
return spaces.replace(RE_NBSP_LEADING_GROUP, '$1 ');
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
/** @param {string} str */
|
|
33
56
|
function collapseWhitespaceAll(str) {
|
|
34
57
|
if (!str) return str;
|
|
35
58
|
// Fast path: If there are no common whitespace characters, return early
|
|
36
|
-
if (
|
|
59
|
+
if (!RE_ANY_WS_NBSP.test(str)) {
|
|
37
60
|
return str;
|
|
38
61
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
return collapseWhitespaceAllKnown(str);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// As `collapseWhitespaceAll`, for callers that already know `str` holds whitespace
|
|
66
|
+
/** @param {string} str */
|
|
67
|
+
function collapseWhitespaceAllKnown(str) {
|
|
68
|
+
// Only a tab or a no-break space makes the replacement depend on the run itself;
|
|
69
|
+
// without either, every run becomes one space and no per-match callback is needed
|
|
70
|
+
if (!RE_TAB_NBSP.test(str)) {
|
|
71
|
+
return RE_NEEDS_COLLAPSE.test(str) ? str.replace(RE_ASCII_WS_RUN, ' ') : str;
|
|
72
|
+
}
|
|
73
|
+
return str.replace(RE_ALL_WS_NBSP, collapseRun);
|
|
49
74
|
}
|
|
50
75
|
|
|
51
76
|
// Collapse whitespace with options
|
|
@@ -58,8 +83,6 @@ function collapseWhitespaceAll(str) {
|
|
|
58
83
|
* @param {boolean} [collapseAll]
|
|
59
84
|
*/
|
|
60
85
|
function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = false) {
|
|
61
|
-
let lineBreakBefore = ''; let lineBreakAfter = '';
|
|
62
|
-
|
|
63
86
|
if (!str) return str;
|
|
64
87
|
|
|
65
88
|
// Fast path: Nothing to do
|
|
@@ -68,16 +91,30 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
68
91
|
}
|
|
69
92
|
|
|
70
93
|
// Fast path: No whitespace at all
|
|
71
|
-
if (
|
|
94
|
+
if (!RE_ANY_WS_NBSP.test(str)) {
|
|
72
95
|
return str;
|
|
73
96
|
}
|
|
74
97
|
|
|
98
|
+
return collapseWhitespaceKnown(str, options, trimLeft, trimRight, collapseAll);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// As `collapseWhitespace`, for callers that already know `str` is non-empty, holds
|
|
102
|
+
// whitespace, and has something to do
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} str
|
|
105
|
+
* @param {{preserveLineBreaks?: boolean | undefined, conservativeCollapse?: boolean | undefined}} options
|
|
106
|
+
* @param {boolean} trimLeft
|
|
107
|
+
* @param {boolean} trimRight
|
|
108
|
+
* @param {boolean} collapseAll
|
|
109
|
+
*/
|
|
110
|
+
function collapseWhitespaceKnown(str, options, trimLeft, trimRight, collapseAll) {
|
|
111
|
+
let lineBreakBefore = ''; let lineBreakAfter = '';
|
|
112
|
+
|
|
75
113
|
if (options.preserveLineBreaks) {
|
|
76
114
|
// Find leading/trailing whitespace containing line breaks manually
|
|
77
115
|
// (avoids polynomial backtracking with end-anchored lazy quantifiers)
|
|
78
|
-
const WS_CHARS = ' \n\r\t\f';
|
|
79
116
|
let leadEnd = 0;
|
|
80
|
-
while (leadEnd < str.length &&
|
|
117
|
+
while (leadEnd < str.length && isAsciiWs(str.charCodeAt(leadEnd))) {
|
|
81
118
|
leadEnd++;
|
|
82
119
|
}
|
|
83
120
|
if (leadEnd > 0) {
|
|
@@ -88,7 +125,7 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
88
125
|
}
|
|
89
126
|
}
|
|
90
127
|
let trailStart = str.length;
|
|
91
|
-
while (trailStart > 0 &&
|
|
128
|
+
while (trailStart > 0 && isAsciiWs(str.charCodeAt(trailStart - 1))) {
|
|
92
129
|
trailStart--;
|
|
93
130
|
}
|
|
94
131
|
if (trailStart < str.length) {
|
|
@@ -101,21 +138,34 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
101
138
|
}
|
|
102
139
|
|
|
103
140
|
if (trimLeft) {
|
|
104
|
-
//
|
|
105
|
-
|
|
141
|
+
// Find the leading whitespace boundary with a loop, so the common case neither
|
|
142
|
+
// allocates a replacer closure nor runs the regex machinery
|
|
143
|
+
let start = 0;
|
|
144
|
+
while (start < str.length && isWsOrNbsp(str.charCodeAt(start))) {
|
|
145
|
+
start++;
|
|
146
|
+
}
|
|
147
|
+
if (start > 0) {
|
|
148
|
+
const spaces = str.slice(0, start);
|
|
106
149
|
const conservative = !lineBreakBefore && options.conservativeCollapse;
|
|
150
|
+
let replacement;
|
|
107
151
|
if (conservative && spaces === '\t') {
|
|
108
|
-
|
|
152
|
+
replacement = '\t';
|
|
153
|
+
} else if (spaces.indexOf('\xA0') === -1) {
|
|
154
|
+
// No no-break space: The whole run goes
|
|
155
|
+
replacement = conservative ? ' ' : '';
|
|
156
|
+
} else {
|
|
157
|
+
// No-break space is specifically handled via the nested regexes
|
|
158
|
+
replacement = spaces.replace(/^[^\xA0]+/, '').replace(RE_NBSP_LEAD_GROUP, '$1 ') || (conservative ? ' ' : '');
|
|
109
159
|
}
|
|
110
|
-
|
|
111
|
-
}
|
|
160
|
+
str = replacement + str.slice(start);
|
|
161
|
+
}
|
|
112
162
|
}
|
|
113
163
|
|
|
114
164
|
if (trimRight) {
|
|
115
165
|
// Find trailing whitespace boundary manually (avoids polynomial backtracking
|
|
116
166
|
// with `/[ \n\r\t\f\xA0]+$/` on strings with long internal whitespace runs)
|
|
117
167
|
let end = str.length;
|
|
118
|
-
while (end > 0 &&
|
|
168
|
+
while (end > 0 && isWsOrNbsp(str.charCodeAt(end - 1))) {
|
|
119
169
|
end--;
|
|
120
170
|
}
|
|
121
171
|
if (end < str.length) {
|
|
@@ -124,6 +174,9 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
124
174
|
let replacement;
|
|
125
175
|
if (conservative && spaces === '\t') {
|
|
126
176
|
replacement = '\t';
|
|
177
|
+
} else if (spaces.indexOf('\xA0') === -1) {
|
|
178
|
+
// No no-break space: The whole run goes
|
|
179
|
+
replacement = conservative ? ' ' : '';
|
|
127
180
|
} else {
|
|
128
181
|
// No-break space is specifically handled via the nested regexes
|
|
129
182
|
replacement = spaces.replace(RE_NBSP_TRAILING_GROUP, ' $1').replace(RE_NBSP_TRAILING_STRIP, '') || (conservative ? ' ' : '');
|
|
@@ -132,9 +185,9 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
132
185
|
}
|
|
133
186
|
}
|
|
134
187
|
|
|
135
|
-
if (collapseAll) {
|
|
188
|
+
if (collapseAll && str) {
|
|
136
189
|
// Strip non-space whitespace then compress spaces to one
|
|
137
|
-
str =
|
|
190
|
+
str = collapseWhitespaceAllKnown(str);
|
|
138
191
|
}
|
|
139
192
|
|
|
140
193
|
// Avoid string concatenation when no line breaks (common case)
|
|
@@ -149,11 +202,10 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll = fal
|
|
|
149
202
|
// Check if an input element has `type="hidden"`; module-scope so the hot path
|
|
150
203
|
// doesn’t allocate a closure per text node
|
|
151
204
|
/**
|
|
152
|
-
* @param {string} tagName
|
|
153
205
|
* @param {Array<{name: string, value?: string}>} attrs
|
|
154
206
|
*/
|
|
155
|
-
function isHiddenInput(
|
|
156
|
-
if (
|
|
207
|
+
function isHiddenInput(attrs) {
|
|
208
|
+
if (!attrs || !attrs.length) return false;
|
|
157
209
|
for (const attr of attrs) {
|
|
158
210
|
if (attr.name === 'type') {
|
|
159
211
|
return attr.value === 'hidden';
|
|
@@ -177,77 +229,67 @@ function collapseWhitespaceSmart(str, prevTag, nextTag, prevAttrs, nextAttrs, op
|
|
|
177
229
|
|
|
178
230
|
// Fast path: No whitespace at all—every decision below would leave `str`
|
|
179
231
|
// untouched (`collapseWhitespace` returns such strings unchanged)
|
|
180
|
-
if (
|
|
232
|
+
if (!RE_ANY_WS_NBSP.test(str)) {
|
|
181
233
|
return str;
|
|
182
234
|
}
|
|
183
235
|
|
|
184
|
-
const
|
|
185
|
-
const nextTagName = nextTag && (nextTag.charAt(0) === '/' ? nextTag.slice(1) : nextTag);
|
|
186
|
-
|
|
187
|
-
// Check if prev/next are non-rendering (hidden) elements
|
|
188
|
-
const prevIsHidden = isHiddenInput(prevTagName, prevAttrs);
|
|
189
|
-
const nextIsHidden = isHiddenInput(nextTagName, nextAttrs);
|
|
190
|
-
|
|
191
|
-
let trimLeft = prevTag && !inlineElementsToKeepWhitespace.has(prevTag);
|
|
192
|
-
|
|
193
|
-
// Whether the text is whitespace only—one scan, shared by the checks below
|
|
194
|
-
// (`str` is known non-empty here)
|
|
195
|
-
const isPureWhitespace = !/\S/.test(str);
|
|
236
|
+
const inlineOption = Boolean(options.collapseInlineTagWhitespace);
|
|
196
237
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (!trimLeft && prevIsHidden && isPureWhitespace) {
|
|
200
|
-
trimLeft = true;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Aggressive mode: Collapse between all form controls (pure whitespace only)
|
|
204
|
-
if (!trimLeft && prevTagName && nextTagName &&
|
|
205
|
-
options.collapseInlineTagWhitespace &&
|
|
206
|
-
isPureWhitespace &&
|
|
207
|
-
formControlElements.has(prevTagName) && formControlElements.has(nextTagName)) {
|
|
208
|
-
trimLeft = true;
|
|
209
|
-
}
|
|
238
|
+
let trimLeft = Boolean(prevTag) && !inlineElementsToKeepWhitespace.has(prevTag);
|
|
239
|
+
let trimRight = Boolean(nextTag) && !inlineElementsToKeepWhitespace.has(nextTag);
|
|
210
240
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
241
|
+
// Every branch below that consults the text’s content needs a side left untrimmed,
|
|
242
|
+
// so the scan for a non-whitespace character is only worth making then
|
|
243
|
+
const isPureWhitespace = (!trimLeft || !trimRight) && !RE_NON_WS.test(str);
|
|
214
244
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
trimLeft =
|
|
245
|
+
if (isPureWhitespace) {
|
|
246
|
+
// Smart default behavior: Collapse space around non-rendering elements
|
|
247
|
+
// (`type="hidden"`); this happens even in basic `collapseWhitespace` mode
|
|
248
|
+
if (!trimLeft && prevTag === 'input' && isHiddenInput(prevAttrs)) {
|
|
249
|
+
trimLeft = true;
|
|
250
|
+
}
|
|
251
|
+
if (!trimRight && nextTag === 'input' && isHiddenInput(nextAttrs)) {
|
|
252
|
+
trimRight = true;
|
|
253
|
+
}
|
|
254
|
+
// Aggressive mode: Collapse between all form controls
|
|
255
|
+
if (inlineOption && (!trimLeft || !trimRight) &&
|
|
256
|
+
formControlElements.has(stripSlash(prevTag)) && formControlElements.has(stripSlash(nextTag))) {
|
|
257
|
+
trimLeft = true;
|
|
258
|
+
trimRight = true;
|
|
220
259
|
}
|
|
221
260
|
}
|
|
222
261
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
options.collapseInlineTagWhitespace &&
|
|
233
|
-
isPureWhitespace &&
|
|
234
|
-
formControlElements.has(prevTagName) && formControlElements.has(nextTagName)) {
|
|
235
|
-
trimRight = true;
|
|
262
|
+
if (trimLeft) {
|
|
263
|
+
if (inlineOption) {
|
|
264
|
+
// Still preserve whitespace around inline text elements
|
|
265
|
+
if (inlineElementsToKeepWhitespaceWithin.has(stripSlash(prevTag))) {
|
|
266
|
+
trimLeft = false;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
trimLeft = prevTag.charCodeAt(0) === 47 /* / */ ? !inlineElements.has(prevTag.slice(1)) : !inlineTextSet.has(prevTag);
|
|
270
|
+
}
|
|
236
271
|
}
|
|
237
272
|
|
|
238
|
-
if (trimRight
|
|
239
|
-
|
|
273
|
+
if (trimRight) {
|
|
274
|
+
if (inlineOption) {
|
|
275
|
+
if (inlineElementsToKeepWhitespaceWithin.has(stripSlash(nextTag))) {
|
|
276
|
+
trimRight = false;
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
trimRight = nextTag.charCodeAt(0) === 47 /* / */ ? !inlineTextSet.has(nextTag.slice(1)) : !inlineElements.has(nextTag);
|
|
280
|
+
}
|
|
240
281
|
}
|
|
241
282
|
|
|
242
|
-
|
|
243
|
-
if (trimRight && options.
|
|
244
|
-
|
|
245
|
-
if (inlineElementsToKeepWhitespaceWithin.has(tagName)) {
|
|
246
|
-
trimRight = false;
|
|
247
|
-
}
|
|
283
|
+
const collapseAll = Boolean(prevTag && nextTag);
|
|
284
|
+
if (!trimLeft && !trimRight && !collapseAll && !options.preserveLineBreaks) {
|
|
285
|
+
return str;
|
|
248
286
|
}
|
|
287
|
+
return collapseWhitespaceKnown(str, options, trimLeft, trimRight, collapseAll);
|
|
288
|
+
}
|
|
249
289
|
|
|
250
|
-
|
|
290
|
+
/** @param {string} tag */
|
|
291
|
+
function stripSlash(tag) {
|
|
292
|
+
return tag && tag.charCodeAt(0) === 47 /* / */ ? tag.slice(1) : tag;
|
|
251
293
|
}
|
|
252
294
|
|
|
253
295
|
// Collapse/trim whitespace for given tag
|