CompilerFlags.parseRaw constructor

CompilerFlags.parseRaw(
  1. dynamic options,
  2. CompilerFlags defaultTo
)

Parses a raw map of flags into CompilerFlags.

Failures are reported to logger.

Implementation

factory CompilerFlags.parseRaw(
  // Untyped because 'argResults' doesn't expose a Map interface.
  dynamic options,
  CompilerFlags defaultTo,
) {
  // Check for invalid (unknown) arguments when possible.
  if (options is Map<Object, Object>) {
    final knownArgs = const {
      _argEnableDevTools,
      _argLegacyStyle,
      _argDataDebugSource,
      _argForceMinifyWhitespace,
      _argNoEmitComponentFactories,
      _argNoEmitInjectableFactories,
      _argPolicyExceptions,
      _argPolicyExceptionInPackages,
    };
    final unknownArgs = options.keys.toSet().difference(knownArgs);
    if (unknownArgs.isNotEmpty) {
      final message = ''
          'Invalid compiler arguments: \n'
          '  - ${unknownArgs.join('\n  - ')}\n\n';
      throw ArgumentError(message);
    }
  }

  final enableDevTools = options[_argEnableDevTools];
  final useLegacyStyle = options[_argLegacyStyle];
  final enableDataDebugSource = options[_argDataDebugSource];
  final forceMinifyWhitespace = options[_argForceMinifyWhitespace];
  final noEmitComponentFactories = options[_argNoEmitComponentFactories];
  final noEmitInjectableFactories = options[_argNoEmitInjectableFactories];
  final policyExceptions = options[_argPolicyExceptions];
  final policyExceptionInPackages = options[_argPolicyExceptionInPackages];

  return CompilerFlags(
    enableDevTools: enableDevTools as bool? ?? defaultTo.enableDevTools,
    useLegacyStyleEncapsulation:
        useLegacyStyle as bool? ?? defaultTo.useLegacyStyleEncapsulation,
    forceMinifyWhitespace:
        forceMinifyWhitespace as bool? ?? defaultTo.forceMinifyWhitespace,
    emitComponentFactories: noEmitComponentFactories != true,
    emitInjectableFactories: noEmitInjectableFactories != true,
    policyExceptions: _buildPolicyExceptions(policyExceptions),
    policyExceptionInPackages:
        _buildPolicyExceptions(policyExceptionInPackages),
    enableDataDebugSource: _forceEnableDataDebugSource ||
        (enableDataDebugSource as bool? ?? defaultTo.enableDataDebugSource),
  );
}