function _objToJson(obj) {
    if (isArray(obj))
        return _arrayToJson(obj);
    if (isString(obj) || isBlank(obj) || isBoolean(obj) || isNumber(obj))
        return obj;
    return obj.toJson();
}
function isListLikeIterable(obj) {
    if (!lang_1.isJsObject(obj))
        return false;
    return lang_1.isArray(obj) ||
        (!(obj instanceof exports.Map) &&
            lang_1.getSymbolIterator() in obj); // JS Iterable have a Symbol.iterator prop
}
function _objFromJson(obj, fn) {
    if (isArray(obj))
        return _arrayFromJson(obj, fn);
    if (isString(obj) || isBlank(obj) || isBoolean(obj) || isNumber(obj))
        return obj;
    return fn(obj);
}
示例#4
0
 deserialize(map, type, data) {
     if (!isPresent(map)) {
         return null;
     }
     if (isArray(map)) {
         var obj = [];
         map.forEach(val => obj.push(this.deserialize(val, type, data)));
         return obj;
     }
     if (type == PRIMITIVE) {
         return map;
     }
     if (type == RenderStoreObject) {
         return this._renderStore.deserialize(map);
     }
     else if (type === RenderComponentType) {
         return this._deserializeRenderComponentType(map);
     }
     else if (type === ViewEncapsulation) {
         return VIEW_ENCAPSULATION_VALUES[map];
     }
     else if (type === LocationType) {
         return this._deserializeLocation(map);
     }
     else {
         throw new BaseException("No deserializer for " + type.toString());
     }
 }
示例#5
0
function debugOutputAstAsTypeScript(ast) {
    var converter = new _TsEmitterVisitor(_debugModuleUrl);
    var ctx = abstract_emitter_1.EmitterVisitorContext.createRoot([]);
    var asts;
    if (lang_1.isArray(ast)) {
        asts = ast;
    }
    else {
        asts = [ast];
    }
    asts.forEach(function (ast) {
        if (ast instanceof o.Statement) {
            ast.visitStatement(converter, ctx);
        }
        else if (ast instanceof o.Expression) {
            ast.visitExpression(converter, ctx);
        }
        else if (ast instanceof o.Type) {
            ast.visitType(converter, ctx);
        }
        else {
            throw new exceptions_1.BaseException("Don't know how to print debug info for " + ast);
        }
    });
    return ctx.toSource();
}
示例#6
0
export function debugOutputAstAsDart(ast) {
    var converter = new _DartEmitterVisitor(_debugModuleUrl);
    var ctx = EmitterVisitorContext.createRoot([]);
    var asts;
    if (isArray(ast)) {
        asts = ast;
    }
    else {
        asts = [ast];
    }
    asts.forEach((ast) => {
        if (ast instanceof o.Statement) {
            ast.visitStatement(converter, ctx);
        }
        else if (ast instanceof o.Expression) {
            ast.visitExpression(converter, ctx);
        }
        else if (ast instanceof o.Type) {
            ast.visitType(converter, ctx);
        }
        else {
            throw new BaseException(`Don't know how to print debug info for ${ast}`);
        }
    });
    return ctx.toSource();
}
 serialize(obj, type) {
     if (!isPresent(obj)) {
         return null;
     }
     if (isArray(obj)) {
         return obj.map(v => this.serialize(v, type));
     }
     if (type == PRIMITIVE) {
         return obj;
     }
     if (type == RenderProtoViewRef) {
         return this._protoViewStore.serialize(obj);
     }
     else if (type == RenderViewRef) {
         return this._renderViewStore.serializeRenderViewRef(obj);
     }
     else if (type == RenderFragmentRef) {
         return this._renderViewStore.serializeRenderFragmentRef(obj);
     }
     else if (type == WebWorkerElementRef) {
         return this._serializeWorkerElementRef(obj);
     }
     else if (type == WebWorkerTemplateCmd) {
         return serializeTemplateCmd(obj);
     }
     else if (type === RenderComponentTemplate) {
         return this._serializeRenderTemplate(obj);
     }
     else if (type === ViewEncapsulation) {
         return serializeEnum(obj);
     }
     else {
         throw new BaseException("No serializer for " + type.toString());
     }
 }
