source: trip-planner-front/node_modules/@angular/cdk/schematics/update-tool/component-resource-collector.mjs@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 21.8 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.ComponentResourceCollector = void 0;
11const path_1 = require("path");
12const ts = require("typescript");
13const decorators_1 = require("./utils/decorators");
14const functions_1 = require("./utils/functions");
15const line_mappings_1 = require("./utils/line-mappings");
16const property_name_1 = require("./utils/property-name");
17/**
18 * Collector that can be used to find Angular templates and stylesheets referenced within
19 * given TypeScript source files (inline or external referenced files)
20 */
21class ComponentResourceCollector {
22 constructor(typeChecker, _fileSystem) {
23 this.typeChecker = typeChecker;
24 this._fileSystem = _fileSystem;
25 this.resolvedTemplates = [];
26 this.resolvedStylesheets = [];
27 }
28 visitNode(node) {
29 if (node.kind === ts.SyntaxKind.ClassDeclaration) {
30 this._visitClassDeclaration(node);
31 }
32 }
33 _visitClassDeclaration(node) {
34 if (!node.decorators || !node.decorators.length) {
35 return;
36 }
37 const ngDecorators = decorators_1.getAngularDecorators(this.typeChecker, node.decorators);
38 const componentDecorator = ngDecorators.find(dec => dec.name === 'Component');
39 // In case no "@Component" decorator could be found on the current class, skip.
40 if (!componentDecorator) {
41 return;
42 }
43 const decoratorCall = componentDecorator.node.expression;
44 // In case the component decorator call is not valid, skip this class declaration.
45 if (decoratorCall.arguments.length !== 1) {
46 return;
47 }
48 const componentMetadata = functions_1.unwrapExpression(decoratorCall.arguments[0]);
49 // Ensure that the component metadata is an object literal expression.
50 if (!ts.isObjectLiteralExpression(componentMetadata)) {
51 return;
52 }
53 const sourceFile = node.getSourceFile();
54 const filePath = this._fileSystem.resolve(sourceFile.fileName);
55 const sourceFileDirPath = path_1.dirname(sourceFile.fileName);
56 // Walk through all component metadata properties and determine the referenced
57 // HTML templates (either external or inline)
58 componentMetadata.properties.forEach(property => {
59 if (!ts.isPropertyAssignment(property)) {
60 return;
61 }
62 const propertyName = property_name_1.getPropertyNameText(property.name);
63 if (propertyName === 'styles' && ts.isArrayLiteralExpression(property.initializer)) {
64 property.initializer.elements.forEach(el => {
65 if (ts.isStringLiteralLike(el)) {
66 // Need to add an offset of one to the start because the template quotes are
67 // not part of the template content.
68 const templateStartIdx = el.getStart() + 1;
69 this.resolvedStylesheets.push({
70 filePath,
71 container: node,
72 content: el.text,
73 inline: true,
74 start: templateStartIdx,
75 getCharacterAndLineOfPosition: pos => ts.getLineAndCharacterOfPosition(sourceFile, pos + templateStartIdx),
76 });
77 }
78 });
79 }
80 // In case there is an inline template specified, ensure that the value is statically
81 // analyzable by checking if the initializer is a string literal-like node.
82 if (propertyName === 'template' && ts.isStringLiteralLike(property.initializer)) {
83 // Need to add an offset of one to the start because the template quotes are
84 // not part of the template content.
85 const templateStartIdx = property.initializer.getStart() + 1;
86 this.resolvedTemplates.push({
87 filePath,
88 container: node,
89 content: property.initializer.text,
90 inline: true,
91 start: templateStartIdx,
92 getCharacterAndLineOfPosition: pos => ts.getLineAndCharacterOfPosition(sourceFile, pos + templateStartIdx)
93 });
94 }
95 if (propertyName === 'styleUrls' && ts.isArrayLiteralExpression(property.initializer)) {
96 property.initializer.elements.forEach(el => {
97 if (ts.isStringLiteralLike(el)) {
98 const stylesheetPath = this._fileSystem.resolve(sourceFileDirPath, el.text);
99 const stylesheet = this.resolveExternalStylesheet(stylesheetPath, node);
100 if (stylesheet) {
101 this.resolvedStylesheets.push(stylesheet);
102 }
103 }
104 });
105 }
106 if (propertyName === 'templateUrl' && ts.isStringLiteralLike(property.initializer)) {
107 const templateUrl = property.initializer.text;
108 const templatePath = this._fileSystem.resolve(sourceFileDirPath, templateUrl);
109 // In case the template does not exist in the file system, skip this
110 // external template.
111 if (!this._fileSystem.fileExists(templatePath)) {
112 return;
113 }
114 const fileContent = this._fileSystem.read(templatePath);
115 if (fileContent) {
116 const lineStartsMap = line_mappings_1.computeLineStartsMap(fileContent);
117 this.resolvedTemplates.push({
118 filePath: templatePath,
119 container: node,
120 content: fileContent,
121 inline: false,
122 start: 0,
123 getCharacterAndLineOfPosition: p => line_mappings_1.getLineAndCharacterFromPosition(lineStartsMap, p),
124 });
125 }
126 }
127 });
128 }
129 /** Resolves an external stylesheet by reading its content and computing line mappings. */
130 resolveExternalStylesheet(filePath, container) {
131 const fileContent = this._fileSystem.read(filePath);
132 if (!fileContent) {
133 return null;
134 }
135 const lineStartsMap = line_mappings_1.computeLineStartsMap(fileContent);
136 return {
137 filePath: filePath,
138 container: container,
139 content: fileContent,
140 inline: false,
141 start: 0,
142 getCharacterAndLineOfPosition: pos => line_mappings_1.getLineAndCharacterFromPosition(lineStartsMap, pos),
143 };
144 }
145}
146exports.ComponentResourceCollector = ComponentResourceCollector;
147//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9uZW50LXJlc291cmNlLWNvbGxlY3Rvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvc2NoZW1hdGljcy91cGRhdGUtdG9vbC9jb21wb25lbnQtcmVzb3VyY2UtY29sbGVjdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7OztBQUVILCtCQUE2QjtBQUM3QixpQ0FBaUM7QUFFakMsbURBQXdEO0FBQ3hELGlEQUFtRDtBQUNuRCx5REFJK0I7QUFDL0IseURBQTBEO0FBcUIxRDs7O0dBR0c7QUFDSCxNQUFhLDBCQUEwQjtJQUlyQyxZQUFtQixXQUEyQixFQUFVLFdBQXVCO1FBQTVELGdCQUFXLEdBQVgsV0FBVyxDQUFnQjtRQUFVLGdCQUFXLEdBQVgsV0FBVyxDQUFZO1F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waW5ncy4gKi9cbiAgcmVzb2x2ZUV4dGVybmFsU3R5bGVzaGVldChmaWxlUGF0aDogV29ya3NwYWNlUGF0aCwgY29udGFpbmVyOiB0cy5DbGFzc0RlY2xhcmF0aW9ufG51bGwpOlxuICAgICAgUmVzb2x2ZWRSZXNvdXJjZXxudWxsIHtcbiAgICBjb25zdCBmaWxlQ29udGVudCA9IHRoaXMuX2ZpbGVTeXN0ZW0ucmVhZChmaWxlUGF0aCk7XG5cbiAgICBpZiAoIWZpbGVDb250ZW50KSB7XG4gICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG5cbiAgICBjb25zdCBsaW5lU3RhcnRzTWFwID0gY29tcHV0ZUxpbmVTdGFydHNNYXAoZmlsZUNvbnRlbnQpO1xuXG4gICAgcmV0dXJuIHtcbiAgICAgIGZpbGVQYXRoOiBmaWxlUGF0aCxcbiAgICAgIGNvbnRhaW5lcjogY29udGFpbmVyLFxuICAgICAgY29udGVudDogZmlsZUNvbnRlbnQsXG4gICAgICBpbmxpbmU6IGZhbHNlLFxuICAgICAgc3RhcnQ6IDAsXG4gICAgICBnZXRDaGFyYWN0ZXJBbmRMaW5lT2ZQb3NpdGlvbjogcG9zID0+IGdldExpbmVBbmRDaGFyYWN0ZXJGcm9tUG9zaXRpb24obGluZVN0YXJ0c01hcCwgcG9zKSxcbiAgICB9O1xuICB9XG59XG4iXX0=
Note: See TracBrowser for help on using the repository browser.