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: numeric enum keys are always prefixed with KEY_ #114

Merged
merged 1 commit into from
Sep 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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