@csszyx/compiler 0.10.7 → 0.10.8

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/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const core = require('@csszyx/core');
4
- const transformCore = require('./shared/compiler.DIYC1vdY.cjs');
4
+ const transformCore = require('./shared/compiler.mibv6qPF.cjs');
5
5
  const oxcParser = require('oxc-parser');
6
6
  const t = require('@babel/types');
7
7
  const node_crypto = require('node:crypto');
@@ -245,6 +245,9 @@ function transformSourceCode(source, filename, options) {
245
245
  }
246
246
  const createMergedClassNameValue = (szExpr) => {
247
247
  if (!existingClassExpr) {
248
+ if (t__namespace.isStringLiteral(szExpr) && szExpr.value === "") {
249
+ return t__namespace.jsxExpressionContainer(t__namespace.identifier("undefined"));
250
+ }
248
251
  return t__namespace.isStringLiteral(szExpr) ? szExpr : t__namespace.jsxExpressionContainer(szExpr);
249
252
  }
250
253
  if (existingClassNameNode && path.parentPath?.isJSXOpeningElement()) {
@@ -826,6 +829,9 @@ function parseStyleStringToObjectExpr(styleStr) {
826
829
  }
827
830
  return t__namespace.objectExpression(objProps);
828
831
  }
832
+ function emptyClassToUndefined(node) {
833
+ return t__namespace.isStringLiteral(node) && node.value === "" ? t__namespace.identifier("undefined") : node;
834
+ }
829
835
  function tryStaticTransformNode(node, getBinding) {
830
836
  if (t__namespace.isTSAsExpression(node) || t__namespace.isTSSatisfiesExpression(node)) {
831
837
  return tryStaticTransformNode(node.expression, getBinding);
@@ -862,7 +868,11 @@ function tryStaticTransformNode(node, getBinding) {
862
868
  const consequent = tryStaticTransformNode(node.consequent, getBinding);
863
869
  const alternate = tryStaticTransformNode(node.alternate, getBinding);
864
870
  if (consequent !== null && alternate !== null) {
865
- return t__namespace.conditionalExpression(node.test, consequent, alternate);
871
+ return t__namespace.conditionalExpression(
872
+ node.test,
873
+ emptyClassToUndefined(consequent),
874
+ emptyClassToUndefined(alternate)
875
+ );
866
876
  }
867
877
  return null;
868
878
  }
@@ -899,7 +909,11 @@ function tryHoistConditionalSpread(node, getBinding) {
899
909
  if (!t__namespace.isStringLiteral(resolvedA) || !t__namespace.isStringLiteral(resolvedB)) {
900
910
  return null;
901
911
  }
902
- return t__namespace.conditionalExpression(conditionalExpr.test, resolvedA, resolvedB);
912
+ return t__namespace.conditionalExpression(
913
+ conditionalExpr.test,
914
+ emptyClassToUndefined(resolvedA),
915
+ emptyClassToUndefined(resolvedB)
916
+ );
903
917
  }
904
918
  function readStaticConfigObject(configExpr, key, scope) {
905
919
  for (const prop of configExpr.properties) {
@@ -1029,20 +1043,20 @@ function buildConditionalClassExpr(baseClasses, conditionalClasses) {
1029
1043
  if (conditionalClasses.length === 0) {
1030
1044
  return t__namespace.stringLiteral(baseClasses);
1031
1045
  }
1032
- const makeCondExpr = (cc) => t__namespace.conditionalExpression(
1046
+ const makeCondExpr = (cc, bare) => t__namespace.conditionalExpression(
1033
1047
  cc.test,
1034
- t__namespace.stringLiteral(cc.consequent),
1035
- t__namespace.stringLiteral(cc.alternate)
1048
+ bare && cc.consequent === "" ? t__namespace.identifier("undefined") : t__namespace.stringLiteral(cc.consequent),
1049
+ bare && cc.alternate === "" ? t__namespace.identifier("undefined") : t__namespace.stringLiteral(cc.alternate)
1036
1050
  );
1037
1051
  if (conditionalClasses.length === 1 && !baseClasses) {
1038
- return makeCondExpr(conditionalClasses[0]);
1052
+ return makeCondExpr(conditionalClasses[0], true);
1039
1053
  }
1040
1054
  const quasis = [];
1041
1055
  const exprs = [];
1042
1056
  for (let i = 0; i < conditionalClasses.length; i++) {
1043
1057
  const prefix = i === 0 ? baseClasses ? `${baseClasses} ` : "" : " ";
1044
1058
  quasis.push(t__namespace.templateElement({ raw: prefix, cooked: prefix }, false));
1045
- exprs.push(makeCondExpr(conditionalClasses[i]));
1059
+ exprs.push(makeCondExpr(conditionalClasses[i], false));
1046
1060
  }
1047
1061
  quasis.push(t__namespace.templateElement({ raw: "", cooked: "" }, true));
1048
1062
  return t__namespace.templateLiteral(quasis, exprs);
@@ -2769,7 +2783,7 @@ function transformOxc(source, filename, options) {
2769
2783
  ...existingRaw ? existingRaw.split(/\s+/).filter(Boolean) : [],
2770
2784
  ...szDerived
2771
2785
  ];
2772
- const mergedAttr = `className="${mergedClasses.join(" ")}"`;
2786
+ const mergedAttr = mergedClasses.length === 0 ? "className={undefined}" : `className="${mergedClasses.join(" ")}"`;
2773
2787
  if (classNameAttr) {
2774
2788
  edits.overwrite(classNameAttr.start, classNameAttr.end, mergedAttr);
2775
2789
  for (const szAttr of szAttrs) {
@@ -3381,7 +3395,8 @@ function buildConditionalSpreadClassExpression(node, filename, bindings, source,
3381
3395
  }
3382
3396
  }
3383
3397
  const testSource = source.slice(conditionalSpread.test.start, conditionalSpread.test.end);
3384
- return `${testSource} ? ${JSON.stringify(consequent)} : ${JSON.stringify(alternate)}`;
3398
+ const branch = (cls) => cls === "" ? "undefined" : JSON.stringify(cls);
3399
+ return `${testSource} ? ${branch(consequent)} : ${branch(alternate)}`;
3385
3400
  }
3386
3401
  function compileConditionalSpreadBranch(branch, otherProps, sourceNode, filename, bindings, globalVarAliases, cssVariableMap) {
3387
3402
  const branchObject = resolveObjectExpression(branch, bindings);
@@ -3444,7 +3459,11 @@ function buildPartialObjectTransform(node, filename, bindings, source, options,
3444
3459
  classParts.push(entry.consequent, entry.alternate);
3445
3460
  }
3446
3461
  const className = classParts.filter(Boolean).join(" ");
3447
- const classNameAttr = partial.conditionalClasses.length > 0 ? `className={${buildConditionalClassSource(classParts, partial.conditionalClasses, source)}}` : `className="${className}"`;
3462
+ const classNameAttr = partial.conditionalClasses.length > 0 ? `className={${buildConditionalClassSource(classParts, partial.conditionalClasses, source)}}` : className === "" ? (
3463
+ // An sz that lowers to zero classes emits `className={undefined}` so the
3464
+ // DOM has no `class` attribute, instead of the noisy `class=""`.
3465
+ "className={undefined}"
3466
+ ) : `className="${className}"`;
3448
3467
  const styleProps = [...partial.dynamicProps.entries()].filter(([id]) => !hoistedNames?.has(id)).map(
3449
3468
  ([, info]) => `${JSON.stringify(info.varName)}: ${generateStyleValueSource(info, source)}`
3450
3469
  );
@@ -4018,9 +4037,11 @@ function buildCSSVarClassName(info) {
4018
4037
  function buildConditionalClassSource(classParts, conditionals, source) {
4019
4038
  if (conditionals.length === 1) {
4020
4039
  const [entry] = conditionals;
4021
- const ternary = `${source.slice(entry.test.start, entry.test.end)} ? ${JSON.stringify(entry.consequent)} : ${JSON.stringify(entry.alternate)}`;
4022
4040
  const staticParts = classParts.slice(0, -2).filter(Boolean);
4023
- if (staticParts.length === 0) {
4041
+ const bare = staticParts.length === 0;
4042
+ const branch = (cls) => bare && cls === "" ? "undefined" : JSON.stringify(cls);
4043
+ const ternary = `${source.slice(entry.test.start, entry.test.end)} ? ${branch(entry.consequent)} : ${branch(entry.alternate)}`;
4044
+ if (bare) {
4024
4045
  return ternary;
4025
4046
  }
4026
4047
  return `\`${staticParts.join(" ")} \${${ternary}}\``;
@@ -4072,7 +4093,8 @@ function buildStaticConditionalClassExpression(node, filename, bindings, source,
4072
4093
  }
4073
4094
  }
4074
4095
  const testSource = source.slice(node.test.start, node.test.end);
4075
- return `${testSource} ? ${JSON.stringify(consequent)} : ${JSON.stringify(alternate)}`;
4096
+ const branch = (cls) => cls === "" ? "undefined" : JSON.stringify(cls);
4097
+ return `${testSource} ? ${branch(consequent)} : ${branch(alternate)}`;
4076
4098
  }
4077
4099
  function resolveStaticClassString(node, filename, bindings, globalVarAliases, cssVariableMap) {
4078
4100
  const unwrapped = unwrapExpression(node);
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { init, version, transform_sz, encode } from '@csszyx/core';
2
- import { t as transform, s as setSzWarnLocation, f as formatSzWarnLocation, C as COLOR_PROPERTIES, P as PROPERTY_MAP, g as getCSSVariableName, a as PropertyCategory, K as KNOWN_VARIANTS, b as getVariantPrefix, c as getPropertyCategory, d as stripInvalidColorStrings } from './shared/compiler.DINxoUCF.mjs';
3
- export { B as BOOLEAN_SHORTHANDS, e as PROPERTY_CATEGORY_MAP, R as REMOVED_BOOLEAN_SUGAR, S as SPECIAL_VARIANTS, h as SUGGESTION_MAP, i as isValidSzProp, n as normalizeClassName } from './shared/compiler.DINxoUCF.mjs';
2
+ import { t as transform, s as setSzWarnLocation, f as formatSzWarnLocation, C as COLOR_PROPERTIES, P as PROPERTY_MAP, g as getCSSVariableName, a as PropertyCategory, K as KNOWN_VARIANTS, b as getVariantPrefix, c as getPropertyCategory, d as stripInvalidColorStrings } from './shared/compiler.CghwJ6p5.mjs';
3
+ export { B as BOOLEAN_SHORTHANDS, e as PROPERTY_CATEGORY_MAP, R as REMOVED_BOOLEAN_SUGAR, S as SPECIAL_VARIANTS, h as SUGGESTION_MAP, i as isValidSzProp, n as normalizeClassName } from './shared/compiler.CghwJ6p5.mjs';
4
4
  import { parseSync } from 'oxc-parser';
5
5
  import * as t from '@babel/types';
6
6
  import { createHash } from 'node:crypto';
@@ -226,6 +226,9 @@ function transformSourceCode(source, filename, options) {
226
226
  }
227
227
  const createMergedClassNameValue = (szExpr) => {
228
228
  if (!existingClassExpr) {
229
+ if (t.isStringLiteral(szExpr) && szExpr.value === "") {
230
+ return t.jsxExpressionContainer(t.identifier("undefined"));
231
+ }
229
232
  return t.isStringLiteral(szExpr) ? szExpr : t.jsxExpressionContainer(szExpr);
230
233
  }
231
234
  if (existingClassNameNode && path.parentPath?.isJSXOpeningElement()) {
@@ -807,6 +810,9 @@ function parseStyleStringToObjectExpr(styleStr) {
807
810
  }
808
811
  return t.objectExpression(objProps);
809
812
  }
813
+ function emptyClassToUndefined(node) {
814
+ return t.isStringLiteral(node) && node.value === "" ? t.identifier("undefined") : node;
815
+ }
810
816
  function tryStaticTransformNode(node, getBinding) {
811
817
  if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node)) {
812
818
  return tryStaticTransformNode(node.expression, getBinding);
@@ -843,7 +849,11 @@ function tryStaticTransformNode(node, getBinding) {
843
849
  const consequent = tryStaticTransformNode(node.consequent, getBinding);
844
850
  const alternate = tryStaticTransformNode(node.alternate, getBinding);
845
851
  if (consequent !== null && alternate !== null) {
846
- return t.conditionalExpression(node.test, consequent, alternate);
852
+ return t.conditionalExpression(
853
+ node.test,
854
+ emptyClassToUndefined(consequent),
855
+ emptyClassToUndefined(alternate)
856
+ );
847
857
  }
848
858
  return null;
849
859
  }
@@ -880,7 +890,11 @@ function tryHoistConditionalSpread(node, getBinding) {
880
890
  if (!t.isStringLiteral(resolvedA) || !t.isStringLiteral(resolvedB)) {
881
891
  return null;
882
892
  }
883
- return t.conditionalExpression(conditionalExpr.test, resolvedA, resolvedB);
893
+ return t.conditionalExpression(
894
+ conditionalExpr.test,
895
+ emptyClassToUndefined(resolvedA),
896
+ emptyClassToUndefined(resolvedB)
897
+ );
884
898
  }
885
899
  function readStaticConfigObject(configExpr, key, scope) {
886
900
  for (const prop of configExpr.properties) {
@@ -1010,20 +1024,20 @@ function buildConditionalClassExpr(baseClasses, conditionalClasses) {
1010
1024
  if (conditionalClasses.length === 0) {
1011
1025
  return t.stringLiteral(baseClasses);
1012
1026
  }
1013
- const makeCondExpr = (cc) => t.conditionalExpression(
1027
+ const makeCondExpr = (cc, bare) => t.conditionalExpression(
1014
1028
  cc.test,
1015
- t.stringLiteral(cc.consequent),
1016
- t.stringLiteral(cc.alternate)
1029
+ bare && cc.consequent === "" ? t.identifier("undefined") : t.stringLiteral(cc.consequent),
1030
+ bare && cc.alternate === "" ? t.identifier("undefined") : t.stringLiteral(cc.alternate)
1017
1031
  );
1018
1032
  if (conditionalClasses.length === 1 && !baseClasses) {
1019
- return makeCondExpr(conditionalClasses[0]);
1033
+ return makeCondExpr(conditionalClasses[0], true);
1020
1034
  }
1021
1035
  const quasis = [];
1022
1036
  const exprs = [];
1023
1037
  for (let i = 0; i < conditionalClasses.length; i++) {
1024
1038
  const prefix = i === 0 ? baseClasses ? `${baseClasses} ` : "" : " ";
1025
1039
  quasis.push(t.templateElement({ raw: prefix, cooked: prefix }, false));
1026
- exprs.push(makeCondExpr(conditionalClasses[i]));
1040
+ exprs.push(makeCondExpr(conditionalClasses[i], false));
1027
1041
  }
1028
1042
  quasis.push(t.templateElement({ raw: "", cooked: "" }, true));
1029
1043
  return t.templateLiteral(quasis, exprs);
@@ -2750,7 +2764,7 @@ function transformOxc(source, filename, options) {
2750
2764
  ...existingRaw ? existingRaw.split(/\s+/).filter(Boolean) : [],
2751
2765
  ...szDerived
2752
2766
  ];
2753
- const mergedAttr = `className="${mergedClasses.join(" ")}"`;
2767
+ const mergedAttr = mergedClasses.length === 0 ? "className={undefined}" : `className="${mergedClasses.join(" ")}"`;
2754
2768
  if (classNameAttr) {
2755
2769
  edits.overwrite(classNameAttr.start, classNameAttr.end, mergedAttr);
2756
2770
  for (const szAttr of szAttrs) {
@@ -3362,7 +3376,8 @@ function buildConditionalSpreadClassExpression(node, filename, bindings, source,
3362
3376
  }
3363
3377
  }
3364
3378
  const testSource = source.slice(conditionalSpread.test.start, conditionalSpread.test.end);
3365
- return `${testSource} ? ${JSON.stringify(consequent)} : ${JSON.stringify(alternate)}`;
3379
+ const branch = (cls) => cls === "" ? "undefined" : JSON.stringify(cls);
3380
+ return `${testSource} ? ${branch(consequent)} : ${branch(alternate)}`;
3366
3381
  }
3367
3382
  function compileConditionalSpreadBranch(branch, otherProps, sourceNode, filename, bindings, globalVarAliases, cssVariableMap) {
3368
3383
  const branchObject = resolveObjectExpression(branch, bindings);
@@ -3425,7 +3440,11 @@ function buildPartialObjectTransform(node, filename, bindings, source, options,
3425
3440
  classParts.push(entry.consequent, entry.alternate);
3426
3441
  }
3427
3442
  const className = classParts.filter(Boolean).join(" ");
3428
- const classNameAttr = partial.conditionalClasses.length > 0 ? `className={${buildConditionalClassSource(classParts, partial.conditionalClasses, source)}}` : `className="${className}"`;
3443
+ const classNameAttr = partial.conditionalClasses.length > 0 ? `className={${buildConditionalClassSource(classParts, partial.conditionalClasses, source)}}` : className === "" ? (
3444
+ // An sz that lowers to zero classes emits `className={undefined}` so the
3445
+ // DOM has no `class` attribute, instead of the noisy `class=""`.
3446
+ "className={undefined}"
3447
+ ) : `className="${className}"`;
3429
3448
  const styleProps = [...partial.dynamicProps.entries()].filter(([id]) => !hoistedNames?.has(id)).map(
3430
3449
  ([, info]) => `${JSON.stringify(info.varName)}: ${generateStyleValueSource(info, source)}`
3431
3450
  );
@@ -3999,9 +4018,11 @@ function buildCSSVarClassName(info) {
3999
4018
  function buildConditionalClassSource(classParts, conditionals, source) {
4000
4019
  if (conditionals.length === 1) {
4001
4020
  const [entry] = conditionals;
4002
- const ternary = `${source.slice(entry.test.start, entry.test.end)} ? ${JSON.stringify(entry.consequent)} : ${JSON.stringify(entry.alternate)}`;
4003
4021
  const staticParts = classParts.slice(0, -2).filter(Boolean);
4004
- if (staticParts.length === 0) {
4022
+ const bare = staticParts.length === 0;
4023
+ const branch = (cls) => bare && cls === "" ? "undefined" : JSON.stringify(cls);
4024
+ const ternary = `${source.slice(entry.test.start, entry.test.end)} ? ${branch(entry.consequent)} : ${branch(entry.alternate)}`;
4025
+ if (bare) {
4005
4026
  return ternary;
4006
4027
  }
4007
4028
  return `\`${staticParts.join(" ")} \${${ternary}}\``;
@@ -4053,7 +4074,8 @@ function buildStaticConditionalClassExpression(node, filename, bindings, source,
4053
4074
  }
4054
4075
  }
4055
4076
  const testSource = source.slice(node.test.start, node.test.end);
4056
- return `${testSource} ? ${JSON.stringify(consequent)} : ${JSON.stringify(alternate)}`;
4077
+ const branch = (cls) => cls === "" ? "undefined" : JSON.stringify(cls);
4078
+ return `${testSource} ? ${branch(consequent)} : ${branch(alternate)}`;
4057
4079
  }
4058
4080
  function resolveStaticClassString(node, filename, bindings, globalVarAliases, cssVariableMap) {
4059
4081
  const unwrapped = unwrapExpression(node);
@@ -1496,6 +1496,16 @@ function handleSupports(supportsObj, prefix) {
1496
1496
  }
1497
1497
  let szTransformDepth = 0;
1498
1498
  let szWarnLocation;
1499
+ let szHintedProjectScan = false;
1500
+ function hintProjectScanOnce(location) {
1501
+ if (szHintedProjectScan || !location || process.env.CSSZYX_NO_PROJECT_SCAN_HINT === "1") {
1502
+ return;
1503
+ }
1504
+ szHintedProjectScan = true;
1505
+ console.warn(
1506
+ "[csszyx] Tip: run `npx @csszyx/cli check` to scan every file for sz key issues at once (dev warnings only surface files as you open them)."
1507
+ );
1508
+ }
1499
1509
  function setSzWarnLocation(location) {
1500
1510
  szWarnLocation = location;
1501
1511
  }
@@ -2370,6 +2380,7 @@ function transformImpl(szProp, prefix, mangleMap) {
2370
2380
  `[csszyx] Unknown property "${rawKey}" in sz prop${at}. This will be ignored. Check for typos.`
2371
2381
  );
2372
2382
  }
2383
+ hintProjectScanOnce(szWarnLocation);
2373
2384
  }
2374
2385
  }
2375
2386
  if (value === true) {
@@ -1498,6 +1498,16 @@ function handleSupports(supportsObj, prefix) {
1498
1498
  }
1499
1499
  let szTransformDepth = 0;
1500
1500
  let szWarnLocation;
1501
+ let szHintedProjectScan = false;
1502
+ function hintProjectScanOnce(location) {
1503
+ if (szHintedProjectScan || !location || process.env.CSSZYX_NO_PROJECT_SCAN_HINT === "1") {
1504
+ return;
1505
+ }
1506
+ szHintedProjectScan = true;
1507
+ console.warn(
1508
+ "[csszyx] Tip: run `npx @csszyx/cli check` to scan every file for sz key issues at once (dev warnings only surface files as you open them)."
1509
+ );
1510
+ }
1501
1511
  function setSzWarnLocation(location) {
1502
1512
  szWarnLocation = location;
1503
1513
  }
@@ -2372,6 +2382,7 @@ function transformImpl(szProp, prefix, mangleMap) {
2372
2382
  `[csszyx] Unknown property "${rawKey}" in sz prop${at}. This will be ignored. Check for typos.`
2373
2383
  );
2374
2384
  }
2385
+ hintProjectScanOnce(szWarnLocation);
2375
2386
  }
2376
2387
  }
2377
2388
  if (value === true) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const transformCore = require('./shared/compiler.DIYC1vdY.cjs');
3
+ const transformCore = require('./shared/compiler.mibv6qPF.cjs');
4
4
 
5
5
 
6
6
 
@@ -1 +1 @@
1
- export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, M as MAX_SZ_DEPTH, P as PROPERTY_MAP, R as REMOVED_BOOLEAN_SUGAR, S as SPECIAL_VARIANTS, h as SUGGESTION_MAP, j as SzDepthError, V as VARIANT_MAP, f as formatSzWarnLocation, b as getVariantPrefix, k as isForbiddenSzKey, i as isValidSzProp, l as normalizeArbitraryValue, m as normalizeArbitraryVariant, n as normalizeClassName, s as setSzWarnLocation, t as transform } from './shared/compiler.DINxoUCF.mjs';
1
+ export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, M as MAX_SZ_DEPTH, P as PROPERTY_MAP, R as REMOVED_BOOLEAN_SUGAR, S as SPECIAL_VARIANTS, h as SUGGESTION_MAP, j as SzDepthError, V as VARIANT_MAP, f as formatSzWarnLocation, b as getVariantPrefix, k as isForbiddenSzKey, i as isValidSzProp, l as normalizeArbitraryValue, m as normalizeArbitraryVariant, n as normalizeClassName, s as setSzWarnLocation, t as transform } from './shared/compiler.CghwJ6p5.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/compiler",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "description": "Core compiler and transformation logic for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -65,7 +65,7 @@
65
65
  "@babel/types": "^7.23.6",
66
66
  "magic-string": "0.30.21",
67
67
  "oxc-parser": "0.131.0",
68
- "@csszyx/core": "0.10.7"
68
+ "@csszyx/core": "0.10.8"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__core": "^7.20.5",