mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 20:15:11 +00:00
Updated documentation generator
... to handle Object.assign(Object.create(foo), { ... })
This commit is contained in:
parent
2cad104fbc
commit
8106d6fd0a
@ -52,11 +52,35 @@ function findExportedObject(ast, recast) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (objPath) {
|
if (objPath) {
|
||||||
|
// Hack: This is easier than replicating the default propType
|
||||||
|
// handler.
|
||||||
|
// This converts any expression, e.g. `foo` to an object expression of
|
||||||
|
// the form `{propTypes: foo}`
|
||||||
var b = recast.types.builders;
|
var b = recast.types.builders;
|
||||||
// This is a bit hacky, but easier than replicating the default propType
|
var nt = recast.types.namedTypes;
|
||||||
// handler. All this does is convert `{...}` to `{propTypes: {...}}`.
|
var obj = objPath.node;
|
||||||
|
|
||||||
|
// Hack: This is converting calls like
|
||||||
|
//
|
||||||
|
// Object.apply(Object.create(foo), { bar: 42 })
|
||||||
|
//
|
||||||
|
// to an AST representing an object literal:
|
||||||
|
//
|
||||||
|
// { ...foo, bar: 42 }
|
||||||
|
if (nt.CallExpression.check(obj) &&
|
||||||
|
recast.print(obj.callee).code === 'Object.assign') {
|
||||||
|
obj = objPath.node.arguments[1];
|
||||||
|
var firstArg = objPath.node.arguments[0];
|
||||||
|
if (recast.print(firstArg.callee).code === 'Object.create') {
|
||||||
|
firstArg = firstArg.arguments[0];
|
||||||
|
}
|
||||||
|
obj.properties.unshift(
|
||||||
|
b.spreadProperty(firstArg)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
objPath.replace(b.objectExpression([
|
objPath.replace(b.objectExpression([
|
||||||
b.property('init', b.literal('propTypes'), objPath.node)
|
b.property('init', b.literal('propTypes'), obj)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
return objPath;
|
return objPath;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user