flow-api-translator
Advanced tools
@@ -274,2 +274,8 @@ /** | ||
case 'HookDeclaration': | ||
{ | ||
const [result, deps] = convertHookDeclaration(stmt, context); | ||
return [result, deps]; | ||
} | ||
case 'FunctionDeclaration': | ||
@@ -517,2 +523,12 @@ { | ||
case 'HookDeclaration': | ||
{ | ||
const [declDecl, deps] = convertHookDeclaration(decl, context); | ||
return [opts.default ? _hermesTransform.t.DeclareExportDefaultDeclaration({ | ||
declaration: declDecl | ||
}) : _hermesTransform.t.DeclareExportDeclarationNamedWithDeclaration({ | ||
declaration: declDecl | ||
}), deps]; | ||
} | ||
case 'FunctionDeclaration': | ||
@@ -911,2 +927,28 @@ { | ||
function convertHookDeclaration(hook, context) { | ||
var _hook$returnType; | ||
const id = hook.id; | ||
const returnType = (_hook$returnType = hook.returnType) != null ? _hook$returnType : // $FlowFixMe[incompatible-type] | ||
_hermesTransform.t.TypeAnnotation({ | ||
typeAnnotation: _hermesTransform.t.VoidTypeAnnotation() | ||
}); | ||
const [resultReturnType, returnDeps] = convertTypeAnnotation(returnType, hook, context); | ||
const [resultParams, restParam, paramsDeps] = convertFunctionParameters(hook.params, context); | ||
const [resultTypeParams, typeParamsDeps] = convertTypeParameterDeclarationOrNull(hook.typeParameters, context); | ||
const resultFunc = _hermesTransform.t.FunctionTypeAnnotation({ | ||
params: resultParams, | ||
returnType: resultReturnType, | ||
rest: restParam, | ||
typeParameters: resultTypeParams | ||
}); | ||
const funcDeps = [...paramsDeps, ...returnDeps, ...typeParamsDeps]; | ||
return [_hermesTransform.t.DeclareHook({ | ||
name: id.name, | ||
functionType: resultFunc | ||
}), [...funcDeps]]; | ||
} | ||
function convertFunctionDeclaration(func, context) { | ||
@@ -913,0 +955,0 @@ const id = func.id; |
{ | ||
"name": "flow-api-translator", | ||
"version": "0.18.2", | ||
"version": "0.19.0", | ||
"description": "Toolkit for creating Flow and TypeScript compatible libraries from Flow source code.", | ||
@@ -15,6 +15,6 @@ "main": "dist/index.js", | ||
"flow-enums-runtime": "^0.0.6", | ||
"hermes-eslint": "0.18.2", | ||
"hermes-estree": "0.18.2", | ||
"hermes-parser": "0.18.2", | ||
"hermes-transform": "0.18.2" | ||
"hermes-eslint": "0.19.0", | ||
"hermes-estree": "0.19.0", | ||
"hermes-parser": "0.19.0", | ||
"hermes-transform": "0.19.0" | ||
}, | ||
@@ -21,0 +21,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
376274
1.65%4097
1.89%