@stylexjs/babel-plugin 0.10.0-beta.2 → 0.10.1

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.
@@ -236,7 +236,7 @@ declare export class Binding {
236
236
  type _VisitorNodeKeys<S: object> = {
237
237
  +[K in keyof t._NodeMap]: ?VisitNode<S, t._NodeMap[K]>,
238
238
  };
239
- type _VistorAliases<S: object> = {
239
+ type _VisitorAliases<S: object> = {
240
240
  +[K in keyof t.Aliases]: ?VisitNode<S, t.Aliases[K]>,
241
241
  };
242
242
 
@@ -244,7 +244,7 @@ export type Visitor<S: object = object> = $ReadOnly<
244
244
  Partial<{
245
245
  ...VisitNodeObject<S, Node>,
246
246
  ..._VisitorNodeKeys<S>,
247
- ..._VistorAliases<S>,
247
+ ..._VisitorAliases<S>,
248
248
  }>,
249
249
  >;
250
250
 
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'),
@@ -1129,43 +1130,27 @@ function possibleAliasedPaths(importPath, aliases) {
1129
1130
  }
1130
1131
  return result;
1131
1132
  }
1133
+ const getPossibleFilePaths = filePath => {
1134
+ const extension = path.extname(filePath);
1135
+ const filePathHasCodeExtension = EXTENSIONS.includes(extension);
1136
+ const filePathNoCodeExtension = filePathHasCodeExtension ? filePath.slice(0, -extension.length) : filePath;
1137
+ return [filePath, ...EXTENSIONS.map(ext => filePathNoCodeExtension + ext)];
1138
+ };
1132
1139
  const filePathResolver = (relativeFilePath, sourceFilePath, aliases) => {
1133
- const esmResolve$1 = esmResolve.buildResolver(sourceFilePath);
1134
- for (const ext of ['', ...EXTENSIONS]) {
1135
- const importPathStr = relativeFilePath + ext;
1140
+ for (const importPathStr of getPossibleFilePaths(relativeFilePath)) {
1136
1141
  if (importPathStr.startsWith('.')) {
1137
1142
  try {
1138
- return require.resolve(importPathStr, {
1139
- paths: [path.dirname(sourceFilePath)]
1140
- });
1143
+ return url.fileURLToPath(importMetaResolve.moduleResolve(importPathStr, url.pathToFileURL(sourceFilePath)));
1141
1144
  } 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
- }
1145
+ continue;
1151
1146
  }
1152
1147
  }
1153
1148
  const allAliases = possibleAliasedPaths(importPathStr, aliases);
1154
1149
  for (const possiblePath of allAliases) {
1155
1150
  try {
1156
- return require.resolve(possiblePath, {
1157
- paths: [path.dirname(sourceFilePath)]
1158
- });
1151
+ return url.fileURLToPath(importMetaResolve.moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath)));
1159
1152
  } 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
- }
1153
+ continue;
1169
1154
  }
1170
1155
  }
1171
1156
  }
@@ -1179,7 +1164,7 @@ const addFileExtension = (importedFilePath, sourceFile) => {
1179
1164
  const fileExtension = path.extname(sourceFile);
1180
1165
  return importedFilePath + fileExtension;
1181
1166
  };
