Skip to content

Commit

Permalink
fix: Add builtins check for return type (#124)
Browse files Browse the repository at this point in the history
* fix: Add builtins check for return type

* export isBuiltIn
  • Loading branch information
nitsakh authored and Cheng Zhao committed Jan 30, 2019
1 parent 593abe2 commit dc4c6e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/module-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const generateModuleDeclaration = (module, index, API) => {
returnType = moduleMethod.returns
// Account for methods on the process module that return a custom type/structure, we need to reference the Electron namespace to use these types
if (module.name === 'process' && moduleMethod.returns.type !== 'Object' &&
typeof moduleMethod.returns.type === 'string' && !utils.isPrimitive(moduleMethod.returns.type)) {
typeof moduleMethod.returns.type === 'string' && !utils.isPrimitive(moduleMethod.returns.type) && !utils.isBuiltIn(moduleMethod.returns.type)) {
returnType = `Electron.${moduleMethod.returns.type}`
}
}
Expand Down
9 changes: 8 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ const isPrimitive = (type) => {
]
return primitives.indexOf(type.toLowerCase().replace(/\[\]/g, '')) !== -1
}
const isBuiltIn = (type) => {
const builtIns = [
'promise',
'buffer'
]
return builtIns.indexOf(type.toLowerCase().replace(/\[\]/g, '')) !== -1
}
const isOptional = (param) => {
// Did we pass a "required"?
if (typeof param.required !== 'undefined') {
Expand Down Expand Up @@ -215,4 +222,4 @@ const genMethodString = (paramInterfaces, module, moduleMethod, parameters, retu
}).join(', ')}${includeType ? `) => ${returns ? typify(returns) : 'void'}` : ''}`
}

module.exports = { extendArray, isEmitter, isOptional, paramify, typify, wrapComment, genMethodString, isPrimitive }
module.exports = { extendArray, isEmitter, isOptional, paramify, typify, wrapComment, genMethodString, isPrimitive, isBuiltIn }

0 comments on commit dc4c6e5

Please sign in to comment.