示例#8
0
 serialize(obj, type) {
     if (!isPresent(obj)) {
         return null;
     }
     if (isArray(obj)) {
         return obj.map(v => this.serialize(v, type));
     }
     if (type == PRIMITIVE) {
         return obj;
     }
     if (type == RenderStoreObject) {
         return this._renderStore.serialize(obj);
     }
     else if (type === RenderComponentType) {
         return this._serializeRenderComponentType(obj);
     }
     else if (type === ViewEncapsulation) {
         return serializeEnum(obj);
     }
     else if (type === LocationType) {
         return this._serializeLocation(obj);
     }
     else {
         throw new BaseException("No serializer for " + type.toString());
     }
 }
function objToJson(obj) {
    if (lang_1.isArray(obj))
        return arrayToJson(obj);
    if (lang_1.isString(obj) || lang_1.isBlank(obj) || lang_1.isBoolean(obj) || lang_1.isNumber(obj))
        return obj;
    return obj.toJson();
}
function objFromJson(obj, fn) {
    if (lang_1.isArray(obj))
        return arrayFromJson(obj, fn);
    if (lang_1.isString(obj) || lang_1.isBlank(obj) || lang_1.isBoolean(obj) || lang_1.isNumber(obj))
        return obj;
    return fn(obj);
}
示例#11
0
 Serializer.prototype.deserialize = function (map, type, data) {
     var _this = this;
     if (!lang_1.isPresent(map)) {
         return null;
     }
     if (lang_1.isArray(map)) {
         var obj = [];
         map.forEach(function (val) { return obj.push(_this.deserialize(val, type, data)); });
         return obj;
     }
     if (type == exports.PRIMITIVE) {
         return map;
     }
     if (type == RenderStoreObject) {
         return this._renderStore.deserialize(map);
     }
     else if (type === api_1.RenderComponentType) {
         return this._deserializeRenderComponentType(map);
     }
     else if (type === view_1.ViewEncapsulation) {
         return view_1.VIEW_ENCAPSULATION_VALUES[map];
     }
     else if (type === serialized_types_1.LocationType) {
         return this._deserializeLocation(map);
     }
     else {
         throw new exceptions_1.BaseException("No deserializer for " + type.toString());
     }
 };
示例#12
0
 Serializer.prototype.serialize = function (obj, type) {
     var _this = this;
     if (!lang_1.isPresent(obj)) {
         return null;
     }
     if (lang_1.isArray(obj)) {
         return obj.map(function (v) { return _this.serialize(v, type); });
     }
     if (type == exports.PRIMITIVE) {
         return obj;
     }
     if (type == RenderStoreObject) {
         return this._renderStore.serialize(obj);
     }
     else if (type === api_1.RenderComponentType) {
         return this._serializeRenderComponentType(obj);
     }
     else if (type === view_1.ViewEncapsulation) {
         return lang_1.serializeEnum(obj);
     }
     else if (type === serialized_types_1.LocationType) {
         return this._serializeLocation(obj);
     }
     else {
         throw new exceptions_1.BaseException("No serializer for " + type.toString());
     }
 };
示例#13
0
function flattenStatements(arg, output) {
    if (lang_1.isArray(arg)) {
        arg.forEach(function (entry) { return flattenStatements(entry, output); });
    }
    else {
        output.push(arg);
    }
}
示例#14
0
function flattenStatements(arg, output) {
    if (isArray(arg)) {
        arg.forEach((entry) => flattenStatements(entry, output));
    }
    else {
        output.push(arg);
    }
}
 CompileIdentifierMetadata.fromJson = function (data) {
     var value = lang_1.isArray(data['value']) ? arrayFromJson(data['value'], metadataFromJson) :
         objFromJson(data['value'], metadataFromJson);
     return new CompileIdentifierMetadata({
         name: data['name'],
         prefix: data['prefix'],
         moduleUrl: data['moduleUrl'],
         constConstructor: data['constConstructor'],
         value: value
     });
 };
 Compiler.prototype._flattenList = function (tree, out) {
     for (var i = 0; i < tree.length; i++) {
         var item = di_1.resolveForwardRef(tree[i]);
         if (lang_1.isArray(item)) {
             this._flattenList(item, out);
         }
         else {
             out.push(item);
         }
     }
 };
