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 { Type } from '../models';
import { interpolate } from './common'; import { interpolate } from './common';
import { parseNamespace } from './namespace'; import { parseNamespace } from './namespace';
import { isValidProp } from './prop';
export interface EnumGeneratorParams { export interface EnumGeneratorParams {
targetPath: string; targetPath: string;
@ -32,7 +33,10 @@ export function createImportRefToEnumMapper({ solution, types }: EnumGeneratorPa
throw new SchematicsException(interpolate(Exception.NoTypeDefinition, ref)); throw new SchematicsException(interpolate(Exception.NoTypeDefinition, ref));
const namespace = parseNamespace(solution, 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 { return {
namespace, namespace,

Loading…
Cancel
Save