Skip to content

Commit b065807

Browse files
MarshallOfSoundckerr
authored andcommitted
fix: prefix inner types for safety (#136)
1 parent 6da58ba commit b065807

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ apiPromise.then(API => {
4646
linter.lint(outFile, output, configuration)
4747
const result = linter.getResult()
4848

49-
if (result.failureCount === 0) {
49+
if (result.failureCount === 0 || process.argv.includes('--force-write')) {
5050
fs.writeFileSync(outFile, output)
5151
} else {
5252
console.error('Failed to lint electron.d.ts')

lib/utils.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const wrapComment = (comment) => {
2525
return result.concat(' */')
2626
}
2727

28+
const prefixTypeForSafety = (type) => {
29+
if (type !== 'Object' && typeof type === 'string' && !isPrimitive(type) && !isBuiltIn(type)) {
30+
return `Electron.${type}`
31+
}
32+
return type
33+
}
34+
2835
const typify = (type) => {
2936
// Capture some weird edge cases
3037
const originalType = type
@@ -105,7 +112,7 @@ const typify = (type) => {
105112
return '(() => void)'
106113
case 'promise':
107114
if (innerType) {
108-
return `Promise<${typify(innerType[0])}>`
115+
return `Promise<${prefixTypeForSafety(typify(innerType[0]))}>`
109116
}
110117
debug('Promise with missing inner type, defaulting to any')
111118
return 'Promise<any>'
@@ -156,7 +163,8 @@ const isPrimitive = (type) => {
156163
'boolean',
157164
'number',
158165
'any',
159-
'string'
166+
'string',
167+
'void'
160168
]
161169
return primitives.indexOf(type.toLowerCase().replace(/\[\]/g, '')) !== -1
162170
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"build": "node cli.js",
9-
"demo": "npm run build -- -o=electron.d.ts",
9+
"demo": "npm run build -- -o=electron.d.ts --force-write",
1010
"prepublishOnly": "npm run demo && npm run test-output",
1111
"lint-output": "tslint -c tslint.json -t verbose electron.d.ts --fix",
1212
"test": "mocha && standard --fix && npm run demo && npm run test-output && npm run lint-output",

vendor/fetch-docs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const mkdirp = require('mkdirp').sync
77
const os = require('os')
88

99
const downloadPath = path.join(os.tmpdir(), 'electron-api-tmp')
10-
const ELECTRON_COMMIT = '241098c7d2fa04c5712c8f6512470a5249bb64b1'
10+
const ELECTRON_COMMIT = '2feb919143d3acd8c6cdd611e98be591db074a38'
1111

1212
rm(downloadPath)
1313

0 commit comments

Comments
 (0)