1182
- const matchesFileSuffix = allowedSuffix => filename => filename.endsWith(`${allowedSuffix}.js`) || filename.endsWith(`${allowedSuffix}.ts`) || filename.endsWith(`${allowedSuffix}.tsx`) || filename.endsWith(`${allowedSuffix}.jsx`) || filename.endsWith(`${allowedSuffix}.mjs`) || filename.endsWith(`${allowedSuffix}.cjs`) || filename.endsWith(allowedSuffix);
1167
+ const matchesFileSuffix = allowedSuffix => filename => ['', ...EXTENSIONS].some(extension => filename.endsWith(`${allowedSuffix}${extension}`));
1183
1168
  const getProgramPath = path => {
1184
1169
  let programPath = path;
1185
1170
  while (programPath != null && !isProgram(programPath)) {
@@ -1355,6 +1340,32 @@ function canBeIdentifier(str) {
1355
1340
  return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
1356
1341
  }
1357
1342
 
1343
+ const IMPORT_FILE_PARSING_ERROR = `There was error when attempting to parse the imported file.
1344
+ Please ensure that the 'babelrc' file is configured to be able to parse this file.
1345
+ `;
1346
+ const IMPORT_FILE_EVAL_ERROR = `There was an error when attempting to evaluate the imported file.
1347
+ Please ensure that the imported file is self-contained and does not rely on dynamic behavior.
1348
+ `;
1349
+ const PATH_WITHOUT_NODE = `Unexpected error:
1350
+ Could not resolve the code being evaluated.
1351
+ `;
1352
+ const UNEXPECTED_MEMBER_LOOKUP = `Unexpected error:
1353
+ Could not determine the property being accessed.
1354
+ `;
1355
+ const IMPORT_PATH_RESOLUTION_ERROR = `Could not resolve the path to the imported file.
1356
+ Please ensure that the theme file has a .stylex.js or .stylex.ts file extension and follows the
1357
+ rules for defining variariables:
1358
+
1359
+ https://stylexjs.com/docs/learn/theming/defining-variables/#rules-when-defining-variables
1360
+ `;
1361
+ const NON_CONSTANT = 'Referenced value is not a constant.\n\n';
1362
+ const USED_BEFORE_DECLARATION = 'Referenced value is used before declaration.\n\n';
1363
+ const UNINITIALIZED_CONST = 'Referenced constant is not initialized.\n\n';
1364
+ const UNDEFINED_CONST = 'Referenced constant is not defined.';
1365
+ const UNSUPPORTED_OPERATOR = op => `Unsupported operator: ${op}\n\n`;
1366
+ const OBJECT_METHOD = 'Unsupported object method.\n\n';
1367
+ const UNSUPPORTED_EXPRESSION = type => `Unsupported expression: ${type}\n\n`;
1368
+
1358
1369
  const VALID_CALLEES = ['String', 'Number', 'Math', 'Object', 'Array'];
1359
1370
  const INVALID_METHODS = ['random', 'assign', 'defineProperties', 'defineProperty', 'freeze', 'seal', 'splice'];
1360
1371
  function isValidCallee(val) {
@@ -1363,19 +1374,20 @@ function isValidCallee(val) {
1363
1374
  function isInvalidMethod(val) {
1364
1375
  return INVALID_METHODS.includes(val);
1365
1376
  }
1366
- function deopt(path, state) {
1377
+ function deopt(path, state, reason) {
1367
1378
  if (!state.confident) return;
1368
1379
  state.deoptPath = path;
1369
1380
  state.confident = false;
1381
+ state.deoptReason = reason;
1370
1382
  }
1371
- function evaluateImportedFile(filePath, namedExport, state) {
1383
+ function evaluateImportedFile(filePath, namedExport, state, bindingPath) {
1372
1384
  const fs = require('fs');
1373
1385
  const fileContents = fs.readFileSync(filePath, 'utf8');
1374
1386
  const ast = core.parseSync(fileContents, {
1375
1387
  babelrc: true
1376
1388
  });
1377
1389
  if (!ast || ast.errors || !t__namespace.isNode(ast)) {
1378
- state.confident = false;
1390
+ deopt(bindingPath, state, IMPORT_FILE_PARSING_ERROR);
1379
1391
  return;
1380
1392
  }
1381
1393
  const astNode = ast;
@@ -1405,7 +1417,7 @@ function evaluateImportedFile(filePath, namedExport, state) {
1405
1417
  if (state.confident) {
1406
1418
  return result;
1407
1419
  } else {
1408
- state.confident = false;
1420
+ deopt(bindingPath, state, IMPORT_FILE_EVAL_ERROR);
1409
1421
  return;
1410
1422
  }
1411
1423
  }
@@ -1422,7 +1434,8 @@ function evaluateThemeRef(fileName, exportName, state) {
1422
1434
  exportName,
1423
1435
  key
1424
1436
  });
1425
- const varName = state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash);
1437
+ const debug = state.traversalState.options.debug;
1438
+ const varName = debug === true ? key + '-' + state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash) : state.traversalState.options.classNamePrefix + shared.utils.hash(strToHash);
1426
1439
  if (key === '__themeName__') {
1427
1440
  return varName;
1428
1441
  }
@@ -1450,22 +1463,25 @@ function evaluateCached(path, state) {
1450
1463
  if (existing.resolved) {
1451
1464
  return existing.value;
1452
1465
  } else {
1453
- deopt(path, state);
1466
+ deopt(path, state, existing.reason);
1454
1467
  return;
1455
1468
  }
1456
1469
  } else {
1457
1470
  const item = {
1458
- resolved: false
1471
+ resolved: false,
1472
+ reason: 'Currently evaluating'
1459
1473
  };
1460
1474
  seen.set(node, item);
1461
1475
  if (node == null) {
1462
- deopt(path, state);
1476
+ deopt(path, state, PATH_WITHOUT_NODE);
1463
1477
  return;
1464
1478
  }
1465
1479
  const val = _evaluate(path, state);
1466
1480
  if (state.confident) {
1467
- item.resolved = true;
1468
- item.value = val;
1481
+ seen.set(node, {
1482
+ resolved: true,
1483
+ value: val
1484
+ });
1469
1485
  }
1470
1486
  return val;
1471
1487
  }
@@ -1565,7 +1581,7 @@ function _evaluate(path, state) {
1565
1581
  } else if (isStringLiteral(propPath)) {
1566
1582
  property = propPath.node.value;
1567
1583
  } else {
1568
- return deopt(propPath, state);
1584
+ return deopt(propPath, state, UNEXPECTED_MEMBER_LOOKUP);
1569
1585
  }
1570
1586
  return object[property];
1571
1587
  }
@@ -1581,10 +1597,10 @@ function _evaluate(path, state) {
1581
1597
  if (importPath && isImportDeclaration(importPath)) {
1582
1598
  const absPath = state.traversalState.importPathResolver(importPath.node.source.value);
1583
1599
  if (!absPath) {
1584
- return deopt(binding.path, state);
1600
+ return deopt(binding.path, state, IMPORT_PATH_RESOLUTION_ERROR);
1585
1601
  }
1586
1602
  const [type, value] = absPath;
1587
- const returnValue = type === 'themeNameRef' ? evaluateThemeRef(value, importedName, state) : evaluateImportedFile(value, importedName, state);
1603
+ const returnValue = type === 'themeNameRef' ? evaluateThemeRef(value, importedName, state) : evaluateImportedFile(value, importedName, state, bindingPath);
1588
1604
  if (state.confident) {
1589
1605
  if (!state.addedImports.has(importPath.node.source.value) && state.traversalState.treeshakeCompensation) {
1590
1606
  importPath.insertBefore(t__namespace.importDeclaration([], importPath.node.source));
@@ -1592,29 +1608,32 @@ function _evaluate(path, state) {
1592
1608
  }
1593
1609
  return returnValue;
1594
1610
  } else {
1595
- deopt(binding.path, state);
1611
+ deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
1596
1612
  }
1597
1613
  }
1598
1614
  }
1615
+ if (binding && bindingPath && isImportDefaultSpecifier(bindingPath)) {
1616
+ deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
1617
+ }
1599
1618
  if (binding && binding.constantViolations.length > 0) {
1600
- return deopt(binding.path, state);
1619
+ return deopt(binding.path, state, NON_CONSTANT);
1601
1620
  }
1602
1621
  if (binding && path.node.start < binding.path.node.end) {
1603
- return deopt(binding.path, state);
1622
+ return deopt(binding.path, state, USED_BEFORE_DECLARATION);
1604
1623
  }
1605
1624
  if (binding && binding.hasValue) {
1606
1625
  return binding.value;
1607
1626
  } else {
1608
1627
  if (path.node.name === 'undefined') {
1609
- return binding ? deopt(binding.path, state) : undefined;
1628
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : undefined;
1610
1629
  } else if (path.node.name === 'Infinity') {
1611
- return binding ? deopt(binding.path, state) : Infinity;
1630
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : Infinity;
1612
1631
  } else if (path.node.name === 'NaN') {
1613
- return binding ? deopt(binding.path, state) : NaN;
1632
+ return binding ? deopt(binding.path, state, UNINITIALIZED_CONST) : NaN;
1614
1633
  }
1615
1634
  const resolved = path.resolve();
1616
1635
  if (resolved === path) {
1617
- return deopt(path, state);
1636
+ return deopt(path, state, UNDEFINED_CONST);
1618
1637
  } else {
1619
1638
  return evaluateCached(resolved, state);
1620
1639
  }
@@ -1646,7 +1665,7 @@ function _evaluate(path, state) {
1646
1665
  case 'void':
1647
1666
  return undefined;
1648
1667
  default:
1649
- return deopt(path, state);
1668
+ return deopt(path, state, UNSUPPORTED_OPERATOR(path.node.operator));
1650
1669
  }
1651
1670
  }
1652
1671
  if (isArrayExpression(path)) {
@@ -1658,7 +1677,7 @@ function _evaluate(path, state) {
1658
1677
  if (elemValue.confident) {
1659
1678
  arr.push(elemValue.value);
1660
1679
  } else {
1661
- elemValue.deopt && deopt(elemValue.deopt, state);
1680
+ elemValue.deopt && deopt(elemValue.deopt, state, elemValue.reason ?? 'unknown error');
1662
1681
  return;
1663
1682
  }
1664
1683
  }
@@ -1669,12 +1688,12 @@ function _evaluate(path, state) {
1669
1688
  const props = path.get('properties');
1670
1689
  for (const prop of props) {
1671
1690
  if (isObjectMethod(prop)) {
1672
- return deopt(prop, state);
1691
+ return deopt(prop, state, OBJECT_METHOD);
1673
1692
  }
1674
1693
  if (isSpreadElement(prop)) {
1675
1694
  const spreadExpression = evaluateCached(prop.get('argument'), state);
1676
1695
  if (!state.confident) {
1677
- return deopt(prop, state);
1696
+ return deopt(prop, state, state.deoptReason ?? 'unknown error');
1678
1697
  }
1679
1698
  Object.assign(obj, spreadExpression);
1680
1699
  continue;
@@ -1686,10 +1705,11 @@ function _evaluate(path, state) {
1686
1705
  const {
1687
1706
  confident,
1688
1707
  deopt: resultDeopt,
1708
+ reason: deoptReason,
1689
1709
  value
1690
1710
  } = evaluate(keyPath, state.traversalState, state.functions);
1691
1711
  if (!confident) {
1692
- resultDeopt && deopt(resultDeopt, state);
1712
+ resultDeopt && deopt(resultDeopt, state, deoptReason ?? 'unknown error');
1693
1713
  return;
1694
1714
  }
1695
1715
  key = value;
@@ -1701,7 +1721,7 @@ function _evaluate(path, state) {
1701
1721
  const valuePath = prop.get('value');
1702
1722
  let value = evaluate(valuePath, state.traversalState, state.functions);
1703
1723
  if (!value.confident) {
1704
- value.deopt && deopt(value.deopt, state);
1724
+ value.deopt && deopt(value.deopt, state, value.reason ?? 'unknown error');
1705
1725
  return;
1706
1726
  }
1707
1727
  value = value.value;
@@ -1711,25 +1731,71 @@ function _evaluate(path, state) {
1711
1731
  return obj;
1712
1732
  }
1713
1733
  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;
1734
+ const stateForLeft = {
1735
+ ...state,
1736
+ deoptPath: null,
1737
+ confident: true
1738
+ };
1739
+ const leftPath = path.get('left');
1740
+ const left = evaluateCached(leftPath, stateForLeft);
1741
+ const leftConfident = stateForLeft.confident;
1742
+ const stateForRight = {
1743
+ ...state,
1744
+ deoptPath: null,
1745
+ confident: true
1746
+ };
1747
+ const rightPath = path.get('right');
1748
+ const right = evaluateCached(rightPath, stateForRight);
1749
+ const rightConfident = stateForRight.confident;
1720
1750
  switch (path.node.operator) {
1721
1751
  case '||':
1722
- state.confident = leftConfident && (!!left || rightConfident);
1723
- if (!state.confident) return;
1724
- return left || right;
1752
+ {
1753
+ if (leftConfident && (!!left || rightConfident)) {
1754
+ return left || right;
1755
+ }
1756
+ if (!leftConfident) {
1757
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1758
+ return;
1759
+ }
1760
+ if (!rightConfident) {
1761
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1762
+ return;
1763
+ }
1764
+ deopt(path, state, 'unknown error');
1765
+ return;
1766
+ }
1725
1767
  case '&&':
1726
- state.confident = leftConfident && (!left || rightConfident);
1727
- if (!state.confident) return;
1728
- return left && right;
1768
+ {
1769
+ if (leftConfident && (!left || rightConfident)) {
1770
+ return left && right;
1771
+ }
1772
+ if (!leftConfident) {
1773
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1774
+ return;
1775
+ }
1776
+ if (!rightConfident) {
1777
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1778
+ return;
1779
+ }
1780
+ deopt(path, state, 'unknown error');
1781
+ return;
1782
+ }
1729
1783
  case '??':
1730
- state.confident = leftConfident && !!(left ?? rightConfident);
1731
- if (!state.confident) return;
1732
- return left ?? right;
1784
+ {
1785
+ if (leftConfident && !!(left ?? rightConfident)) {
1786
+ return left ?? right;
1787
+ }
1788
+ if (!leftConfident) {
1789
+ deopt(leftPath, state, stateForLeft.deoptReason ?? 'unknown error');
1790
+ return;
1791
+ }
1792
+ if (!rightConfident) {
1793
+ deopt(rightPath, state, stateForRight.deoptReason ?? 'unknown error');
1794
+ return;
1795
+ }
1796
+ deopt(path, state, 'unknown error');
1797
+ return;
1798
+ }
1733
1799
  default:
1734
1800
  path.node.operator;
1735
1801
  }
@@ -1796,6 +1862,13 @@ function _evaluate(path, state) {
1796
1862
  func = global[callee.node.name];
1797
1863
  } else if (isIdentifier(callee) && state.functions.identifiers[callee.node.name]) {
1798
1864
  func = state.functions.identifiers[callee.node.name];
1865
+ } else if (isIdentifier(callee)) {
1866
+ const maybeFunction = evaluateCached(callee, state);
1867
+ if (state.confident) {
1868
+ func = maybeFunction;
1869
+ } else {
1870
+ deopt(callee, state, NON_CONSTANT);
1871
+ }
1799
1872
  }
1800
1873
  if (isMemberExpression(callee)) {
1801
1874
  const object = callee.get('object');
@@ -1847,7 +1920,7 @@ function _evaluate(path, state) {
1847
1920
  }
1848
1921
  }
1849
1922
  }
1850
- deopt(path, state);
1923
+ deopt(path, state, UNSUPPORTED_EXPRESSION(path.node.type));
1851
1924
  }
1852
1925
  function evaluateQuasis(path, quasis, state) {
1853
1926
  let raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
@@ -1884,6 +1957,7 @@ function evaluate(path, traversalState) {
1884
1957
  return {
1885
1958
  confident: state.confident,
1886
1959
  deopt: state.deoptPath,
1960
+ reason: state.deoptReason,
1887
1961
  value: value
1888
1962
  };
1889
1963
  }
@@ -3714,19 +3788,33 @@ function transformStyleXCreate(path, state) {
3714
3788
  const {
3715
3789
  confident,
3716
3790
  value,
3717
- fns
3791
+ fns,
3792
+ reason,
3793
+ deopt
3718
3794
  } = evaluateStyleXCreateArg(firstArg, state, {
3719
3795
  identifiers,
3720
3796
  memberExpressions
3721
3797
  });
3722
3798
  if (!confident) {
3723
- throw path.buildCodeFrameError(shared.messages.NON_STATIC_VALUE, SyntaxError);
3799
+ throw (deopt ?? path).buildCodeFrameError(reason ?? shared.messages.NON_STATIC_VALUE, SyntaxError);
3724
3800
  }
3725
3801
  const plainObject = value;
3802
+ const injectedInheritStyles = {};
3803
+ if (fns != null) {
3804
+ const dynamicFnsNames = Object.values(fns)?.map(entry => Object.keys(entry[1])).flat();
3805
+ dynamicFnsNames.forEach(fnsName => {
3806
+ injectedInheritStyles[fnsName] = {
3807
+ priority: 0,
3808
+ ltr: `@property ${fnsName} { syntax: "*"; inherits: false;}`,
3809
+ rtl: null
3810
+ };
3811
+ });
3812
+ }
3726
3813
  let [compiledStyles, injectedStylesSansKeyframes, classPathsPerNamespace] = shared.create(plainObject, state.options);
3727
3814
  const injectedStyles = {
3728
3815
  ...injectedKeyframes,
3729
- ...injectedStylesSansKeyframes
3816
+ ...injectedStylesSansKeyframes,
3817
+ ...injectedInheritStyles
3730
3818
  };
3731
3819
  let varName = null;
3732
3820
  if (isVariableDeclarator(path.parentPath)) {
@@ -4902,18 +4990,42 @@ function styleXTransform() {
4902
4990
  }
4903
4991
  }
4904
4992
  }
4993
+ },
4994
+ exit: path => {
4905
4995
  path.traverse({
4906
- CallExpression(path) {
4907
- if (isVariableDeclarator(path.parentPath)) {
4908
- transformStyleXKeyframes(path.parentPath, state);
4996
+ Identifier(path) {
4997
+ if (isReferencedIdentifier(path)) {
4998
+ const {
4999
+ name
5000
+ } = path.node;
5001
+ if (state.styleMap.has(name)) {
5002
+ const parentPath = path.parentPath;
5003
+ if (isMemberExpression(parentPath)) {
5004
+ const {
5005
+ property,
5006
+ computed
5007
+ } = parentPath.node;
5008
+ if (property.type === 'Identifier' && !computed) {
5009
+ state.markComposedNamespace([name, property.name, true]);
5010
+ } else if (property.type === 'StringLiteral' && computed) {
5011
+ state.markComposedNamespace([name, property.value, true]);
5012
+ } else if (property.type === 'NumericLiteral' && computed) {
5013
+ state.markComposedNamespace([name, String(property.value), true]);
5014
+ } else {
5015
+ state.markComposedNamespace([name, true, true]);
5016
+ }
5017
+ } else {
5018
+ state.markComposedNamespace([name, true, true]);
5019
+ }
5020
+ }
4909
5021
  }
4910
- transformStyleXDefineVars(path, state);
4911
- transformStyleXCreateTheme(path, state);
4912
- transformStyleXCreate(path, state);
5022
+ },
5023
+ CallExpression(path) {
5024
+ skipStylexMergeChildren(path, state);
5025
+ skipStylexPropsChildren(path, state);
5026
+ skipStylexAttrsChildren(path, state);
4913
5027
  }
4914
5028
  });
4915
- },
4916
- exit: path => {
4917
5029
  path.traverse({
4918
5030
  CallExpression(path) {
4919
5031
  transformStyleXMerge(path, state);
@@ -4998,36 +5110,12 @@ function styleXTransform() {
4998
5110
  }
4999
5111
  },
5000
5112
  CallExpression(path) {
5001
- skipStylexMergeChildren(path, state);
5002
- skipStylexPropsChildren(path, state);
5003
- skipStylexAttrsChildren(path, state);
5004
- },
5005
- Identifier(path) {
5006
- if (isReferencedIdentifier(path)) {
5007
- const {
5008
- name
5009
- } = path.node;
5010
- if (state.styleMap.has(name)) {
5011
- const parentPath = path.parentPath;
5012
- if (isMemberExpression(parentPath)) {
5013
- const {
5014
- property,
5015
- computed
5016
- } = parentPath.node;
5017
- if (property.type === 'Identifier' && !computed) {
5018
- state.markComposedNamespace([name, property.name, true]);
5019
- } else if (property.type === 'StringLiteral' && computed) {
5020
- state.markComposedNamespace([name, property.value, true]);
5021
- } else if (property.type === 'NumericLiteral' && computed) {
5022
- state.markComposedNamespace([name, String(property.value), true]);
5023
- } else {
5024
- state.markComposedNamespace([name, true, true]);
5025
- }
5026
- } else {
5027
- state.markComposedNamespace([name, true, true]);
5028
- }
5029
- }
5113
+ if (isVariableDeclarator(path.parentPath)) {
5114
+ transformStyleXKeyframes(path.parentPath, state);
5030
5115
  }
5116
+ transformStyleXDefineVars(path, state);
5117
+ transformStyleXCreateTheme(path, state);
5118
+ transformStyleXCreate(path, state);
5031
5119
  }
5032
5120
  }
5033
5121
  };
@@ -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
  }>;
@@ -11,7 +11,7 @@ import * as t from '../../flow_modules/@babel/types';
11
11
  import type { NodePath } from '../../flow_modules/@babel/traverse';
12
12
  import StateManager from '../utils/state-manager';
13
13
 
14
- // Read imports of react and remember the name of the local varsiables for later
14
+ // Read imports of react and remember the name of the local variables for later
15
15
  declare export function readImportDeclarations(
16
16
  path: NodePath<t.ImportDeclaration>,
17
17
  state: StateManager,
@@ -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.2",
3
+ "version": "0.10.1",
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.2",
18
- "@stylexjs/stylex": "0.10.0-beta.2",
17
+ "@stylexjs/shared": "0.10.1",
18
+ "@stylexjs/stylex": "0.10.1",
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,