ngast
Version:
Parsing tools for Angular. The project is an abstraction over the Angular compiler which provides friendly interface.
124 lines • 5.17 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Symbol } from './symbol';
import { assertDeps, exists } from './utils';
import { parseCss } from '../css-parser/parse-css';
import { WrappedNodeExpr } from '@angular/compiler';
import { TransformTemplateVisitor } from './template-transform.visitor';
var ComponentSymbol = /** @class */ (function (_super) {
__extends(ComponentSymbol, _super);
function ComponentSymbol() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.annotation = 'Component';
return _this;
}
ComponentSymbol.prototype.assertScope = function () {
var scope = this.getScope();
if (scope === null) {
throw new Error("Could not find scope for component " + this.name + ". Check [ComponentSymbol].diagnostics");
}
else {
return scope;
}
};
Object.defineProperty(ComponentSymbol.prototype, "deps", {
/** @internal */
get: function () {
var _a;
return (_a = this.analysis) === null || _a === void 0 ? void 0 : _a.meta.deps;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ComponentSymbol.prototype, "metadata", {
get: function () {
var _a;
var meta = (_a = this.analysis) === null || _a === void 0 ? void 0 : _a.meta;
if (!meta) {
return null;
}
return {
exportAs: meta.exportAs,
changeDetection: meta.changeDetection,
selector: meta.selector,
inputs: meta.inputs,
outputs: meta.outputs
};
},
enumerable: false,
configurable: true
});
/** Get the module scope of the component */
ComponentSymbol.prototype.getScope = function () {
this.ensureAnalysis();
return this.workspace.scopeRegistry.getScopeForComponent(this.node);
};
/** Return the list of available selectors for the template */
ComponentSymbol.prototype.getSelectorScope = function () {
var scope = this.assertScope();
if (!scope) {
return [];
}
else {
return scope.compilation.directives.map(function (d) { return d.selector; })
.filter(exists)
.map(function (selector) { return selector.split(',').map(function (s) { return s.trim(); }); })
.flat();
}
};
/** Return the list of pipe available for the template */
ComponentSymbol.prototype.getPipeScope = function () {
var _a;
var scope = this.assertScope();
return (_a = scope === null || scope === void 0 ? void 0 : scope.compilation.pipes.map(function (p) { return p.name; })) !== null && _a !== void 0 ? _a : [];
};
/**
* Return class & factory providers specific to this class
* @note only providers specified in the `provider` fields of the component will be returned (not the module).
*/
ComponentSymbol.prototype.getProviders = function () {
var _a;
var providers = (_a = this.analysis) === null || _a === void 0 ? void 0 : _a.meta.providers;
if (providers instanceof WrappedNodeExpr) {
return this.workspace.providerRegistry.getAllProviders(providers.node);
}
else {
return [];
}
};
/** Return dependencies injected in the constructor of the component */
ComponentSymbol.prototype.getDependencies = function () {
var _this = this;
assertDeps(this.deps, this.name);
return this.deps.map(function (dep) { return _this.workspace.findSymbol(dep.token, _this.path); }).filter(exists);
};
/** The Style AST provided by ngast */
ComponentSymbol.prototype.getStylesAst = function () {
var _a;
return (_a = this.analysis) === null || _a === void 0 ? void 0 : _a.meta.styles.map(function (s) { return parseCss(s); });
};
/** The Template AST provided by Ivy */
ComponentSymbol.prototype.getTemplateAst = function () {
var _a;
var scope = this.getScope();
if (scope === null) {
return null;
}
var visitor = new TransformTemplateVisitor(scope, this.workspace);
return (_a = this.analysis) === null || _a === void 0 ? void 0 : _a.meta.template.nodes.map(function (node) { return node.visit(visitor); });
};
return ComponentSymbol;
}(Symbol));
export { ComponentSymbol };
//# sourceMappingURL=component.symbol.js.map