@fairfox/polly 0.3.4 → 0.3.8
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.
|
@@ -1321,11 +1321,7 @@ class HandlerExtractor {
|
|
|
1321
1321
|
typeGuardCache;
|
|
1322
1322
|
constructor(tsConfigPath) {
|
|
1323
1323
|
this.project = new Project4({
|
|
1324
|
-
tsConfigFilePath: tsConfigPath
|
|
1325
|
-
compilerOptions: {
|
|
1326
|
-
allowImportingTsExtensions: true,
|
|
1327
|
-
moduleResolution: 99
|
|
1328
|
-
}
|
|
1324
|
+
tsConfigFilePath: tsConfigPath
|
|
1329
1325
|
});
|
|
1330
1326
|
this.typeGuardCache = new WeakMap;
|
|
1331
1327
|
}
|
|
@@ -1382,8 +1378,12 @@ class HandlerExtractor {
|
|
|
1382
1378
|
handlers.push(...mapHandlers);
|
|
1383
1379
|
}
|
|
1384
1380
|
if (Node4.isIfStatement(node)) {
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1381
|
+
const parent = node.getParent();
|
|
1382
|
+
const isElseIf = parent && Node4.isIfStatement(parent);
|
|
1383
|
+
if (!isElseIf) {
|
|
1384
|
+
const typeGuardHandlers = this.extractTypeGuardHandlers(node, context, filePath);
|
|
1385
|
+
handlers.push(...typeGuardHandlers);
|
|
1386
|
+
}
|
|
1387
1387
|
}
|
|
1388
1388
|
});
|
|
1389
1389
|
return handlers;
|
|
@@ -1685,9 +1685,8 @@ class HandlerExtractor {
|
|
|
1685
1685
|
const typeGuards = new Map;
|
|
1686
1686
|
sourceFile.forEachDescendant((node) => {
|
|
1687
1687
|
if (Node4.isFunctionDeclaration(node) || Node4.isFunctionExpression(node) || Node4.isArrowFunction(node)) {
|
|
1688
|
-
const
|
|
1689
|
-
|
|
1690
|
-
if (/is\s+\w+/.test(returnTypeText)) {
|
|
1688
|
+
const returnTypeNode = node.getReturnTypeNode();
|
|
1689
|
+
if (returnTypeNode && Node4.isTypePredicate(returnTypeNode)) {
|
|
1691
1690
|
let functionName;
|
|
1692
1691
|
if (Node4.isFunctionDeclaration(node)) {
|
|
1693
1692
|
functionName = node.getName();
|
|
@@ -1703,10 +1702,10 @@ class HandlerExtractor {
|
|
|
1703
1702
|
}
|
|
1704
1703
|
}
|
|
1705
1704
|
if (functionName) {
|
|
1705
|
+
const typeNode = returnTypeNode.getTypeNode();
|
|
1706
1706
|
let messageType = null;
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
const typeName = typeMatch[1];
|
|
1707
|
+
if (typeNode) {
|
|
1708
|
+
const typeName = typeNode.getText();
|
|
1710
1709
|
messageType = this.extractMessageTypeFromTypeName(typeName);
|
|
1711
1710
|
}
|
|
1712
1711
|
if (!messageType) {
|
|
@@ -1740,34 +1739,38 @@ class HandlerExtractor {
|
|
|
1740
1739
|
}
|
|
1741
1740
|
for (const def of definitions) {
|
|
1742
1741
|
if (Node4.isFunctionDeclaration(def) || Node4.isFunctionExpression(def) || Node4.isArrowFunction(def)) {
|
|
1743
|
-
const
|
|
1744
|
-
const returnTypeText = returnType.getText();
|
|
1742
|
+
const returnTypeNode = def.getReturnTypeNode();
|
|
1745
1743
|
if (process.env.POLLY_DEBUG) {
|
|
1746
|
-
|
|
1744
|
+
const returnType = def.getReturnType().getText();
|
|
1745
|
+
console.log(`[DEBUG] Function ${funcName} return type (resolved): ${returnType}`);
|
|
1746
|
+
console.log(`[DEBUG] Has return type node: ${!!returnTypeNode}`);
|
|
1747
|
+
console.log(`[DEBUG] Is type predicate node: ${returnTypeNode && Node4.isTypePredicate(returnTypeNode)}`);
|
|
1747
1748
|
}
|
|
1748
|
-
if (
|
|
1749
|
-
const
|
|
1750
|
-
if (
|
|
1751
|
-
const typeName =
|
|
1749
|
+
if (returnTypeNode && Node4.isTypePredicate(returnTypeNode)) {
|
|
1750
|
+
const typeNode = returnTypeNode.getTypeNode();
|
|
1751
|
+
if (typeNode) {
|
|
1752
|
+
const typeName = typeNode.getText();
|
|
1752
1753
|
const messageType = this.extractMessageTypeFromTypeName(typeName);
|
|
1753
|
-
if (
|
|
1754
|
-
console.log(`[DEBUG] Resolved ${funcName} → ${messageType}`);
|
|
1755
|
-
}
|
|
1756
|
-
return messageType;
|
|
1757
|
-
}
|
|
1758
|
-
const body = def.getBody();
|
|
1759
|
-
if (body) {
|
|
1760
|
-
const bodyText = body.getText();
|
|
1761
|
-
const typeValueMatch = bodyText.match(/\.type\s*===?\s*['"](\w+)['"]/);
|
|
1762
|
-
if (typeValueMatch) {
|
|
1763
|
-
const messageType = typeValueMatch[1];
|
|
1754
|
+
if (messageType) {
|
|
1764
1755
|
if (process.env.POLLY_DEBUG) {
|
|
1765
|
-
console.log(`[DEBUG] Resolved ${funcName} → ${messageType} (from
|
|
1756
|
+
console.log(`[DEBUG] Resolved ${funcName} → ${messageType} (from AST type predicate)`);
|
|
1766
1757
|
}
|
|
1767
1758
|
return messageType;
|
|
1768
1759
|
}
|
|
1769
1760
|
}
|
|
1770
1761
|
}
|
|
1762
|
+
const body = def.getBody();
|
|
1763
|
+
if (body) {
|
|
1764
|
+
const bodyText = body.getText();
|
|
1765
|
+
const typeValueMatch = bodyText.match(/\.type\s*===?\s*['"](\w+)['"]/);
|
|
1766
|
+
if (typeValueMatch) {
|
|
1767
|
+
const messageType = typeValueMatch[1];
|
|
1768
|
+
if (process.env.POLLY_DEBUG) {
|
|
1769
|
+
console.log(`[DEBUG] Resolved ${funcName} → ${messageType} (from body)`);
|
|
1770
|
+
}
|
|
1771
|
+
return messageType;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1771
1774
|
}
|
|
1772
1775
|
}
|
|
1773
1776
|
} catch (error) {
|
|
@@ -2768,10 +2771,11 @@ async function generateCommand() {
|
|
|
2768
2771
|
console.log(color(`
|
|
2769
2772
|
\uD83D\uDCDD Generating Structurizr DSL...
|
|
2770
2773
|
`, COLORS.blue));
|
|
2774
|
+
const contextTypes = Object.keys(analysis.contexts);
|
|
2771
2775
|
const dsl = generateStructurizrDSL(analysis, {
|
|
2772
2776
|
includeDynamicDiagrams: true,
|
|
2773
2777
|
includeComponentDiagrams: true,
|
|
2774
|
-
componentDiagramContexts: ["background"]
|
|
2778
|
+
componentDiagramContexts: contextTypes.length > 0 ? contextTypes : ["background"]
|
|
2775
2779
|
});
|
|
2776
2780
|
const outputDir = path6.join(process.cwd(), "docs");
|
|
2777
2781
|
if (!fs6.existsSync(outputDir)) {
|
|
@@ -3003,4 +3007,4 @@ Stack trace:`, COLORS.gray));
|
|
|
3003
3007
|
process.exit(1);
|
|
3004
3008
|
});
|
|
3005
3009
|
|
|
3006
|
-
//# debugId=
|
|
3010
|
+
//# debugId=78733C0D94700D7D64756E2164756E21
|