<commit_before>'use strict';

/**
 * Requirements
 * @ignore
 */
const NodeTransformer = require('../NodeTransformer.js').NodeTransformer;
const ViewModelRepository = require('../../model/viewmodel/ViewModelRepository.js').ViewModelRepository;
const NodeList = require('../node/NodeList.js').NodeList;
const SetNode = require('../node/SetNode.js').SetNode;
const ExpressionNode = require('../node/ExpressionNode.js').ExpressionNode;
const ComplexVariableNode = require('../node/ComplexVariableNode.js').ComplexVariableNode;
const VariableNode = require('../node/VariableNode.js').VariableNode;
const synchronize = require('../../utils/synchronize.js');
const assertParameter = require('../../utils/assert.js').assertParameter;


/**
 * Globals
 */
let uniqueId = 1;


/**
 *
 */
class JspStaticModelTransformer extends NodeTransformer
{
    /**
     * @ignore
     */
    constructor(viewModelRepository)
    {
        super();

        //Check params
        assertParameter(this, 'viewModelRepository', viewModelRepository, true, ViewModelRepository);

        // Assign options
        this._viewModelRepository = viewModelRepository;
    }


    /**
     * @inheritDoc
     */
    static get injections()
    {
        return { 'parameters': [ViewModelRepository] };
    }


    /**
     * @inheritDoc
     */
    static get className()
    {
        return 'transformer/nodetransformer/JspStaticModelTransformer';
    }


    /**
     * @inheritDoc
     * @todo  support for extended sites is missing
     */
    transformNode(node, transformer, options)
    {
        // prepend call nodes with jsonLaoder when model is a string literal
        if (node.type === 'CallNode' &&
            node.parameters.getParameter('model'))
        {
            const model = node.parameters.getParameter('model');
            if (model.value.children.length === 1 &&
                model.value.children[0].type === 'LiteralNode' &&
                model.value.children[0].valueType === 'string')
            {
                // Generate a static json set
                const modelName = 'staticModel' + (uniqueId++);
                const modelPath = model.value.children[0].value;
                const viewModel = synchronize.execute(this._viewModelRepository, 'getByPath', [modelPath]);
                const jsonNode = new ComplexVariableNode(viewModel.data);
                const setNode = new SetNode(new VariableNode([modelName]), new ExpressionNode([jsonNode]));

                // Set model parameter to generated variable
                model.value = new ExpressionNode([new VariableNode([modelName])])

                // Add<commit_msg>fix(transformer): add check for value to static model transformer<commit_after>'use strict';

/**
 * Requirements
 * @ignore
 */
const NodeTransformer = require('../NodeTransformer.js').NodeTransformer;
const ViewModelRepository = require('../../model/viewmodel/ViewModelRepository.js').ViewModelRepository;
const NodeList = require('../node/NodeList.js').NodeList;
const SetNode = require('../node/SetNode.js').SetNode;
const ExpressionNode = require('../node/ExpressionNode.js').ExpressionNode;
const ComplexVariableNode = require('../node/ComplexVariableNode.js').ComplexVariableNode;
const VariableNode = require('../node/VariableNode.js').VariableNode;
const synchronize = require('../../utils/synchronize.js');
const assertParameter = require('../../utils/assert.js').assertParameter;


/**
 * Globals
 */
let uniqueId = 1;


/**
 *
 */
class JspStaticModelTransformer extends NodeTransformer
{
    /**
     * @ignore
     */
    constructor(viewModelRepository)
    {
        super();

        //Check params
        assertParameter(this, 'viewModelRepository', viewModelRepository, true, ViewModelRepository);

        // Assign options
        this._viewModelRepository = viewModelRepository;
    }


    /**
     * @inheritDoc
     */
    static get injections()
    {
        return { 'parameters': [ViewModelRepository] };
    }


    /**
     * @inheritDoc
     */
    static get className()
    {
        return 'transformer/nodetransformer/JspStaticModelTransformer';
    }


    /**
     * @inheritDoc
     * @todo  support for extended sites is missing
     */
    transformNode(node, transformer, options)
    {
        // prepend call nodes with jsonLaoder when model is a string literal
        if (node.type === 'CallNode' &&
            node.parameters.getParameter('model'))
        {
            const model = node.parameters.getParameter('model');
            if (model.value &&
                model.value.children.length === 1 &&
                model.value.children[0].type === 'LiteralNode' &&
                model.value.children[0].valueType === 'string')
            {
                // Generate a static json set
                const modelName = 'staticModel' + (uniqueId++);
                const modelPath = model.value.children[0].value;
                const viewModel = synchronize.execute(this._viewModelRepository, 'getByPath', [modelPath]);
                const jsonNode = new ComplexVariableNode(viewModel.data);
                const setNode = new SetNode(new VariableNode([modelName]), new ExpressionNode([jsonNode]));

                // Set model parameter to generated variable
                model.value = new ExpressionNode([new VariableNode([modelName])])

                // Add
{'fraction_non_alphanumeric': 0.12966747167007245, 'fraction_numerical': 0.001857700167193015, 'mean_word_length': 2.5235602094240837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4263440', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1350, 'n_words': 290}