@stylexjs/babel-plugin 0.10.0 → 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 +286 -282
- package/lib/index.js +221 -232
- 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/lib/visitors/imports.js.flow +1 -1
- 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;
|
|
@@ -1130,12 +1033,17 @@ function possibleAliasedPaths(importPath, aliases) {
|
|
|
1130
1033
|
}
|
|
1131
1034
|
return result;
|
|
1132
1035
|
}
|
|
1036
|
+
const getPossibleFilePaths = filePath => {
|
|
1037
|
+
const extension = path.extname(filePath);
|
|
1038
|
+
const filePathHasCodeExtension = EXTENSIONS.includes(extension);
|
|
1039
|
+
const filePathNoCodeExtension = filePathHasCodeExtension ? filePath.slice(0, -extension.length) : filePath;
|
|
1040
|
+
return [filePath, ...EXTENSIONS.map(ext => filePathNoCodeExtension + ext)];
|
|
1041
|
+
};
|
|
1133
1042
|
const filePathResolver = (relativeFilePath, sourceFilePath, aliases) => {
|
|
1134
|
-
for (const
|
|
1135
|
-
const importPathStr = relativeFilePath + ext;
|
|
1043
|
+
for (const importPathStr of getPossibleFilePaths(relativeFilePath)) {
|
|
1136
1044
|
if (importPathStr.startsWith('.')) {
|
|
1137
1045
|
try {
|
|
1138
|
-
return importMetaResolve.moduleResolve(importPathStr, url.pathToFileURL(sourceFilePath))
|
|
1046
|
+
return url.fileURLToPath(importMetaResolve.moduleResolve(importPathStr, url.pathToFileURL(sourceFilePath)));
|
|
1139
1047
|
} catch {
|
|
1140
1048
|
continue;
|
|
1141
1049
|
}
|
|
@@ -1143,7 +1051,7 @@ const filePathResolver = (relativeFilePath, sourceFilePath, aliases) => {
|
|
|
1143
1051
|
const allAliases = possibleAliasedPaths(importPathStr, aliases);
|
|
1144
1052
|
for (const possiblePath of allAliases) {
|
|
1145
1053
|
try {
|
|
1146
|
-
return importMetaResolve.moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath))
|
|
1054
|
+
return url.fileURLToPath(importMetaResolve.moduleResolve(possiblePath, url.pathToFileURL(sourceFilePath)));
|
|
1147
1055
|
} catch {
|
|
1148
1056
|
continue;
|
|
1149
1057
|
}
|
|
@@ -1159,10 +1067,10 @@ const addFileExtension = (importedFilePath, sourceFile) => {
|
|
|
1159
1067
|
const fileExtension = path.extname(sourceFile);
|
|
1160
1068
|
return importedFilePath + fileExtension;
|
|
1161
1069
|
};
|
|
1162
|
-
const matchesFileSuffix = allowedSuffix => filename =>
|
|
1070
|
+
const matchesFileSuffix = allowedSuffix => filename => ['', ...EXTENSIONS].some(extension => filename.endsWith(`${allowedSuffix}${extension}`));
|
|
1163
1071
|
const getProgramPath = path => {
|
|
1164
1072
|
let programPath = path;
|
|
1165
|
-
while (programPath != null && !isProgram(
|
|
1073
|
+
while (programPath != null && !programPath.isProgram()) {
|
|
1166
1074
|
if (programPath.parentPath) {
|
|
1167
1075
|
programPath = programPath.parentPath;
|
|
1168
1076
|
} else {
|
|
@@ -1173,11 +1081,21 @@ const getProgramPath = path => {
|
|
|
1173
1081
|
};
|
|
1174
1082
|
const getProgramStatement = path => {
|
|
1175
1083
|
let programPath = path;
|
|
1176
|
-
while (programPath.parentPath != null && !
|
|
1084
|
+
while (programPath.parentPath != null && !programPath.parentPath.isProgram() && programPath.parentPath != null) {
|
|
1177
1085
|
programPath = programPath.parentPath;
|
|
1178
1086
|
}
|
|
1179
1087
|
return programPath;
|
|
1180
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
|
+
}
|
|
1181
1099
|
|
|
1182
1100
|
function readImportDeclarations(path, state) {
|
|
1183
1101
|
const {
|
|
@@ -1291,6 +1209,63 @@ function readRequires(path, state) {
|
|
|
1291
1209
|
}
|
|
1292
1210
|
}
|
|
1293
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
|
+
|
|
1294
1269
|
function namespaceToDevClassName(namespace, varName, filename) {
|
|
1295
1270
|
const basename = path.basename(filename).split('.')[0];
|
|
1296
1271
|
const className = `${basename}__${varName ? `${varName}.` : ''}${namespace}`;
|
|
@@ -1322,14 +1297,11 @@ function convertToTestStyles(obj, varName, state) {
|
|
|
1322
1297
|
function convertObjectToAST(obj) {
|
|
1323
1298
|
return t__namespace.objectExpression(Object.entries(obj).map(_ref => {
|
|
1324
1299
|
let [key, value] = _ref;
|
|
1325
|
-
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));
|
|
1326
1301
|
}));
|
|
1327
1302
|
}
|
|
1328
1303
|
function removeObjectsWithSpreads(obj) {
|
|
1329
|
-
return Object.fromEntries(Object.entries(obj).filter(
|
|
1330
|
-
let [_key, value] = _ref2;
|
|
1331
|
-
return Object.values(value).every(val => !(val instanceof shared.IncludedStyles));
|
|
1332
|
-
}).filter(Boolean));
|
|
1304
|
+
return Object.fromEntries(Object.entries(obj).filter(Boolean));
|
|
1333
1305
|
}
|
|
1334
1306
|
function canBeIdentifier(str) {
|
|
1335
1307
|
return str.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) != null;
|
|
@@ -1390,13 +1362,13 @@ function evaluateImportedFile(filePath, namedExport, state, bindingPath) {
|
|
|
1390
1362
|
traverse(astNode, {
|
|
1391
1363
|
ExportNamedDeclaration(path) {
|
|
1392
1364
|
const declaration = path.get('declaration');
|
|
1393
|
-
if (isVariableDeclaration(
|
|
1365
|
+
if (declaration.isVariableDeclaration()) {
|
|
1394
1366
|
const decls = declaration.get('declarations');
|
|
1395
1367
|
const finder = decl => {
|
|
1396
|
-
if (isVariableDeclarator(
|
|
1368
|
+
if (decl.isVariableDeclarator()) {
|
|
1397
1369
|
const id = decl.get('id');
|
|
1398
1370
|
const init = decl.get('init');
|
|
1399
|
-
if (isIdentifier(
|
|
1371
|
+
if (id.isIdentifier() && id.node.name === namedExport && init != null && init.isExpression()) {
|
|
1400
1372
|
result = evaluateCached(init, state);
|
|
1401
1373
|
}
|
|
1402
1374
|
}
|
|
@@ -1483,11 +1455,11 @@ function evaluateCached(path, state) {
|
|
|
1483
1455
|
}
|
|
1484
1456
|
function _evaluate(path, state) {
|
|
1485
1457
|
if (!state.confident) return;
|
|
1486
|
-
if (isArrowFunctionExpression(
|
|
1458
|
+
if (path.isArrowFunctionExpression()) {
|
|
1487
1459
|
const body = path.get('body');
|
|
1488
1460
|
const params = path.get('params');
|
|
1489
|
-
const identParams = params.filter(param => isIdentifier(
|
|
1490
|
-
if (isExpression(
|
|
1461
|
+
const identParams = params.filter(param => param.isIdentifier()).map(paramPath => paramPath.node.name);
|
|
1462
|
+
if (body.isExpression() && identParams.length === params.length) {
|
|
1491
1463
|
const expr = body;
|
|
1492
1464
|
return function () {
|
|
1493
1465
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1506,13 +1478,13 @@ function _evaluate(path, state) {
|
|
|
1506
1478
|
};
|
|
1507
1479
|
}
|
|
1508
1480
|
}
|
|
1509
|
-
if (isIdentifier(
|
|
1481
|
+
if (path.isIdentifier()) {
|
|
1510
1482
|
const name = path.node.name;
|
|
1511
1483
|
if (Object.keys(state.functions?.identifiers ?? {}).includes(name)) {
|
|
1512
1484
|
return state.functions.identifiers[name];
|
|
1513
1485
|
}
|
|
1514
1486
|
}
|
|
1515
|
-
if (isTSAsExpression(
|
|
1487
|
+
if (path.isTSAsExpression()) {
|
|
1516
1488
|
const expr = path.get('expression');
|
|
1517
1489
|
return evaluateCached(expr, state);
|
|
1518
1490
|
}
|
|
@@ -1520,32 +1492,32 @@ function _evaluate(path, state) {
|
|
|
1520
1492
|
const expr = path.get('expression');
|
|
1521
1493
|
return evaluateCached(expr, state);
|
|
1522
1494
|
}
|
|
1523
|
-
if (isSequenceExpression(
|
|
1495
|
+
if (path.isSequenceExpression()) {
|
|
1524
1496
|
const exprs = path.get('expressions');
|
|
1525
1497
|
return evaluateCached(exprs[exprs.length - 1], state);
|
|
1526
1498
|
}
|
|
1527
|
-
if (isStringLiteral(
|
|
1499
|
+
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
|
|
1528
1500
|
return path.node.value;
|
|
1529
1501
|
}
|
|
1530
|
-
if (isNullLiteral(
|
|
1502
|
+
if (path.isNullLiteral()) {
|
|
1531
1503
|
return null;
|
|
1532
1504
|
}
|
|
1533
|
-
if (isTemplateLiteral(
|
|
1505
|
+
if (path.isTemplateLiteral()) {
|
|
1534
1506
|
return evaluateQuasis(path, path.node.quasis, state);
|
|
1535
1507
|
}
|
|
1536
|
-
const maybeTag = isTaggedTemplateExpression(
|
|
1537
|
-
if (isTaggedTemplateExpression(
|
|
1508
|
+
const maybeTag = path.isTaggedTemplateExpression() && path.get('tag');
|
|
1509
|
+
if (path.isTaggedTemplateExpression() && maybeTag && maybeTag.isMemberExpression()) {
|
|
1538
1510
|
const tag = maybeTag;
|
|
1539
1511
|
const object = tag.get('object');
|
|
1540
|
-
if (isIdentifier(
|
|
1512
|
+
if (object.isIdentifier()) {
|
|
1541
1513
|
const name = object.node.name;
|
|
1542
1514
|
const property = tag.get('property');
|
|
1543
|
-
if (name === 'String' && !path.scope.hasBinding(name) && isIdentifier(
|
|
1515
|
+
if (name === 'String' && !path.scope.hasBinding(name) && property.isIdentifier() && property.node.name === 'raw') {
|
|
1544
1516
|
return evaluateQuasis(path, path.node.quasi.quasis, state, true);
|
|
1545
1517
|
}
|
|
1546
1518
|
}
|
|
1547
1519
|
}
|
|
1548
|
-
if (isConditionalExpression(
|
|
1520
|
+
if (path.isConditionalExpression()) {
|
|
1549
1521
|
const testResult = evaluateCached(path.get('test'), state);
|
|
1550
1522
|
if (!state.confident) return;
|
|
1551
1523
|
if (testResult) {
|
|
@@ -1554,10 +1526,10 @@ function _evaluate(path, state) {
|
|
|
1554
1526
|
return evaluateCached(path.get('alternate'), state);
|
|
1555
1527
|
}
|
|
1556
1528
|
}
|
|
1557
|
-
if (isExpressionWrapper(
|
|
1529
|
+
if (path.isExpressionWrapper()) {
|
|
1558
1530
|
return evaluateCached(path.get('expression'), state);
|
|
1559
1531
|
}
|
|
1560
|
-
if (isMemberExpression(
|
|
1532
|
+
if (path.isMemberExpression() && !path.parentPath.isCallExpression({
|
|
1561
1533
|
callee: path.node
|
|
1562
1534
|
})) {
|
|
1563
1535
|
const object = evaluateCached(path.get('object'), state);
|
|
@@ -1571,25 +1543,25 @@ function _evaluate(path, state) {
|
|
|
1571
1543
|
if (!state.confident) {
|
|
1572
1544
|
return;
|
|
1573
1545
|
}
|
|
1574
|
-
} else if (isIdentifier(
|
|
1546
|
+
} else if (propPath.isIdentifier()) {
|
|
1575
1547
|
property = propPath.node.name;
|
|
1576
|
-
} else if (isStringLiteral(
|
|
1548
|
+
} else if (propPath.isStringLiteral()) {
|
|
1577
1549
|
property = propPath.node.value;
|
|
1578
1550
|
} else {
|
|
1579
1551
|
return deopt(propPath, state, UNEXPECTED_MEMBER_LOOKUP);
|
|
1580
1552
|
}
|
|
1581
1553
|
return object[property];
|
|
1582
1554
|
}
|
|
1583
|
-
if (isReferencedIdentifier(
|
|
1555
|
+
if (path.isReferencedIdentifier()) {
|
|
1584
1556
|
const binding = path.scope?.getBinding(path.node.name);
|
|
1585
1557
|
const bindingPath = binding?.path;
|
|
1586
|
-
if (binding && bindingPath && !isImportDefaultSpecifier(
|
|
1558
|
+
if (binding && bindingPath && !bindingPath.isImportDefaultSpecifier() && !bindingPath.isImportNamespaceSpecifier() && bindingPath.isImportSpecifier()) {
|
|
1587
1559
|
const importSpecifierPath = bindingPath;
|
|
1588
1560
|
const importSpecifierNode = importSpecifierPath.node;
|
|
1589
1561
|
const imported = importSpecifierNode.imported;
|
|
1590
1562
|
const importedName = imported.type === 'Identifier' ? imported.name : imported.value;
|
|
1591
1563
|
const importPath = binding.path.parentPath;
|
|
1592
|
-
if (importPath && isImportDeclaration(
|
|
1564
|
+
if (importPath && importPath.isImportDeclaration()) {
|
|
1593
1565
|
const absPath = state.traversalState.importPathResolver(importPath.node.source.value);
|
|
1594
1566
|
if (!absPath) {
|
|
1595
1567
|
return deopt(binding.path, state, IMPORT_PATH_RESOLUTION_ERROR);
|
|
@@ -1607,7 +1579,7 @@ function _evaluate(path, state) {
|
|
|
1607
1579
|
}
|
|
1608
1580
|
}
|
|
1609
1581
|
}
|
|
1610
|
-
if (binding && bindingPath && isImportDefaultSpecifier(
|
|
1582
|
+
if (binding && bindingPath && bindingPath.isImportDefaultSpecifier()) {
|
|
1611
1583
|
deopt(binding.path, state, IMPORT_FILE_EVAL_ERROR);
|
|
1612
1584
|
}
|
|
1613
1585
|
if (binding && binding.constantViolations.length > 0) {
|
|
@@ -1634,14 +1606,14 @@ function _evaluate(path, state) {
|
|
|
1634
1606
|
}
|
|
1635
1607
|
}
|
|
1636
1608
|
}
|
|
1637
|
-
if (isUnaryExpression(
|
|
1609
|
+
if (path.isUnaryExpression({
|
|
1638
1610
|
prefix: true
|
|
1639
1611
|
})) {
|
|
1640
1612
|
if (path.node.operator === 'void') {
|
|
1641
1613
|
return undefined;
|
|
1642
1614
|
}
|
|
1643
1615
|
const argument = path.get('argument');
|
|
1644
|
-
if (path.node.operator === 'typeof' && (isFunction(
|
|
1616
|
+
if (path.node.operator === 'typeof' && (argument.isFunction() || argument.isClass())) {
|
|
1645
1617
|
return 'function';
|
|
1646
1618
|
}
|
|
1647
1619
|
const arg = evaluateCached(argument, state);
|
|
@@ -1663,7 +1635,7 @@ function _evaluate(path, state) {
|
|
|
1663
1635
|
return deopt(path, state, UNSUPPORTED_OPERATOR(path.node.operator));
|
|
1664
1636
|
}
|
|
1665
1637
|
}
|
|
1666
|
-
if (isArrayExpression(
|
|
1638
|
+
if (path.isArrayExpression()) {
|
|
1667
1639
|
const arrPath = path;
|
|
1668
1640
|
const arr = [];
|
|
1669
1641
|
const elems = arrPath.get('elements');
|
|
@@ -1678,14 +1650,14 @@ function _evaluate(path, state) {
|
|
|
1678
1650
|
}
|
|
1679
1651
|
return arr;
|
|
1680
1652
|
}
|
|
1681
|
-
if (isObjectExpression(
|
|
1653
|
+
if (path.isObjectExpression()) {
|
|
1682
1654
|
const obj = {};
|
|
1683
1655
|
const props = path.get('properties');
|
|
1684
1656
|
for (const prop of props) {
|
|
1685
|
-
if (isObjectMethod(
|
|
1657
|
+
if (prop.isObjectMethod()) {
|
|
1686
1658
|
return deopt(prop, state, OBJECT_METHOD);
|
|
1687
1659
|
}
|
|
1688
|
-
if (isSpreadElement(
|
|
1660
|
+
if (prop.isSpreadElement()) {
|
|
1689
1661
|
const spreadExpression = evaluateCached(prop.get('argument'), state);
|
|
1690
1662
|
if (!state.confident) {
|
|
1691
1663
|
return deopt(prop, state, state.deoptReason ?? 'unknown error');
|
|
@@ -1693,7 +1665,7 @@ function _evaluate(path, state) {
|
|
|
1693
1665
|
Object.assign(obj, spreadExpression);
|
|
1694
1666
|
continue;
|
|
1695
1667
|
}
|
|
1696
|
-
if (isObjectProperty(
|
|
1668
|
+
if (prop.isObjectProperty()) {
|
|
1697
1669
|
const keyPath = prop.get('key');
|
|
1698
1670
|
let key;
|
|
1699
1671
|
if (prop.node.computed) {
|
|
@@ -1708,7 +1680,7 @@ function _evaluate(path, state) {
|
|
|
1708
1680
|
return;
|
|
1709
1681
|
}
|
|
1710
1682
|
key = value;
|
|
1711
|
-
} else if (isIdentifier(
|
|
1683
|
+
} else if (keyPath.isIdentifier()) {
|
|
1712
1684
|
key = keyPath.node.name;
|
|
1713
1685
|
} else {
|
|
1714
1686
|
key = keyPath.node.value;
|
|
@@ -1725,7 +1697,7 @@ function _evaluate(path, state) {
|
|
|
1725
1697
|
}
|
|
1726
1698
|
return obj;
|
|
1727
1699
|
}
|
|
1728
|
-
if (isLogicalExpression(
|
|
1700
|
+
if (path.isLogicalExpression()) {
|
|
1729
1701
|
const stateForLeft = {
|
|
1730
1702
|
...state,
|
|
1731
1703
|
deoptPath: null,
|
|
@@ -1795,7 +1767,7 @@ function _evaluate(path, state) {
|
|
|
1795
1767
|
path.node.operator;
|
|
1796
1768
|
}
|
|
1797
1769
|
}
|
|
1798
|
-
if (isBinaryExpression(
|
|
1770
|
+
if (path.isBinaryExpression()) {
|
|
1799
1771
|
const left = evaluateCached(path.get('left'), state);
|
|
1800
1772
|
if (!state.confident) return;
|
|
1801
1773
|
const right = evaluateCached(path.get('right'), state);
|
|
@@ -1849,15 +1821,15 @@ function _evaluate(path, state) {
|
|
|
1849
1821
|
return;
|
|
1850
1822
|
}
|
|
1851
1823
|
}
|
|
1852
|
-
if (isCallExpression(
|
|
1824
|
+
if (path.isCallExpression()) {
|
|
1853
1825
|
const callee = path.get('callee');
|
|
1854
1826
|
let context;
|
|
1855
1827
|
let func;
|
|
1856
|
-
if (isIdentifier(
|
|
1828
|
+
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && isValidCallee(callee.node.name)) {
|
|
1857
1829
|
func = global[callee.node.name];
|
|
1858
|
-
} else if (isIdentifier(
|
|
1830
|
+
} else if (callee.isIdentifier() && state.functions.identifiers[callee.node.name]) {
|
|
1859
1831
|
func = state.functions.identifiers[callee.node.name];
|
|
1860
|
-
} else if (isIdentifier(
|
|
1832
|
+
} else if (callee.isIdentifier()) {
|
|
1861
1833
|
const maybeFunction = evaluateCached(callee, state);
|
|
1862
1834
|
if (state.confident) {
|
|
1863
1835
|
func = maybeFunction;
|
|
@@ -1865,10 +1837,10 @@ function _evaluate(path, state) {
|
|
|
1865
1837
|
deopt(callee, state, NON_CONSTANT);
|
|
1866
1838
|
}
|
|
1867
1839
|
}
|
|
1868
|
-
if (isMemberExpression(
|
|
1840
|
+
if (callee.isMemberExpression()) {
|
|
1869
1841
|
const object = callee.get('object');
|
|
1870
1842
|
const property = callee.get('property');
|
|
1871
|
-
if (isIdentifier(
|
|
1843
|
+
if (object.isIdentifier() && property.isIdentifier()) {
|
|
1872
1844
|
if (isValidCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
|
1873
1845
|
context = global[object.node.name];
|
|
1874
1846
|
func = context[property.node.name];
|
|
@@ -1877,11 +1849,11 @@ function _evaluate(path, state) {
|
|
|
1877
1849
|
func = context[property.node.name];
|
|
1878
1850
|
}
|
|
1879
1851
|
}
|
|
1880
|
-
if (isIdentifier(
|
|
1852
|
+
if (object.isIdentifier() && property.isStringLiteral() && state.functions.memberExpressions[object.node.name] && state.functions.memberExpressions[object.node.name][property.node.value]) {
|
|
1881
1853
|
context = state.functions.memberExpressions[object.node.name];
|
|
1882
1854
|
func = context[property.node.value];
|
|
1883
1855
|
}
|
|
1884
|
-
if ((isStringLiteral(
|
|
1856
|
+
if ((object.isStringLiteral() || object.isNumericLiteral()) && property.isIdentifier()) {
|
|
1885
1857
|
const val = object.node.value;
|
|
1886
1858
|
func = val[property.node.name];
|
|
1887
1859
|
if (typeof val === 'string') {
|
|
@@ -1890,11 +1862,11 @@ function _evaluate(path, state) {
|
|
|
1890
1862
|
}
|
|
1891
1863
|
if (func == null) {
|
|
1892
1864
|
const parsedObj = evaluate(object, state.traversalState, state.functions);
|
|
1893
|
-
if (parsedObj.confident && isIdentifier(
|
|
1865
|
+
if (parsedObj.confident && property.isIdentifier()) {
|
|
1894
1866
|
func = parsedObj.value[property.node.name];
|
|
1895
1867
|
context = parsedObj.value;
|
|
1896
1868
|
}
|
|
1897
|
-
if (parsedObj.confident && isStringLiteral(
|
|
1869
|
+
if (parsedObj.confident && property.isStringLiteral()) {
|
|
1898
1870
|
func = parsedObj.value[property.node.value];
|
|
1899
1871
|
context = parsedObj.value;
|
|
1900
1872
|
}
|
|
@@ -1921,7 +1893,7 @@ function evaluateQuasis(path, quasis, state) {
|
|
|
1921
1893
|
let raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1922
1894
|
let str = '';
|
|
1923
1895
|
let i = 0;
|
|
1924
|
-
const exprs = isTemplateLiteral(
|
|
1896
|
+
const exprs = path.isTemplateLiteral() ? path.get('expressions') : path.isTaggedTemplateExpression() ? path.get('quasi').get('expressions') : [];
|
|
1925
1897
|
for (const elem of quasis) {
|
|
1926
1898
|
if (!state.confident) break;
|
|
1927
1899
|
str += raw ? elem.value.raw : elem.value.cooked;
|
|
@@ -2794,7 +2766,7 @@ function requireMessages () {
|
|
|
2794
2766
|
Object.defineProperty(messages, "__esModule", {
|
|
2795
2767
|
value: true
|
|
2796
2768
|
});
|
|
2797
|
-
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;
|
|
2798
2770
|
messages.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
|
|
2799
2771
|
messages.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
|
|
2800
2772
|
messages.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
|
|
@@ -2821,7 +2793,6 @@ function requireMessages () {
|
|
|
2821
2793
|
messages.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
|
|
2822
2794
|
messages.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
|
|
2823
2795
|
messages.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
|
|
2824
|
-
messages.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
|
|
2825
2796
|
messages.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
|
|
2826
2797
|
messages.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
|
|
2827
2798
|
messages.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
|
|
@@ -3004,13 +2975,13 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3004
2975
|
identifiers: {},
|
|
3005
2976
|
memberExpressions: {}
|
|
3006
2977
|
};
|
|
3007
|
-
if (!isObjectExpression(
|
|
2978
|
+
if (!path.isObjectExpression()) {
|
|
3008
2979
|
return evaluate(path, traversalState, functions);
|
|
3009
2980
|
}
|
|
3010
2981
|
const value = {};
|
|
3011
2982
|
const fns = {};
|
|
3012
2983
|
for (const prop of path.get('properties')) {
|
|
3013
|
-
if (!isObjectProperty(
|
|
2984
|
+
if (!prop.isObjectProperty()) {
|
|
3014
2985
|
return evaluate(path, traversalState, functions);
|
|
3015
2986
|
}
|
|
3016
2987
|
const objPropPath = prop;
|
|
@@ -3024,7 +2995,7 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3024
2995
|
}
|
|
3025
2996
|
const key = keyResult.value;
|
|
3026
2997
|
const valPath = prop.get('value');
|
|
3027
|
-
if (!isArrowFunctionExpression(
|
|
2998
|
+
if (!valPath.isArrowFunctionExpression()) {
|
|
3028
2999
|
const val = evaluate(valPath, traversalState, functions);
|
|
3029
3000
|
if (!val.confident) {
|
|
3030
3001
|
return val;
|
|
@@ -3035,9 +3006,9 @@ function evaluateStyleXCreateArg(path, traversalState) {
|
|
|
3035
3006
|
const fnPath = valPath;
|
|
3036
3007
|
const allParams = fnPath.get('params');
|
|
3037
3008
|
validateDynamicStyleParams(fnPath, allParams);
|
|
3038
|
-
const params = allParams.filter(param => isIdentifier(
|
|
3009
|
+
const params = allParams.filter(param => param.isIdentifier()).map(param => param.node);
|
|
3039
3010
|
const fnBody = fnPath.get('body');
|
|
3040
|
-
if (!isObjectExpression(
|
|
3011
|
+
if (!fnBody.isObjectExpression()) {
|
|
3041
3012
|
return evaluate(path, traversalState, functions);
|
|
3042
3013
|
}
|
|
3043
3014
|
const fnObjectBody = fnBody;
|
|
@@ -3077,13 +3048,13 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3077
3048
|
const inlineStyles = {};
|
|
3078
3049
|
const props = path.get('properties');
|
|
3079
3050
|
for (const prop of props) {
|
|
3080
|
-
if (isObjectMethod(
|
|
3051
|
+
if (prop.isObjectMethod()) {
|
|
3081
3052
|
return {
|
|
3082
3053
|
value: null,
|
|
3083
3054
|
confident: false
|
|
3084
3055
|
};
|
|
3085
3056
|
}
|
|
3086
|
-
if (isSpreadElement(
|
|
3057
|
+
if (prop.isSpreadElement()) {
|
|
3087
3058
|
const result = evaluate(prop.get('argument'), traversalState, functions);
|
|
3088
3059
|
if (!result.confident) {
|
|
3089
3060
|
return result;
|
|
@@ -3091,7 +3062,7 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3091
3062
|
Object.assign(obj, result.value);
|
|
3092
3063
|
continue;
|
|
3093
3064
|
}
|
|
3094
|
-
if (isObjectProperty(
|
|
3065
|
+
if (prop.isObjectProperty()) {
|
|
3095
3066
|
const keyResult = evaluateObjKey(prop, traversalState, functions);
|
|
3096
3067
|
if (!keyResult.confident) {
|
|
3097
3068
|
return {
|
|
@@ -3105,7 +3076,7 @@ function evaluatePartialObjectRecursively(path, traversalState) {
|
|
|
3105
3076
|
key = key.slice(4, -1);
|
|
3106
3077
|
}
|
|
3107
3078
|
const valuePath = prop.get('value');
|
|
3108
|
-
if (isObjectExpression(
|
|
3079
|
+
if (valuePath.isObjectExpression()) {
|
|
3109
3080
|
const result = evaluatePartialObjectRecursively(valuePath, traversalState, functions, [...keyPath, key]);
|
|
3110
3081
|
if (!result.confident) {
|
|
3111
3082
|
return {
|
|
@@ -3159,7 +3130,7 @@ function evaluateObjKey(prop, traversalState, functions) {
|
|
|
3159
3130
|
};
|
|
3160
3131
|
}
|
|
3161
3132
|
key = result.value;
|
|
3162
|
-
} else if (isIdentifier(
|
|
3133
|
+
} else if (keyPath.isIdentifier()) {
|
|
3163
3134
|
key = keyPath.node.name;
|
|
3164
3135
|
} else {
|
|
3165
3136
|
key = keyPath.node.value;
|
|
@@ -3170,7 +3141,7 @@ function evaluateObjKey(prop, traversalState, functions) {
|
|
|
3170
3141
|
};
|
|
3171
3142
|
}
|
|
3172
3143
|
function validateDynamicStyleParams(path, params) {
|
|
3173
|
-
if (params.some(param => !isIdentifier(
|
|
3144
|
+
if (params.some(param => !param.isIdentifier())) {
|
|
3174
3145
|
throw path.buildCodeFrameError(shared.messages.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS, SyntaxError);
|
|
3175
3146
|
}
|
|
3176
3147
|
}
|
|
@@ -3749,12 +3720,6 @@ function transformStyleXCreate(path, state) {
|
|
|
3749
3720
|
}
|
|
3750
3721
|
const identifiers = {};
|
|
3751
3722
|
const memberExpressions = {};
|
|
3752
|
-
state.stylexIncludeImport.forEach(name => {
|
|
3753
|
-
identifiers[name] = {
|
|
3754
|
-
fn: shared.include,
|
|
3755
|
-
takesPath: true
|
|
3756
|
-
};
|
|
3757
|
-
});
|
|
3758
3723
|
state.stylexFirstThatWorksImport.forEach(name => {
|
|
3759
3724
|
identifiers[name] = {
|
|
3760
3725
|
fn: shared.firstThatWorks
|
|
@@ -3769,10 +3734,6 @@ function transformStyleXCreate(path, state) {
|
|
|
3769
3734
|
if (memberExpressions[name] == null) {
|
|
3770
3735
|
memberExpressions[name] = {};
|
|
3771
3736
|
}
|
|
3772
|
-
memberExpressions[name].include = {
|
|
3773
|
-
fn: shared.include,
|
|
3774
|
-
takesPath: true
|
|
3775
|
-
};
|
|
3776
3737
|
memberExpressions[name].firstThatWorks = {
|
|
3777
3738
|
fn: shared.firstThatWorks
|
|
3778
3739
|
};
|
|
@@ -3800,7 +3761,7 @@ function transformStyleXCreate(path, state) {
|
|
|
3800
3761
|
dynamicFnsNames.forEach(fnsName => {
|
|
3801
3762
|
injectedInheritStyles[fnsName] = {
|
|
3802
3763
|
priority: 0,
|
|
3803
|
-
ltr: `@property ${fnsName} { syntax: "*"; inherits: false;
|
|
3764
|
+
ltr: `@property ${fnsName} { syntax: "*"; inherits: false;}`,
|
|
3804
3765
|
rtl: null
|
|
3805
3766
|
};
|
|
3806
3767
|
});
|
|
@@ -3812,21 +3773,27 @@ function transformStyleXCreate(path, state) {
|
|
|
3812
3773
|
...injectedInheritStyles
|
|
3813
3774
|
};
|
|
3814
3775
|
let varName = null;
|
|
3815
|
-
if (
|
|
3776
|
+
if (path.parentPath.isVariableDeclarator()) {
|
|
3816
3777
|
const idNode = path.parentPath.node.id;
|
|
3817
3778
|
if (idNode.type === 'Identifier') {
|
|
3818
3779
|
varName = idNode.name;
|
|
3819
3780
|
}
|
|
3820
3781
|
}
|
|
3821
|
-
if (state.
|
|
3782
|
+
if (state.isDebug && state.opts.enableDebugDataProp) {
|
|
3822
3783
|
compiledStyles = {
|
|
3823
|
-
...
|
|
3784
|
+
...addSourceMapData(compiledStyles, path, state)
|
|
3824
3785
|
};
|
|
3825
|
-
}
|
|
3786
|
+
}
|
|
3787
|
+
if (state.isDev && state.opts.enableDevClassNames) {
|
|
3826
3788
|
compiledStyles = {
|
|
3827
3789
|
...injectDevClassNames(compiledStyles, varName, state)
|
|
3828
3790
|
};
|
|
3829
3791
|
}
|
|
3792
|
+
if (state.isTest) {
|
|
3793
|
+
compiledStyles = {
|
|
3794
|
+
...convertToTestStyles(compiledStyles, varName, state)
|
|
3795
|
+
};
|
|
3796
|
+
}
|
|
3830
3797
|
if (varName != null) {
|
|
3831
3798
|
const stylesToRemember = removeObjectsWithSpreads(compiledStyles);
|
|
3832
3799
|
state.styleMap.set(varName, stylesToRemember);
|
|
@@ -3939,11 +3906,11 @@ function transformStyleXCreate(path, state) {
|
|
|
3939
3906
|
state.inStyleXCreate = false;
|
|
3940
3907
|
}
|
|
3941
3908
|
function validateStyleXCreate(path) {
|
|
3942
|
-
if (path.parentPath == null ||
|
|
3909
|
+
if (path.parentPath == null || path.parentPath.isExpressionStatement()) {
|
|
3943
3910
|
throw path.buildCodeFrameError(shared.messages.UNBOUND_STYLEX_CALL_VALUE, SyntaxError);
|
|
3944
3911
|
}
|
|
3945
3912
|
const nearestStatement = findNearestStatementAncestor(path);
|
|
3946
|
-
if (!
|
|
3913
|
+
if (!nearestStatement.parentPath.isProgram() && !nearestStatement.parentPath.isExportNamedDeclaration()) {
|
|
3947
3914
|
throw path.buildCodeFrameError(shared.messages.ONLY_TOP_LEVEL, SyntaxError);
|
|
3948
3915
|
}
|
|
3949
3916
|
if (path.node.arguments.length !== 1) {
|
|
@@ -3954,7 +3921,7 @@ function validateStyleXCreate(path) {
|
|
|
3954
3921
|
}
|
|
3955
3922
|
}
|
|
3956
3923
|
function findNearestStatementAncestor(path) {
|
|
3957
|
-
if (isStatement(
|
|
3924
|
+
if (path.isStatement()) {
|
|
3958
3925
|
return path;
|
|
3959
3926
|
}
|
|
3960
3927
|
if (path.parentPath == null) {
|
|
@@ -3994,7 +3961,7 @@ function transformStyleXDefineVars(callExpressionPath, state) {
|
|
|
3994
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)) {
|
|
3995
3962
|
validateStyleXDefineVars(callExpressionPath);
|
|
3996
3963
|
const variableDeclaratorPath = callExpressionPath.parentPath;
|
|
3997
|
-
if (!isVariableDeclarator(
|
|
3964
|
+
if (!variableDeclaratorPath.isVariableDeclarator()) {
|
|
3998
3965
|
return;
|
|
3999
3966
|
}
|
|
4000
3967
|
const variableDeclaratorNode = variableDeclaratorPath.node;
|
|
@@ -4094,11 +4061,11 @@ function transformStyleXCreateTheme(callExpressionPath, state) {
|
|
|
4094
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)) {
|
|
4095
4062
|
validateStyleXCreateTheme(callExpressionPath);
|
|
4096
4063
|
const variableDeclaratorPath = callExpressionPath.parentPath;
|
|
4097
|
-
if (!isVariableDeclarator(
|
|
4064
|
+
if (!variableDeclaratorPath.isVariableDeclarator()) {
|
|
4098
4065
|
return;
|
|
4099
4066
|
}
|
|
4100
4067
|
const id = variableDeclaratorPath.get('id');
|
|
4101
|
-
if (!isIdentifier(
|
|
4068
|
+
if (!id.isIdentifier()) {
|
|
4102
4069
|
return;
|
|
4103
4070
|
}
|
|
4104
4071
|
const variableName = id.node.name;
|
|
@@ -4217,7 +4184,7 @@ function transformStyleXKeyframes(path, state) {
|
|
|
4217
4184
|
throw path.buildCodeFrameError(shared.messages.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL, SyntaxError);
|
|
4218
4185
|
}
|
|
4219
4186
|
const init = path.get('init');
|
|
4220
|
-
if (init == null || !isCallExpression(
|
|
4187
|
+
if (init == null || !init.isCallExpression()) {
|
|
4221
4188
|
throw path.buildCodeFrameError(shared.messages.NON_STATIC_KEYFRAME_VALUE, SyntaxError);
|
|
4222
4189
|
}
|
|
4223
4190
|
const args = init.get('arguments');
|
|
@@ -4409,7 +4376,7 @@ function transformStyleXMerge(path, state) {
|
|
|
4409
4376
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4410
4377
|
}
|
|
4411
4378
|
}
|
|
4412
|
-
if (isMemberExpression(
|
|
4379
|
+
if (argPath.isMemberExpression()) {
|
|
4413
4380
|
MemberExpression(argPath);
|
|
4414
4381
|
} else {
|
|
4415
4382
|
argPath.traverse({
|
|
@@ -4455,7 +4422,7 @@ function parseNullableStyle$2(node, state) {
|
|
|
4455
4422
|
function makeStringExpression$2(values) {
|
|
4456
4423
|
const conditions = values.filter(v => Array.isArray(v)).map(v => v[0]);
|
|
4457
4424
|
if (conditions.length === 0) {
|
|
4458
|
-
return t__namespace.stringLiteral(stylex(...values));
|
|
4425
|
+
return t__namespace.stringLiteral(stylex.legacyMerge(...values));
|
|
4459
4426
|
}
|
|
4460
4427
|
const conditionPermutations = genConditionPermutations$2(conditions.length);
|
|
4461
4428
|
const objEntries = conditionPermutations.map(permutation => {
|
|
@@ -4469,7 +4436,7 @@ function makeStringExpression$2(values) {
|
|
|
4469
4436
|
}
|
|
4470
4437
|
});
|
|
4471
4438
|
const key = permutation.reduce((soFar, bool) => soFar << 1 | (bool ? 1 : 0), 0);
|
|
4472
|
-
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)));
|
|
4473
4440
|
});
|
|
4474
4441
|
const objExpressions = t__namespace.objectExpression(objEntries);
|
|
4475
4442
|
const conditionsToKey = genBitwiseOrOfConditions$2(conditions);
|
|
@@ -4631,7 +4598,7 @@ function transformStylexProps(path, state) {
|
|
|
4631
4598
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4632
4599
|
}
|
|
4633
4600
|
}
|
|
4634
|
-
if (isMemberExpression(
|
|
4601
|
+
if (argPath.isMemberExpression()) {
|
|
4635
4602
|
MemberExpression(argPath);
|
|
4636
4603
|
} else {
|
|
4637
4604
|
argPath.traverse({
|
|
@@ -4866,7 +4833,7 @@ function transformStylexAttrs(path, state) {
|
|
|
4866
4833
|
state.styleVarsToKeep.add([objName, propName != null ? String(propName) : true, styleNonNullProps]);
|
|
4867
4834
|
}
|
|
4868
4835
|
}
|
|
4869
|
-
if (isMemberExpression(
|
|
4836
|
+
if (argPath.isMemberExpression()) {
|
|
4870
4837
|
MemberExpression(argPath);
|
|
4871
4838
|
} else {
|
|
4872
4839
|
argPath.traverse({
|
|
@@ -4976,10 +4943,10 @@ function styleXTransform() {
|
|
|
4976
4943
|
enter: (path, s) => {
|
|
4977
4944
|
state = new StateManager(s);
|
|
4978
4945
|
for (const block of path.get('body')) {
|
|
4979
|
-
if (isImportDeclaration(
|
|
4946
|
+
if (block.isImportDeclaration()) {
|
|
4980
4947
|
readImportDeclarations(block, state);
|
|
4981
4948
|
}
|
|
4982
|
-
if (isVariableDeclaration(
|
|
4949
|
+
if (block.isVariableDeclaration()) {
|
|
4983
4950
|
for (const decl of block.get('declarations')) {
|
|
4984
4951
|
readRequires(decl, state);
|
|
4985
4952
|
}
|
|
@@ -4988,14 +4955,36 @@ function styleXTransform() {
|
|
|
4988
4955
|
},
|
|
4989
4956
|
exit: path => {
|
|
4990
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
|
+
},
|
|
4991
4980
|
Identifier(path) {
|
|
4992
|
-
if (isReferencedIdentifier(
|
|
4981
|
+
if (path.isReferencedIdentifier()) {
|
|
4993
4982
|
const {
|
|
4994
4983
|
name
|
|
4995
4984
|
} = path.node;
|
|
4996
4985
|
if (state.styleMap.has(name)) {
|
|
4997
4986
|
const parentPath = path.parentPath;
|
|
4998
|
-
if (isMemberExpression(
|
|
4987
|
+
if (parentPath.isMemberExpression()) {
|
|
4999
4988
|
const {
|
|
5000
4989
|
property,
|
|
5001
4990
|
computed
|
|
@@ -5059,11 +5048,11 @@ function styleXTransform() {
|
|
|
5059
5048
|
path.remove();
|
|
5060
5049
|
return;
|
|
5061
5050
|
}
|
|
5062
|
-
if (isVariableDeclarator(
|
|
5051
|
+
if (path.isVariableDeclarator()) {
|
|
5063
5052
|
const init = path.get('init');
|
|
5064
|
-
if (init != null && isObjectExpression(
|
|
5053
|
+
if (init != null && init.isObjectExpression()) {
|
|
5065
5054
|
for (const prop of init.get('properties')) {
|
|
5066
|
-
if (isObjectProperty(
|
|
5055
|
+
if (prop.isObjectProperty()) {
|
|
5067
5056
|
const key = prop.get('key').node;
|
|
5068
5057
|
const keyAsString = key.type === 'Identifier' ? key.name : key.type === 'StringLiteral' ? key.value : key.type === 'NumericLiteral' ? String(key.value) : null;
|
|
5069
5058
|
if (keyAsString != null) {
|
|
@@ -5080,9 +5069,9 @@ function styleXTransform() {
|
|
|
5080
5069
|
if (!allNullsToKeep.includes(true)) {
|
|
5081
5070
|
const nullsToKeep = new Set(allNullsToKeep.filter(x => x !== true).flat());
|
|
5082
5071
|
const styleObject = prop.get('value');
|
|
5083
|
-
if (isObjectExpression(
|
|
5072
|
+
if (styleObject.isObjectExpression()) {
|
|
5084
5073
|
for (const styleProp of styleObject.get('properties')) {
|
|
5085
|
-
if (isObjectProperty(
|
|
5074
|
+
if (styleProp.isObjectProperty() && styleProp.get('value').isNullLiteral()) {
|
|
5086
5075
|
const styleKey = styleProp.get('key').node;
|
|
5087
5076
|
const styleKeyAsString = styleKey.type === 'Identifier' ? styleKey.name : styleKey.type === 'StringLiteral' ? styleKey.value : styleKey.type === 'NumericLiteral' ? String(styleKey.value) : null;
|
|
5088
5077
|
if (styleKeyAsString != null && !nullsToKeep.has(styleKeyAsString)) {
|
|
@@ -5105,7 +5094,7 @@ function styleXTransform() {
|
|
|
5105
5094
|
}
|
|
5106
5095
|
},
|
|
5107
5096
|
CallExpression(path) {
|
|
5108
|
-
if (
|
|
5097
|
+
if (path.parentPath.isVariableDeclarator()) {
|
|
5109
5098
|
transformStyleXKeyframes(path.parentPath, state);
|
|
5110
5099
|
}
|
|
5111
5100
|
transformStyleXDefineVars(path, state);
|
|
@@ -5120,10 +5109,10 @@ function stylexPluginWithOptions(options) {
|
|
|
5120
5109
|
}
|
|
5121
5110
|
styleXTransform.withOptions = stylexPluginWithOptions;
|
|
5122
5111
|
function isExported(path) {
|
|
5123
|
-
if (path == null || isProgram(
|
|
5112
|
+
if (path == null || path.isProgram()) {
|
|
5124
5113
|
return false;
|
|
5125
5114
|
}
|
|
5126
|
-
if (isExportNamedDeclaration(
|
|
5115
|
+
if (path.isExportNamedDeclaration() || path.isExportDefaultDeclaration()) {
|
|
5127
5116
|
return true;
|
|
5128
5117
|
}
|
|
5129
5118
|
return isExported(path.parentPath);
|