Merge pull request #8036 from abpframework/feat/8034

Improved handling of quotes when jsonName cannot be used with dot notation in JavaScript
pull/8038/head
Mehmet Erim 5 years ago committed by GitHub
commit f9185e49ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"

Loading…
Cancel
Save