@fairfox/polly 0.3.1 → 0.3.2
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.
|
@@ -1619,10 +1619,15 @@ class HandlerExtractor {
|
|
|
1619
1619
|
if (Node4.isIdentifier(funcExpr)) {
|
|
1620
1620
|
funcName = funcExpr.getText();
|
|
1621
1621
|
}
|
|
1622
|
-
|
|
1622
|
+
let messageType = undefined;
|
|
1623
|
+
if (funcName && typeGuards.has(funcName)) {
|
|
1624
|
+
messageType = typeGuards.get(funcName);
|
|
1625
|
+
} else if (Node4.isIdentifier(funcExpr)) {
|
|
1626
|
+
messageType = this.resolveImportedTypeGuard(funcExpr);
|
|
1627
|
+
}
|
|
1628
|
+
if (!messageType) {
|
|
1623
1629
|
return null;
|
|
1624
1630
|
}
|
|
1625
|
-
const messageType = typeGuards.get(funcName);
|
|
1626
1631
|
const line = ifNode.getStartLineNumber();
|
|
1627
1632
|
return {
|
|
1628
1633
|
messageType,
|
|
@@ -1683,6 +1688,33 @@ class HandlerExtractor {
|
|
|
1683
1688
|
});
|
|
1684
1689
|
return typeGuards;
|
|
1685
1690
|
}
|
|
1691
|
+
resolveImportedTypeGuard(identifier) {
|
|
1692
|
+
try {
|
|
1693
|
+
const definitions = identifier.getDefinitionNodes();
|
|
1694
|
+
for (const def of definitions) {
|
|
1695
|
+
if (Node4.isFunctionDeclaration(def) || Node4.isFunctionExpression(def) || Node4.isArrowFunction(def)) {
|
|
1696
|
+
const returnType = def.getReturnType();
|
|
1697
|
+
const returnTypeText = returnType.getText();
|
|
1698
|
+
if (/is\s+\w+/.test(returnTypeText)) {
|
|
1699
|
+
const typeMatch = returnTypeText.match(/is\s+(\w+)/);
|
|
1700
|
+
if (typeMatch) {
|
|
1701
|
+
const typeName = typeMatch[1];
|
|
1702
|
+
return this.extractMessageTypeFromTypeName(typeName);
|
|
1703
|
+
}
|
|
1704
|
+
const body = def.getBody();
|
|
1705
|
+
if (body) {
|
|
1706
|
+
const bodyText = body.getText();
|
|
1707
|
+
const typeValueMatch = bodyText.match(/\.type\s*===?\s*['"](\w+)['"]/);
|
|
1708
|
+
if (typeValueMatch) {
|
|
1709
|
+
return typeValueMatch[1];
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
} catch (error) {}
|
|
1716
|
+
return null;
|
|
1717
|
+
}
|
|
1686
1718
|
extractMessageTypeFromTypeName(typeName) {
|
|
1687
1719
|
const messageType = typeName.replace(/Message$/, "").replace(/Event$/, "").replace(/Request$/, "").replace(/Command$/, "").replace(/Query$/, "").toLowerCase();
|
|
1688
1720
|
return messageType;
|
|
@@ -2909,4 +2941,4 @@ Stack trace:`, COLORS.gray));
|
|
|
2909
2941
|
process.exit(1);
|
|
2910
2942
|
});
|
|
2911
2943
|
|
|
2912
|
-
//# debugId=
|
|
2944
|
+
//# debugId=0C75E6084607493864756E2164756E21
|