Browse Source

quote enum member keys if not a valid prop name

pull/8015/head
Arman Ozak 5 years ago
parent
commit
45dcefc6b2
  1. 6
      npm/ng-packs/packages/schematics/src/utils/enum.ts

6
npm/ng-packs/packages/schematics/src/utils/enum.ts

@ -3,6 +3,7 @@ import { Exception } from '../enums';
import { Type } from '../models';
import { interpolate } from './common';
import { parseNamespace } from './namespace';
import { isValidProp } from './prop';
export interface EnumGeneratorParams {
targetPath: string;
@ -32,7 +33,10 @@ export function createImportRefToEnumMapper({ solution, types }: EnumGeneratorPa
throw new SchematicsException(interpolate(Exception.NoTypeDefinition, ref));
const namespace = parseNamespace(solution, ref);
const members = enumNames!.map((key, i) => ({ key, value: enumValues[i] }));
const members = enumNames!.map((key, i) => ({
key: isValidProp(key) ? key : `'${key}'`,
value: enumValues[i],
}));
return {
namespace,

Loading…
Cancel
Save