<commit_before>/// <reference path="../../typings/tsd.d.ts" />

import * as path from 'path';
import * as fs from 'fs';
import * as ts from 'typescript';
import {logger} from '../logger';

let q = require('q');


export namespace Crawler {
    
    interface NodeObject {
        pos: Number;
        end: Number;
        text: string;
        initializer: {
            elements: NodeObject[]
        };
        name?: {text: string};
        expression?: NodeObject;
        arguments?: NodeObject[];
        properties?: any[];
        parserContextFlags?: Number;
        Component?: String;
    }
    
    interface Deps {
        name: string;
        file: string;
        directives: string[];
        providers: string[];
    }
    
    export class Dependencies {
        
        private files: string[];
        private program: ts.Program;
        private engine: any;
        
        constructor(file: string[]) {
            this.files = file;
            this.program = ts.createProgram(this.files, {
                target: ts.ScriptTarget.ES5, 
                module: ts.ModuleKind.CommonJS
            });
            
        }
        
        getDependencies() {
            let links: Deps[] = [];
            this.program.getSourceFiles().map((file) => {
                
                let filePath = file.fileName;
                
                if(filePath.lastIndexOf('.d.ts') === -1) {
                    logger.info('parsing      : ', filePath);
                    this.getSourceFileDecorators(file, links);
                }
                else {
                    logger.warn('ignoring tsd : ', filePath);
                }
                
                return links;
                
            });
            
            return links;
        }
        
        
        private getSourceFileDecorators(srcFile: ts.SourceFile, rawDecorators: Deps[]): void {
            ts.forEachChild(srcFile, (node: ts.Node) => {
        
                if(node.decorators) {
                    let filterByComponent = (node) => node.expression.expression.text === 'Component';
                    let getComponents = (node) => node.expression.arguments.pop();
                    let getProps = (nodes) => nodes.properties;
                    let visitNode = (props, index) => {
                        
                        let componentName = this.getComponentName(node);
                        let component: Deps = {
                            name: componentName,
                            file: srcFile.fileName,
                            directives: this.getComponentDirectives(props),
                            providers: this.getComponentProviders(props)
                        };
                        
                        rawDecorators.push(component);<commit_msg>try to match Components and Views decorators<commit_after>/// <reference path="../../typings/tsd.d.ts" />

import * as path from 'path';
import * as fs from 'fs';
import * as ts from 'typescript';
import {logger} from '../logger';

let q = require('q');


export namespace Crawler {
    
    interface NodeObject {
        pos: Number;
        end: Number;
        text: string;
        initializer: {
            elements: NodeObject[]
        };
        name?: {text: string};
        expression?: NodeObject;
        arguments?: NodeObject[];
        properties?: any[];
        parserContextFlags?: Number;
        Component?: String;
    }
    
    interface Deps {
        name: string;
        file: string;
        directives: string[];
        providers: string[];
    }
    
    export class Dependencies {
        
        private files: string[];
        private program: ts.Program;
        private engine: any;
        
        constructor(file: string[]) {
            this.files = file;
            this.program = ts.createProgram(this.files, {
                target: ts.ScriptTarget.ES5, 
                module: ts.ModuleKind.CommonJS
            });
            
        }
        
        getDependencies() {
            let links: Deps[] = [];
            this.program.getSourceFiles().map((file) => {
                
                let filePath = file.fileName;
                
                if(filePath.lastIndexOf('.d.ts') === -1) {
                    logger.info('parsing', filePath);
                    this.getSourceFileDecorators(file, links);
                }
                else {
                    logger.warn('ignoring tsd', filePath);
                }
                
                return links;
                
            });
            
            return links;
        }
        
        
        private getSourceFileDecorators(srcFile: ts.SourceFile, rawDecorators: Deps[]): void {
            ts.forEachChild(srcFile, (node: ts.Node) => {
        
                if(node.decorators) {
                    let filterByComponent = (node) => /(Component|View)/.test(node.expression.expression.text);
                    let getComponents = (node) => node.expression.arguments.pop();
                    let getProps = (nodes) => nodes.properties;
                    let visitNode = (props, index) => {
                        
                        let componentName = this.getComponentName(node);
                        let component: Deps = {
                            name: componentName,
                            file: srcFile.fileName,
                            directives: this.getComponentDirectives(props),
                            providers: this.getComponentProviders(props)
                        };
                        
                        rawDecorators.push(component);
{'fraction_non_alphanumeric': 0.10482879719051799, 'fraction_numerical': 0.0007023705004389816, 'mean_word_length': 1.2258694802657288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '942685', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1357, 'n_words': 300}