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AI,IAAI,YAAY,oBAAoB,EAAE;YACxC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3B,OAAO,IAAI,CAAC;SACb;QAED,IAAM,iBAAiB,QAAO,CAAA,KAAM,oBAAqB,CAAA,yCAAI,IAAI,KAAC,CAAC;QAEnE,OAAO,SAAS,aAAa,CAAC,MAAW,EAAE,IAAY;YACrD,IAAM,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC9E,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7D,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YACtC,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,EAAE;QACf,oBAAoB,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;KACvE;IAED,oBAAoB,CAAC,SAAS,CAAC,QAAQ,GAAG,cAAM,OAAA,MAAI,IAAM,EAAV,CAAU,CAAC;IACrD,oBAAqB,CAAC,aAAa,GAAG,oBAAoB,CAAC;IACjE,OAAO,oBAAoB,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { global, stringify } from '../facade/lang';\nimport { Type } from '../facade/type';\n\nlet _nextClassId = 0;\nconst Reflect = global['Reflect'];\n\n/**\n * Declares the interface to be used with {@link Class}.\n *\n * @stable\n */\nexport type ClassDefinition = {\n /**\n * Optional argument for specifying the superclass.\n */\n extends?: Type<any>;\n\n /**\n * Required constructor function for a class.\n *\n * The function may be optionally wrapped in an `Array`, in which case additional parameter\n * annotations may be specified.\n * The number of arguments and the number of parameter annotations must match.\n *\n * See {@link Class} for example of usage.\n */\n constructor: Function | any[];\n} & {\n /**\n * Other methods on the class. Note that values should have type 'Function' but TS requires\n * all properties to have a narrower type than the index signature.\n */\n [x: string]: Type<any> | Function | any[];\n};\n\n/**\n * An interface implemented by all Angular type decorators, which allows them to be used as ES7\n * decorators as well as\n * Angular DSL syntax.\n *\n * DSL syntax:\n *\n * ```\n * var MyClass = ng\n * .Component({...})\n * .Class({...});\n * ```\n *\n * ES7 syntax:\n *\n * ```\n * @ng.Component({...})\n * class MyClass {...}\n * ```\n * @stable\n */\nexport interface TypeDecorator {\n /**\n * Invoke as ES7 decorator.\n */\n <T extends Type<any>>(type: T): T;\n\n // Make TypeDecorator assignable to built-in ParameterDecorator type.\n // ParameterDecorator is declared in lib.d.ts as a `declare type`\n // so we cannot declare this interface as a subtype.\n // see https://github.com/angular/angular/issues/3379#issuecomment-126169417\n (target: Object, propertyKey?: string | symbol, parameterIndex?: number): void;\n\n /**\n * Storage for the accumulated annotations so far used by the DSL syntax.\n *\n * Used by {@link Class} to annotate the generated class.\n */\n annotations: any[];\n\n /**\n * Generate a class from the definition and annotate it with {@link TypeDecorator#annotations}.\n */\n Class(obj: ClassDefinition): Type<any>;\n}\n\nfunction extractAnnotation(annotation: any): any {\n if (typeof annotation === 'function' && annotation.hasOwnProperty('annotation')) {\n // it is a decorator, extract annotation\n annotation = annotation.annotation;\n }\n return annotation;\n}\n\nfunction applyParams(fnOrArray: Function | any[] | undefined, key: string): Function {\n if (fnOrArray === Object || fnOrArray === String || fnOrArray === Function || fnOrArray === Number || fnOrArray === Array) {\n throw new Error(`Can not use native ${stringify(fnOrArray)} as constructor`);\n }\n\n if (typeof fnOrArray === 'function') {\n return fnOrArray;\n }\n\n if (Array.isArray(fnOrArray)) {\n const annotations: any[] = fnOrArray as any[];\n const annoLength = annotations.length - 1;\n const fn: Function = fnOrArray[annoLength];\n if (typeof fn !== 'function') {\n throw new Error(`Last position of Class method array must be Function in key ${key} was '${stringify(fn)}'`);\n }\n if (annoLength !== fn.length) {\n throw new Error(\n `Number of annotations (${annoLength}) does not match number of arguments (${fn.length}) in the function: ${stringify(fn)}`\n );\n }\n const paramsAnnotations: any[][] = [];\n for (let i = 0, ii = annotations.length - 1; i < ii; i++) {\n const paramAnnotations: any[] = [];\n paramsAnnotations.push(paramAnnotations);\n const annotation = annotations[i];\n if (Array.isArray(annotation)) {\n for (let j = 0; j < annotation.length; j++) {\n paramAnnotations.push(extractAnnotation(annotation[j]));\n }\n } else if (typeof annotation === 'function') {\n paramAnnotations.push(extractAnnotation(annotation));\n } else {\n paramAnnotations.push(annotation);\n }\n }\n Reflect.defineMetadata('parameters', paramsAnnotations, fn);\n return fn;\n }\n\n throw new Error(`Only Function or Array is supported in Class definition for key '${key}' is '${stringify(fnOrArray)}'`);\n}\n\n/**\n * Provides a way for expressing ES6 classes with parameter annotations in ES5.\n *\n * ## Basic Example\n *\n * ```\n * var Greeter = ng.Class({\n * constructor: function(name) {\n * this.name = name;\n * },\n *\n * greet: function() {\n * alert('Hello ' + this.name + '!');\n * }\n * });\n * ```\n *\n * is equivalent to ES6:\n *\n * ```\n * class Greeter {\n * constructor(name) {\n * this.name = name;\n * }\n *\n * greet() {\n * alert('Hello ' + this.name + '!');\n * }\n * }\n * ```\n *\n * or equivalent to ES5:\n *\n * ```\n * var Greeter = function (name) {\n * this.name = name;\n * }\n *\n * Greeter.prototype.greet = function () {\n * alert('Hello ' + this.name + '!');\n * }\n * ```\n *\n * ### Example with parameter annotations\n *\n * ```\n * var MyService = ng.Class({\n * constructor: [String, [new Optional(), Service], function(name, myService) {\n * ...\n * }]\n * });\n * ```\n *\n * is equivalent to ES6:\n *\n * ```\n * class MyService {\n * constructor(name: string, @Optional() myService: Service) {\n * ...\n * }\n * }\n * ```\n *\n * ### Example with inheritance\n *\n * ```\n * var Shape = ng.Class({\n * constructor: (color) {\n * this.color = color;\n * }\n * });\n *\n * var Square = ng.Class({\n * extends: Shape,\n * constructor: function(color, size) {\n * Shape.call(this, color);\n * this.size = size;\n * }\n * });\n * ```\n * @suppress {globalThis}\n * @stable\n */\nexport function Class(this: any, clsDef: ClassDefinition): Type<any> {\n const constructor = applyParams(clsDef.hasOwnProperty('constructor') ? clsDef.constructor : undefined, 'constructor');\n\n let proto = constructor.prototype;\n\n if (clsDef.hasOwnProperty('extends')) {\n if (typeof clsDef.extends === 'function') {\n (<Function>constructor).prototype = proto = Object.create((<Function>clsDef.extends).prototype);\n } else {\n throw new Error(`Class definition 'extends' property must be a constructor function was: ${stringify(clsDef.extends)}`);\n }\n }\n\n for (const key in clsDef) {\n if (key !== 'extends' && key !== 'prototype' && clsDef.hasOwnProperty(key)) {\n proto[key] = applyParams(clsDef[key], key);\n }\n }\n\n if (this && this.annotations instanceof Array) {\n Reflect.defineMetadata('annotations', this.annotations, constructor);\n }\n\n const constructorName = constructor['name'];\n if (!constructorName || constructorName === 'constructor') {\n (constructor as any)['overriddenName'] = `class${_nextClassId++}`;\n }\n\n return <Type<any>>constructor;\n}\n\n/**\n * @suppress {globalThis}\n */\nexport function makeDecorator(\n name: string,\n props: { [name: string]: any },\n parentClass?: any,\n chainFn?: (fn: Function) => void\n): (...args: any[]) => (cls: any) => any {\n const metaCtor = makeMetadataCtor([props]);\n\n function DecoratorFactory(this: any, objOrType: any): (cls: any) => any {\n if (!(Reflect && Reflect.getOwnMetadata)) {\n throw 'reflect-metadata shim is required when using class decorators';\n }\n\n if (this instanceof DecoratorFactory) {\n metaCtor.call(this, objOrType);\n return this as typeof DecoratorFactory;\n }\n\n const annotationInstance = new (<any>DecoratorFactory)(objOrType);\n const chainAnnotation = typeof this === 'function' && Array.isArray(this.annotations) ? this.annotations : [];\n chainAnnotation.push(annotationInstance);\n const TypeDecorator: TypeDecorator = <TypeDecorator>function TypeDecorator(cls: Type<any>) {\n const annotations = Reflect.getOwnMetadata('annotations', cls) || [];\n annotations.push(annotationInstance);\n Reflect.defineMetadata('annotations', annotations, cls);\n return cls;\n };\n TypeDecorator.annotations = chainAnnotation;\n TypeDecorator.Class = Class;\n if (chainFn) chainFn(TypeDecorator);\n return TypeDecorator;\n }\n\n if (parentClass) {\n DecoratorFactory.prototype = Object.create(parentClass.prototype);\n }\n\n DecoratorFactory.prototype.toString = () => `@${name}`;\n (<any>DecoratorFactory).annotationCls = DecoratorFactory;\n return DecoratorFactory;\n}\n\nfunction makeMetadataCtor(props: ([string, any] | { [key: string]: any })[]): any {\n return function ctor(this: any, ...args: any[]) {\n props.forEach((prop, i) => {\n const argVal = args[i];\n if (Array.isArray(prop)) {\n // plain parameter\n this[prop[0]] = argVal === undefined ? prop[1] : argVal;\n } else {\n for (const propName in prop) {\n this[propName] = argVal && argVal.hasOwnProperty(propName) ? argVal[propName] : prop[propName];\n }\n }\n });\n };\n}\n\nexport function makeParamDecorator(name: string, props: ([string, any] | { [name: string]: any })[], parentClass?: any): any {\n const metaCtor = makeMetadataCtor(props);\n function ParamDecoratorFactory(this: unknown, ...args: any[]): any {\n if (this instanceof ParamDecoratorFactory) {\n metaCtor.apply(this, args);\n return this;\n }\n const annotationInstance = new (<any>ParamDecoratorFactory)(...args);\n\n (<any>ParamDecorator).annotation = annotationInstance;\n return ParamDecorator;\n\n function ParamDecorator(cls: any, unusedKey: any, index: number): any {\n const parameters: (any[] | null)[] = Reflect.getOwnMetadata('parameters', cls) || [];\n\n // there might be gaps if some in between parameters do not have annotations.\n // we pad with nulls.\n while (parameters.length <= index) {\n parameters.push(null);\n }\n\n parameters[index] = parameters[index] || [];\n parameters[index]!.push(annotationInstance);\n\n Reflect.defineMetadata('parameters', parameters, cls);\n return cls;\n }\n }\n if (parentClass) {\n ParamDecoratorFactory.prototype = Object.create(parentClass.prototype);\n }\n ParamDecoratorFactory.prototype.toString = () => `@${name}`;\n (<any>ParamDecoratorFactory).annotationCls = ParamDecoratorFactory;\n return ParamDecoratorFactory;\n}\n\nexport function makePropDecorator(name: string, props: ([string, any] | { [key: string]: any })[], parentClass?: any): any {\n const metaCtor = makeMetadataCtor(props);\n\n function PropDecoratorFactory(this: unknown, ...args: any[]): any {\n if (this instanceof PropDecoratorFactory) {\n metaCtor.apply(this, args);\n return this;\n }\n\n const decoratorInstance = new (<any>PropDecoratorFactory)(...args);\n\n return function PropDecorator(target: any, name: string) {\n const meta = Reflect.getOwnMetadata('propMetadata', target.constructor) || {};\n meta[name] = (meta.hasOwnProperty(name) && meta[name]) || [];\n meta[name].unshift(decoratorInstance);\n Reflect.defineMetadata('propMetadata', meta, target.constructor);\n };\n }\n\n if (parentClass) {\n PropDecoratorFactory.prototype = Object.create(parentClass.prototype);\n }\n\n PropDecoratorFactory.prototype.toString = () => `@${name}`;\n (<any>PropDecoratorFactory).annotationCls = PropDecoratorFactory;\n return PropDecoratorFactory;\n}\n"]}
\No newline at end of file