function flattenArray(tree, out) {
    for (var i = 0; i < tree.length; i++) {
        var item = resolveForwardRef(tree[i]);
        if (isArray(item)) {
            flattenArray(item, out);
        }
        else {
            out.push(item);
        }
    }
}
示例#18
0
 toJson() {
     let value = isArray(this.value) ? _arrayToJson(this.value) : _objToJson(this.value);
     return {
         // Note: Runtime type can't be serialized...
         'class': 'Identifier',
         'name': this.name,
         'moduleUrl': this.moduleUrl,
         'prefix': this.prefix,
         'value': value
     };
 }
 // todo(vicb): optim for UnmodifiableListView (frozen arrays)
 check(collection) {
     this._reset();
     var record = this._itHead;
     var mayBeDirty = false;
     var index;
     var item;
     var itemTrackBy;
     if (isArray(collection)) {
         var list = collection;
         this._length = collection.length;
         for (index = 0; index < this._length; index++) {
             item = list[index];
             itemTrackBy = this._trackByFn(index, item);
             if (record === null || !looseIdentical(record.trackById, itemTrackBy)) {
                 record = this._mismatch(record, item, itemTrackBy, index);
                 mayBeDirty = true;
             }
             else {
                 if (mayBeDirty) {
                     // TODO(misko): can we limit this to duplicates only?
                     record = this._verifyReinsertion(record, item, itemTrackBy, index);
                 }
                 if (!looseIdentical(record.item, item))
                     this._addIdentityChange(record, item);
             }
             record = record._next;
         }
     }
     else {
         index = 0;
         iterateListLike(collection, (item) => {
             itemTrackBy = this._trackByFn(index, item);
             if (record === null || !looseIdentical(record.trackById, itemTrackBy)) {
                 record = this._mismatch(record, item, itemTrackBy, index);
                 mayBeDirty = true;
             }
             else {
                 if (mayBeDirty) {
                     // TODO(misko): can we limit this to duplicates only?
                     record = this._verifyReinsertion(record, item, itemTrackBy, index);
                 }
                 if (!looseIdentical(record.item, item))
                     this._addIdentityChange(record, item);
             }
             record = record._next;
             index++;
         });
         this._length = index;
     }
     this._truncate(record);
     this._collection = collection;
     return this.isDirty;
 }
 CompileIdentifierMetadata.prototype.toJson = function () {
     var value = lang_1.isArray(this.value) ? arrayToJson(this.value) : objToJson(this.value);
     return {
         // Note: Runtime type can't be serialized...
         'class': 'Identifier',
         'name': this.name,
         'moduleUrl': this.moduleUrl,
         'prefix': this.prefix,
         'constConstructor': this.constConstructor,
         'value': value
     };
 };
示例#21
0
 return providers.map(function (provider) {
     provider = di_1.resolveForwardRef(provider);
     if (lang_1.isArray(provider)) {
         return _this.getProvidersMetadata(provider);
     }
     else if (provider instanceof provider_1.Provider) {
         return _this.getProviderMetadata(provider);
     }
     else {
         return _this.getTypeMetadata(provider, null);
     }
 });
 return providers.map((provider) => {
     provider = resolveForwardRef(provider);
     if (isArray(provider)) {
         return this.getProvidersMetadata(provider);
     }
     else if (provider instanceof Provider) {
         return this.getProviderMetadata(provider);
     }
     else {
         return this.getTypeMetadata(provider, null);
     }
 });
