react-docgen-typescript
Advanced tools
Comparing version
@@ -224,3 +224,3 @@ "use strict"; | ||
sampleJSDoc: { type: 'string', required: false, defaultValue: 'test' }, | ||
sampleProp: { type: 'string', required: false, defaultValue: 'hello' } | ||
sampleProp: { type: 'string', required: false, defaultValue: 'test' } | ||
} | ||
@@ -227,0 +227,0 @@ }); |
@@ -258,2 +258,9 @@ "use strict"; | ||
if (!possibleStatements.length) { | ||
// if no class declaration is found, try to find a | ||
// expression statement used in a React.StatelessComponent | ||
possibleStatements = source.statements.filter(function (stmt) { | ||
return ts.isExpressionStatement(stmt); | ||
}); | ||
} | ||
if (!possibleStatements.length) { | ||
return {}; | ||
@@ -270,15 +277,16 @@ } | ||
var properties = initializer.properties; | ||
var propMap = properties.reduce(function (acc, property) { | ||
var literalValue = getLiteralValueFromPropertyAssignment(property); | ||
var propertyName = getPropertyName(property.name); | ||
if (typeof literalValue === 'string' && propertyName !== null) { | ||
var value = getLiteralValueFromPropertyAssignment(property); | ||
if (value !== null) { | ||
acc[propertyName] = value; | ||
} | ||
} | ||
return acc; | ||
}, {}); | ||
var propMap = getPropMap(properties); | ||
return propMap; | ||
} | ||
else if (statementIsStateless(statement)) { | ||
var propMap_1 = {}; | ||
statement.getChildren().forEach(function (child) { | ||
var right = child.right; | ||
if (right) { | ||
var properties = right.properties; | ||
propMap_1 = getPropMap(properties); | ||
} | ||
}); | ||
return propMap_1; | ||
} | ||
return {}; | ||
@@ -291,2 +299,30 @@ }; | ||
} | ||
function statementIsStateless(statement) { | ||
var children = statement.getChildren(); | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
var left = child.left; | ||
if (left) { | ||
var name_1 = left.name; | ||
if (name_1.escapedText === 'defaultProps') { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
function getPropMap(properties) { | ||
var propMap = properties.reduce(function (acc, property) { | ||
var literalValue = getLiteralValueFromPropertyAssignment(property); | ||
var propertyName = getPropertyName(property.name); | ||
if (typeof literalValue === 'string' && propertyName !== null) { | ||
var value = getLiteralValueFromPropertyAssignment(property); | ||
if (value !== null) { | ||
acc[propertyName] = value; | ||
} | ||
} | ||
return acc; | ||
}, {}); | ||
return propMap; | ||
} | ||
function getPropertyName(name) { | ||
@@ -293,0 +329,0 @@ switch (name.kind) { |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "1.2.6", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -133,2 +133,6 @@ # react-docgen-typescript | ||
**@asilgag** *Alberto Silva* | ||
**@basarat** *Basarat Ali Syed* | ||
**@brettjurgens** *Brett Jurgens* - adding support for default props | ||
@@ -135,0 +139,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
90677
2.57%1136
3.27%162
2.53%