Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// component exists, does not exist, stop.
let block: Block | undefined = await this.resolveBlock(dir, componentName);
if (!block) { return analysis; }
self.debug(`Analyzing ${componentName}. Got block for component.`);
// Add all transitive block dependencies
let localBlockNames: string[] = [];
block.eachBlockExport((name, refBlock) => {
analysis.addBlock(name, refBlock);
localBlockNames.push(name);
});
self.debug(`Analyzing ${componentName}. ${localBlockNames.length} blocks in scope: ${localBlockNames.join(", ")}.`);
let elementAnalyzer = new ElementAnalyzer(analysis, this.cssBlocksOptions);
traverse(ast, {
MustacheStatement(node: AST.MustacheStatement) {
const name = node.path.original;
if (!isEmberBuiltIn(name)) { return; }
elementCount++;
const atRootElement = (elementCount === 1);
const element = elementAnalyzer.analyze(node, atRootElement);
if (self.debug.enabled) self.debug(`{{${name}}} analyzed:`, element.class.forOptimizer(self.cssBlocksOptions).toString());
},
BlockStatement(node: AST.BlockStatement) {
const name = node.path.original;
if (!isEmberBuiltIn(name)) { return; }
elementCount++;
const atRootElement = (elementCount === 1);
const element = elementAnalyzer.analyze(node, atRootElement);
if (self.debug.enabled) self.debug(`{{#${name}}} analyzed:`, element.class.forOptimizer(self.cssBlocksOptions).toString());
exports.prepareProgramPaths = function (program, isComponent) {
var namespaces = createNamespaceStack();
// Global component namespace
if (isComponent) {
namespaces.push({ node: program, name: 'props' });
}
var eachStatementEntered = false;
syntax_1.traverse(program, {
// Process block statements
All: {
enter: function (node) {
if (node.type === 'Program' && eachStatementEntered) {
namespaces.push({ node: node });
eachStatementEntered = false;
}
if (isEachStatement(node)) {
eachStatementEntered = true;
}
},
exit: function (node) {
// Exit from namespace
if (namespaces.length > 0 && node === namespaces.head().node) {
namespaces.pop();
}
export function discoverTemplateDependencies(templateName: string, project: Project): TemplateDependencies {
let resolver = project.resolver;
let template = project.templateFor(templateName);
let ast = preprocess(template.string);
let usedComponents = new Set();
let hasComponentHelper = false;
traverse(ast, {
MustacheStatement(node) {
if (isComponentHelper(node)) {
hasComponentHelper = true;
}
},
ElementNode(node) {
let { tag } = node;
let specifier = resolver.identify(`template:${tag}`, template.specifier);
if (specifier) {
usedComponents.add(pathFromSpecifier(specifier));
}
}
});
processString(content) {
let parents = new Map();
let title = { level: Infinity, node: null, contents: null };
let body = [];
syntax.traverse(syntax.preprocess(content), {
Program(node) {
addContentNodes(parents, node, node.body);
},
ElementNode(node) {
addContentNodes(parents, node, node.children);
},
TextNode(node) {
let parent = parents.get(node);
if (!parent) { return; }
body.push(node.chars);
if (title.node === parent) {
title.contents.push(node.chars);
process(content: string): SymbolInformation[] {
let ast = preprocess(content);
let symbols: SymbolInformation[] = [];
traverse(ast, {
BlockStatement(node: any) {
if (node.program.blockParams.length === 0) return;
node.program.blockParams.forEach((blockParam: string) => {
let symbol = SymbolInformation.create(blockParam, SymbolKind.Variable, toLSRange(node.loc));
symbols.push(symbol);
});
}
});
return symbols;
}
}