示例#23
0
function _flattenStyleArr(arr, out) {
    for (var i = 0; i < arr.length; i++) {
        var entry = arr[i];
        if (isArray(entry)) {
            _flattenStyleArr(entry, out);
        }
        else {
            out.push(entry);
        }
    }
    return out;
}
function _flattenStyles(compId, styles, target) {
    for (var i = 0; i < styles.length; i++) {
        var style = styles[i];
        if (lang_1.isArray(style)) {
            _flattenStyles(compId, style, target);
        }
        else {
            style = lang_1.StringWrapper.replaceAll(style, COMPONENT_REGEX, compId);
            target.push(style);
        }
    }
    return target;
}
function iterateListLike(obj, fn) {
    if (lang_1.isArray(obj)) {
        for (var i = 0; i < obj.length; i++) {
            fn(obj[i]);
        }
    }
    else {
        var iterator = obj[lang_1.getSymbolIterator()]();
        var item;
        while (!((item = iterator.next()).done)) {
            fn(item.value);
        }
    }
}
示例#26
0
function flattenArray(source, target) {
    if (lang_1.isPresent(source)) {
        for (var i = 0; i < source.length; i++) {
            var item = source[i];
            if (lang_1.isArray(item)) {
                flattenArray(item, target);
            }
            else {
                target.push(item);
            }
        }
    }
    return target;
}
示例#27
0
function _extractToken(typeOrFunc, metadata /*any[] | any*/, params) {
    var depProps = [];
    var token = null;
    var optional = false;
    if (!lang_1.isArray(metadata)) {
        if (metadata instanceof metadata_1.InjectMetadata) {
            return _createDependency(metadata.token, optional, null, null, depProps);
        }
        else {
            return _createDependency(metadata, optional, null, null, depProps);
        }
    }
    var lowerBoundVisibility = null;
    var upperBoundVisibility = null;
    for (var i = 0; i < metadata.length; ++i) {
        var paramMetadata = metadata[i];
        if (paramMetadata instanceof lang_1.Type) {
            token = paramMetadata;
        }
        else if (paramMetadata instanceof metadata_1.InjectMetadata) {
            token = paramMetadata.token;
        }
        else if (paramMetadata instanceof metadata_1.OptionalMetadata) {
            optional = true;
        }
        else if (paramMetadata instanceof metadata_1.SelfMetadata) {
            upperBoundVisibility = paramMetadata;
        }
        else if (paramMetadata instanceof metadata_1.HostMetadata) {
            upperBoundVisibility = paramMetadata;
        }
        else if (paramMetadata instanceof metadata_1.SkipSelfMetadata) {
            lowerBoundVisibility = paramMetadata;
        }
        else if (paramMetadata instanceof metadata_1.DependencyMetadata) {
            if (lang_1.isPresent(paramMetadata.token)) {
                token = paramMetadata.token;
            }
            depProps.push(paramMetadata);
        }
    }
    token = forward_ref_1.resolveForwardRef(token);
    if (lang_1.isPresent(token)) {
        return _createDependency(token, optional, lowerBoundVisibility, upperBoundVisibility, depProps);
    }
    else {
        throw new reflective_exceptions_1.NoAnnotationError(typeOrFunc, params);
    }
}
 _createControl(controlConfig) {
     if (controlConfig instanceof modelModule.Control || controlConfig instanceof
         modelModule.ControlGroup || controlConfig instanceof
         modelModule.ControlArray) {
         return controlConfig;
     }
     else if (isArray(controlConfig)) {
         var value = ListWrapper.get(controlConfig, 0);
         var validator = controlConfig.length > 1 ? controlConfig[1] : null;
         return this.control(value, validator);
     }
     else {
         return this.control(controlConfig);
     }
 }
 FormBuilder.prototype._createControl = function (controlConfig) {
     if (controlConfig instanceof modelModule.Control ||
         controlConfig instanceof modelModule.ControlGroup ||
         controlConfig instanceof modelModule.ControlArray) {
         return controlConfig;
     }
     else if (lang_1.isArray(controlConfig)) {
         var value = controlConfig[0];
         var validator = controlConfig.length > 1 ? controlConfig[1] : null;
         var asyncValidator = controlConfig.length > 2 ? controlConfig[2] : null;
         return this.control(value, validator, asyncValidator);
     }
     else {
         return this.control(controlConfig);
     }
 };
示例#30
0
 _applyClasses(rawClassVal, isCleanup) {
     if (isPresent(rawClassVal)) {
         if (isArray(rawClassVal)) {
             rawClassVal.forEach(className => this._toggleClass(className, !isCleanup));
         }
         else if (rawClassVal instanceof Set) {
             rawClassVal.forEach(className => this._toggleClass(className, !isCleanup));
         }
         else {
             StringMapWrapper.forEach(rawClassVal, (expVal, className) => {
                 if (isPresent(expVal))
                     this._toggleClass(className, !isCleanup);
             });
         }
     }
 }