@stylexjs/babel-plugin 0.15.2 → 0.15.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/lib/index.js +93 -6
- package/package.json +3 -3
- package/lib/babel-path-utils.d.ts +0 -1100
- package/lib/babel-path-utils.js.flow +0 -1108
- package/lib/shared/utils/genCSSRule.d.ts +0 -15
- package/lib/shared/utils/genCSSRule.js.flow +0 -15
- package/lib/visitors/stylex-attrs.d.ts +0 -21
- package/lib/visitors/stylex-attrs.js.flow +0 -25
- package/lib/visitors/stylex-create/index.d.ts +0 -17
- package/lib/visitors/stylex-create/index.js.flow +0 -24
- package/lib/visitors/stylex-create/parse-stylex-create-arg.d.ts +0 -37
- package/lib/visitors/stylex-create/parse-stylex-create-arg.js.flow +0 -41
package/lib/index.js
CHANGED
|
@@ -2070,8 +2070,9 @@ var parser = /*@__PURE__*/getDefaultExportFromCjs(libExports$1);
|
|
|
2070
2070
|
function printNode(node) {
|
|
2071
2071
|
switch (node.type) {
|
|
2072
2072
|
case 'word':
|
|
2073
|
-
case 'string':
|
|
2074
2073
|
return `${node.value}`;
|
|
2074
|
+
case 'string':
|
|
2075
|
+
return `${node.quote}${node.value}${node.quote}`;
|
|
2075
2076
|
case 'function':
|
|
2076
2077
|
return `${node.value}(${node.nodes.map(printNode).join('')})`;
|
|
2077
2078
|
default:
|
|
@@ -2093,6 +2094,9 @@ function splitValue(str) {
|
|
|
2093
2094
|
return nodes;
|
|
2094
2095
|
}
|
|
2095
2096
|
|
|
2097
|
+
const listStyleGlobalValues = new Set(['inherit', 'initial', 'revert', 'unset']);
|
|
2098
|
+
const listStylePositionValues = new Set(['inside', 'outside']);
|
|
2099
|
+
const listStyleTypeRegex = /^([a-z-]+|".*?"|'.*?')$/;
|
|
2096
2100
|
const shorthands$1 = {
|
|
2097
2101
|
border: rawValue => {
|
|
2098
2102
|
return [['borderTop', rawValue], ['borderInlineEnd', rawValue], ['borderBottom', rawValue], ['borderInlineStart', rawValue]];
|
|
@@ -2156,6 +2160,49 @@ const shorthands$1 = {
|
|
|
2156
2160
|
const [row, column = row] = splitValue(rawValue);
|
|
2157
2161
|
return [['rowGap', row], ['columnGap', column]];
|
|
2158
2162
|
},
|
|
2163
|
+
listStyle: rawValue => {
|
|
2164
|
+
if (rawValue == null) {
|
|
2165
|
+
return [['listStyleType', null], ['listStylePosition', null], ['listStyleImage', null]];
|
|
2166
|
+
}
|
|
2167
|
+
const parts = splitValue(rawValue);
|
|
2168
|
+
let image = null;
|
|
2169
|
+
let position = null;
|
|
2170
|
+
let type = null;
|
|
2171
|
+
if (parts.length === 1 && parts[0] != null && typeof parts[0] === 'string' && listStyleGlobalValues.has(parts[0])) {
|
|
2172
|
+
const globalValue = parts[0];
|
|
2173
|
+
return [['listStyleType', globalValue], ['listStylePosition', globalValue], ['listStyleImage', globalValue]];
|
|
2174
|
+
}
|
|
2175
|
+
const remainingParts = [];
|
|
2176
|
+
for (const part of parts) {
|
|
2177
|
+
if (part == null || typeof part !== 'string') continue;
|
|
2178
|
+
if (listStyleGlobalValues.has(part) || part.includes('var(--')) {
|
|
2179
|
+
throw new Error(`invalid "listStyle" value of "${JSON.stringify(rawValue)}"`);
|
|
2180
|
+
} else if (listStylePositionValues.has(part)) {
|
|
2181
|
+
if (position != null) {
|
|
2182
|
+
throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
|
|
2183
|
+
}
|
|
2184
|
+
position = part;
|
|
2185
|
+
} else if (part !== 'none' && listStyleTypeRegex.test(part)) {
|
|
2186
|
+
if (type != null) {
|
|
2187
|
+
throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
|
|
2188
|
+
}
|
|
2189
|
+
type = part;
|
|
2190
|
+
} else {
|
|
2191
|
+
remainingParts.push(part);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
for (const part of remainingParts) {
|
|
2195
|
+
if (part === 'none' && type == null) {
|
|
2196
|
+
type = part;
|
|
2197
|
+
} else {
|
|
2198
|
+
if (image != null) {
|
|
2199
|
+
throw new Error(`invalid "listStyle" value of ${JSON.stringify(rawValue)}`);
|
|
2200
|
+
}
|
|
2201
|
+
image = part;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
return [['listStyleType', type], ['listStylePosition', position], ['listStyleImage', image]];
|
|
2205
|
+
},
|
|
2159
2206
|
margin: rawValue => {
|
|
2160
2207
|
const [top, right = top, bottom = top, left = right] = splitValue(rawValue);
|
|
2161
2208
|
return [['marginTop', top], ['marginInlineEnd', right], ['marginBottom', bottom], ['marginInlineStart', left]];
|
|
@@ -3971,6 +4018,8 @@ function requireMediaQuery () {
|
|
|
3971
4018
|
width: [],
|
|
3972
4019
|
height: []
|
|
3973
4020
|
};
|
|
4021
|
+
const units = {};
|
|
4022
|
+
let hasAnyUnitConflicts = false;
|
|
3974
4023
|
for (const rule of rules) {
|
|
3975
4024
|
if (rule.type === 'not' && rule.rule.type === 'and') {
|
|
3976
4025
|
const inner = rule.rule.rules;
|
|
@@ -3998,10 +4047,20 @@ function requireMediaQuery () {
|
|
|
3998
4047
|
for (const dim of dimensions) {
|
|
3999
4048
|
if (rule.type === 'pair' && (rule.key === `min-${dim}` || rule.key === `max-${dim}`) && isNumericLength(rule.value)) {
|
|
4000
4049
|
const val = rule.value;
|
|
4050
|
+
if (intervals[dim].length === 0) {
|
|
4051
|
+
units[dim] = val.unit;
|
|
4052
|
+
} else if (units[dim] !== val.unit) {
|
|
4053
|
+
hasAnyUnitConflicts = true;
|
|
4054
|
+
}
|
|
4001
4055
|
intervals[dim].push(rule.key === `min-${dim}` ? [val.value, Infinity] : [-Infinity, val.value]);
|
|
4002
4056
|
break;
|
|
4003
4057
|
} else if (rule.type === 'not' && rule.rule && rule.rule.type === 'pair' && (rule.rule.key === `min-${dim}` || rule.rule.key === `max-${dim}`) && isNumericLength(rule.rule.value)) {
|
|
4004
4058
|
const val = rule.rule.value;
|
|
4059
|
+
if (intervals[dim].length === 0) {
|
|
4060
|
+
units[dim] = val.unit;
|
|
4061
|
+
} else if (units[dim] !== val.unit) {
|
|
4062
|
+
hasAnyUnitConflicts = true;
|
|
4063
|
+
}
|
|
4005
4064
|
if (rule.rule.key === `min-${dim}`) {
|
|
4006
4065
|
intervals[dim].push([-Infinity, val.value - epsilon]);
|
|
4007
4066
|
} else {
|
|
@@ -4015,6 +4074,9 @@ function requireMediaQuery () {
|
|
|
4015
4074
|
}
|
|
4016
4075
|
}
|
|
4017
4076
|
const result = [];
|
|
4077
|
+
if (hasAnyUnitConflicts) {
|
|
4078
|
+
return rules;
|
|
4079
|
+
}
|
|
4018
4080
|
for (const dim of dimensions) {
|
|
4019
4081
|
const dimIntervals = intervals[dim];
|
|
4020
4082
|
if (dimIntervals.length === 0) continue;
|
|
@@ -4033,7 +4095,7 @@ function requireMediaQuery () {
|
|
|
4033
4095
|
key: `min-${dim}`,
|
|
4034
4096
|
value: {
|
|
4035
4097
|
value: lower,
|
|
4036
|
-
unit:
|
|
4098
|
+
unit: units[dim],
|
|
4037
4099
|
type: 'integer'
|
|
4038
4100
|
}
|
|
4039
4101
|
});
|
|
@@ -4044,7 +4106,7 @@ function requireMediaQuery () {
|
|
|
4044
4106
|
key: `max-${dim}`,
|
|
4045
4107
|
value: {
|
|
4046
4108
|
value: upper,
|
|
4047
|
-
unit:
|
|
4109
|
+
unit: units[dim],
|
|
4048
4110
|
type: 'integer'
|
|
4049
4111
|
}
|
|
4050
4112
|
});
|
|
@@ -7340,15 +7402,17 @@ function transformStyleXCreate(path, state) {
|
|
|
7340
7402
|
const classList = t__namespace.isStringLiteral(objProp.value) ? objProp.value.value.split(' ') : [];
|
|
7341
7403
|
let isStatic = true;
|
|
7342
7404
|
const exprList = [];
|
|
7343
|
-
classList.forEach(cls => {
|
|
7405
|
+
classList.forEach((cls, index) => {
|
|
7344
7406
|
const expr = dynamicStyles.find(({
|
|
7345
7407
|
path
|
|
7346
7408
|
}) => origClassPaths[cls] === path)?.expression;
|
|
7409
|
+
const isLast = index === classList.length - 1;
|
|
7410
|
+
const clsWithSpace = isLast ? cls : cls + ' ';
|
|
7347
7411
|
if (expr && !isSafeToSkipNullCheck(expr)) {
|
|
7348
7412
|
isStatic = false;
|
|
7349
|
-
exprList.push(t__namespace.conditionalExpression(t__namespace.binaryExpression('!=', expr, t__namespace.nullLiteral()), t__namespace.stringLiteral(
|
|
7413
|
+
exprList.push(t__namespace.conditionalExpression(t__namespace.binaryExpression('!=', expr, t__namespace.nullLiteral()), t__namespace.stringLiteral(clsWithSpace), expr));
|
|
7350
7414
|
} else {
|
|
7351
|
-
exprList.push(t__namespace.stringLiteral(
|
|
7415
|
+
exprList.push(t__namespace.stringLiteral(clsWithSpace));
|
|
7352
7416
|
}
|
|
7353
7417
|
});
|
|
7354
7418
|
const joined = exprList.length === 0 ? t__namespace.stringLiteral('') : exprList.reduce((acc, curr) => t__namespace.binaryExpression('+', acc, curr));
|
|
@@ -8238,6 +8302,29 @@ function transformStylexProps(path, state) {
|
|
|
8238
8302
|
} else {
|
|
8239
8303
|
path.skip();
|
|
8240
8304
|
const stringExpression = makeStringExpression(resolvedArgs);
|
|
8305
|
+
if (path.parentPath.node.type === 'JSXSpreadAttribute') {
|
|
8306
|
+
if (t__namespace.isObjectExpression(stringExpression) && stringExpression.properties.length > 0 && stringExpression.properties.every(prop => t__namespace.isObjectProperty(prop) && (t__namespace.isIdentifier(prop.key) || t__namespace.isStringLiteral(prop.key)) && !prop.computed)) {
|
|
8307
|
+
const jsxAttributes = stringExpression.properties.filter(prop => t__namespace.isObjectProperty(prop)).map(prop => {
|
|
8308
|
+
const objectProp = prop;
|
|
8309
|
+
const key = objectProp.key;
|
|
8310
|
+
let attrName = '';
|
|
8311
|
+
if (t__namespace.isIdentifier(key)) {
|
|
8312
|
+
attrName = key.name;
|
|
8313
|
+
} else if (t__namespace.isStringLiteral(key)) {
|
|
8314
|
+
attrName = key.value;
|
|
8315
|
+
}
|
|
8316
|
+
let attributeValue;
|
|
8317
|
+
if (t__namespace.isStringLiteral(objectProp.value)) {
|
|
8318
|
+
attributeValue = objectProp.value;
|
|
8319
|
+
} else {
|
|
8320
|
+
attributeValue = t__namespace.stringLiteral(String(objectProp.value));
|
|
8321
|
+
}
|
|
8322
|
+
return t__namespace.jsxAttribute(t__namespace.jsxIdentifier(attrName), attributeValue);
|
|
8323
|
+
});
|
|
8324
|
+
path.parentPath.replaceWithMultiple(jsxAttributes);
|
|
8325
|
+
return;
|
|
8326
|
+
}
|
|
8327
|
+
}
|
|
8241
8328
|
path.replaceWith(stringExpression);
|
|
8242
8329
|
}
|
|
8243
8330
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/babel-plugin",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "StyleX babel plugin.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@babel/traverse": "^7.26.8",
|
|
22
22
|
"@babel/types": "^7.26.8",
|
|
23
23
|
"@dual-bundle/import-meta-resolve": "^4.1.0",
|
|
24
|
-
"@stylexjs/stylex": "0.15.
|
|
24
|
+
"@stylexjs/stylex": "0.15.3",
|
|
25
25
|
"postcss-value-parser": "^4.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@rollup/plugin-replace": "^6.0.1",
|
|
34
34
|
"babel-plugin-syntax-hermes-parser": "^0.26.0",
|
|
35
35
|
"rollup": "^4.24.0",
|
|
36
|
-
"scripts": "0.15.
|
|
36
|
+
"scripts": "0.15.3"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"flow_modules/*",
|