Skip to content

Commit dc4c6e5

Browse files
nitsakhCheng Zhao
authored andcommitted
fix: Add builtins check for return type (#124)
* fix: Add builtins check for return type * export isBuiltIn
1 parent 593abe2 commit dc4c6e5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/module-declaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const generateModuleDeclaration = (module, index, API) => {
126126
returnType = moduleMethod.returns
127127
// Account for methods on the process module that return a custom type/structure, we need to reference the Electron namespace to use these types
128128
if (module.name === 'process' && moduleMethod.returns.type !== 'Object' &&
129-
typeof moduleMethod.returns.type === 'string' && !utils.isPrimitive(moduleMethod.returns.type)) {
129+
typeof moduleMethod.returns.type === 'string' && !utils.isPrimitive(moduleMethod.returns.type) && !utils.isBuiltIn(moduleMethod.returns.type)) {
130130
returnType = `Electron.${moduleMethod.returns.type}`
131131
}
132132
}

lib/utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ const isPrimitive = (type) => {
150150
]
151151
return primitives.indexOf(type.toLowerCase().replace(/\[\]/g, '')) !== -1
152152
}
153+
const isBuiltIn = (type) => {
154+
const builtIns = [
155+
'promise',
156+
'buffer'
157+
]
158+
return builtIns.indexOf(type.toLowerCase().replace(/\[\]/g, '')) !== -1
159+
}
153160
const isOptional = (param) => {
154161
// Did we pass a "required"?
155162
if (typeof param.required !== 'undefined') {
@@ -215,4 +222,4 @@ const genMethodString = (paramInterfaces, module, moduleMethod, parameters, retu
215222
}).join(', ')}${includeType ? `) => ${returns ? typify(returns) : 'void'}` : ''}`
216223
}
217224

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

0 commit comments

Comments
 (0)