Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
emit(ref: Reference, context: ts.SourceFile, importMode: ImportMode): Expression|null {
// If the emitter has specified ForceNewImport, then LocalIdentifierStrategy should not use a
// local identifier at all, *except* in the source file where the node is actually declared.
if (importMode === ImportMode.ForceNewImport &&
getSourceFile(ref.node) !== getSourceFile(context)) {
return null;
}
// A Reference can have multiple identities in different files, so it may already have an
// Identifier in the requested context file.
const identifier = ref.getIdentityIn(context);
if (identifier !== null) {
return new WrappedNodeExpr(identifier);
} else {
return null;
}
}
}
internalType,
adjacentType,
bootstrap,
declarations,
exports,
imports,
containsForwardDecls,
id,
emitInline: false,
// TODO: to be implemented as a part of FW-1004.
schemas: [],
};
const rawProviders = ngModule.has('providers') ? ngModule.get('providers') ! : null;
const wrapperProviders = rawProviders !== null ?
new WrappedNodeExpr(
this.annotateForClosureCompiler ? wrapFunctionExpressionsInParens(rawProviders) :
rawProviders) :
null;
// At this point, only add the module's imports as the injectors' imports. Any exported modules
// are added during `resolve`, as we need scope information to be able to filter out directives
// and pipes from the module exports.
const injectorImports: WrappedNodeExpr[] = [];
if (ngModule.has('imports')) {
injectorImports.push(new WrappedNodeExpr(ngModule.get('imports') !));
}
if (this.routeAnalyzer !== null) {
this.routeAnalyzer.add(node.getSourceFile(), name, rawImports, rawExports, rawProviders);
}
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, node, `@${name} predicate cannot be interpreted`);
}
// Extract the read and descendants options.
let read: Expression|null = null;
// The default value for descendants is true for every decorator except @ContentChildren.
let descendants: boolean = name !== 'ContentChildren';
if (args.length === 2) {
const optionsExpr = unwrapExpression(args[1]);
if (!ts.isObjectLiteralExpression(optionsExpr)) {
throw new Error(`@${name} options must be an object literal`);
}
const options = reflectObjectLiteral(optionsExpr);
if (options.has('read')) {
read = new WrappedNodeExpr(options.get('read') !);
}
if (options.has('descendants')) {
const descendantsValue = evaluator.evaluate(options.get('descendants') !);
if (typeof descendantsValue !== 'boolean') {
throw new Error(`@${name} options.descendants must be a boolean`);
}
descendants = descendantsValue;
}
if (options.has('static')) {
const staticValue = evaluator.evaluate(options.get('static') !);
if (typeof staticValue !== 'boolean') {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, node, `@${name} options.static must be a boolean`);
}
styles = directive_1.parseFieldArrayValue(component, 'styles', this.reflector, this.checker);
}
var styleUrls = this._extractStyleUrls(component);
if (styleUrls !== null) {
if (styles === null) {
styles = [];
}
styles.push.apply(styles, tslib_1.__spread(styleUrls.map(function (styleUrl) { return _this.resourceLoader.load(styleUrl, containingFile); })));
}
var encapsulation = 0;
if (component.has('encapsulation')) {
encapsulation = parseInt(metadata_1.staticallyResolve(component.get('encapsulation'), this.reflector, this.checker));
}
var animations = null;
if (component.has('animations')) {
animations = new compiler_1.WrappedNodeExpr(component.get('animations'));
}
return {
analysis: {
meta: tslib_1.__assign({}, metadata, { template: template,
viewQueries: viewQueries,
encapsulation: encapsulation,
interpolation: interpolation, styles: styles || [],
// These will be replaced during the compilation step, after all `NgModule`s have been
// analyzed and the full compilation scope for the component can be realized.
pipes: EMPTY_MAP, directives: EMPTY_ARRAY, wrapDirectivesAndPipesInClosure: false, //
animations: animations,
viewProviders: viewProviders, i18nUseExternalIds: this.i18nUseExternalIds, relativeContextFilePath: relativeContextFilePath }),
metadataStmt: metadata_2.generateSetClassMetadataCall(node, this.reflector, this.isCore),
parsedTemplate: template.nodes,
},
typeCheck: true,
ctorDeps,
providedIn,
useExisting: new WrappedNodeExpr(meta.get('useExisting') !),
};
} else if (meta.has('useClass')) {
return {
name,
type,
typeArgumentCount,
ctorDeps,
providedIn,
useClass: new WrappedNodeExpr(meta.get('useClass') !), userDeps,
};
} else if (meta.has('useFactory')) {
// useFactory is special - the 'deps' property must be analyzed.
const factory = new WrappedNodeExpr(meta.get('useFactory') !);
return {
name,
type,
typeArgumentCount,
providedIn,
useFactory: factory, ctorDeps, userDeps,
};
} else {
if (strictCtorDeps) {
// Since use* was not provided, validate the deps according to strictCtorDeps.
validateConstructorDependencies(clazz, rawCtorDeps);
}
return {name, type, typeArgumentCount, providedIn, ctorDeps};
}
} else {
throw new FatalDiagnosticError(
export function wrapTypeReference(reflector: ReflectionHost, clazz: ClassDeclaration): R3Reference {
const dtsClass = reflector.getDtsDeclaration(clazz);
const value = new WrappedNodeExpr(clazz.name);
const type = dtsClass !== null && isNamedClassDeclaration(dtsClass) ?
new WrappedNodeExpr(dtsClass.name) :
value;
return {value, type};
}
function maybeUpdateDecorator(
dec: ts.Identifier, reflector: ReflectionHost, token?: ts.Expression): void {
const source = reflector.getImportOfIdentifier(dec);
if (source === null || source.from !== '@angular/core') {
return;
}
switch (source.name) {
case 'Inject':
if (token !== undefined) {
meta.token = new WrappedNodeExpr(token);
}
break;
case 'Optional':
meta.optional = true;
break;
case 'SkipSelf':
meta.skipSelf = true;
break;
case 'Self':
meta.self = true;
break;
}
}
function getDep(dep: ts.Expression, reflector: ReflectionHost): R3DependencyMetadata {
const meta: R3DependencyMetadata = {
token: new WrappedNodeExpr(dep),
host: false,
resolved: R3ResolvedDependencyType.Token,
optional: false,
self: false,
skipSelf: false,
};
function maybeUpdateDecorator(
dec: ts.Identifier, reflector: ReflectionHost, token?: ts.Expression): void {
const source = reflector.getImportOfIdentifier(dec);
if (source === null || source.from !== '@angular/core') {
return;
}
switch (source.name) {
case 'Inject':
if (token !== undefined) {
case 'CUSTOM_ELEMENTS_SCHEMA':
schemas.push(CUSTOM_ELEMENTS_SCHEMA);
break;
case 'NO_ERRORS_SCHEMA':
schemas.push(NO_ERRORS_SCHEMA);
break;
default:
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, rawExpr,
`'${schemaRef.debugName}' is not a valid NgModule schema`);
}
}
}
const id: Expression|null =
ngModule.has('id') ? new WrappedNodeExpr(ngModule.get('id') !) : null;
const valueContext = node.getSourceFile();
let typeContext = valueContext;
const typeNode = this.reflector.getDtsDeclaration(node);
if (typeNode !== null) {
typeContext = typeNode.getSourceFile();
}
const bootstrap =
bootstrapRefs.map(bootstrap => this._toR3Reference(bootstrap, valueContext, typeContext));
const declarations =
declarationRefs.map(decl => this._toR3Reference(decl, valueContext, typeContext));
const imports = importRefs.map(imp => this._toR3Reference(imp, valueContext, typeContext));
const exports = exportRefs.map(exp => this._toR3Reference(exp, valueContext, typeContext));
const isForwardReference = (ref: R3Reference) =>
function wrap(value) {
return new WrappedNodeExpr(value);
}
function isModuleWithProviders(value) {