Skip to content

Commit

Permalink
fix: numeric enum keys are always prefixed with KEY_; relates to Ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
vil committed Sep 21, 2020
1 parent bdfc8e8 commit ef97984
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
17 changes: 7 additions & 10 deletions src/componentsCodegen/createDefinitionEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import { IEnumDef } from "../baseInterfaces";
* @param type 枚举的类型
*/
export function createDefinitionEnum(className: string, enumArray: any[], type: string): IEnumDef {
let result = ''
if (type === 'string') {
result = enumArray.map(item => `'${item}'='${item}'`).join(',')
}
else {
result = type === 'string' ?
enumArray.map(item => `'${item}'`).join('|') :
enumArray.join('|')
}

const result = type === 'string'
? enumArray
.map(item => Number.isNaN(item)
? `'${item}'='${item}'`
: `'KEY_${item}'='${item}'`)
.join(',')
: enumArray.join('|')
return { name: className, enumProps: result, type: type }
}
7 changes: 6 additions & 1 deletion src/componentsCodegen/propTrueType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export function propTrueType(v: IDefinitionProperty): {
// 是枚举 并且是字符串类型
else if (v.enum && v.type === 'string') {
result.isEnum = true
result.propType = getEnums(v.enum).map(item => `'${item}'='${item}'`).join(',')
result.propType = getEnums(v.enum)
.map(item =>
isNaN(item)
? `'${item}'='${item}'`
: `'KEY_${item}'='${item}'`)
.join(',')
}
else if (v.enum) {
result.isType = true
Expand Down
17 changes: 7 additions & 10 deletions src/definitionCodegen/createDefinitionEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import { IEnumDef } from "../baseInterfaces";
* @param type 枚举的类型
*/
export function createDefinitionEnum(className: string, enumArray: any[], type: string): IEnumDef {
let result = ''
if (type === 'string') {
result = enumArray.map(item => `'${item}'='${item}'`).join(',')
}
else {
result = type === 'string' ?
enumArray.map(item => `'${item}'`).join('|') :
enumArray.join('|')
}

const result = type === 'string'
? enumArray
.map(item => Number.isNaN(item)
? `'${item}'='${item}'`
: `'KEY_${item}'='${item}'`)
.join(',')
: enumArray.join('|')
return { name: className, enumProps: result, type: type }
}
12 changes: 6 additions & 6 deletions src/definitionCodegen/propTrueType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export function propTrueType(v: IDefinitionProperty): {
// 是枚举 并且是字符串类型
else if (v.enum && v.type === 'string') {
result.isEnum = true
result.propType = getEnums(v.enum).map(item => {
if (isNaN(item)){
return `'${item}'='${item}'`;
}
return `'KEY_${item}'='${item}'`;
}).join(',')
result.propType = getEnums(v.enum)
.map(item =>
isNaN(item)
? `'${item}'='${item}'`
: `'KEY_${item}'='${item}'`)
.join(',')
}
else if (v.enum) {
result.isType = true
Expand Down

0 comments on commit ef97984

Please sign in to comment.