diff --git a/npm/ng-packs/packages/schematics/src/models/method.ts b/npm/ng-packs/packages/schematics/src/models/method.ts index 96db013c8f..6602c0b653 100644 --- a/npm/ng-packs/packages/schematics/src/models/method.ts +++ b/npm/ng-packs/packages/schematics/src/models/method.ts @@ -1,5 +1,5 @@ import { eBindingSourceId, eMethodModifier } from '../enums'; -import { isValidProp } from '../utils/prop'; +import { shouldQuoteProp } from '../utils/prop'; import { camel } from '../utils/text'; import { ParameterInBody } from './api-definition'; import { Property } from './model'; @@ -46,9 +46,9 @@ export class Body { const camelName = camel(name); const paramName = jsonName || camelName; const value = descriptorName - ? isValidProp(paramName) - ? `${descriptorName}.${paramName}` - : `${descriptorName}['${paramName}']` + ? shouldQuoteProp(paramName) + ? `${descriptorName}['${paramName}']` + : `${descriptorName}.${paramName}` : nameOnMethod; switch (bindingSourceId) { diff --git a/npm/ng-packs/packages/schematics/src/utils/enum.ts b/npm/ng-packs/packages/schematics/src/utils/enum.ts index 5ff644db82..ffa07c1998 100644 --- a/npm/ng-packs/packages/schematics/src/utils/enum.ts +++ b/npm/ng-packs/packages/schematics/src/utils/enum.ts @@ -3,7 +3,7 @@ import { Exception } from '../enums'; import { Type } from '../models'; import { interpolate } from './common'; import { parseNamespace } from './namespace'; -import { isValidProp } from './prop'; +import { shouldQuoteProp } from './prop'; export interface EnumGeneratorParams { targetPath: string; @@ -34,7 +34,7 @@ export function createImportRefToEnumMapper({ solution, types }: EnumGeneratorPa const namespace = parseNamespace(solution, ref); const members = enumNames!.map((key, i) => ({ - key: isValidProp(key) ? key : `'${key}'`, + key: shouldQuoteProp(key) ? `'${key}'` : key, value: enumValues[i], })); diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 96856fdbe4..84e86f35c5 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -8,7 +8,7 @@ import { } from './generics'; import { parseNamespace } from './namespace'; import { relativePathToModel } from './path'; -import { isValidProp } from './prop'; +import { shouldQuoteProp } from './prop'; import { camel } from './text'; import { parseGenerics } from './tree'; import { @@ -136,7 +136,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP typeDef.properties?.forEach(prop => { let name = prop.jsonName || camel(prop.name); - name = isValidProp(name) ? name : `'${name}'`; + name = shouldQuoteProp(name) ? `'${name}'` : name; const type = simplifyType(prop.typeSimple); const refs = parseType(prop.type).reduce( (acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), diff --git a/npm/ng-packs/packages/schematics/src/utils/prop.ts b/npm/ng-packs/packages/schematics/src/utils/prop.ts index 0c78de7b14..3530aff057 100644 --- a/npm/ng-packs/packages/schematics/src/utils/prop.ts +++ b/npm/ng-packs/packages/schematics/src/utils/prop.ts @@ -1,9 +1,9 @@ -export const isValidProp = (name: string) => { +export const shouldQuoteProp = (key: string) => { try { - new Function('return {}.' + name); + new Function('return {}.' + key); } catch (_) { - return false; + return true; } - return true; + return false; };