@embeddable.com/sdk-react 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +3 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +3 -28
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -685,7 +685,6 @@ const componentMetaSchema = zod.z
|
|
|
685
685
|
}
|
|
686
686
|
});
|
|
687
687
|
|
|
688
|
-
const getObjectProperty = (value) => value.object.name + "." + value.property.name;
|
|
689
688
|
// @ts-ignore
|
|
690
689
|
const babelTraverse = traverse.default;
|
|
691
690
|
const parseAndTraverse = (code, visitor) => {
|
|
@@ -713,14 +712,13 @@ const validateComponentProps = (metaInfo) => {
|
|
|
713
712
|
const errors = [];
|
|
714
713
|
parseAndTraverse(metaInfo.moduleInfo.code, {
|
|
715
714
|
ExportDefaultDeclaration: (path) => {
|
|
716
|
-
var _a
|
|
715
|
+
var _a;
|
|
717
716
|
const componentConfig = path.node.declaration
|
|
718
717
|
.arguments[2];
|
|
719
718
|
const propsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((x) => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.name) === "props"; });
|
|
720
719
|
// There is no props defined
|
|
721
720
|
if (!propsNode)
|
|
722
721
|
return;
|
|
723
|
-
let functionBody;
|
|
724
722
|
// if propsNode is a function defined elsewhere
|
|
725
723
|
if (propsNode.value.type === "Identifier") {
|
|
726
724
|
const functionName = propsNode.value.name;
|
|
@@ -731,38 +729,15 @@ const validateComponentProps = (metaInfo) => {
|
|
|
731
729
|
if (path.node.id.name === functionName &&
|
|
732
730
|
(path.node.init.type === "FunctionExpression" ||
|
|
733
731
|
path.node.init.type === "ArrowFunctionExpression")) {
|
|
734
|
-
|
|
732
|
+
path.node.init.body.body;
|
|
735
733
|
}
|
|
736
734
|
},
|
|
737
735
|
});
|
|
738
736
|
}
|
|
739
737
|
else {
|
|
740
738
|
// assume that propsNode is anonymous function
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
const propsReturnStatement = functionBody === null || functionBody === void 0 ? void 0 : functionBody.find((x) => x.type === "ReturnStatement");
|
|
744
|
-
const results = (_c = (_b = propsReturnStatement === null || propsReturnStatement === void 0 ? void 0 : propsReturnStatement.argument) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.find((x) => { var _a; return ((_a = x === null || x === void 0 ? void 0 : x.key) === null || _a === void 0 ? void 0 : _a.name) === "results"; });
|
|
745
|
-
// There is no results defined inside props
|
|
746
|
-
if (results === undefined) {
|
|
747
|
-
return;
|
|
739
|
+
propsNode.value.body.body;
|
|
748
740
|
}
|
|
749
|
-
const loadDataProperties = (_d = results === null || results === void 0 ? void 0 : results.value) === null || _d === void 0 ? void 0 : _d.arguments[0].properties;
|
|
750
|
-
const dimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "dimensions");
|
|
751
|
-
const timeDimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "timeDimensions");
|
|
752
|
-
// There is no missuse of dimensions and timeDimensions
|
|
753
|
-
if (!dimensions || !timeDimensions)
|
|
754
|
-
return;
|
|
755
|
-
const usedDimensions = dimensions.value.elements.map((x) => getObjectProperty(x));
|
|
756
|
-
const usedTimeDimensions = timeDimensions.value.elements
|
|
757
|
-
.map((x) => x.properties)
|
|
758
|
-
.flatMap((group) => group
|
|
759
|
-
.filter((property) => property.key.name === "dimension")
|
|
760
|
-
.map((property) => getObjectProperty(property.value.object)));
|
|
761
|
-
usedDimensions.forEach((dimension) => {
|
|
762
|
-
if (usedTimeDimensions.includes(dimension)) {
|
|
763
|
-
errors.push(`Dimension ${dimension} should not be requested as both a dimension and a timeDimension.`);
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
741
|
},
|
|
767
742
|
});
|
|
768
743
|
return errors;
|