@stylexjs/babel-plugin 0.10.0-beta.1 → 0.10.0

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 CHANGED
@@ -3,8 +3,9 @@
3
3
  var t = require('@babel/types');
4
4
  var path = require('path');
5
5
  var fs = require('fs');
6
+ var url = require('url');
6
7
  var require$$0 = require('assert');
7
- var esmResolve = require('esm-resolve');
8
+ var importMetaResolve = require('@dual-bundle/import-meta-resolve');
8
9
  var shared = require('@stylexjs/shared');
9
10
  var core = require('@babel/core');
10
11
  var traverse = require('@babel/traverse');
@@ -798,7 +799,7 @@ function isReferencedIdentifier(path, props) {
798
799
 
799
800
  const CheckModuleResolution = unionOf3(object({
800
801
  type: literal('commonJS'),
801
- rootDir: string(),
802
+ rootDir: unionOf(nullish(), string()),
802
803
  themeFileExtension: unionOf(nullish(), string())
803
804
  }), object({
804
805
  type: literal('haste'),
@@ -1130,42 +1131,21 @@ function possibleAliasedPaths(importPath, aliases) {
1130
1131
  return result;
1131
1132
  }
1132
1133
  const filePathResolver = (relativeFilePath, sourceFilePath, aliases) => {
1133
- const esmResolve$1 = esmResolve.buildResolver(sourceFilePath);
1134
1134
  for (const ext of ['', ...EXTENSIONS]) {
1135
1135
  const importPathStr = relativeFilePath + ext;
1136
1136
  if (importPathStr.startsWith('.')) {
1137
1137
  try {
1138
- return require.resolve(importPathStr, {
1139
- paths: [path.dirname(sourceFilePath)]
1140
- });
1138
+ return importMetaResolve.moduleResolve(importPathStr, url.pathToFileURL(sourceFilePath)).pathname;
1141
1139
  } catch {
1142
- const resolved = esmResolve$1(importPathStr, {
1143
- allowImportingExtraExtensions: true
1144
- });
1145
- if (resolved) {
1146
- if (resolved.startsWith('.')) {
1147
- return path.resolve(path.dirname(sourceFilePath), resolved);
1148
- }
1149
- return resolved;
1150
- }
1140
+ continue;
1151
1141
  }
1152
1142
  }
1153
1143
  const allAliases = possibleAliasedPaths(importPathStr, aliases);
1154
1144
  for (const possiblePath of allAliases) {
1155
1145
  try {
1156
- return require.resolve(possiblePath, {
1157
- paths: [path.dirname(sourceFilePath)]
1158
- });
1146
+ return importMetaResolve.moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath)).pathname;
1159
1147
  } catch {
1160
- const resolved = esmResolve$1(importPathStr, {
1161
- allowImportingExtraExtensions: true
1162
- });
1163
- if (resolved) {
1164
- if (resolved.startsWith('.')) {
1165
- return path.resolve(path.dirname(sourceFilePath), resolved);
1166
- }
1167
- return resolved;
1168
- }
1148
+ continue;
1169
1149
  }
1170
1150
  }
1171
1151
  }
@@ -1355,6 +1335,32 @@ function canBeIdentifier(str) {
1355
1335
  return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
1356
1336
  }
1357
1337
 
1338
+ const IMPORT_FILE_PARSING_ERROR = `There was error when attempting to parse the imported file.
1339
+ Please ensure that the 'babelrc' file is configured to be able to parse this file.
1340
+ `;
1341
+ const IMPORT_FILE_EVAL_ERROR = `There was an error when attempting to evaluate the imported file.
1342
+ Please ensure that the imported file is self-contained and does not rely on dynamic behavior.
1343
+ `;
1344
+ const PATH_WITHOUT_NODE = `Unexpected error:
1345
+ Could not resolve the code being evaluated.
1346
+ `;
1347
+ const UNEXPECTED_MEMBER_LOOKUP = `Unexpected error:
1348
+ Could not determine the property being accessed.
1349
+ `;
1350
+ const IMPORT_PATH_RESOLUTION_ERROR = `Could not resolve the path to the imported file.
1351
+ Please ensure that the theme file has a .stylex.js or .stylex.ts file extension and follows the
1352
+ rules for defining variariables:
1353
+
1354
+ https://stylexjs.com/docs/learn/theming/defining-variables/#rules-when-defining-variables
1355
+ `;
1356
+ const NON_CONSTANT = 'Referenced value is not a constant.\n\n';
1357
+ const USED_BEFORE_DECLARATION = 'Referenced value is used before declaration.\n\n';
1358
+ const UNINITIALIZED_CONST = 'Referenced constant is not initialized.\n\n';
1359
+ const UNDEFINED_CONST = 'Referenced constant is not defined.';
1360
+ const UNSUPPORTED_OPERATOR = op => `Unsupported operator: ${op}\n\n`;
1361
+ const OBJECT_METHOD = 'Unsupported object method.\n\n';
1362
+ const UNSUPPORTED_EXPRESSION = type => `Unsupported expression: ${type}\n\n`;
1363
+
1358
1364
  const VALID_CALLEES = ['String', 'Number', 'Math', 'Object', 'Array'];
1359
1365
  const INVALID_METHODS = ['random', 'assign', 'defineProperties', 'defineProperty', 'freeze', 'seal', 'splice'];
1360
1366
  function isValidCallee(val) {
@@ -1363,19 +1369,20 @@ function isValidCallee(val) {
1363
1369
  function isInvalidMethod(val) {
1364
1370
  return INVALID_METHODS.includes(val);
1365
1371
  }
1366
- function deopt(path, state) {
1372
+ function deopt(path, state, reason) {
1367
1373
  if (!state.confident) return;
1368
1374
  state.deoptPath = path;
1369
1375
  state.confident = false;
1376
+ state.deoptReason = reason;
1370
1377
  }
1371
- function evaluateImportedFile(filePath, namedExport, state) {
1378
+ function evaluateImportedFile(filePath, namedExport, state, bindingPath) {
1372
1379
  const fs = require('fs');
1373
1380
  const fileContents = fs.readFileSync(filePath, 'utf8');
1374
1381
  const ast = core.parseSync(fileContents, {
1375
1382
  babelrc: true
1376
1383
  });
1377
1384
  if (!ast || ast.errors || !t__namespace.isNode(ast)) {
1378
- state.confident = false;
1385
+ deopt(bindingPath, state, IMPORT_FILE_PARSING_ERROR);
1379
1386
  return;
1380
1387
  }
1381
1388
  const astNode = ast;
@@ -1405,7 +1412,7 @@ function evaluateImportedFile(filePath, namedExport, state) {
1405
1412
  if (state.confident) {
1406
1413
  return result;
1407
1414
  } else {
1408
- state.confident = false;
1415
+ deopt(bindingPath, state, IMPORT_FILE_EVAL_ERROR);
1409
1416
  return;
1410
1417
  }
1411
1418
  }
@@ -1422,7 +1429,8 @@ function evaluateThemeRef(fileName, exportName, state) {
1422
1429
  exportName,
1423
1430
  key
1424
1431
  });
1425
- const varName = state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash);
1432
+ const debug = state.traversalState.options.debug;
1433
+ const varName = debug === true ? key + '-' + state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash) : state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash);
1426
1434
  if (key === '__themeName__') {
1427
1435
  return varName;
1428
1436
  }
@@ -1450,22 +1458,25 @@ function evaluateCached(path, state) {
1450
1458
  if (existing.resolved) {
1451
1459
  return existing.value;
1452
1460
  } else {
1453
- deopt(path, state);
1461
+ deopt(path, state, existing.reason);
1454
1462
  return;
1455
1463
  }
1456
1464
  } else {
1457
1465
  const item = {
1458
- resolved: false
1466
+ resolved: false,
1467
+ reason: 'Currently evaluating'
1459
1468
  };
1460
1469
  seen.set(node, item);
1461
1470
  if (node == null) {
1462
- deopt(path, state);
1471
+ deopt(path, state, PATH_WITHOUT_NODE);
1463
1472
  return;
1464
1473
  }
1465
1474
  const val = _evaluate(path, state);
1466
1475
  if (state.confident) {
1467
- item.resolved = true;
1468
- item.value = val;
1476
+ seen.set(node, {
1477
+ resolved: true,
1478
+ value: val
1479
+ });
1469
1480
  }
1470
1481
  return val;
1471
1482
  }
@@ -1565,7 +1576,7 @@ function _evaluate(path, state) {
1565
1576
  } else if (isStringLiteral(propPath)) {
1566
1577
  property = propPath.node.value;
1567
1578
  } else {
1568
- return deopt(propPath, state);
1579
+ return deopt(propPath, state, UNEXPECTED_MEMBER_LOOKUP);
1569
1580
  }
1570
1581
  return object[property];
1571
1582
  }
@@ -1581,10 +1592,10 @@ function _evaluate(path, state) {
1581
1592
  if (importPath && isImportDeclaration(importPath)) {
1582
1593
  const absPath = state.traversalState.importPathResolver(importPath.node.source.value);
1583
1594
  if (!absPath) {
1584
- return deopt(binding.path, state);
1595
+ return deopt(binding.path, state, IMPORT_PATH_RESOLUTION_ERROR);
1585
1596
  }
1586
1597
  const [type, value] = absPath;
1587
- const returnValue = type === 'themeNameRef' ? evaluateThemeRef(value, importedName, state) : evaluateImportedFile(value, importedName, state);
1598
+ const returnValue = type === 'themeNameRef' ? evaluateThemeRef(value, importedName, state) : evaluateImportedFile(value, importedName, state, bindingPath);
1588
1599
  if (state.confident) {
1589
1600
  if (!state.addedImports.has(importPath.node.source.value) && state.traversalState.treeshakeCompensation) {
1590
1601
  importPath.insertBefore(t__namespace.importDeclaration([], importPath.node.source));
@@ -1592,29 +1603,32 @@ function _evaluate(path, state) {
1592
1603
  }
1593
1604
  return returnValue;
1594
1605
  } else {
1595
- deopt(binding.path, state);
1606
+ deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
1596
1607
  }
1597
1608
  }
1598
1609
  }
1610
+ if (binding && bindingPath && isImportDefaultSpecifier(bindingPath)) {
1611
+ deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
1612
+ }
1599
1613
  if (binding && binding.constantViolations.length > 0) {
1600
- return deopt(binding.path, state);
1614
+ return deopt(binding.path, state, NON_CONSTANT);
1601
1615
  }
1602
1616
  if (binding && path.node.start < binding.path.node.end) {
1603
- return deopt(binding.path, state);
1617
+ return deopt(binding.path, state, USED_BEFORE_DECLARATION);
1604
1618
  }
1605
1619
  if (binding && binding.hasValue) {
1606
1620
  return binding.value;
1607
1621
  } else {
1608
1622
  if (path.node.name === 'undefined') {
1609
- return binding ? deopt(binding.path, state) : undefined;
1623
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : undefined;
1610
1624
  } else if (path.node.name === 'Infinity') {
1611
- return binding ? deopt(binding.path, state) : Infinity;
1625
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : Infinity;
1612
1626
  } else if (path.node.name === 'NaN') {
1613
- return binding ? deopt(binding.path, state) : NaN;
1627
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : NaN;
1614
1628
  }
1615
1629
  const resolved = path.resolve();
1616
1630
  if (resolved === path) {
1617
- return deopt(path, state);
1631
+ return deopt(path, state, UNDEFINED_CONST);
1618
1632
  } else {
1619
1633
  return evaluateCached(resolved, state);
1620
1634
  }
@@ -1646,7 +1660,7 @@ function _evaluate(path, state) {
1646
1660
  case 'void':
1647
1661
  return undefined;
1648
1662
  default:
1649
- return deopt(path, state);
1663
+ return deopt(path, state, UNSUPPORTED_OPERATOR(path.node.operator));
1650
1664
  }
1651
1665
  }
1652
1666
  if (isArrayExpression(path)) {
@@ -1658,7 +1672,7 @@ function _evaluate(path, state) {
1658
1672
  if (elemValue.confident) {
1659
1673
  arr.push(elemValue.value);
1660
1674
  } else {
1661
- elemValue.deopt && deopt(elemValue.deopt, state);
1675
+ elemValue.deopt && deopt(elemValue.deopt, state, elemValue.reason ?? 'unknown error');
1662
1676
  return;
1663
1677
  }
1664
1678
  }
@@ -1669,12 +1683,12 @@ function _evaluate(path, state) {
1669
1683
  const props = path.get('properties');
1670
1684
  for (const prop of props) {
1671
1685
  if (isObjectMethod(prop)) {
1672
- return deopt(prop, state);
1686
+ return deopt(prop, state, OBJECT_METHOD);
1673
1687
  }
1674
1688
  if (isSpreadElement(prop)) {
1675
1689
  const spreadExpression = evaluateCached(prop.get('argument'), state);
1676
1690
  if (!state.confident) {
1677
- return deopt(prop, state);
1691
+ return deopt(prop, state, state.deoptReason ?? 'unknown error');
1678
1692
  }
1679
1693
  Object.assign(obj, spreadExpression);
1680
1694
  continue;
@@ -1686,10 +1700,11 @@ function _evaluate(path, state) {
1686
1700
  const {
1687
1701
  confident,
1688
1702
  deopt: resultDeopt,
1703
+ reason: deoptReason,
1689
1704
  value
1690
1705
  } = evaluate(keyPath, state.traversalState, state.functions);
1691
1706
  if (!confident) {
1692
- resultDeopt && deopt(resultDeopt, state);
1707
+ resultDeopt && deopt(resultDeopt, state, deoptReason ?? 'unknown error');
1693
1708
  return;
1694
1709
  }
1695
1710
  key = value;
@@ -1701,7 +1716,7 @@ function _evaluate(path, state) {
1701
1716
  const valuePath = prop.get('value');
1702
1717
  let value = evaluate(valuePath, state.traversalState, state.functions);
1703
1718
  if (!value.confident) {
1704
- value.deopt && deopt(value.deopt, state);
1719
+ value.deopt && deopt(value.deopt, state, value.reason ?? 'unknown error');
1705
1720
  return;
1706
1721
  }
1707
1722
  value = value.value;
@@ -1711,25 +1726,71 @@ function _evaluate(path, state) {
1711
1726
  return obj;
1712
1727
  }
1713
1728
  if (isLogicalExpression(path)) {
1714
- const wasConfident = state.confident;
1715
- const left = evaluateCached(path.get('left'), state);
1716
- const leftConfident = state.confident;
1717
- state.confident = wasConfident;
1718
- const right = evaluateCached(path.get('right'), state);
1719
- const rightConfident = state.confident;
1729
+ const stateForLeft = {
1730
+ ...state,
1731
+ deoptPath: null,
1732
+ confident: true
1733
+ };
1734
+ const leftPath = path.get('left');
1735
+ const left = evaluateCached(leftPath, stateForLeft);
1736
+ const leftConfident = stateForLeft.confident;
1737
+ const stateForRight = {
1738
+ ...state,
1739
+ deoptPath: null,
1740
+ confident: true
1741
+ };
1742
+ const rightPath = path.get('right');
1743
+ const right = evaluateCached(rightPath, stateForRight);
1744
+ const rightConfident = stateForRight.confident;
1720
1745
  switch (path.node.operator) {
1721
1746
  case '||':
1722
- state.confident = leftConfident && (!!left || rightConfident);
1723
- if (!state.confident) return;
1724
- return left || right;
1747
+ {
1748
+ if (leftConfident && (!!left || rightConfident)) {
1749
+ return left || right;
1750
+ }
1751
+ if (!leftConfident) {
1752
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1753
+ return;
1754
+ }
1755
+ if (!rightConfident) {
1756
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1757
+ return;
1758
+ }
1759
+ deopt(path, state, 'unknown error');
1760
+ return;
1761
+ }
1725
1762
  case '&&':
1726
- state.confident = leftConfident && (!left || rightConfident);
1727
- if (!state.confident) return;
1728
- return left && right;
1763
+ {
1764
+ if (leftConfident && (!left || rightConfident)) {
1765
+ return left && right;
1766
+ }
1767
+ if (!leftConfident) {
1768
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1769
+ return;
1770
+ }
1771
+ if (!rightConfident) {
1772
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1773
+ return;
1774
+ }
1775
+ deopt(path, state, 'unknown error');
1776
+ return;
1777
+ }
1729
1778
  case '??':
1730
- state.confident = leftConfident && !!(left ?? rightConfident);
1731
- if (!state.confident) return;
1732
- return left ?? right;
1779
+ {
1780
+ if (leftConfident && !!(left ?? rightConfident)) {
1781
+ return left ?? right;
1782
+ }
1783
+ if (!leftConfident) {
1784
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1785
+ return;
1786
+ }
1787
+ if (!rightConfident) {
1788
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1789
+ return;
1790
+ }
1791
+ deopt(path, state, 'unknown error');
1792
+ return;
1793
+ }
1733
1794
  default:
1734
1795
  path.node.operator;
1735
1796
  }
@@ -1796,6 +1857,13 @@ function _evaluate(path, state) {
1796
1857
  func = global[callee.node.name];
1797
1858
  } else if (isIdentifier(callee) && state.functions.identifiers[callee.node.name]) {
1798
1859
  func = state.functions.identifiers[callee.node.name];
1860
+ } else if (isIdentifier(callee)) {
1861
+ const maybeFunction = evaluateCached(callee, state);
1862
+ if (state.confident) {
1863
+ func = maybeFunction;
1864
+ } else {
1865
+ deopt(callee, state, NON_CONSTANT);
1866
+ }
1799
1867
  }
1800
1868
  if (isMemberExpression(callee)) {
1801
1869
  const object = callee.get('object');
@@ -1847,7 +1915,7 @@ function _evaluate(path, state) {
1847
1915
  }
1848
1916
  }
1849
1917
  }
1850
- deopt(path, state);
1918
+ deopt(path, state, UNSUPPORTED_EXPRESSION(path.node.type));
1851
1919
  }
1852
1920
  function evaluateQuasis(path, quasis, state) {
1853
1921
  let raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
@@ -1884,6 +1952,7 @@ function evaluate(path, traversalState) {
1884
1952
  return {
1885
1953
  confident: state.confident,
1886
1954
  deopt: state.deoptPath,
1955
+ reason: state.deoptReason,
1887
1956
  value: value
1888
1957
  };
1889
1958
  }
@@ -2889,12 +2958,15 @@ function requireTransformValue () {
2889
2958
  const value = typeof rawValue === 'number' ? String(Math.round(rawValue * 10000) / 10000) + getNumberSuffix(key) : rawValue;
2890
2959
  if ((key === 'content' || key === 'hyphenateCharacter' || key === 'hyphenate-character') && typeof value === 'string') {
2891
2960
  const val = value.trim();
2892
- if (val.match(/^attr\([a-zA-Z0-9-]+\)$/)) {
2961
+ const cssContentFunctions = ['attr(', 'counter(', 'counters(', 'url(', 'linear-gradient(', 'image-set('];
2962
+ const cssContentKeywords = new Set(['normal', 'none', 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', 'inherit', 'initial', 'revert', 'revert-layer', 'unset']);
2963
+ const isCssFunction = cssContentFunctions.some(func => val.includes(func));
2964
+ const isKeyword = cssContentKeywords.has(val);
2965
+ const hasMatchingQuotes = (val.match(/"/g)?.length ?? 0) >= 2 || (val.match(/'/g)?.length ?? 0) >= 2;
2966
+ if (isCssFunction || isKeyword || hasMatchingQuotes) {
2893
2967
  return val;
2894
2968
  }
2895
- if (!(val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'"))) {
2896
- return `"${val}"`;
2897
- }
2969
+ return `"${val}"`;
2898
2970
  }
2899
2971
  return (0, _normalizeValue.default)(value, key, options);
2900
2972
  }
@@ -3711,19 +3783,33 @@ function transformStyleXCreate(path, state) {
3711
3783
  const {
3712
3784
  confident,
3713
3785
  value,
3714
- fns
3786
+ fns,
3787
+ reason,
3788
+ deopt
3715
3789
  } = evaluateStyleXCreateArg(firstArg, state, {
3716
3790
  identifiers,
3717
3791
  memberExpressions
3718
3792
  });
3719
3793
  if (!confident) {
3720
- throw path.buildCodeFrameError(shared.messages.NON_STATIC_VALUE, SyntaxError);
3794
+ throw (deopt ?? path).buildCodeFrameError(reason ?? shared.messages.NON_STATIC_VALUE, SyntaxError);
3721
3795
  }
3722
3796
  const plainObject = value;
3797
+ const injectedInheritStyles = {};
3798
+ if (fns != null) {
3799
+ const dynamicFnsNames = Object.values(fns)?.map(entry => Object.keys(entry[1])).flat();
3800
+ dynamicFnsNames.forEach(fnsName => {
3801
+ injectedInheritStyles[fnsName] = {
3802
+ priority: 0,
3803
+ ltr: `@property ${fnsName} { syntax: "*"; inherits: false; initial-value: "*";}`,
3804
+ rtl: null
3805
+ };
3806
+ });
3807
+ }
3723
3808
  let [compiledStyles, injectedStylesSansKeyframes, classPathsPerNamespace] = shared.create(plainObject, state.options);
3724
3809
  const injectedStyles = {
3725
3810
  ...injectedKeyframes,
3726
- ...injectedStylesSansKeyframes
3811
+ ...injectedStylesSansKeyframes,
3812
+ ...injectedInheritStyles
3727
3813
  };
3728
3814
  let varName = null;
3729
3815
  if (isVariableDeclarator(path.parentPath)) {
@@ -4899,18 +4985,42 @@ function styleXTransform() {
4899
4985
  }
4900
4986
  }
4901
4987
  }
4988
+ },
4989
+ exit: path => {
4902
4990
  path.traverse({
4903
- CallExpression(path) {
4904
- if (isVariableDeclarator(path.parentPath)) {
4905
- transformStyleXKeyframes(path.parentPath, state);
4991
+ Identifier(path) {
4992
+ if (isReferencedIdentifier(path)) {
4993
+ const {
4994
+ name
4995
+ } = path.node;
4996
+ if (state.styleMap.has(name)) {
4997
+ const parentPath = path.parentPath;
4998
+ if (isMemberExpression(parentPath)) {
4999
+ const {
5000
+ property,
5001
+ computed
5002
+ } = parentPath.node;
5003
+ if (property.type === 'Identifier' && !computed) {
5004
+ state.markComposedNamespace([name, property.name, true]);
5005
+ } else if (property.type === 'StringLiteral' && computed) {
5006
+ state.markComposedNamespace([name, property.value, true]);
5007
+ } else if (property.type === 'NumericLiteral' && computed) {
5008
+ state.markComposedNamespace([name, String(property.value), true]);
5009
+ } else {
5010
+ state.markComposedNamespace([name, true, true]);
5011
+ }
5012
+ } else {
5013
+ state.markComposedNamespace([name, true, true]);
5014
+ }
5015
+ }
4906
5016
  }
4907
- transformStyleXDefineVars(path, state);
4908
- transformStyleXCreateTheme(path, state);
4909
- transformStyleXCreate(path, state);
5017
+ },
5018
+ CallExpression(path) {
5019
+ skipStylexMergeChildren(path, state);
5020
+ skipStylexPropsChildren(path, state);
5021
+ skipStylexAttrsChildren(path, state);
4910
5022
  }
4911
5023
  });
4912
- },
4913
- exit: path => {
4914
5024
  path.traverse({
4915
5025
  CallExpression(path) {
4916
5026
  transformStyleXMerge(path, state);
@@ -4995,36 +5105,12 @@ function styleXTransform() {
4995
5105
  }
4996
5106
  },
4997
5107
  CallExpression(path) {
4998
- skipStylexMergeChildren(path, state);
4999
- skipStylexPropsChildren(path, state);
5000
- skipStylexAttrsChildren(path, state);
5001
- },
5002
- Identifier(path) {
5003
- if (isReferencedIdentifier(path)) {
5004
- const {
5005
- name
5006
- } = path.node;
5007
- if (state.styleMap.has(name)) {
5008
- const parentPath = path.parentPath;
5009
- if (isMemberExpression(parentPath)) {
5010
- const {
5011
- property,
5012
- computed
5013
- } = parentPath.node;
5014
- if (property.type === 'Identifier' && !computed) {
5015
- state.markComposedNamespace([name, property.name, true]);
5016
- } else if (property.type === 'StringLiteral' && computed) {
5017
- state.markComposedNamespace([name, property.value, true]);
5018
- } else if (property.type === 'NumericLiteral' && computed) {
5019
- state.markComposedNamespace([name, String(property.value), true]);
5020
- } else {
5021
- state.markComposedNamespace([name, true, true]);
5022
- }
5023
- } else {
5024
- state.markComposedNamespace([name, true, true]);
5025
- }
5026
- }
5108
+ if (isVariableDeclarator(path.parentPath)) {
5109
+ transformStyleXKeyframes(path.parentPath, state);
5027
5110
  }
5111
+ transformStyleXDefineVars(path, state);
5112
+ transformStyleXCreateTheme(path, state);
5113
+ transformStyleXCreate(path, state);
5028
5114
  }
5029
5115
  }
5030
5116
  };
@@ -24,4 +24,9 @@ export declare function evaluate(
24
24
  path: NodePath,
25
25
  traversalState: StateManager,
26
26
  functions: FunctionConfig,
27
- ): Readonly<{ confident: boolean; value: any; deopt?: null | NodePath }>;
27
+ ): Readonly<{
28
+ confident: boolean;
29
+ value: any;
30
+ deopt?: null | NodePath;
31
+ reason?: string;
32
+ }>;
@@ -31,4 +31,5 @@ declare export function evaluate(
31
31
  confident: boolean,
32
32
  value: any,
33
33
  deopt?: null | NodePath<>,
34
+ reason?: string,
34
35
  }>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ export declare const IMPORT_FILE_PARSING_ERROR: any;
11
+ export declare const IMPORT_FILE_EVAL_ERROR: any;
12
+ export declare const DEFAULT_IMPORT: any;
13
+ export declare const PATH_WITHOUT_NODE: any;
14
+ export declare const UNEXPECTED_MEMBER_LOOKUP: any;
15
+ export declare const IMPORT_PATH_RESOLUTION_ERROR: any;
16
+ export declare const NON_CONSTANT: 'Referenced value is not a constant.\n\n';
17
+ export declare const USED_BEFORE_DECLARATION: 'Referenced value is used before declaration.\n\n';
18
+ export declare const UNINITIALIZED_CONST: 'Referenced constant is not initialized.\n\n';
19
+ export declare const UNDEFINED_CONST: 'Referenced constant is not defined.';
20
+ export declare const UNSUPPORTED_OPERATOR: (op: string) => string;
21
+ export declare const OBJECT_METHOD: 'Unsupported object method.\n\n';
22
+ export declare const UNSUPPORTED_EXPRESSION: (type: string) => string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ declare export const IMPORT_FILE_PARSING_ERROR: $FlowFixMe;
11
+
12
+ // export const
13
+ declare export const IMPORT_FILE_EVAL_ERROR: $FlowFixMe;
14
+
15
+ declare export const DEFAULT_IMPORT: $FlowFixMe;
16
+
17
+ declare export const PATH_WITHOUT_NODE: $FlowFixMe;
18
+
19
+ declare export const UNEXPECTED_MEMBER_LOOKUP: $FlowFixMe;
20
+
21
+ declare export const IMPORT_PATH_RESOLUTION_ERROR: $FlowFixMe;
22
+
23
+ declare export const NON_CONSTANT: 'Referenced value is not a constant.\n\n';
24
+
25
+ declare export const USED_BEFORE_DECLARATION: 'Referenced value is used before declaration.\n\n';
26
+
27
+ declare export const UNINITIALIZED_CONST: 'Referenced constant is not initialized.\n\n';
28
+
29
+ declare export const UNDEFINED_CONST: 'Referenced constant is not defined.';
30
+
31
+ declare export const UNSUPPORTED_OPERATOR: (op: string) => string;
32
+
33
+ declare export const OBJECT_METHOD: 'Unsupported object method.\n\n';
34
+
35
+ declare export const UNSUPPORTED_EXPRESSION: (type: string) => string;
@@ -25,7 +25,7 @@ export type ImportPathResolution =
25
25
  type ModuleResolution =
26
26
  | Readonly<{
27
27
  type: 'commonJS';
28
- rootDir?: string;
28
+ rootDir?: null | undefined | string;
29
29
  themeFileExtension?: null | undefined | string;
30
30
  }>
31
31
  | Readonly<{ type: 'haste'; themeFileExtension?: null | undefined | string }>
@@ -47,7 +47,7 @@ export type StyleXOptions = Readonly<
47
47
  | Readonly<{ from: string; as: string }>;
48
48
  treeshakeCompensation?: boolean;
49
49
  genConditionalClasses: boolean;
50
- unstable_moduleResolution: null | undefined | ModuleResolution;
50
+ unstable_moduleResolution?: null | undefined | ModuleResolution;
51
51
  aliases?:
52
52
  | null
53
53
  | undefined
@@ -63,7 +63,7 @@ export type StyleXOptions = Readonly<
63
63
  | Readonly<{ from: string; as: string }>;
64
64
  treeshakeCompensation?: boolean;
65
65
  genConditionalClasses: boolean;
66
- unstable_moduleResolution: null | undefined | ModuleResolution;
66
+ unstable_moduleResolution?: null | undefined | ModuleResolution;
67
67
  aliases?:
68
68
  | null
69
69
  | undefined
@@ -27,7 +27,7 @@ export type ImportPathResolution =
27
27
  type ModuleResolution =
28
28
  | $ReadOnly<{
29
29
  type: 'commonJS',
30
- rootDir?: string,
30
+ rootDir?: ?string,
31
31
  themeFileExtension?: ?string,
32
32
  }>
33
33
  | $ReadOnly<{
@@ -48,7 +48,7 @@ export type StyleXOptions = $ReadOnly<{
48
48
  runtimeInjection: boolean | ?string | $ReadOnly<{ from: string, as: string }>,
49
49
  treeshakeCompensation?: boolean,
50
50
  genConditionalClasses: boolean,
51
- unstable_moduleResolution: ?ModuleResolution,
51
+ unstable_moduleResolution?: ?ModuleResolution,
52
52
  aliases?: ?$ReadOnly<{ [string]: string | $ReadOnlyArray<string> }>,
53
53
  ...
54
54
  }>;
@@ -32,5 +32,6 @@ export declare function evaluateStyleXCreateArg(
32
32
  confident: boolean;
33
33
  value: any;
34
34
  deopt?: null | NodePath;
35
+ reason?: string;
35
36
  fns?: DynamicFns;
36
37
  }>;
@@ -36,5 +36,6 @@ declare export function evaluateStyleXCreateArg(
36
36
  confident: boolean,
37
37
  value: any,
38
38
  deopt?: null | NodePath<>,
39
+ reason?: string,
39
40
  fns?: DynamicFns,
40
41
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.10.0-beta.1",
3
+ "version": "0.10.0",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/facebook/stylex",
@@ -14,12 +14,12 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/helper-module-imports": "^7.22.15",
17
- "@stylexjs/shared": "0.10.0-beta.1",
18
- "@stylexjs/stylex": "0.10.0-beta.1",
17
+ "@stylexjs/shared": "0.10.0",
18
+ "@stylexjs/stylex": "0.10.0",
19
19
  "@babel/core": "^7.25.8",
20
20
  "@babel/traverse": "^7.25.7",
21
21
  "@babel/types": "^7.25.8",
22
- "esm-resolve": "^1.0.11"
22
+ "@dual-bundle/import-meta-resolve": "^4.1.0"
23
23
  },
24
24
  "jest": {
25
25
  "verbose": true,