docs: improve Web Types generation - remove quotes around default value (#3707)

This commit is contained in:
Piotr Tomiak 2022-09-12 18:23:43 +02:00 committed by GitHub
parent 447a1d4252
commit fef8972e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -297,13 +297,7 @@ exports.genWebTypes = function genWebTypes () {
if (!docs) return
if (docs.parameters) {
// For slot
let type = docs.parameters
if (type && type.startsWith('`') && type.endsWith('`')) {
type = type.substring(1, type.length - 1).trim()
}
if (type && type.startsWith('(') && type.endsWith(')')) {
type = type.substring(1, type.length - 1).trim()
}
const type = strip(strip(docs.parameters, '`'), '(', ')')
const objDefStart = type ? type.indexOf('{') : -1
if (objDefStart >= 0) {
target.type = type.substring(objDefStart).replaceAll('\\|', '|')
@ -311,22 +305,27 @@ exports.genWebTypes = function genWebTypes () {
}
if (docs.type) {
// For props and events
let type = docs.type
if (type && type.startsWith('`') && type.endsWith('`')) {
type = type.substring(1, type.length - 1).trim()
}
target.type = type.replaceAll('\\|', '|')
target.type = strip(docs.type, '`').replaceAll('\\|', '|')
}
if (docs.description) {
target.description = docs.description
}
if (docs.default) {
target.default = docs.default
target.default = strip(docs.default, '`')
}
if (docs.version) {
target['description-sections'] = { since: docs.version }
}
}
function strip (str, prefix, suffix) {
if (!str) return str
if (!suffix) suffix = prefix
if (str.startsWith(prefix) && str.endsWith(suffix)) {
return str.substring(1, str.length - 1).trim()
}
return str
}
}
if (require.main === module) {