diff --git a/npm/ng-packs/packages/schematics/src/models/method.ts b/npm/ng-packs/packages/schematics/src/models/method.ts index 6602c0b653..7259a61884 100644 --- a/npm/ng-packs/packages/schematics/src/models/method.ts +++ b/npm/ng-packs/packages/schematics/src/models/method.ts @@ -1,9 +1,9 @@ import { eBindingSourceId, eMethodModifier } from '../enums'; -import { shouldQuoteProp } from '../utils/prop'; import { camel } from '../utils/text'; import { ParameterInBody } from './api-definition'; import { Property } from './model'; import { Omissible } from './util'; +const shouldQuote = require('should-quote'); export class Method { body: Body; @@ -46,7 +46,7 @@ export class Body { const camelName = camel(name); const paramName = jsonName || camelName; const value = descriptorName - ? shouldQuoteProp(paramName) + ? shouldQuote(paramName) ? `${descriptorName}['${paramName}']` : `${descriptorName}.${paramName}` : nameOnMethod; diff --git a/npm/ng-packs/packages/schematics/src/utils/enum.ts b/npm/ng-packs/packages/schematics/src/utils/enum.ts index ffa07c1998..78b1ad355d 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 { shouldQuoteProp } from './prop'; +const shouldQuote = require('should-quote'); 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: shouldQuoteProp(key) ? `'${key}'` : key, + key: shouldQuote(key) ? `'${key}'` : key, value: enumValues[i], })); diff --git a/npm/ng-packs/packages/schematics/src/utils/index.ts b/npm/ng-packs/packages/schematics/src/utils/index.ts index a33218d1ef..e6df05b2e2 100644 --- a/npm/ng-packs/packages/schematics/src/utils/index.ts +++ b/npm/ng-packs/packages/schematics/src/utils/index.ts @@ -10,7 +10,6 @@ export * from './import'; export * from './model'; export * from './namespace'; export * from './path'; -export * from './prop'; export * from './rule'; export * from './service'; export * from './source'; diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 84e86f35c5..0924524392 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -8,7 +8,6 @@ import { } from './generics'; import { parseNamespace } from './namespace'; import { relativePathToModel } from './path'; -import { shouldQuoteProp } from './prop'; import { camel } from './text'; import { parseGenerics } from './tree'; import { @@ -18,6 +17,7 @@ import { extendsSelf, removeTypeModifiers, } from './type'; +const shouldQuote = require('should-quote'); export interface ModelGeneratorParams { targetPath: string; @@ -136,7 +136,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP typeDef.properties?.forEach(prop => { let name = prop.jsonName || camel(prop.name); - name = shouldQuoteProp(name) ? `'${name}'` : name; + name = shouldQuote(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 deleted file mode 100644 index 3530aff057..0000000000 --- a/npm/ng-packs/packages/schematics/src/utils/prop.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const shouldQuoteProp = (key: string) => { - try { - new Function('return {}.' + key); - } catch (_) { - return true; - } - - return false; -};