mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
style: collapse if statements (#15449)
This commit is contained in:
parent
a6fbee6865
commit
26dd51221a
@ -98,10 +98,8 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
|
||||
|
||||
let schematicName = options.schematic;
|
||||
|
||||
if (schematicName) {
|
||||
if (schematicName.includes(':')) {
|
||||
[collectionName, schematicName] = schematicName.split(':', 2);
|
||||
}
|
||||
if (schematicName && schematicName.includes(':')) {
|
||||
[collectionName, schematicName] = schematicName.split(':', 2);
|
||||
}
|
||||
|
||||
return [collectionName, schematicName];
|
||||
|
@ -179,10 +179,8 @@ export abstract class ArchitectCommand<
|
||||
|
||||
// Update options to remove analytics from options if the builder isn't safelisted.
|
||||
for (const o of this.description.options) {
|
||||
if (o.userAnalytics) {
|
||||
if (!isPackageNameSafeForAnalytics(builderConf)) {
|
||||
o.userAnalytics = undefined;
|
||||
}
|
||||
if (o.userAnalytics && !isPackageNameSafeForAnalytics(builderConf)) {
|
||||
o.userAnalytics = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,10 +84,8 @@ function _coerce(str: string | undefined, o: Option | null, v?: Value): Value |
|
||||
// enum. If there's no enum, just return the first one that matches.
|
||||
for (const type of types) {
|
||||
const maybeResult = _coerceType(str, type, v);
|
||||
if (maybeResult !== undefined) {
|
||||
if (!o.enum || o.enum.includes(maybeResult)) {
|
||||
return maybeResult;
|
||||
}
|
||||
if (maybeResult !== undefined && (!o.enum || o.enum.includes(maybeResult))) {
|
||||
return maybeResult;
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,11 +157,9 @@ function _assignOption(
|
||||
value = nextArg;
|
||||
let shouldShift = true;
|
||||
|
||||
if (value && value.startsWith('-')) {
|
||||
if (value && value.startsWith('-') && _coerce(undefined, maybeOption) !== undefined) {
|
||||
// Verify if not having a value results in a correct parse, if so don't shift.
|
||||
if (_coerce(undefined, maybeOption) !== undefined) {
|
||||
shouldShift = false;
|
||||
}
|
||||
shouldShift = false;
|
||||
}
|
||||
|
||||
// Only absorb it if it leads to a better value.
|
||||
|
@ -103,10 +103,8 @@ export abstract class SchematicCommand<
|
||||
|
||||
// Remove any user analytics from schematics that are NOT part of our safelist.
|
||||
for (const o of this.description.options) {
|
||||
if (o.userAnalytics) {
|
||||
if (!isPackageNameSafeForAnalytics(this.collectionName)) {
|
||||
o.userAnalytics = undefined;
|
||||
}
|
||||
if (o.userAnalytics && !isPackageNameSafeForAnalytics(this.collectionName)) {
|
||||
o.userAnalytics = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,22 +56,18 @@ export class BundleBudgetPlugin {
|
||||
}
|
||||
|
||||
private checkMinimum(threshold: number | undefined, size: Size, messages: string[]) {
|
||||
if (threshold) {
|
||||
if (threshold > size.size) {
|
||||
const sizeDifference = formatSize(threshold - size.size);
|
||||
messages.push(`budgets, minimum exceeded for ${size.label}. `
|
||||
+ `Budget ${formatSize(threshold)} was not reached by ${sizeDifference}.`);
|
||||
}
|
||||
if (threshold && threshold > size.size) {
|
||||
const sizeDifference = formatSize(threshold - size.size);
|
||||
messages.push(`budgets, minimum exceeded for ${size.label}. `
|
||||
+ `Budget ${formatSize(threshold)} was not reached by ${sizeDifference}.`);
|
||||
}
|
||||
}
|
||||
|
||||
private checkMaximum(threshold: number | undefined, size: Size, messages: string[]) {
|
||||
if (threshold) {
|
||||
if (threshold < size.size) {
|
||||
const sizeDifference = formatSize(size.size - threshold);
|
||||
messages.push(`budgets, maximum exceeded for ${size.label}. `
|
||||
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
|
||||
}
|
||||
if (threshold && threshold < size.size) {
|
||||
const sizeDifference = formatSize(size.size - threshold);
|
||||
messages.push(`budgets, maximum exceeded for ${size.label}. `
|
||||
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,20 +286,23 @@ export function buildServerConfig(
|
||||
browserOptions: BrowserBuilderSchema,
|
||||
logger: logging.LoggerApi,
|
||||
): WebpackDevServer.Configuration {
|
||||
if (serverOptions.host) {
|
||||
// Check that the host is either localhost or prints out a message.
|
||||
if (!/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host) && serverOptions.host !== 'localhost') {
|
||||
logger.warn(tags.stripIndent`
|
||||
WARNING: This is a simple server for use in testing or debugging Angular applications
|
||||
locally. It hasn't been reviewed for security issues.
|
||||
// Check that the host is either localhost or prints out a message.
|
||||
if (
|
||||
serverOptions.host
|
||||
&& !/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host)
|
||||
&& serverOptions.host !== 'localhost'
|
||||
) {
|
||||
logger.warn(tags.stripIndent`
|
||||
WARNING: This is a simple server for use in testing or debugging Angular applications
|
||||
locally. It hasn't been reviewed for security issues.
|
||||
|
||||
Binding this server to an open connection can result in compromising your application or
|
||||
computer. Using a different host than the one passed to the "--host" flag might result in
|
||||
websocket connection issues. You might need to use "--disableHostCheck" if that's the
|
||||
case.
|
||||
`);
|
||||
}
|
||||
Binding this server to an open connection can result in compromising your application or
|
||||
computer. Using a different host than the one passed to the "--host" flag might result in
|
||||
websocket connection issues. You might need to use "--disableHostCheck" if that's the
|
||||
case.
|
||||
`);
|
||||
}
|
||||
|
||||
if (serverOptions.disableHostCheck) {
|
||||
logger.warn(tags.oneLine`
|
||||
WARNING: Running a server with --disable-host-check is a security risk.
|
||||
|
@ -549,18 +549,16 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'list' && !items) {
|
||||
if (Array.isArray(parentSchema.enum)) {
|
||||
type = 'list';
|
||||
items = [];
|
||||
for (const value of parentSchema.enum) {
|
||||
if (typeof value == 'string') {
|
||||
items.push(value);
|
||||
} else if (typeof value == 'object') {
|
||||
// Invalid
|
||||
} else {
|
||||
items.push({ label: value.toString(), value });
|
||||
}
|
||||
if (type === 'list' && !items && Array.isArray(parentSchema.enum)) {
|
||||
type = 'list';
|
||||
items = [];
|
||||
for (const value of parentSchema.enum) {
|
||||
if (typeof value == 'string') {
|
||||
items.push(value);
|
||||
} else if (typeof value == 'object') {
|
||||
// Invalid
|
||||
} else {
|
||||
items.push({ label: value.toString(), value });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,15 +128,12 @@ export class Chunk {
|
||||
}
|
||||
|
||||
assert(left: boolean, _content: boolean, right: boolean) {
|
||||
if (left) {
|
||||
if (this._assertLeft) {
|
||||
throw new ContentCannotBeRemovedException();
|
||||
}
|
||||
if (left && this._assertLeft) {
|
||||
throw new ContentCannotBeRemovedException();
|
||||
}
|
||||
if (right) {
|
||||
if (this._assertRight) {
|
||||
throw new ContentCannotBeRemovedException();
|
||||
}
|
||||
|
||||
if (right && this._assertRight) {
|
||||
throw new ContentCannotBeRemovedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user