Browse Source

replace internal util fn with should-quote

pull/8036/head
Arman Ozak 6 years ago
parent
commit
704beb57b7
  1. 4
      npm/ng-packs/packages/schematics/src/models/method.ts
  2. 4
      npm/ng-packs/packages/schematics/src/utils/enum.ts
  3. 1
      npm/ng-packs/packages/schematics/src/utils/index.ts
  4. 4
      npm/ng-packs/packages/schematics/src/utils/model.ts
  5. 9
      npm/ng-packs/packages/schematics/src/utils/prop.ts

4
npm/ng-packs/packages/schematics/src/models/method.ts

@ -1,9 +1,9 @@
import { eBindingSourceId, eMethodModifier } from '../enums'; import { eBindingSourceId, eMethodModifier } from '../enums';
import { shouldQuoteProp } from '../utils/prop';
import { camel } from '../utils/text'; import { camel } from '../utils/text';
import { ParameterInBody } from './api-definition'; import { ParameterInBody } from './api-definition';
import { Property } from './model'; import { Property } from './model';
import { Omissible } from './util'; import { Omissible } from './util';
const shouldQuote = require('should-quote');
export class Method { export class Method {
body: Body; body: Body;
@ -46,7 +46,7 @@ export class Body {
const camelName = camel(name); const camelName = camel(name);
const paramName = jsonName || camelName; const paramName = jsonName || camelName;
const value = descriptorName const value = descriptorName
? shouldQuoteProp(paramName) ? shouldQuote(paramName)
? `${descriptorName}['${paramName}']` ? `${descriptorName}['${paramName}']`
: `${descriptorName}.${paramName}` : `${descriptorName}.${paramName}`
: nameOnMethod; : nameOnMethod;

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

@ -3,7 +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 { shouldQuoteProp } from './prop'; const shouldQuote = require('should-quote');
export interface EnumGeneratorParams { export interface EnumGeneratorParams {
targetPath: string; targetPath: string;
@ -34,7 +34,7 @@ export function createImportRefToEnumMapper({ solution, types }: EnumGeneratorPa
const namespace = parseNamespace(solution, ref); const namespace = parseNamespace(solution, ref);
const members = enumNames!.map((key, i) => ({ const members = enumNames!.map((key, i) => ({
key: shouldQuoteProp(key) ? `'${key}'` : key, key: shouldQuote(key) ? `'${key}'` : key,
value: enumValues[i], value: enumValues[i],
})); }));

1
npm/ng-packs/packages/schematics/src/utils/index.ts

@ -10,7 +10,6 @@ export * from './import';
export * from './model'; export * from './model';
export * from './namespace'; export * from './namespace';
export * from './path'; export * from './path';
export * from './prop';
export * from './rule'; export * from './rule';
export * from './service'; export * from './service';
export * from './source'; export * from './source';

4
npm/ng-packs/packages/schematics/src/utils/model.ts

@ -8,7 +8,6 @@ import {
} from './generics'; } from './generics';
import { parseNamespace } from './namespace'; import { parseNamespace } from './namespace';
import { relativePathToModel } from './path'; import { relativePathToModel } from './path';
import { shouldQuoteProp } from './prop';
import { camel } from './text'; import { camel } from './text';
import { parseGenerics } from './tree'; import { parseGenerics } from './tree';
import { import {
@ -18,6 +17,7 @@ import {
extendsSelf, extendsSelf,
removeTypeModifiers, removeTypeModifiers,
} from './type'; } from './type';
const shouldQuote = require('should-quote');
export interface ModelGeneratorParams { export interface ModelGeneratorParams {
targetPath: string; targetPath: string;
@ -136,7 +136,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP
typeDef.properties?.forEach(prop => { typeDef.properties?.forEach(prop => {
let name = prop.jsonName || camel(prop.name); let name = prop.jsonName || camel(prop.name);
name = shouldQuoteProp(name) ? `'${name}'` : name; name = shouldQuote(name) ? `'${name}'` : name;
const type = simplifyType(prop.typeSimple); const type = simplifyType(prop.typeSimple);
const refs = parseType(prop.type).reduce( const refs = parseType(prop.type).reduce(
(acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), (acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()),

9
npm/ng-packs/packages/schematics/src/utils/prop.ts

@ -1,9 +0,0 @@
export const shouldQuoteProp = (key: string) => {
try {
new Function('return {}.' + key);
} catch (_) {
return true;
}
return false;
};
Loading…
Cancel
Save