@stylexjs/babel-plugin 0.10.1 → 0.11.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/flow_modules/@babel/traverse/index.js.flow +284 -280
- package/lib/index.js +210 -226
- package/lib/utils/add-sourcemap-data.d.ts +23 -0
- package/lib/utils/add-sourcemap-data.js.flow +25 -0
- package/lib/utils/js-to-ast.d.ts +1 -8
- package/lib/utils/js-to-ast.js.flow +1 -8
- package/lib/utils/state-manager.d.ts +32 -10
- package/lib/utils/state-manager.js.flow +23 -2
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -685,118 +685,6 @@ function requireLib$1 () {
|
|
|
685
685
|
|
|
686
686
|
var libExports = requireLib$1();
|
|
687
687
|
|
|
688
|
-
function isArrayExpression(path, props) {
|
|
689
|
-
return path.isArrayExpression(props);
|
|
690
|
-
}
|
|
691
|
-
function isArrowFunctionExpression(path, props) {
|
|
692
|
-
return path.isArrowFunctionExpression(props);
|
|
693
|
-
}
|
|
694
|
-
function isBinaryExpression(path, props) {
|
|
695
|
-
return path.isBinaryExpression(props);
|
|
696
|
-
}
|
|
697
|
-
function isBooleanLiteral(path, props) {
|
|
698
|
-
return path.isBooleanLiteral(props);
|
|
699
|
-
}
|
|
700
|
-
function isCallExpression(path, props) {
|
|
701
|
-
return path.isCallExpression(props);
|
|
702
|
-
}
|
|
703
|
-
function isClass(path, props) {
|
|
704
|
-
return path.isClass(props);
|
|
705
|
-
}
|
|
706
|
-
function isConditionalExpression(path, props) {
|
|
707
|
-
return path.isConditionalExpression(props);
|
|
708
|
-
}
|
|
709
|
-
function isExportDefaultDeclaration(path, props) {
|
|
710
|
-
return path.isExportDefaultDeclaration(props);
|
|
711
|
-
}
|
|
712
|
-
function isExportNamedDeclaration(path, props) {
|
|
713
|
-
return path.isExportNamedDeclaration(props);
|
|
714
|
-
}
|
|
715
|
-
function isExpression(path, props) {
|
|
716
|
-
return path.isExpression(props);
|
|
717
|
-
}
|
|
718
|
-
function isExpressionStatement(path, props) {
|
|
719
|
-
return path.isExpressionStatement(props);
|
|
720
|
-
}
|
|
721
|
-
function isExpressionWrapper(path, props) {
|
|
722
|
-
return path.isExpressionWrapper(props);
|
|
723
|
-
}
|
|
724
|
-
function isFunction(path, props) {
|
|
725
|
-
return path.isFunction(props);
|
|
726
|
-
}
|
|
727
|
-
function isIdentifier(path, props) {
|
|
728
|
-
return path.isIdentifier(props);
|
|
729
|
-
}
|
|
730
|
-
function isImportDeclaration(path, props) {
|
|
731
|
-
return path.isImportDeclaration(props);
|
|
732
|
-
}
|
|
733
|
-
function isImportDefaultSpecifier(path, props) {
|
|
734
|
-
return path.isImportDefaultSpecifier(props);
|
|
735
|
-
}
|
|
736
|
-
function isImportNamespaceSpecifier(path, props) {
|
|
737
|
-
return path.isImportNamespaceSpecifier(props);
|
|
738
|
-
}
|
|
739
|
-
function isImportSpecifier(path, props) {
|
|
740
|
-
return path.isImportSpecifier(props);
|
|
741
|
-
}
|
|
742
|
-
function isLogicalExpression(path, props) {
|
|
743
|
-
return path.isLogicalExpression(props);
|
|
744
|
-
}
|
|
745
|
-
function isMemberExpression(path, props) {
|
|
746
|
-
return path.isMemberExpression(props);
|
|
747
|
-
}
|
|
748
|
-
function isNullLiteral(path, props) {
|
|
749
|
-
return path.isNullLiteral(props);
|
|
750
|
-
}
|
|
751
|
-
function isNumericLiteral(path, props) {
|
|
752
|
-
return path.isNumericLiteral(props);
|
|
753
|
-
}
|
|
754
|
-
function isObjectExpression(path, props) {
|
|
755
|
-
return path.isObjectExpression(props);
|
|
756
|
-
}
|
|
757
|
-
function isObjectMethod(path, props) {
|
|
758
|
-
return path.isObjectMethod(props);
|
|
759
|
-
}
|
|
760
|
-
function isObjectProperty(path, props) {
|
|
761
|
-
return path.isObjectProperty(props);
|
|
762
|
-
}
|
|
763
|
-
function isProgram(path, props) {
|
|
764
|
-
return path.isProgram(props);
|
|
765
|
-
}
|
|
766
|
-
function isSequenceExpression(path, props) {
|
|
767
|
-
return path.isSequenceExpression(props);
|
|
768
|
-
}
|
|
769
|
-
function isSpreadElement(path, props) {
|
|
770
|
-
return path.isSpreadElement(props);
|
|
771
|
-
}
|
|
772
|
-
function isStatement(path, props) {
|
|
773
|
-
return path.isStatement(props);
|
|
774
|
-
}
|
|
775
|
-
function isStringLiteral(path, props) {
|
|
776
|
-
return path.isStringLiteral(props);
|
|
777
|
-
}
|
|
778
|
-
function isTSAsExpression(path, props) {
|
|
779
|
-
return path.isTSAsExpression(props);
|
|
780
|
-
}
|
|
781
|
-
function isTaggedTemplateExpression(path, props) {
|
|
782
|
-
return path.isTaggedTemplateExpression(props);
|
|
783
|
-
}
|
|
784
|
-
function isTemplateLiteral(path, props) {
|
|
785
|
-
return path.isTemplateLiteral(props);
|
|
786
|
-
}
|
|
787
|
-
function isUnaryExpression(path, props) {
|
|
788
|
-
return path.isUnaryExpression(props);
|
|
789
|
-
}
|
|
790
|
-
function isVariableDeclaration(path, props) {
|
|
791
|
-
return path.isVariableDeclaration(props);
|
|
792
|
-
}
|
|
793
|
-
function isVariableDeclarator(path, props) {
|
|
794
|
-
return path.isVariableDeclarator(props);
|
|
795
|
-
}
|
|
796
|
-
function isReferencedIdentifier(path, props) {
|
|
797
|
-
return path.isReferencedIdentifier(props);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
688
|
const CheckModuleResolution = unionOf3(object({
|
|
801
689
|
type: literal('commonJS'),
|
|
802
690
|
rootDir: unionOf(nullish(), string()),
|
|
@@ -844,6 +732,9 @@ class StateManager {
|
|
|
844
732
|
setOptions(options) {
|
|
845
733
|
const dev = logAndDefault(boolean(), options.dev ?? false, false, 'options.dev');
|
|
846
734
|
const debug = logAndDefault(boolean(), options.debug ?? dev, false, 'options.debug');
|
|
735
|
+
const enableDebugClassNames = logAndDefault(boolean(), options.enableDebugClassNames ?? true, true, 'options.enableDebugClassNames');
|
|
736
|
+
const enableDebugDataProp = logAndDefault(boolean(), options.enableDebugDataProp ?? true, true, 'options.enableDebugDataProp');
|
|
737
|
+
const enableDevClassNames = logAndDefault(boolean(), options.enableDevClassNames ?? false, false, 'options.enableDevClassNames');
|
|
847
738
|
const test = logAndDefault(boolean(), options.test ?? false, false, 'options.test');
|
|
848
739
|
const configRuntimeInjection = logAndDefault(checkRuntimeInjection, options.runtimeInjection ?? dev, dev, 'options.runtimeInjection');
|
|
849
740
|
const runtimeInjection = configRuntimeInjection === true ? DEFAULT_INJECT_PATH : configRuntimeInjection === false ? undefined : configRuntimeInjection;
|
|
@@ -865,18 +756,22 @@ class StateManager {
|
|
|
865
756
|
}));
|
|
866
757
|
const opts = {
|
|
867
758
|
aliases,
|
|
868
|
-
dev,
|
|
869
|
-
debug,
|
|
870
|
-
test,
|
|
871
|
-
runtimeInjection,
|
|
872
759
|
classNamePrefix,
|
|
873
|
-
|
|
760
|
+
debug,
|
|
874
761
|
definedStylexCSSVariables: {},
|
|
762
|
+
dev,
|
|
763
|
+
enableDebugClassNames,
|
|
764
|
+
enableDebugDataProp,
|
|
765
|
+
enableDevClassNames,
|
|
875
766
|
genConditionalClasses,
|
|
876
|
-
|
|
767
|
+
importSources,
|
|
768
|
+
rewriteAliases: typeof options.rewriteAliases === 'boolean' ? options.rewriteAliases : false,
|
|
769
|
+
runtimeInjection,
|
|
877
770
|
styleResolution,
|
|
771
|
+
test,
|
|
772
|
+
treeshakeCompensation,
|
|
878
773
|
unstable_moduleResolution,
|
|
879
|
-
|
|
774
|
+
useRemForFontSize
|
|
880
775
|
};
|
|
881
776
|
return opts;
|
|
882
777
|
}
|
|
@@ -925,7 +820,7 @@ class StateManager {
|
|
|
925
820
|
let targetImportIndex = -1;
|
|
926
821
|
for (let i = 0; i < bodyPath.length; i++) {
|
|
927
822
|
const statement = bodyPath[i];
|
|
928
|
-
if (isImportDeclaration(
|
|
823
|
+
if (statement.isImportDeclaration()) {
|
|
929
824
|
targetImportIndex = i;
|
|
930
825
|
if (statement.node.specifiers.find(s => s.type === 'ImportSpecifier' && s.local.type === 'Identifier' && s.local.name === identifier.name)) {
|
|
931
826
|
break;
|
|
@@ -953,7 +848,7 @@ class StateManager {
|
|
|
953
848
|
let targetImportIndex = -1;
|
|
954
849
|
for (let i = 0; i < bodyPath.length; i++) {
|
|
955
850
|
const statement = bodyPath[i];
|
|
956
|
-
if (isImportDeclaration(
|
|
851
|
+
if (statement.isImportDeclaration()) {
|
|
957
852
|
targetImportIndex = i;
|
|
958
853
|
if (statement.node.specifiers.find(s => s.type === 'ImportDefaultSpecifier' && s.local.type === 'Identifier' && s.local.name === identifier.name)) {
|
|
959
854
|
break;
|
|
@@ -971,6 +866,14 @@ class StateManager {
|
|
|
971
866
|
lastImport.insertAfter(t__namespace.variableDeclaration('var', [t__namespace.variableDeclarator(importName, identifier)]));
|
|
972
867
|
return importName;
|
|
973
868
|
}
|
|
869
|
+
get opts() {
|
|
870
|
+
return {
|
|
871
|
+
...this.options
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
get isDebug() {
|
|
875
|
+
return !!this.options.debug;
|
|
876
|
+
}
|
|
974
877
|
get isDev() {
|
|
975
878
|
return !!this.options.dev;
|
|
976
879
|
}
|
|
@@ -1081,7 +984,7 @@ class StateManager {
|
|
|
1081
984
|
return;
|
|
1082
985
|
}
|
|
1083
986
|
const runtimeInjection = this.runtimeInjection;
|
|
1084
|
-
const statementPath = path.parentPath != null &&
|
|
987
|
+
const statementPath = path.parentPath != null && path.parentPath.isProgram() ? path : getProgramStatement(path);
|
|
1085
988
|
let injectName;
|
|
1086
989
|
if (this.injectImportInserted != null) {
|
|
1087
990
|
injectName = this.injectImportInserted;
|
|
@@ -1167,7 +1070,7 @@ const addFileExtension = (importedFilePath, sourceFile) => {
|
|
|
1167
1070
|
const matchesFileSuffix = allowedSuffix => filename => ['', ...EXTENSIONS].some(extension => filename.endsWith(`${allowedSuffix}${extension}`));
|
|
1168
1071
|
const getProgramPath = path => {
|
|
1169
1072
|
let programPath = path;
|
|
1170
|
-
while (programPath != null && !isProgram(
|
|
1073
|
+
while (programPath != null && !programPath.isProgram()) {
|
|
1171
1074
|
if (programPath.parentPath) {
|
|
1172
1075
|
programPath = programPath.parentPath;
|
|
1173
1076
|
} else {
|
|
@@ -1178,11 +1081,21 @@ const getProgramPath = path => {
|
|
|
1178
1081
|
};
|
|
1179
1082
|
const getProgramStatement = path => {
|
|
1180
1083
|
let programPath = path;
|
|
1181
|
-
while (programPath.parentPath != null && !
|
|
1084
|
+
while (programPath.parentPath != null && !programPath.parentPath.isProgram() && programPath.parentPath != null) {
|
|
1182
1085
|
programPath = programPath.parentPath;
|
|
1183
1086
|
}
|
|
1184
1087
|
return programPath;
|
|
1185
1088
|
};
|
|
1089
|
+
function getRelativePath(from, to) {
|
|
1090
|
+
const relativePath = path.relative(path.parse(from).dir, to);
|
|
1091
|
+
return formatRelativePath(toPosixPath(relativePath));
|
|
1092
|
+
}
|
|
1093
|
+
function toPosixPath(filePath) {
|
|
1094
|
+
return filePath.split(path.sep).join(path.posix.sep);
|
|
1095
|
+
}
|
|
1096
|
+
function formatRelativePath(filePath) {
|
|
1097
|
+
return filePath.startsWith('.') ? filePath : './' + filePath;
|
|
1098
|
+
}
|
|
1186
1099
|
|
|
1187
1100
|
function readImportDeclarations(path, state) {
|
|
1188
1101
|
const {
|
|
@@ -1296,6 +1209,63 @@ function readRequires(path, state) {
|
|
|
1296
1209
|
}
|
|
1297
1210
|
}
|
|
1298
1211
|
|
|
1212
|
+
function getPackagePrefix(absolutePath) {
|
|
1213
|
+
const nodeModulesIndex = absolutePath.indexOf('node_modules');
|
|
1214
|
+
if (nodeModulesIndex !== -1) {
|
|
1215
|
+
const packageName = absolutePath.substring(nodeModulesIndex + 'node_modules'.length + 1);
|
|
1216
|
+
return packageName.split(path.sep)[0];
|
|
1217
|
+
}
|
|
1218
|
+
return undefined;
|
|
1219
|
+
}
|
|
1220
|
+
function getShortPath(relativePath) {
|
|
1221
|
+
return relativePath.split(path.sep).slice(-2).join('/');
|
|
1222
|
+
}
|
|
1223
|
+
function createShortFilename(absolutePath, state) {
|
|
1224
|
+
const isHaste = state.options.unstable_moduleResolution?.type === 'haste';
|
|
1225
|
+
const relativePath = path.relative(process.cwd(), absolutePath);
|
|
1226
|
+
const packagePrefix = getPackagePrefix(absolutePath);
|
|
1227
|
+
if (packagePrefix) {
|
|
1228
|
+
const shortPath = getShortPath(relativePath);
|
|
1229
|
+
return `${packagePrefix}:${shortPath}`;
|
|
1230
|
+
} else {
|
|
1231
|
+
if (isHaste) {
|
|
1232
|
+
return path.basename(absolutePath);
|
|
1233
|
+
}
|
|
1234
|
+
return getShortPath(relativePath);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function addSourceMapData(obj, babelPath, state) {
|
|
1238
|
+
const result = {};
|
|
1239
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1240
|
+
const currentFile = babelPath.hub.file;
|
|
1241
|
+
const sourceMap = currentFile.codeMap;
|
|
1242
|
+
const styleNodePath = babelPath.get('arguments.0.properties').find(prop => prop.node.key.name === key);
|
|
1243
|
+
if (!styleNodePath) {
|
|
1244
|
+
console.warn(`Style node path not found for key: ${key}`);
|
|
1245
|
+
continue;
|
|
1246
|
+
}
|
|
1247
|
+
const generatedLineNumber = styleNodePath.node.loc?.start.line;
|
|
1248
|
+
let originalLineNumber = generatedLineNumber;
|
|
1249
|
+
if (sourceMap && originalLineNumber) {
|
|
1250
|
+
const originalPosition = sourceMap.originalPositionFor({
|
|
1251
|
+
line: generatedLineNumber,
|
|
1252
|
+
column: styleNodePath.node.loc?.start.column
|
|
1253
|
+
});
|
|
1254
|
+
if (originalPosition && originalPosition.line !== null) {
|
|
1255
|
+
originalLineNumber = originalPosition.line;
|
|
1256
|
+
} else {
|
|
1257
|
+
console.warn(`Could not determine original line number for key: ${key}`);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
const shortFilename = createShortFilename(currentFile.opts.filename || '', state);
|
|
1261
|
+
result[key] = {
|
|
1262
|
+
...value,
|
|
1263
|
+
$$css: shortFilename !== '' && originalLineNumber ? `${shortFilename}:${originalLineNumber}` : true
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
return result;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1299
1269
|
function namespaceToDevClassName(namespace, varName, filename) {
|
|
1300
1270
|
const basename = path.basename(filename).split('.')[0];
|
|
1301
1271
|
const className = `${basename}__${varName ? `${varName}.` : ''}${namespace}`;
|
|
@@ -1327,14 +1297,11 @@ function convertToTestStyles(obj, varName, state) {
|
|
|
1327
1297
|
function convertObjectToAST(obj) {
|
|
1328
1298
|
return t__namespace.objectExpression(Object.entries(obj).map(_ref => {
|
|
1329
1299
|
let [key, value] = _ref;
|
|
1330
|
-
return
|
|
1300
|
+
return t__namespace.objectProperty(canBeIdentifier(key) ? t__namespace.identifier(key) : t__namespace.stringLiteral(key), typeof value === 'string' ? t__namespace.stringLiteral(value) : typeof value === 'number' ? t__namespace.numericLiteral(value) : typeof value === 'boolean' ? t__namespace.booleanLiteral(value) : value === null ? t__namespace.nullLiteral() : convertObjectToAST(value));
|
|
1331
1301
|
}));
|
|
1332
1302
|
}
|
|
1333
1303
|
function removeObjectsWithSpreads(obj) {
|
|
1334
|
-
return Object.fromEntries(Object.entries(obj).filter(
|
|
1335
|
-
let [_key, value] = _ref2;
|
|
1336
|
-
return Object.values(value).every(val => !(val instanceof shared.IncludedStyles));
|
|
1337
|
-
}).filter(Boolean));
|
|
1304
|
+
return Object.fromEntries(Object.entries(obj).filter(Boolean));
|
|
1338
1305
|
}
|
|
1339
1306
|
function canBeIdentifier(str) {
|
|
1340
1307
|
return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
|
|
@@ -1395,13 +1362,13 @@ function evaluateImportedFile(filePath, namedExport, state, bindingPath) {
|
|
|
1395
1362
|
traverse(astNode, {
|
|
1396
1363
|
ExportNamedDeclaration(path) {
|
|
1397
1364
|
const declaration = path.get('declaration');
|
|
1398
|
-
if (isVariableDeclaration(
|
|
1365
|
+
if (declaration.isVariableDeclaration()) {
|
|
1399
1366
|
const decls = declaration.get('declarations');
|
|
1400
1367
|
const finder = decl => {
|
|
1401
|
-
if (isVariableDeclarator(
|
|
1368
|
+
if (decl.isVariableDeclarator()) {
|
|
1402
1369
|
const id = decl.get('id');
|
|
1403
1370
|
const init = decl.get('init');
|
|
1404
|
-
if (isIdentifier(
|
|
1371
|
+
if (id.isIdentifier() && id.node.name === namedExport && init != null && init.isExpression()) {
|
|
1405
1372
|
result = evaluateCached(init, state);
|
|
1406
1373
|
}
|
|
1407
1374
|
}
|
|
@@ -1488,11 +1455,11 @@ function evaluateCached(path, state) {
|
|
|
1488
1455
|
}
|
|
1489
1456
|
function _evaluate(path, state) {
|
|
1490
1457
|
if (!state.confident) return;
|
|
1491
|
-
if (isArrowFunctionExpression(
|
|
1458
|
+
if (path.isArrowFunctionExpression()) {
|
|
1492
1459
|
const body = path.get('body');
|
|
1493
1460
|
const params = path.get('params');
|
|
1494
|
-
const identParams = params.filter(param => isIdentifier(
|
|
1495
|
-
if (isExpression(
|
|
1461
|
+
const identParams = params.filter(param => param.isIdentifier()).map(paramPath => paramPath.node.name);
|
|
1462
|
+
if (body.isExpression() && identParams.length === params.length) {
|
|
1496
1463
|
const expr = body;
|
|
1497
1464
|
return function () {
|
|
1498
1465
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1511,13 +1478,13 @@ function _evaluate(path, state) {
|
|
|
1511
1478
|
};
|
|
1512
1479
|
}
|
|
1513
1480
|
}
|
|
1514
|
-
if (isIdentifier(
|
|
1481
|
+
if (path.isIdentifier()) {
|
|
1515
1482
|
const name = path.node.name;
|
|
1516
1483
|
if (Object.keys(state.functions?.identifiers ?? {}).includes(name)) {
|
|
1517
1484
|
return state.functions.identifiers[name];
|
|
1518
1485
|
}
|
|
1519
1486
|
}
|
|
1520
|
-
if (isTSAsExpression(
|
|
1487
|
+
if (path.isTSAsExpression()) {
|
|
1521
1488
|
const expr = path.get('expression');
|
|
1522
1489
|
return evaluateCached(expr, state);
|
|
1523
1490
|
}
|
|
@@ -1525,32 +1492,32 @@ function _evaluate(path, state) {
|
|
|
1525
1492
|
const expr = path.get('expression');
|
|
1526
1493
|
return evaluateCached(expr, state);
|
|
1527
1494
|
}
|
|
1528
|
-
if (isSequenceExpression(
|
|
1495
|
+
if (path.isSequenceExpression()) {
|
|
1529
1496
|
const exprs = path.get('expressions');
|
|
1530
1497
|
return evaluateCached(exprs[exprs.length - 1], state);
|
|
1531
1498
|
}
|
|
1532
|
-
if (isStringLiteral(
|
|
1499
|
+
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
|
|
1533
1500
|
return path.node.value;
|
|
1534
1501
|
}
|
|
1535
|
-
if (isNullLiteral(
|
|
1502
|
+
if (path.isNullLiteral()) {
|
|
1536
1503
|
return null;
|
|
1537
1504
|
}
|
|
1538
|
-
if (isTemplateLiteral(
|
|
1505
|
+
if (path.isTemplateLiteral()) {
|
|
1539
1506
|
return evaluateQuasis(path, path.node.quasis, state);
|
|
1540
1507
|
}
|
|
1541
|
-
const maybeTag = isTaggedTemplateExpression(
|
|
1542
|
-
if (isTaggedTemplateExpression(
|
|
1508
|
+
const maybeTag = path.isTaggedTemplateExpression() && path.get('tag');
|
|
1509
|
+
if (path.isTaggedTemplateExpression() && maybeTag && maybeTag.isMemberExpression()) {
|
|
1543
1510
|
const tag = maybeTag;
|
|
1544
1511
|
const object = tag.get('object');
|
|
1545
|
-
if (isIdentifier(
|
|
1512
|
+
if (object.isIdentifier()) {
|
|
1546
1513
|
const name = object.node.name;
|
|
1547
1514
|
const property = tag.get('property');
|
|
1548
|
-
if (name === 'String' && !path.scope.hasBinding(name) && isIdentifier(
|
|
1515
|
+
if (name === 'String' && !path.scope.hasBinding(name) && property.isIdentifier() && property.node.name === 'raw') {
|
|
1549
1516
|
return evaluateQuasis(path, path.node.quasi.quasis, state, true);
|
|
1550
1517
|
}
|
|
1551
1518
|
}
|
|
1552
1519
|
}
|
|
1553
|
-
if (isConditionalExpression(
|
|
1520
|
+
if (path.isConditionalExpression()) {
|
|
1554
1521
|
const testResult = evaluateCached(path.get('test'), state);
|
|
1555
1522
|
if (!state.confident) return;
|
|
1556
1523
|
if (testResult) {
|
|
@@ -1559,10 +1526,10 @@ function _evaluate(path, state) {
|
|
|
1559
1526
|
return evaluateCached(path.get('alternate'), state);
|
|
1560
1527
|
}
|
|
1561
1528
|
}
|
|
1562
|
-
if (isExpressionWrapper(
|
|
1529
|
+
if (path.isExpressionWrapper()) {
|
|
1563
1530
|
return evaluateCached(path.get('expression'), state);
|
|
1564
1531
|
}
|
|
1565
|
-
if (isMemberExpression(
|
|
1532
|
+
if (path.isMemberExpression() && !path.parentPath.isCallExpression({
|
|
1566
1533
|
callee: path.node
|
|
1567
1534
|
})) {
|
|
1568
1535
|
const object = evaluateCached(path.get('object'), state);
|
|
@@ -1576,25 +1543,25 @@ function _evaluate(path, state) {
|
|
|
1576
1543
|
if (!state.confident) {
|
|
1577
1544
|
return;
|
|
1578
1545
|
}
|
|
1579
|
-
} else if (isIdentifier(
|
|
1546
|
+
} else if (propPath.isIdentifier()) {
|
|
1580
1547
|
property = propPath.node.name;
|
|
1581
|
-
} else if (isStringLiteral(
|
|
1548
|
+
} else if (propPath.isStringLiteral()) {
|
|
1582
1549
|
property = propPath.node.value;
|
|
1583
1550
|
} else {
|
|
1584
1551
|
return deopt(propPath, state, UNEXPECTED_MEMBER_LOOKUP);
|
|
1585
1552
|
}
|
|
1586
1553
|
return object[property];
|
|
1587
1554
|
}
|
|
1588
|
-
if (isReferencedIdentifier(
|
|
1555
|
+
if (path.isReferencedIdentifier()) {
|
|
1589
1556
|
const binding = path.scope?.getBinding(path.node.name);
|
|
1590
1557
|
const bindingPath = binding?.path;
|
|
1591
|
-
if (binding && bindingPath && !isImportDefaultSpecifier(
|
|
1558
|
+
if (binding && bindingPath && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier() && bindingPath.isImportSpecifier()) {
|
|
1592
1559
|
const importSpecifierPath = bindingPath;
|
|
1593
1560
|
const importSpecifierNode = importSpecifierPath.node;
|
|
1594
1561
|
const imported = importSpecifierNode.imported;
|
|
1595
1562
|
const importedName = imported.type === 'Identifier' ? imported.name : imported.value;
|
|
1596
1563
|
const importPath = binding.path.parentPath;
|
|
1597
|
-
if (importPath && isImportDeclaration(
|
|
1564
|
+
if (importPath && importPath.isImportDeclaration()) {
|
|
1598
1565
|
const absPath = state.traversalState.importPathResolver(importPath.node.source.value);
|
|
1599
1566
|
if (!absPath) {
|
|
1600
1567
|
return deopt(binding.path, state, IMPORT_PATH_RESOLUTION_ERROR);
|
|
@@ -1612,7 +1579,7 @@ function _evaluate(path, state) {
|
|
|
1612
1579
|
}
|
|
1613
1580
|
}
|
|
1614
1581
|
}
|
|
1615
|
-
if (binding && bindingPath && isImportDefaultSpecifier(
|
|
1582
|
+
if (binding && bindingPath && bindingPath.isImportDefaultSpecifier()) {
|
|
1616
1583
|
deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
|
|
1617
1584
|
}
|
|
1618
1585
|
if (binding && binding.constantViolations.length > 0) {
|
|
@@ -1639,14 +1606,14 @@ function _evaluate(path, state) {
|
|
|
1639
1606
|
}
|
|
1640
1607
|
}
|
|
1641
1608
|
}
|
|
1642
|
-
if (isUnaryExpression(
|
|
1609
|
+
if (path.isUnaryExpression({
|
|
1643
1610
|
prefix: true
|
|
1644
1611
|
})) {
|
|
1645
1612
|
if (path.node.operator === 'void') {
|
|
1646
1613
|
return undefined;
|
|
1647
1614
|
}
|
|
1648
1615
|
const argument = path.get('argument');
|
|
1649
|
-
if (path.node.operator === 'typeof' && (isFunction(
|
|
1616
|
+
if (path.node.operator === 'typeof' && (argument.isFunction() || argument.isClass())) {
|
|
1650
1617
|
return 'function';
|
|
1651
1618
|
}
|
|
1652
1619
|
const arg = evaluateCached(argument, state);
|
|
@@ -1668,7 +1635,7 @@ function _evaluate(path, state) {
|
|
|
1668
1635
|
return deopt(path, state, UNSUPPORTED_OPERATOR(path.node.operator));
|
|
1669
1636
|
}
|
|
1670
1637
|
}
|
|
1671
|
-
if (isArrayExpression(
|
|
1638
|
+
if (path.isArrayExpression()) {
|
|
1672
1639
|
const arrPath = path;
|
|
1673
1640
|
const arr = [];
|
|
1674
1641
|
const elems = arrPath.get('elements');
|
|
@@ -1683,14 +1650,14 @@ function _evaluate(path, state) {
|
|
|
1683
1650
|
}
|
|
1684
1651
|
return arr;
|
|
1685
1652
|
}
|
|
1686
|
-
if (isObjectExpression(
|
|
1653
|
+
if (path.isObjectExpression()) {
|
|
1687
1654
|
const obj = {};
|
|
1688
1655
|
const props = path.get('properties');
|
|
1689
1656
|
for (const prop of props) {
|
|
1690
|
-
if (isObjectMethod(
|
|
1657
|
+
if (prop.isObjectMethod()) {
|
|
1691
1658
|
return deopt(prop, state, OBJECT_METHOD);
|
|
1692
1659
|
}
|
|
1693
|
-
if (isSpreadElement(
|
|
1660
|
+
if (prop.isSpreadElement()) {
|
|
1694
1661
|
const spreadExpression = evaluateCached(prop.get('argument'), state);
|
|
1695
1662
|
if (!state.confident) {
|
|
1696
1663
|
return deopt(prop, state, state.deoptReason ?? 'unknown error');
|
|
@@ -1698,7 +1665,7 @@ function _evaluate(path, state) {
|
|
|
1698
1665
|
Object.assign(obj, spreadExpression);
|
|
1699
1666
|
continue;
|
|
1700
1667
|
}
|
|
1701
|
-
if (isObjectProperty(
|
|
1668
|
+
if (prop.isObjectProperty()) {
|
|
1702
1669
|
const keyPath = prop.get('key');
|
|
1703
1670
|
let key;
|
|
1704
1671
|
if (prop.node.computed) {
|
|
@@ -1713,7 +1680,7 @@ function _evaluate(path, state) {
|
|
|
1713
1680
|
return;
|
|
1714
1681
|
}
|
|
1715
1682
|
key = value;
|
|
1716
|
-
} else if (isIdentifier(
|
|
1683
|
+
} else if (keyPath.isIdentifier()) {
|
|
1717
1684
|
key = keyPath.node.name;
|
|
1718
1685
|
} else {
|
|
1719
1686
|
key = keyPath.node.value;
|
|
@@ -1730,7 +1697,7 @@ function _evaluate(path, state) {
|
|
|
1730
1697
|
}
|
|
1731
1698
|
return obj;
|
|
1732
1699
|
}
|
|
1733
|
-
if (isLogicalExpression(
|
|
1700
|
+
if (path.isLogicalExpression()) {
|
|
1734
1701
|
const stateForLeft = {
|
|
1735
1702
|
...state,
|
|
1736
1703
|
deoptPath: null,
|
|
@@ -1800,7 +1767,7 @@ function _evaluate(path, state) {
|
|
|
1800
1767
|
path.node.operator;
|
|
1801
1768
|
}
|
|
1802
1769
|
}
|
|
1803
|
-
if (isBinaryExpression(
|
|
1770
|
+
if (path.isBinaryExpression()) {
|
|
1804
1771
|
const left = evaluateCached(path.get('left'), state);
|
|
1805
1772
|
if (!state.confident) return;
|
|
1806
1773
|
const right = evaluateCached(path.get('right'), state);
|
|
@@ -1854,15 +1821,15 @@ function _evaluate(path, state) {
|
|
|
1854
1821
|
return;
|
|
1855
1822
|
}
|
|
1856
1823
|
}
|
|
1857
|
-
if (isCallExpression(
|
|
1824
|
+
if (path.isCallExpression()) {
|
|
1858
1825
|
const callee = path.get('callee');
|
|
1859
1826
|
let context;
|
|
1860
1827
|
let func;
|
|
1861
|
-
if (isIdentifier(
|
|
1828
|
+
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && isValidCallee(callee.node.name)) {
|
|
1862
1829
|
func = global[callee.node.name];
|
|
1863
|
-
} else if (isIdentifier(
|
|
1830
|
+
} else if (callee.isIdentifier() && state.functions.identifiers[callee.node.name]) {
|
|
1864
1831
|
func = state.functions.identifiers[callee.node.name];
|
|
1865
|
-
} else if (isIdentifier(
|
|
1832
|
+
} else if (callee.isIdentifier()) {
|
|
1866
1833
|
const maybeFunction = evaluateCached(callee, state);
|
|
1867
1834
|
if (state.confident) {
|
|
1868
1835
|
func = maybeFunction;
|
|
@@ -1870,10 +1837,10 @@ function _evaluate(path, state) {
|
|
|
1870
1837
|
deopt(callee, state, NON_CONSTANT);
|
|
1871
1838
|
}
|
|
1872
1839
|
}
|
|
1873
|
-
if (isMemberExpression(
|
|
1840
|
+
if (callee.isMemberExpression()) {
|
|
1874
1841
|
const object = callee.get('object');
|
|
1875
1842
|
const property = callee.get('property');
|
|
1876
|
-
if (isIdentifier(
|
|
1843
|
+
if (object.isIdentifier() && property.isIdentifier()) {
|
|
1877
1844
|
if (isValidCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
|
1878
1845
|
context = global[object.node.name];
|
|
1879
1846
|
func = context[property.node.name];
|
|
@@ -1882,11 +1849,11 @@ function _evaluate(path, state) {
|
|
|
1882
1849
|
func = context[property.node.name];
|
|
1883
1850
|
}
|
|
1884
1851
|
}
|
|
1885
|
-
if (isIdentifier(
|
|
1852
|
+
if (object.isIdentifier() && property.isStringLiteral() && state.functions.memberExpressions[object.node.name] && state.functions.memberExpressions[object.node.name][property.node.value]) {
|
|
1886
1853
|
context = state.functions.memberExpressions[object.node.name];
|
|
1887
1854
|
func = context[property.node.value];
|
|
1888
1855
|
}
|
|
1889
|
-
if ((isStringLiteral(
|
|
1856
|
+
if ((object.isStringLiteral() || object.isNumericLiteral()) && property.isIdentifier()) {
|
|
1890
1857
|
const val = object.node.value;
|
|
1891
1858
|
func = val[property.node.name];
|
|
1892
1859
|
if (typeof val === 'string') {
|
|
@@ -1895,11 +1862,11 @@ function _evaluate(path, state) {
|
|
|
1895
1862
|
}
|
|
1896
1863
|
if (func == null) {
|
|
1897
1864
|
const parsedObj = evaluate(object, state.traversalState, state.functions);
|
|
1898
|
-
if (parsedObj.confident && isIdentifier(
|
|
1865
|
+
if (parsedObj.confident && property.isIdentifier()) {
|
|
1899
1866
|
func = parsedObj.value[property.node.name];
|
|
1900
1867
|
context = parsedObj.value;
|
|
1901
1868
|
}
|
|
1902
|
-
if (parsedObj.confident && isStringLiteral(
|
|
1869
|
+
if (parsedObj.confident && property.isStringLiteral()) {
|
|
1903
1870
|
func = parsedObj.value[property.node.value];
|
|
1904
1871
|
context = parsedObj.value;
|
|
1905
1872
|
}
|
|
@@ -1926,7 +1893,7 @@ function evaluateQuasis(path, quasis, state) {
|
|
|
1926
1893
|
let raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1927
1894
|
let str = '';
|
|
1928
1895
|
let i = 0;
|
|
1929
|
-
const exprs = isTemplateLiteral(
|
|
1896
|
+
const exprs = path.isTemplateLiteral() ? path.get('expressions') : path.isTaggedTemplateExpression() ? path.get('quasi').get('expressions') : [];
|
|
1930
1897
|
for (const elem of quasis) {
|
|
1931
1898
|
if (!state.confident) break;
|
|
1932
1899
|
str += raw ? elem.value.raw : elem.value.cooked;
|
|
@@ -2799,7 +2766,7 @@ function requireMessages () {
|
|
|
2799
2766
|
Object.defineProperty(messages, "__esModule", {
|
|
2800
2767
|
value: true
|
|
2801
2768
|
});
|
|
2802
|
-
messages.UNKNOWN_PROP_KEY = messages.UNKNOWN_NAMESPACE = messages.UNEXPECTED_ARGUMENT = messages.UNBOUND_STYLEX_CALL_VALUE = messages.
|
|
2769
|
+
messages.UNKNOWN_PROP_KEY = messages.UNKNOWN_NAMESPACE = messages.UNEXPECTED_ARGUMENT = messages.UNBOUND_STYLEX_CALL_VALUE = messages.ONLY_TOP_LEVEL = messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = messages.NO_PROJECT_ROOT_DIRECTORY = messages.NO_PARENT_PATH = messages.NO_CONDITIONAL_SHORTHAND = messages.NON_STATIC_VALUE = messages.NON_STATIC_KEYFRAME_VALUE = messages.NON_OBJECT_KEYFRAME = messages.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = messages.NON_OBJECT_FOR_STYLEX_CALL = messages.NON_EXPORT_NAMED_DECLARATION = messages.NON_CONTIGUOUS_VARS = messages.LOCAL_ONLY = messages.LINT_UNCLOSED_FUNCTION = messages.INVALID_SPREAD = messages.INVALID_PSEUDO_OR_AT_RULE = messages.INVALID_PSEUDO = messages.ILLEGAL_PROP_VALUE = messages.ILLEGAL_PROP_ARRAY_VALUE = messages.ILLEGAL_NESTED_PSEUDO = messages.ILLEGAL_NAMESPACE_VALUE = messages.ILLEGAL_NAMESPACE_TYPE = messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = messages.ILLEGAL_ARGUMENT_LENGTH = messages.EXPECTED_FUNCTION_CALL = messages.ESCAPED_STYLEX_VALUE = messages.DUPLICATE_CONDITIONAL = messages.ANONYMOUS_THEME = void 0;
|
|
2803
2770
|
messages.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
|
|
2804
2771
|
messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
|
|
2805
2772
|
messages.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
|
@@ -2826,7 +2793,6 @@ function requireMessages () {
|
|
|
2826
2793
|
messages.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
|
|
2827
2794
|
messages.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
|
|
2828
2795
|
messages.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
|
|
2829
|
-
messages.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
|
|
2830
2796
|
messages.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
|
|
2831
2797
|
messages.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
|
|
2832
2798
|
messages.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
|
|
@@ -3009,13 +2975,13 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3009
2975
|
identifiers: {},
|
|
3010
2976
|
memberExpressions: {}
|
|
3011
2977
|
};
|
|
3012
|
-
if (!isObjectExpression(
|
|
2978
|
+
if (!path.isObjectExpression()) {
|
|
3013
2979
|
return evaluate(path, traversalState, functions);
|
|
3014
2980
|
}
|
|
3015
2981
|
const value = {};
|
|
3016
2982
|
const fns = {};
|
|
3017
2983
|
for (const prop of path.get('properties')) {
|
|
3018
|
-
if (!isObjectProperty(
|
|
2984
|
+
if (!prop.isObjectProperty()) {
|
|
3019
2985
|
return evaluate(path, traversalState, functions);
|
|
3020
2986
|
}
|
|
3021
2987
|
const objPropPath = prop;
|
|
@@ -3029,7 +2995,7 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3029
2995
|
}
|
|
3030
2996
|
const key = keyResult.value;
|
|
3031
2997
|
const valPath = prop.get('value');
|
|
3032
|
-
if (!isArrowFunctionExpression(
|
|
2998
|
+
if (!valPath.isArrowFunctionExpression()) {
|
|
3033
2999
|
const val = evaluate(valPath, traversalState, functions);
|
|
3034
3000
|
if (!val.confident) {
|
|
3035
3001
|
return val;
|
|
@@ -3040,9 +3006,9 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3040
3006
|
const fnPath = valPath;
|
|
3041
3007
|
const allParams = fnPath.get('params');
|
|
3042
3008
|
validateDynamicStyleParams(fnPath, allParams);
|
|
3043
|
-
const params = allParams.filter(param => isIdentifier(
|
|
3009
|
+
const params = allParams.filter(param => param.isIdentifier()).map(param => param.node);
|
|
3044
3010
|
const fnBody = fnPath.get('body');
|
|
3045
|
-
if (!isObjectExpression(
|
|
3011
|
+
if (!fnBody.isObjectExpression()) {
|
|
3046
3012
|
return evaluate(path, traversalState, functions);
|
|
3047
3013
|
}
|
|
3048
3014
|
const fnObjectBody = fnBody;
|
|
@@ -3082,13 +3048,13 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3082
3048
|
const inlineStyles = {};
|
|
3083
3049
|
const props = path.get('properties');
|
|
3084
3050
|
for (const prop of props) {
|
|
3085
|
-
if (isObjectMethod(
|
|
3051
|
+
if (prop.isObjectMethod()) {
|
|
3086
3052
|
return {
|
|
3087
3053
|
value: null,
|
|
3088
3054
|
confident: false
|
|
3089
3055
|
};
|
|
3090
3056
|
}
|
|
3091
|
-
if (isSpreadElement(
|
|
3057
|
+
if (prop.isSpreadElement()) {
|
|
3092
3058
|
const result = evaluate(prop.get('argument'), traversalState, functions);
|
|
3093
3059
|
if (!result.confident) {
|
|
3094
3060
|
return result;
|
|
@@ -3096,7 +3062,7 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3096
3062
|
Object.assign(obj, result.value);
|
|
3097
3063
|
continue;
|
|
3098
3064
|
}
|
|
3099
|
-
if (isObjectProperty(
|
|
3065
|
+
if (prop.isObjectProperty()) {
|
|
3100
3066
|
const keyResult = evaluateObjKey(prop, traversalState, functions);
|
|
3101
3067
|
if (!keyResult.confident) {
|
|
3102
3068
|
return {
|
|
@@ -3110,7 +3076,7 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3110
3076
|
key = key.slice(4, -1);
|
|
3111
3077
|
}
|
|
3112
3078
|
const valuePath = prop.get('value');
|
|
3113
|
-
if (isObjectExpression(
|
|
3079
|
+
if (valuePath.isObjectExpression()) {
|
|
3114
3080
|
const result = evaluatePartialObjectRecursively(valuePath, traversalState, functions, [...keyPath, key]);
|
|
3115
3081
|
if (!result.confident) {
|
|
3116
3082
|
return {
|
|
@@ -3164,7 +3130,7 @@ function evaluateObjKey(prop, traversalState, functions) {
|
|
|
3164
3130
|
};
|
|
3165
3131
|
}
|
|
3166
3132
|
key = result.value;
|
|
3167
|
-
} else if (isIdentifier(
|
|
3133
|
+
} else if (keyPath.isIdentifier()) {
|
|
3168
3134
|
key = keyPath.node.name;
|
|
3169
3135
|
} else {
|
|
3170
3136
|
key = keyPath.node.value;
|
|
@@ -3175,7 +3141,7 @@ function evaluateObjKey(prop, traversalState, functions) {
|
|
|
3175
3141
|
};
|
|
3176
3142
|
}
|
|
3177
3143
|
function validateDynamicStyleParams(path, params) {
|
|
3178
|
-
if (params.some(param => !isIdentifier(
|
|
3144
|
+
if (params.some(param => !param.isIdentifier())) {
|
|
3179
3145
|
throw path.buildCodeFrameError(shared.messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS, SyntaxError);
|
|
3180
3146
|
}
|
|
3181
3147
|
}
|
|
@@ -3754,12 +3720,6 @@ function transformStyleXCreate(path, state) {
|
|
|
3754
3720
|
}
|
|
3755
3721
|
const identifiers = {};
|
|
3756
3722
|
const memberExpressions = {};
|
|
3757
|
-
state.stylexIncludeImport.forEach(name => {
|
|
3758
|
-
identifiers[name] = {
|
|
3759
|
-
fn: shared.include,
|
|
3760
|
-
takesPath: true
|
|
3761
|
-
};
|
|
3762
|
-
});
|
|
3763
3723
|
state.stylexFirstThatWorksImport.forEach(name => {
|
|
3764
3724
|
identifiers[name] = {
|
|
3765
3725
|
fn: shared.firstThatWorks
|
|
@@ -3774,10 +3734,6 @@ function transformStyleXCreate(path, state) {
|
|
|
3774
3734
|
if (memberExpressions[name] == null) {
|
|
3775
3735
|
memberExpressions[name] = {};
|
|
3776
3736
|
}
|
|
3777
|
-
memberExpressions[name].include = {
|
|
3778
|
-
fn: shared.include,
|
|
3779
|
-
takesPath: true
|
|
3780
|
-
};
|
|
3781
3737
|
memberExpressions[name].firstThatWorks = {
|
|
3782
3738
|
fn: shared.firstThatWorks
|
|
3783
3739
|
};
|
|
@@ -3817,21 +3773,27 @@ function transformStyleXCreate(path, state) {
|
|
|
3817
3773
|
...injectedInheritStyles
|
|
3818
3774
|
};
|
|
3819
3775
|
let varName = null;
|
|
3820
|
-
if (
|
|
3776
|
+
if (path.parentPath.isVariableDeclarator()) {
|
|
3821
3777
|
const idNode = path.parentPath.node.id;
|
|
3822
3778
|
if (idNode.type === 'Identifier') {
|
|
3823
3779
|
varName = idNode.name;
|
|
3824
3780
|
}
|
|
3825
3781
|
}
|
|
3826
|
-
if (state.
|
|
3782
|
+
if (state.isDebug && state.opts.enableDebugDataProp) {
|
|
3827
3783
|
compiledStyles = {
|
|
3828
|
-
...
|
|
3784
|
+
...addSourceMapData(compiledStyles, path, state)
|
|
3829
3785
|
};
|
|
3830
|
-
}
|
|
3786
|
+
}
|
|
3787
|
+
if (state.isDev && state.opts.enableDevClassNames) {
|
|
3831
3788
|
compiledStyles = {
|
|
3832
3789
|
...injectDevClassNames(compiledStyles, varName, state)
|
|
3833
3790
|
};
|
|
3834
3791
|
}
|
|
3792
|
+
if (state.isTest) {
|
|
3793
|
+
compiledStyles = {
|
|
3794
|
+
...convertToTestStyles(compiledStyles, varName, state)
|
|
3795
|
+
};
|
|
3796
|
+
}
|
|
3835
3797
|
if (varName != null) {
|
|
3836
3798
|
const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
|
|
3837
3799
|
state.styleMap.set(varName, stylesToRemember);
|
|
@@ -3944,11 +3906,11 @@ function transformStyleXCreate(path, state) {
|
|
|
3944
3906
|
state.inStyleXCreate = false;
|
|
3945
3907
|
}
|
|
3946
3908
|
function validateStyleXCreate(path) {
|
|
3947
|
-
if (path.parentPath == null ||
|
|
3909
|
+
if (path.parentPath == null || path.parentPath.isExpressionStatement()) {
|
|
3948
3910
|
throw path.buildCodeFrameError(shared.messages.UNBOUND_STYLEX_CALL_VALUE, SyntaxError);
|
|
3949
3911
|
}
|
|
3950
3912
|
const nearestStatement = findNearestStatementAncestor(path);
|
|
3951
|
-
if (!
|
|
3913
|
+
if (!nearestStatement.parentPath.isProgram() && !nearestStatement.parentPath.isExportNamedDeclaration()) {
|
|
3952
3914
|
throw path.buildCodeFrameError(shared.messages.ONLY_TOP_LEVEL, SyntaxError);
|
|
3953
3915
|
}
|
|
3954
3916
|
if (path.node.arguments.length !== 1) {
|
|
@@ -3959,7 +3921,7 @@ function validateStyleXCreate(path) {
|
|
|
3959
3921
|
}
|
|
3960
3922
|
}
|
|
3961
3923
|
function findNearestStatementAncestor(path) {
|
|
3962
|
-
if (isStatement(
|
|
3924
|
+
if (path.isStatement()) {
|
|
3963
3925
|
return path;
|
|
3964
3926
|
}
|
|
3965
3927
|
if (path.parentPath == null) {
|
|
@@ -3999,7 +3961,7 @@ function transformStyleXDefineVars(callExpressionPath, state) {
|
|
|
3999
3961
|
if (callExpressionNode.callee.type === 'Identifier' && state.stylexDefineVarsImport.has(callExpressionNode.callee.name) || callExpressionNode.callee.type === 'MemberExpression' && callExpressionNode.callee.property.name === 'defineVars' && callExpressionNode.callee.object.type === 'Identifier' && callExpressionNode.callee.property.type === 'Identifier' && state.stylexImport.has(callExpressionNode.callee.object.name)) {
|
|
4000
3962
|
validateStyleXDefineVars(callExpressionPath);
|
|
4001
3963
|
const variableDeclaratorPath = callExpressionPath.parentPath;
|
|
4002
|
-
if (!isVariableDeclarator(
|
|
3964
|
+
if (!variableDeclaratorPath.isVariableDeclarator()) {
|
|
4003
3965
|
return;
|
|
4004
3966
|
}
|
|
4005
3967
|
const variableDeclaratorNode = variableDeclaratorPath.node;
|
|
@@ -4099,11 +4061,11 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
|
|
|
4099
4061
|
if (callExpressionNode.callee.type === 'Identifier' && state.stylexCreateThemeImport.has(callExpressionNode.callee.name) || callExpressionNode.callee.type === 'MemberExpression' && callExpressionNode.callee.object.type === 'Identifier' && callExpressionNode.callee.property.type === 'Identifier' && callExpressionNode.callee.property.name === 'createTheme' && state.stylexImport.has(callExpressionNode.callee.object.name)) {
|
|
4100
4062
|
validateStyleXCreateTheme(callExpressionPath);
|
|
4101
4063
|
const variableDeclaratorPath = callExpressionPath.parentPath;
|
|
4102
|
-
if (!isVariableDeclarator(
|
|
4064
|
+
if (!variableDeclaratorPath.isVariableDeclarator()) {
|
|
4103
4065
|
return;
|
|
4104
4066
|
}
|
|
4105
4067
|
const id = variableDeclaratorPath.get('id');
|
|
4106
|
-
if (!isIdentifier(
|
|
4068
|
+
if (!id.isIdentifier()) {
|
|
4107
4069
|
return;
|
|
4108
4070
|
}
|
|
4109
4071
|
const variableName = id.node.name;
|
|
@@ -4222,7 +4184,7 @@ function transformStyleXKeyframes(path, state) {
|
|
|
4222
4184
|
throw path.buildCodeFrameError(shared.messages.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL, SyntaxError);
|
|
4223
4185
|
}
|
|
4224
4186
|
const init = path.get('init');
|
|
4225
|
-
if (init == null || !isCallExpression(
|
|
4187
|
+
if (init == null || !init.isCallExpression()) {
|
|
4226
4188
|
throw path.buildCodeFrameError(shared.messages.NON_STATIC_KEYFRAME_VALUE, SyntaxError);
|
|
4227
4189
|
}
|
|
4228
4190
|
const args = init.get('arguments');
|
|
@@ -4414,7 +4376,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4414
4376
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4415
4377
|
}
|
|
4416
4378
|
}
|
|
4417
|
-
if (isMemberExpression(
|
|
4379
|
+
if (argPath.isMemberExpression()) {
|
|
4418
4380
|
MemberExpression(argPath);
|
|
4419
4381
|
} else {
|
|
4420
4382
|
argPath.traverse({
|
|
@@ -4460,7 +4422,7 @@ function parseNullableStyle$2(node, state) {
|
|
|
4460
4422
|
function makeStringExpression$2(values) {
|
|
4461
4423
|
const conditions = values.filter(v => Array.isArray(v)).map(v => v[0]);
|
|
4462
4424
|
if (conditions.length === 0) {
|
|
4463
|
-
return t__namespace.stringLiteral(stylex(...values));
|
|
4425
|
+
return t__namespace.stringLiteral(stylex.legacyMerge(...values));
|
|
4464
4426
|
}
|
|
4465
4427
|
const conditionPermutations = genConditionPermutations$2(conditions.length);
|
|
4466
4428
|
const objEntries = conditionPermutations.map(permutation => {
|
|
@@ -4474,7 +4436,7 @@ function makeStringExpression$2(values) {
|
|
|
4474
4436
|
}
|
|
4475
4437
|
});
|
|
4476
4438
|
const key = permutation.reduce((soFar, bool) => soFar << 1 | (bool ? 1 : 0), 0);
|
|
4477
|
-
return t__namespace.objectProperty(t__namespace.numericLiteral(key), t__namespace.stringLiteral(stylex(...args)));
|
|
4439
|
+
return t__namespace.objectProperty(t__namespace.numericLiteral(key), t__namespace.stringLiteral(stylex.legacyMerge(...args)));
|
|
4478
4440
|
});
|
|
4479
4441
|
const objExpressions = t__namespace.objectExpression(objEntries);
|
|
4480
4442
|
const conditionsToKey = genBitwiseOrOfConditions$2(conditions);
|
|
@@ -4636,7 +4598,7 @@ function transformStylexProps(path, state) {
|
|
|
4636
4598
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4637
4599
|
}
|
|
4638
4600
|
}
|
|
4639
|
-
if (isMemberExpression(
|
|
4601
|
+
if (argPath.isMemberExpression()) {
|
|
4640
4602
|
MemberExpression(argPath);
|
|
4641
4603
|
} else {
|
|
4642
4604
|
argPath.traverse({
|
|
@@ -4871,7 +4833,7 @@ function transformStylexAttrs(path, state) {
|
|
|
4871
4833
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4872
4834
|
}
|
|
4873
4835
|
}
|
|
4874
|
-
if (isMemberExpression(
|
|
4836
|
+
if (argPath.isMemberExpression()) {
|
|
4875
4837
|
MemberExpression(argPath);
|
|
4876
4838
|
} else {
|
|
4877
4839
|
argPath.traverse({
|
|
@@ -4981,10 +4943,10 @@ function styleXTransform() {
|
|
|
4981
4943
|
enter: (path, s) => {
|
|
4982
4944
|
state = new StateManager(s);
|
|
4983
4945
|
for (const block of path.get('body')) {
|
|
4984
|
-
if (isImportDeclaration(
|
|
4946
|
+
if (block.isImportDeclaration()) {
|
|
4985
4947
|
readImportDeclarations(block, state);
|
|
4986
4948
|
}
|
|
4987
|
-
if (isVariableDeclaration(
|
|
4949
|
+
if (block.isVariableDeclaration()) {
|
|
4988
4950
|
for (const decl of block.get('declarations')) {
|
|
4989
4951
|
readRequires(decl, state);
|
|
4990
4952
|
}
|
|
@@ -4993,14 +4955,36 @@ function styleXTransform() {
|
|
|
4993
4955
|
},
|
|
4994
4956
|
exit: path => {
|
|
4995
4957
|
path.traverse({
|
|
4958
|
+
ImportDeclaration(path) {
|
|
4959
|
+
const filename = state.filename;
|
|
4960
|
+
if (filename == null || !state.options.rewriteAliases) {
|
|
4961
|
+
return;
|
|
4962
|
+
}
|
|
4963
|
+
const source = path.node.source.value;
|
|
4964
|
+
const aliases = state.options.aliases;
|
|
4965
|
+
const themeFileExtension = '.stylex';
|
|
4966
|
+
if (!matchesFileSuffix(themeFileExtension)(source)) {
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4969
|
+
const resolvedFilePath = filePathResolver(source, filename, aliases);
|
|
4970
|
+
if (resolvedFilePath == null) {
|
|
4971
|
+
return;
|
|
4972
|
+
}
|
|
4973
|
+
let relativeFilePath = getRelativePath(filename, resolvedFilePath);
|
|
4974
|
+
const extension = EXTENSIONS.find(ext => relativeFilePath.endsWith(ext));
|
|
4975
|
+
if (extension != null) {
|
|
4976
|
+
relativeFilePath = relativeFilePath.slice(0, -extension.length);
|
|
4977
|
+
}
|
|
4978
|
+
path.node.source.value = relativeFilePath;
|
|
4979
|
+
},
|
|
4996
4980
|
Identifier(path) {
|
|
4997
|
-
if (isReferencedIdentifier(
|
|
4981
|
+
if (path.isReferencedIdentifier()) {
|
|
4998
4982
|
const {
|
|
4999
4983
|
name
|
|
5000
4984
|
} = path.node;
|
|
5001
4985
|
if (state.styleMap.has(name)) {
|
|
5002
4986
|
const parentPath = path.parentPath;
|
|
5003
|
-
if (isMemberExpression(
|
|
4987
|
+
if (parentPath.isMemberExpression()) {
|
|
5004
4988
|
const {
|
|
5005
4989
|
property,
|
|
5006
4990
|
computed
|
|
@@ -5064,11 +5048,11 @@ function styleXTransform() {
|
|
|
5064
5048
|
path.remove();
|
|
5065
5049
|
return;
|
|
5066
5050
|
}
|
|
5067
|
-
if (isVariableDeclarator(
|
|
5051
|
+
if (path.isVariableDeclarator()) {
|
|
5068
5052
|
const init = path.get('init');
|
|
5069
|
-
if (init != null && isObjectExpression(
|
|
5053
|
+
if (init != null && init.isObjectExpression()) {
|
|
5070
5054
|
for (const prop of init.get('properties')) {
|
|
5071
|
-
if (isObjectProperty(
|
|
5055
|
+
if (prop.isObjectProperty()) {
|
|
5072
5056
|
const key = prop.get('key').node;
|
|
5073
5057
|
const keyAsString = key.type === 'Identifier' ? key.name : key.type === 'StringLiteral' ? key.value : key.type === 'NumericLiteral' ? String(key.value) : null;
|
|
5074
5058
|
if (keyAsString != null) {
|
|
@@ -5085,9 +5069,9 @@ function styleXTransform() {
|
|
|
5085
5069
|
if (!allNullsToKeep.includes(true)) {
|
|
5086
5070
|
const nullsToKeep = new Set(allNullsToKeep.filter(x => x !== true).flat());
|
|
5087
5071
|
const styleObject = prop.get('value');
|
|
5088
|
-
if (isObjectExpression(
|
|
5072
|
+
if (styleObject.isObjectExpression()) {
|
|
5089
5073
|
for (const styleProp of styleObject.get('properties')) {
|
|
5090
|
-
if (isObjectProperty(
|
|
5074
|
+
if (styleProp.isObjectProperty() && styleProp.get('value').isNullLiteral()) {
|
|
5091
5075
|
const styleKey = styleProp.get('key').node;
|
|
5092
5076
|
const styleKeyAsString = styleKey.type === 'Identifier' ? styleKey.name : styleKey.type === 'StringLiteral' ? styleKey.value : styleKey.type === 'NumericLiteral' ? String(styleKey.value) : null;
|
|
5093
5077
|
if (styleKeyAsString != null && !nullsToKeep.has(styleKeyAsString)) {
|
|
@@ -5110,7 +5094,7 @@ function styleXTransform() {
|
|
|
5110
5094
|
}
|
|
5111
5095
|
},
|
|
5112
5096
|
CallExpression(path) {
|
|
5113
|
-
if (
|
|
5097
|
+
if (path.parentPath.isVariableDeclarator()) {
|
|
5114
5098
|
transformStyleXKeyframes(path.parentPath, state);
|
|
5115
5099
|
}
|
|
5116
5100
|
transformStyleXDefineVars(path, state);
|
|
@@ -5125,10 +5109,10 @@ function stylexPluginWithOptions(options) {
|
|
|
5125
5109
|
}
|
|
5126
5110
|
styleXTransform.withOptions = stylexPluginWithOptions;
|
|
5127
5111
|
function isExported(path) {
|
|
5128
|
-
if (path == null || isProgram(
|
|
5112
|
+
if (path == null || path.isProgram()) {
|
|
5129
5113
|
return false;
|
|
5130
5114
|
}
|
|
5131
|
-
if (isExportNamedDeclaration(
|
|
5115
|
+
if (path.isExportNamedDeclaration() || path.isExportDefaultDeclaration()) {
|
|
5132
5116
|
return true;
|
|
5133
5117
|
}
|
|
5134
5118
|
return isExported(path.parentPath);
|