Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ctorDeps: ctorDeps,
providedIn: providedIn,
useClass: new compiler_1.WrappedNodeExpr(meta.get('useClass')), userDeps: userDeps
};
}
else if (meta.has('useFactory')) {
// useFactory is special - the 'deps' property must be analyzed.
var factory = new compiler_1.WrappedNodeExpr(meta.get('useFactory'));
return { name: name, type: type, typeArgumentCount: typeArgumentCount, providedIn: providedIn, useFactory: factory, ctorDeps: ctorDeps, userDeps: userDeps };
}
else {
return { name: name, type: type, typeArgumentCount: typeArgumentCount, providedIn: providedIn, ctorDeps: ctorDeps };
}
}
else {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.args[2], 'Too many arguments to @Injectable');
}
}
function getDep(dep, reflector) {
// transport references from one location to another. This is the problem that lowering
// used to solve - if this restriction proves too undesirable we can re-implement lowering.
if (!ts.isObjectLiteralExpression(metaNode)) {
throw new Error("In Ivy, decorator metadata must be inline.");
}
// Resolve the fields of the literal into a map of field name to expression.
var meta = metadata_1.reflectObjectLiteral(metaNode);
var providedIn = new compiler_1.LiteralExpr(null);
if (meta.has('providedIn')) {
providedIn = new compiler_1.WrappedNodeExpr(meta.get('providedIn'));
}
var userDeps = undefined;
if ((meta.has('useClass') || meta.has('useFactory')) && meta.has('deps')) {
var depsExpr = meta.get('deps');
if (!ts.isArrayLiteralExpression(depsExpr)) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_NOT_LITERAL, depsExpr, "In Ivy, deps metadata must be an inline array.");
}
if (depsExpr.elements.length > 0) {
throw new Error("deps not yet supported");
}
userDeps = depsExpr.elements.map(function (dep) { return getDep(dep, reflector); });
}
if (meta.has('useValue')) {
return {
name: name,
type: type,
typeArgumentCount: typeArgumentCount,
ctorDeps: ctorDeps,
providedIn: providedIn,
useValue: new compiler_1.WrappedNodeExpr(meta.get('useValue'))
};
}
function extractDirectiveMetadata(clazz, decorator, checker, reflector, isCore, defaultSelector) {
if (defaultSelector === void 0) { defaultSelector = null; }
if (decorator.args === null || decorator.args.length !== 1) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.node, "Incorrect number of arguments to @" + decorator.name + " decorator");
}
var meta = util_1.unwrapExpression(decorator.args[0]);
if (!ts.isObjectLiteralExpression(meta)) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, meta, "@" + decorator.name + " argument must be literal.");
}
var directive = metadata_1.reflectObjectLiteral(meta);
if (directive.has('jit')) {
// The only allowed value is true, so there's no need to expand further.
return undefined;
}
var members = reflector.getMembersOfClass(clazz);
// Precompute a list of ts.ClassElements that have decorators. This includes things like @Input,
// @Output, @HostBinding, etc.
var decoratedElements = members.filter(function (member) { return !member.isStatic && member.decorators !== null; });
var coreModule = isCore ? undefined : '@angular/core';
// Construct the map of inputs both from the @Directive/@Component
resolvedList.forEach(function (entry, idx) {
// Unwrap ModuleWithProviders for modules that are locally declared (and thus static
// resolution was able to descend into the function and return an object literal, a Map).
if (entry instanceof Map && entry.has('ngModule')) {
entry = entry.get('ngModule');
}
if (Array.isArray(entry)) {
// Recurse into nested arrays.
refList.push.apply(refList, tslib_1.__spread(_this.resolveTypeList(expr, entry, name)));
}
else if (isDeclarationReference(entry)) {
if (!entry.expressable) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, expr, "One entry in " + name + " is not a type");
}
else if (!_this.reflector.isClass(entry.node)) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, entry.node, "Entry is not a type, but is used as such in " + name + " array");
}
refList.push(entry);
}
else {
// TODO(alxhub): expand ModuleWithProviders.
throw new Error("Value at position " + idx + " in " + name + " array is not a reference: " + entry);
}
});
return refList;
ComponentDecoratorHandler.prototype._resolveLiteral = function (decorator) {
if (this.literalCache.has(decorator)) {
return this.literalCache.get(decorator);
}
if (decorator.args === null || decorator.args.length !== 1) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.node, "Incorrect number of arguments to @Component decorator");
}
var meta = util_1.unwrapExpression(decorator.args[0]);
if (!ts.isObjectLiteralExpression(meta)) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, meta, "Decorator argument must be literal.");
}
this.literalCache.set(decorator, meta);
return meta;
};
ComponentDecoratorHandler.prototype._extractStyleUrls = function (component) {
function extractInjectableMetadata(clazz, decorator, reflector, isCore) {
if (clazz.name === undefined) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ON_ANONYMOUS_CLASS, decorator.node, "@Injectable on anonymous class");
}
var name = clazz.name.text;
var type = new compiler_1.WrappedNodeExpr(clazz.name);
var ctorDeps = util_1.getConstructorDependencies(clazz, reflector, isCore);
var typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
if (decorator.args === null) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_NOT_CALLED, decorator.node, '@Injectable must be called');
}
if (decorator.args.length === 0) {
return {
name: name,
type: type,
typeArgumentCount: typeArgumentCount,
providedIn: new compiler_1.LiteralExpr(null), ctorDeps: ctorDeps,
};
}
decorators.forEach(function (decorator) {
var eventName = member.name;
var args = [];
if (decorator.args !== null && decorator.args.length > 0) {
if (decorator.args.length > 2) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.args[2], "@HostListener() can have at most two arguments");
}
var resolved = metadata_1.staticallyResolve(decorator.args[0], reflector, checker);
if (typeof resolved !== 'string') {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[0], "@HostListener()'s event name argument must be a string");
}
eventName = resolved;
if (decorator.args.length === 2) {
var resolvedArgs = metadata_1.staticallyResolve(decorator.args[1], reflector, checker);
if (!isStringArrayOrDie(resolvedArgs, '@HostListener.args')) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[1], "@HostListener second argument must be a string array");
}
args = resolvedArgs;
}
}
listeners[eventName] = member.name + "(" + args.join(',') + ")";
});
PipeDecoratorHandler.prototype.analyze = function (clazz, decorator) {
if (clazz.name === undefined) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ON_ANONYMOUS_CLASS, clazz, "@Pipes must have names");
}
var name = clazz.name.text;
var type = new compiler_1.WrappedNodeExpr(clazz.name);
if (decorator.args === null) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_NOT_CALLED, decorator.node, "@Pipe must be called");
}
if (decorator.args.length !== 1) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.node, '@Pipe must have exactly one argument');
}
var meta = util_1.unwrapExpression(decorator.args[0]);
if (!ts.isObjectLiteralExpression(meta)) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, meta, '@Pipe must have a literal argument');
}
var pipe = metadata_1.reflectObjectLiteral(meta);
if (!pipe.has('name')) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.PIPE_MISSING_NAME, meta, "@Pipe decorator is missing name field");
}
var pipeNameExpr = pipe.get('name');
var pipeName = metadata_1.staticallyResolve(pipeNameExpr, this.reflector, this.checker);
if (typeof pipeName !== 'string') {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, pipeNameExpr, "@Pipe.name must be a string");
}
this.scopeRegistry.registerPipe(clazz, pipeName);
var pure = true;
if (pipe.has('pure')) {
var expr = pipe.get('pure');
var pureValue = metadata_1.staticallyResolve(expr, this.reflector, this.checker);
if (typeof pureValue !== 'boolean') {
decorators.forEach(function (decorator) {
var eventName = member.name;
var args = [];
if (decorator.args !== null && decorator.args.length > 0) {
if (decorator.args.length > 2) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.args[2], "@HostListener() can have at most two arguments");
}
var resolved = metadata_1.staticallyResolve(decorator.args[0], reflector, checker);
if (typeof resolved !== 'string') {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[0], "@HostListener()'s event name argument must be a string");
}
eventName = resolved;
if (decorator.args.length === 2) {
var resolvedArgs = metadata_1.staticallyResolve(decorator.args[1], reflector, checker);
if (!isStringArrayOrDie(resolvedArgs, '@HostListener.args')) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[1], "@HostListener second argument must be a string array");
}
args = resolvedArgs;
}
}
listeners[eventName] = member.name + "(" + args.join(',') + ")";
});
});
decorators.forEach(function (decorator) {
var eventName = member.name;
var args = [];
if (decorator.args !== null && decorator.args.length > 0) {
if (decorator.args.length > 2) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, decorator.args[2], "@HostListener() can have at most two arguments");
}
var resolved = metadata_1.staticallyResolve(decorator.args[0], reflector, checker);
if (typeof resolved !== 'string') {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[0], "@HostListener()'s event name argument must be a string");
}
eventName = resolved;
if (decorator.args.length === 2) {
var resolvedArgs = metadata_1.staticallyResolve(decorator.args[1], reflector, checker);
if (!isStringArrayOrDie(resolvedArgs, '@HostListener.args')) {
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_HAS_WRONG_TYPE, decorator.args[1], "@HostListener second argument must be a string array");
}
args = resolvedArgs;
}
}
listeners[eventName] = member.name + "(" + args.join(',') + ")";
});
});