.forEach((node) => { const key = _getContentOfKeyLiteral(node.name); if (key == 'templateUrl') { const resourcePath = _getResourceRequest(node.initializer, sourceFile); const requireCall = _createRequireCall(resourcePath); const propAssign = ts.createPropertyAssignment('template', requireCall); replacements.push({ resourcePaths: [resourcePath], replaceNodeOperation: new interfaces_1.ReplaceNodeOperation(sourceFile, node, propAssign), }); } else if (key == 'styleUrls') { const arr = ast_helpers_1.collectDeepNodes(node, ts.SyntaxKind.ArrayLiteralExpression); if (!arr || arr.length == 0 || arr[0].elements.length == 0) { return; } const stylePaths = arr[0].elements.map((element) => { return _getResourceRequest(element, sourceFile); }); const requireArray = ts.createArrayLiteral(stylePaths.map((path) => _createRequireCall(path))); const propAssign = ts.createPropertyAssignment('styles', requireArray); replacements.push({ resourcePaths: stylePaths, replaceNodeOperation: new interfaces_1.ReplaceNodeOperation(sourceFile, node, propAssign), }); } });
/** * Convert a reflected decorator to metadata. */ function decoratorToMetadata(decorator) { // Decorators have a type. var properties = [ ts.createPropertyAssignment('type', ts.updateIdentifier(decorator.identifier)), ]; // Sometimes they have arguments. if (decorator.args !== null && decorator.args.length > 0) { var args = decorator.args.map(function (arg) { return ts.getMutableClone(arg); }); properties.push(ts.createPropertyAssignment('args', ts.createArrayLiteral(args))); } return ts.createObjectLiteral(properties, true); }
const lazyModuleObjectLiteral = ts.createObjectLiteral(modules.map((mod, idx) => { let [modulePath, moduleName] = mod.loadChildrenString.split('#'); if (modulePath.match(/\.ngfactory/)) { modulePath = modulePath.replace('.ngfactory', ''); moduleName = moduleName.replace('NgFactory', ''); } return ts.createPropertyAssignment(ts.createLiteral(`${modulePath}#${moduleName}`), ts.createPropertyAccess(ts.createIdentifier(`__lazy_${idx}__`), mod.moduleName)); }));
/** * For each property in the object literal, if it's templateUrl or styleUrls, replace it * with content. * @param node the arguments to @Component() or args property of decorators: [{type:Component}] * @param loader provides access to the loadResource method of the host * @returns updated arguments */ function updateComponentProperties(args, loader) { if (args.length !== 1) { // User should have gotten a type-check error because @Component takes one argument return args; } var componentArg = args[0]; if (!ts.isObjectLiteralExpression(componentArg)) { // User should have gotten a type-check error because @Component takes an object literal // argument return args; } var newProperties = []; var newStyleExprs = []; componentArg.properties.forEach(function (prop) { if (!ts.isPropertyAssignment(prop) || ts.isComputedPropertyName(prop.name)) { newProperties.push(prop); return; } switch (prop.name.text) { case 'styles': if (!ts.isArrayLiteralExpression(prop.initializer)) { throw new Error('styles takes an array argument'); } newStyleExprs.push.apply(newStyleExprs, tslib_1.__spread(prop.initializer.elements)); break; case 'styleUrls': if (!ts.isArrayLiteralExpression(prop.initializer)) { throw new Error('styleUrls takes an array argument'); } newStyleExprs.push.apply(newStyleExprs, tslib_1.__spread(prop.initializer.elements.map(function (expr) { if (!ts.isStringLiteral(expr) && !ts.isNoSubstitutionTemplateLiteral(expr)) { throw new Error('Can only accept string literal arguments to styleUrls. ' + PRECONDITIONS_TEXT); } var styles = loader.get(expr.text); return ts.createLiteral(styles); }))); break; case 'templateUrl': if (!ts.isStringLiteral(prop.initializer) && !ts.isNoSubstitutionTemplateLiteral(prop.initializer)) { throw new Error('Can only accept a string literal argument to templateUrl. ' + PRECONDITIONS_TEXT); } var template = loader.get(prop.initializer.text); newProperties.push(ts.updatePropertyAssignment(prop, ts.createIdentifier('template'), ts.createLiteral(template))); break; default: newProperties.push(prop); } }); // Add the non-inline styles if (newStyleExprs.length > 0) { var newStyles = ts.createPropertyAssignment(ts.createIdentifier('styles'), ts.createArrayLiteral(newStyleExprs)); newProperties.push(newStyles); } return ts.createNodeArray([ts.updateObjectLiteral(componentArg, newProperties)]); }
var routerModuleFFR = function routerModuleFFR(ref, args) { if (!isMethodNodeReference(ref) || !ts.isClassDeclaration(ref.node.parent)) { return null; } else if (ref.bestGuessOwningModule === null || ref.bestGuessOwningModule.specifier !== '@angular/router') { return null; } else if (ref.node.parent.name === undefined || ref.node.parent.name.text !== 'RouterModule') { return null; } else if (!ts.isIdentifier(ref.node.name) || (ref.node.name.text !== 'forRoot' && ref.node.name.text !== 'forChild')) { return null; } var routes = args[0]; return ts.createObjectLiteral([ ts.createPropertyAssignment(ROUTES_MARKER, ts.createTrue()), ts.createPropertyAssignment('routes', routes), ]); };
return this.record(expr, ts.createObjectLiteral(expr.entries.map(function (entry) { return ts.createPropertyAssignment(entry.quoted || !_VALID_IDENTIFIER_RE.test(entry.key) ? ts.createLiteral(entry.key) : entry.key, entry.value.visitExpression(_this, null)); })));
var properties = ast.keys.map(function (_a, idx) { var key = _a.key; var value = astToTypescript(ast.values[idx], maybeResolve, config); return ts.createPropertyAssignment(ts.createStringLiteral(key), value); });
/** * Convert a reflected class member to metadata. */ function classMemberToMetadata(name, decorators, isCore) { var ngDecorators = decorators.filter(function (dec) { return isAngularDecorator(dec, isCore); }).map(decoratorToMetadata); var decoratorMeta = ts.createArrayLiteral(ngDecorators); return ts.createPropertyAssignment(name, decoratorMeta); }