@@ -716,6 +716,26 @@ exports.ModuleScopeEnumOptions = void 0;
716716 * export using ICSS module format
717717 */
718718 ModuleScopeEnumOptions[ModuleScopeEnumOptions["ICSS"] = 256] = "ICSS";
719+ /**
720+ * use the shortest name possible. pattern is ignored.
721+ * it will produce names such as
722+ *
723+ * ```css
724+ * .a {
725+ * content: 'a';
726+ * }
727+ *
728+ * .b {
729+ * content: 'b';
730+ * }
731+ *
732+ * .c {
733+ * content: 'c';
734+ * }
735+ * ...
736+ * ```
737+ */
738+ ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
719739})(exports.ModuleScopeEnumOptions || (exports.ModuleScopeEnumOptions = {}));
720740
721741// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
@@ -18134,6 +18154,24 @@ function getKeyName(key, how) {
1813418154 }
1813518155 return key;
1813618156}
18157+ let keyNameCounter = 0;
18158+ let keyNameCache = {};
18159+ function getShortNameGenerator() {
18160+ const forbidden = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].map(c => c.charCodeAt(0));
18161+ return (localName, filePath, pattern, hashLength = 5) => {
18162+ const key = `${localName}_${filePath}_${pattern}_${hashLength}`;
18163+ if (key in keyNameCache) {
18164+ return keyNameCache[key];
18165+ }
18166+ let value = keyNameCounter.toString(36);
18167+ keyNameCounter++;
18168+ while (forbidden.includes(value.charCodeAt(0))) {
18169+ value = keyNameCounter.toString(36);
18170+ keyNameCounter++;
18171+ }
18172+ return keyNameCache[key] ?? (keyNameCache[key] = value);
18173+ };
18174+ }
1813718175/**
1813818176 * generate scoped name
1813918177 * @param localName
@@ -18786,6 +18824,10 @@ async function doParse(iter, options = {}) {
1878618824 // @ts-ignore
1878718825 moduleSettings.scoped |= exports.ModuleScopeEnumOptions.Pure;
1878818826 }
18827+ if (options.module & exports.ModuleScopeEnumOptions.Shortest) {
18828+ // @ts-ignore
18829+ moduleSettings.scoped |= exports.ModuleScopeEnumOptions.Shortest;
18830+ }
1878918831 if (options.module & exports.ModuleScopeEnumOptions.ICSS) {
1879018832 // @ts-ignore
1879118833 moduleSettings.scoped |= exports.ModuleScopeEnumOptions.ICSS;
@@ -18794,6 +18836,9 @@ async function doParse(iter, options = {}) {
1879418836 if (typeof moduleSettings.scoped == 'boolean') {
1879518837 moduleSettings.scoped = moduleSettings.scoped ? exports.ModuleScopeEnumOptions.Local : exports.ModuleScopeEnumOptions.Global;
1879618838 }
18839+ if (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Shortest) {
18840+ moduleSettings.generateScopedName = getShortNameGenerator();
18841+ }
1879718842 moduleSettings.filePath = filePath;
1879818843 moduleSettings.pattern = pattern != null && pattern !== '' ? pattern : (filePath === '' ? `[local]_[hash]` : `[local]_[hash]_[name]`);
1879918844 for (const { node, parent } of walk(ast)) {
@@ -21320,10 +21365,9 @@ class InlineCssVariablesFeature {
2132021365 }
2132121366 }
2132221367 run(ast, options = {}, parent, context) {
21323- // if (!('chi' in ast)) {
21324- //
21325- // return null;
21326- // }
21368+ if (!('chi' in ast)) {
21369+ return null;
21370+ }
2132721371 if (!('variableScope' in context)) {
2132821372 context.variableScope = new Map;
2132921373 }
@@ -21369,10 +21413,9 @@ class InlineCssVariablesFeature {
2136921413 }
2137021414 cleanup(ast, options = {}, context) {
2137121415 const variableScope = context.variableScope;
21372- // if (variableScope == null) {
21373- //
21374- // return;
21375- // }
21416+ if (variableScope == null) {
21417+ return;
21418+ }
2137621419 for (const info of variableScope.values()) {
2137721420 if (info.replaceable) {
2137821421 let i;
0 commit comments