Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add builtins check for return type #124

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }