diff --git a/npm/ng-packs/package.json b/npm/ng-packs/package.json index 6f8b534d14..b07f5d5136 100644 --- a/npm/ng-packs/package.json +++ b/npm/ng-packs/package.json @@ -85,6 +85,7 @@ "prettier": "^2.2.0", "protractor": "~7.0.0", "rxjs": "~6.6.3", + "should-quote": "^1.0.0", "snq": "^1.0.3", "symlink-manager": "^1.5.0", "ts-node": "~7.0.0", @@ -102,4 +103,4 @@ "path": "cz-conventional-changelog" } } -} \ No newline at end of file +} 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; -}; diff --git a/npm/ng-packs/yarn.lock b/npm/ng-packs/yarn.lock index 02c45022a9..e6874978b7 100644 --- a/npm/ng-packs/yarn.lock +++ b/npm/ng-packs/yarn.lock @@ -12539,6 +12539,11 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== +should-quote@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/should-quote/-/should-quote-1.0.0.tgz#18e58cb92a3fecb6e163cf92c8158847058589d7" + integrity sha512-mQN5Meec3CTPmykzwXfDGWDpi75HUD8NT21wRWaJ7oqxpFIhXq80Hiy4ziccUNOwzhWeFkT9/kNSZbaugL9jsA== + signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"