Browse Source
Merge pull request #8036 from abpframework/feat/8034
Improved handling of quotes when jsonName cannot be used with dot notation in JavaScript
pull/7193/head
Mehmet Erim
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
13 additions and
17 deletions
-
npm/ng-packs/package.json
-
npm/ng-packs/packages/schematics/src/models/method.ts
-
npm/ng-packs/packages/schematics/src/utils/enum.ts
-
npm/ng-packs/packages/schematics/src/utils/index.ts
-
npm/ng-packs/packages/schematics/src/utils/model.ts
-
npm/ng-packs/packages/schematics/src/utils/prop.ts
-
npm/ng-packs/yarn.lock
|
|
|
@ -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" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|
|
|
|
@ -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], |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
@ -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'; |
|
|
|
|
|
|
|
@ -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()), |
|
|
|
|
|
|
|
@ -1,9 +0,0 @@ |
|
|
|
export const shouldQuoteProp = (key: string) => { |
|
|
|
try { |
|
|
|
new Function('return {}.' + key); |
|
|
|
} catch (_) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
}; |
|
|
|
@ -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" |
|
|
|
|