123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import * as estraverse from 'estraverse';
- import { IProgramNode } from "../interfaces/nodes/IProgramNode";
- import { ITreeNode } from "../interfaces/nodes/ITreeNode";
- import { Node } from './Node';
- export class UnicodeArrayRotateFunctionCallNode extends Node {
- /**
- * @type {ITreeNode}
- */
- private astTree: ITreeNode;
- /**
- * @type {string}
- */
- private unicodeArrayName: string;
- /**
- * @type {number}
- */
- private unicodeArrayRotateValue: number;
- /**
- * @param {string}
- */
- private unicodeArrayRotateFunctionName: string;
- /**
- * @type {ITreeNode}
- */
- protected node: ITreeNode;
- /**
- * @param astTree
- * @param unicodeArrayRotateFunctionName
- * @param unicodeArrayName
- * @param unicodeArrayRotateValue
- */
- constructor (
- astTree: ITreeNode,
- unicodeArrayRotateFunctionName: string,
- unicodeArrayName: string,
- unicodeArrayRotateValue: number
- ) {
- super();
- this.astTree = astTree;
- this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
- this.unicodeArrayName = unicodeArrayName;
- this.unicodeArrayRotateValue = unicodeArrayRotateValue;
- this.node = this.getNodeStructure();
- }
- public appendNode (): void {
- estraverse.replace(this.astTree, {
- leave: (node: ITreeNode, parent: ITreeNode) => {
- switch (node.type) {
- case 'Program':
- (<IProgramNode>node).body.unshift(this.getNode());
- break;
- }
- }
- });
- }
- /**
- * @returns any
- */
- protected getNodeStructure (): any {
- return {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'CallExpression',
- 'callee': {
- 'type': 'Identifier',
- 'name': this.unicodeArrayRotateFunctionName
- },
- 'arguments': [
- {
- 'type': 'Identifier',
- 'name': this.unicodeArrayName
- },
- {
- 'type': 'Literal',
- 'value': this.unicodeArrayRotateValue,
- 'raw': `'${this.unicodeArrayRotateValue}'`
- },
- {
- 'type': 'Literal',
- 'value': true,
- 'raw': 'true'
- }
- ]
- }
- };
- }
- }
|