123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- "use strict";
- const estraverse = require('estraverse');
- const Node_1 = require('./Node');
- const Utils_1 = require('../Utils');
- class UnicodeArrayRotateFunctionNode extends Node_1.Node {
- constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName) {
- super();
- this.astTree = astTree;
- this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
- this.unicodeArrayName = unicodeArrayName;
- this.node = this.getNodeStructure();
- }
- appendNode() {
- estraverse.replace(this.astTree, {
- leave: (node, parent) => {
- switch (node.type) {
- case 'Program':
- node.body.push(this.getNode());
- break;
- }
- }
- });
- }
- getNodeIdentifier() {
- return this.unicodeArrayRotateFunctionName;
- }
- getNodeStructure() {
- return {
- 'type': 'FunctionExpression',
- 'id': {
- 'type': 'Identifier',
- 'name': this.unicodeArrayRotateFunctionName
- },
- 'params': [
- {
- 'type': 'Identifier',
- 'name': 'array'
- },
- {
- 'type': 'Identifier',
- 'name': 'times'
- },
- {
- 'type': 'Identifier',
- 'name': 'reverse'
- }
- ],
- 'defaults': [],
- 'body': {
- 'type': 'BlockStatement',
- 'body': [
- {
- 'type': 'IfStatement',
- 'test': {
- 'type': 'BinaryExpression',
- 'operator': '<',
- 'left': {
- 'type': 'Identifier',
- 'name': 'times'
- },
- 'right': {
- 'type': 'Literal',
- 'value': 0,
- 'raw': '0'
- }
- },
- 'consequent': {
- 'type': 'BlockStatement',
- 'body': [
- {
- 'type': 'ReturnStatement',
- 'argument': null
- }
- ]
- },
- 'alternate': null
- },
- {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'AssignmentExpression',
- 'operator': '=',
- 'left': {
- 'type': 'Identifier',
- 'name': 'reverse'
- },
- 'right': {
- 'type': 'LogicalExpression',
- 'operator': '||',
- 'left': {
- 'type': 'Identifier',
- 'name': 'reverse'
- },
- 'right': {
- 'type': 'Literal',
- 'value': false,
- 'raw': 'false'
- }
- }
- }
- },
- {
- 'type': 'VariableDeclaration',
- 'declarations': [
- {
- 'type': 'VariableDeclarator',
- 'id': {
- 'type': 'Identifier',
- 'name': 'temp'
- },
- 'init': null
- }
- ],
- 'kind': 'var'
- },
- {
- 'type': 'WhileStatement',
- 'test': {
- 'type': 'UpdateExpression',
- 'operator': '--',
- 'argument': {
- 'type': 'Identifier',
- 'name': 'times'
- },
- 'prefix': false
- },
- 'body': {
- 'type': 'BlockStatement',
- 'body': [
- {
- 'type': 'IfStatement',
- 'test': {
- 'type': 'UnaryExpression',
- 'operator': '!',
- 'argument': {
- 'type': 'Identifier',
- 'name': 'reverse'
- },
- 'prefix': true
- },
- 'consequent': {
- 'type': 'BlockStatement',
- 'body': [
- {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'AssignmentExpression',
- 'operator': '=',
- 'left': {
- 'type': 'Identifier',
- 'name': 'temp'
- },
- 'right': {
- 'type': 'CallExpression',
- 'callee': {
- 'type': 'MemberExpression',
- 'computed': true,
- 'object': {
- 'type': 'Identifier',
- 'name': 'array'
- },
- 'property': {
- 'type': 'Literal',
- 'name': 'pop',
- 'x-verbatim-property': Utils_1.Utils.stringToUnicode('pop')
- }
- },
- 'arguments': []
- }
- }
- },
- {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'CallExpression',
- 'callee': {
- 'type': 'MemberExpression',
- 'computed': true,
- 'object': {
- 'type': 'Identifier',
- 'name': 'array'
- },
- 'property': {
- 'type': 'Literal',
- 'name': 'unshift',
- 'x-verbatim-property': Utils_1.Utils.stringToUnicode('unshift')
- }
- },
- 'arguments': [
- {
- 'type': 'Identifier',
- 'name': 'temp'
- }
- ]
- }
- }
- ]
- },
- 'alternate': {
- 'type': 'BlockStatement',
- 'body': [
- {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'AssignmentExpression',
- 'operator': '=',
- 'left': {
- 'type': 'Identifier',
- 'name': 'temp'
- },
- 'right': {
- 'type': 'CallExpression',
- 'callee': {
- 'type': 'MemberExpression',
- 'computed': true,
- 'object': {
- 'type': 'Identifier',
- 'name': 'array'
- },
- 'property': {
- 'type': 'Literal',
- 'name': 'shift',
- 'x-verbatim-property': Utils_1.Utils.stringToUnicode('shift')
- }
- },
- 'arguments': []
- }
- }
- },
- {
- 'type': 'ExpressionStatement',
- 'expression': {
- 'type': 'CallExpression',
- 'callee': {
- 'type': 'MemberExpression',
- 'computed': true,
- 'object': {
- 'type': 'Identifier',
- 'name': 'array'
- },
- 'property': {
- 'type': 'Literal',
- 'name': 'push',
- 'x-verbatim-property': Utils_1.Utils.stringToUnicode('push')
- }
- },
- 'arguments': [
- {
- 'type': 'Identifier',
- 'name': 'temp'
- }
- ]
- }
- }
- ]
- }
- }
- ]
- }
- }
- ]
- },
- 'generator': false,
- 'expression': false
- };
- }
- }
- exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
|