Skip to content

Commit

Permalink
fixed flow type interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
oyilmaztekin committed Nov 7, 2018
1 parent 62e42fd commit 250822a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
45 changes: 2 additions & 43 deletions lib/astStages.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,51 +100,10 @@ AstStages.prototype.transformToAst = function(ast){
"flow":true
}

for(let p of props) {
if ( p.value.hasOwnProperty("id") ) {
if ( p.value.id.hasOwnProperty('id') ) {
fn.params.push(
{
"name": p.key.name,
"type": p.value.id.id.name || "type"
}
)
}
else {
fn.params.push(
{
"name": p.key.name,
"type": p.value.id.name || "type"
}
)
}
const newFn = AstStages.prototype.checkTypeInterfacesFlow(props, fn)

}

if ( p.value.hasOwnProperty('types') ) {
// FIXME: fix multiple propname : type problem
for (let t of p.value.types) {
if ( t.hasOwnProperty('id') ) {
fn.params.push(
{
"name": p.key.name,
"type": t.id.id.name
}
)
}
else {
fn.params.push(
{
"name": p.key.name,
"type": t.type
}
)
}
}
}
}

let processedTemplate = AstStages.prototype.createDocTemplate(fn)
let processedTemplate = AstStages.prototype.createDocTemplate(newFn)

let leadComment = [
{
Expand Down
68 changes: 57 additions & 11 deletions lib/astTransformMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ function AstTransformMethods() {}

AstTransformMethods.prototype.checkParameterTypeForFlow = function( params, fn ) {
let variableType

for ( let p of params ) {
if(p.hasOwnProperty('typeAnnotation')){
p.typeAnnotation.typeAnnotation.hasOwnProperty("id")
? variableType = p.typeAnnotation.typeAnnotation.id.name
p.typeAnnotation.typeAnnotation.hasOwnProperty("id")
? variableType = p.typeAnnotation.typeAnnotation.id.name
: variableType = p.typeAnnotation.typeAnnotation.type
}

fn.params.push(
{
"name": p.name,
"type": variableType || "type"
}
)
}
}

return variableType
}

Expand All @@ -27,16 +27,16 @@ AstTransformMethods.prototype.checkReturnedTypeForFlow = function ( node, fn ) {
node.returnType.typeAnnotation.hasOwnProperty("id")
? fn.returnedValue = node.returnType.typeAnnotation.id.name
: fn.returnedValue = node.returnType.typeAnnotation.type

fn.flow = true
}
return returnedValue
return returnedValue
}

AstTransformMethods.prototype.checkReturnedStatementsForJSFiles = function ( activeScope, fn ) {
if ( activeScope.type === "ReturnStatement" ) {
activeScope.argument.name
? fn.returnedValue = activeScope.argument.name
activeScope.argument.name
? fn.returnedValue = activeScope.argument.name
: fn.returnedValue = activeScope.argument.value || activeScope.argument.type
fn.returnedValue = fn.returnedValue.toString()
}
Expand All @@ -57,4 +57,50 @@ AstTransformMethods.prototype.checkStatesForJSFiles = function ( isMemberAssignm
}
}

exports.AstTransformer = AstTransformMethods
AstTransformMethods.prototype.checkTypeInterfacesFlow = function( props, fn ) {
for(let p of props) {
if ( p.value.hasOwnProperty("type") ) {
if(p.value.hasOwnProperty('id')) {
fn.params.push(
{
"name": p.key.name,
"type": p.value.id.name || p.value.id.type
}
)
}
else {
fn.params.push(
{
"name": p.key.name,
"type": p.value.type || "type"
}
)
}
}

if ( p.value.hasOwnProperty('types') ) {
// FIXME: fix multiple propname : type problem
for (let t of p.value.types) {
if ( t.hasOwnProperty('id') ) {
fn.params.push(
{
"name": p.key.name,
"type": t.id.id.name
}
)
}
else {
fn.params.push(
{
"name": p.key.name,
"type": t.type
}
)
}
}
}
}
return fn
}

exports.AstTransformer = AstTransformMethods

0 comments on commit 250822a

Please sign in to comment.