|
@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
|
|
import { IProgramNode } from '../interfaces/nodes/IProgramNode';
|
|
import { IProgramNode } from '../interfaces/nodes/IProgramNode';
|
|
import { ITreeNode } from '../interfaces/nodes/ITreeNode';
|
|
import { ITreeNode } from '../interfaces/nodes/ITreeNode';
|
|
|
|
|
|
|
|
+import { NodeType } from "../enums/NodeType";
|
|
|
|
+
|
|
import { Node } from './Node';
|
|
import { Node } from './Node';
|
|
import { Utils } from '../Utils';
|
|
import { Utils } from '../Utils';
|
|
|
|
|
|
@@ -48,7 +50,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
estraverse.replace(this.astTree, {
|
|
estraverse.replace(this.astTree, {
|
|
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
|
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
|
switch (node.type) {
|
|
switch (node.type) {
|
|
- case 'Program':
|
|
|
|
|
|
+ case NodeType.Program:
|
|
(<IProgramNode>node).body.push(this.getNode());
|
|
(<IProgramNode>node).body.push(this.getNode());
|
|
|
|
|
|
break;
|
|
break;
|
|
@@ -72,49 +74,49 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
*/
|
|
*/
|
|
protected getNodeStructure (): any {
|
|
protected getNodeStructure (): any {
|
|
return {
|
|
return {
|
|
- 'type': 'FunctionExpression',
|
|
|
|
|
|
+ 'type': NodeType.FunctionExpression,
|
|
'id': {
|
|
'id': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': this.unicodeArrayRotateFunctionName
|
|
'name': this.unicodeArrayRotateFunctionName
|
|
},
|
|
},
|
|
'params': [
|
|
'params': [
|
|
{
|
|
{
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'array'
|
|
'name': 'array'
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'times'
|
|
'name': 'times'
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'reverse'
|
|
'name': 'reverse'
|
|
}
|
|
}
|
|
],
|
|
],
|
|
'defaults': [],
|
|
'defaults': [],
|
|
'body': {
|
|
'body': {
|
|
- 'type': 'BlockStatement',
|
|
|
|
|
|
+ 'type': NodeType.BlockStatement,
|
|
'body': [
|
|
'body': [
|
|
{
|
|
{
|
|
- 'type': 'IfStatement',
|
|
|
|
|
|
+ 'type': NodeType.IfStatement,
|
|
'test': {
|
|
'test': {
|
|
- 'type': 'BinaryExpression',
|
|
|
|
|
|
+ 'type': NodeType.BinaryExpression,
|
|
'operator': '<',
|
|
'operator': '<',
|
|
'left': {
|
|
'left': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'times'
|
|
'name': 'times'
|
|
},
|
|
},
|
|
'right': {
|
|
'right': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'value': 0,
|
|
'value': 0,
|
|
'raw': '0'
|
|
'raw': '0'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'consequent': {
|
|
'consequent': {
|
|
- 'type': 'BlockStatement',
|
|
|
|
|
|
+ 'type': NodeType.BlockStatement,
|
|
'body': [
|
|
'body': [
|
|
{
|
|
{
|
|
- 'type': 'ReturnStatement',
|
|
|
|
|
|
+ 'type': NodeType.ReturnStatement,
|
|
'argument': null
|
|
'argument': null
|
|
}
|
|
}
|
|
]
|
|
]
|
|
@@ -122,23 +124,23 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
'alternate': null
|
|
'alternate': null
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'ExpressionStatement',
|
|
|
|
|
|
+ 'type': NodeType.ExpressionStatement,
|
|
'expression': {
|
|
'expression': {
|
|
- 'type': 'AssignmentExpression',
|
|
|
|
|
|
+ 'type': NodeType.AssignmentExpression,
|
|
'operator': '=',
|
|
'operator': '=',
|
|
'left': {
|
|
'left': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'reverse'
|
|
'name': 'reverse'
|
|
},
|
|
},
|
|
'right': {
|
|
'right': {
|
|
- 'type': 'LogicalExpression',
|
|
|
|
|
|
+ 'type': NodeType.LogicalExpression,
|
|
'operator': '||',
|
|
'operator': '||',
|
|
'left': {
|
|
'left': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'reverse'
|
|
'name': 'reverse'
|
|
},
|
|
},
|
|
'right': {
|
|
'right': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'value': false,
|
|
'value': false,
|
|
'raw': 'false'
|
|
'raw': 'false'
|
|
}
|
|
}
|
|
@@ -146,12 +148,12 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'VariableDeclaration',
|
|
|
|
|
|
+ 'type': NodeType.VariableDeclaration,
|
|
'declarations': [
|
|
'declarations': [
|
|
{
|
|
{
|
|
- 'type': 'VariableDeclarator',
|
|
|
|
|
|
+ 'type': NodeType.VariableDeclarator,
|
|
'id': {
|
|
'id': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'temp'
|
|
'name': 'temp'
|
|
},
|
|
},
|
|
'init': null
|
|
'init': null
|
|
@@ -160,53 +162,53 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
'kind': 'var'
|
|
'kind': 'var'
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'WhileStatement',
|
|
|
|
|
|
+ 'type': NodeType.WhileStatement,
|
|
'test': {
|
|
'test': {
|
|
- 'type': 'UpdateExpression',
|
|
|
|
|
|
+ 'type': NodeType.UpdateExpression,
|
|
'operator': '--',
|
|
'operator': '--',
|
|
'argument': {
|
|
'argument': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'times'
|
|
'name': 'times'
|
|
},
|
|
},
|
|
'prefix': false
|
|
'prefix': false
|
|
},
|
|
},
|
|
'body': {
|
|
'body': {
|
|
- 'type': 'BlockStatement',
|
|
|
|
|
|
+ 'type': NodeType.BlockStatement,
|
|
'body': [
|
|
'body': [
|
|
{
|
|
{
|
|
- 'type': 'IfStatement',
|
|
|
|
|
|
+ 'type': NodeType.IfStatement,
|
|
'test': {
|
|
'test': {
|
|
- 'type': 'UnaryExpression',
|
|
|
|
|
|
+ 'type': NodeType.UnaryExpression,
|
|
'operator': '!',
|
|
'operator': '!',
|
|
'argument': {
|
|
'argument': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'reverse'
|
|
'name': 'reverse'
|
|
},
|
|
},
|
|
'prefix': true
|
|
'prefix': true
|
|
},
|
|
},
|
|
'consequent': {
|
|
'consequent': {
|
|
- 'type': 'BlockStatement',
|
|
|
|
|
|
+ 'type': NodeType.BlockStatement,
|
|
'body': [
|
|
'body': [
|
|
{
|
|
{
|
|
- 'type': 'ExpressionStatement',
|
|
|
|
|
|
+ 'type': NodeType.ExpressionStatement,
|
|
'expression': {
|
|
'expression': {
|
|
- 'type': 'AssignmentExpression',
|
|
|
|
|
|
+ 'type': NodeType.AssignmentExpression,
|
|
'operator': '=',
|
|
'operator': '=',
|
|
'left': {
|
|
'left': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'temp'
|
|
'name': 'temp'
|
|
},
|
|
},
|
|
'right': {
|
|
'right': {
|
|
- 'type': 'CallExpression',
|
|
|
|
|
|
+ 'type': NodeType.CallExpression,
|
|
'callee': {
|
|
'callee': {
|
|
- 'type': 'MemberExpression',
|
|
|
|
|
|
+ 'type': NodeType.MemberExpression,
|
|
'computed': true,
|
|
'computed': true,
|
|
'object': {
|
|
'object': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'array'
|
|
'name': 'array'
|
|
},
|
|
},
|
|
'property': {
|
|
'property': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'name': 'pop',
|
|
'name': 'pop',
|
|
'x-verbatim-property': Utils.stringToUnicode('pop')
|
|
'x-verbatim-property': Utils.stringToUnicode('pop')
|
|
}
|
|
}
|
|
@@ -216,25 +218,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'ExpressionStatement',
|
|
|
|
|
|
+ 'type': NodeType.ExpressionStatement,
|
|
'expression': {
|
|
'expression': {
|
|
- 'type': 'CallExpression',
|
|
|
|
|
|
+ 'type': NodeType.CallExpression,
|
|
'callee': {
|
|
'callee': {
|
|
- 'type': 'MemberExpression',
|
|
|
|
|
|
+ 'type': NodeType.MemberExpression,
|
|
'computed': true,
|
|
'computed': true,
|
|
'object': {
|
|
'object': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'array'
|
|
'name': 'array'
|
|
},
|
|
},
|
|
'property': {
|
|
'property': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'name': 'unshift',
|
|
'name': 'unshift',
|
|
'x-verbatim-property': Utils.stringToUnicode('unshift')
|
|
'x-verbatim-property': Utils.stringToUnicode('unshift')
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'arguments': [
|
|
'arguments': [
|
|
{
|
|
{
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'temp'
|
|
'name': 'temp'
|
|
}
|
|
}
|
|
]
|
|
]
|
|
@@ -243,28 +245,28 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
]
|
|
]
|
|
},
|
|
},
|
|
'alternate': {
|
|
'alternate': {
|
|
- 'type': 'BlockStatement',
|
|
|
|
|
|
+ 'type': NodeType.BlockStatement,
|
|
'body': [
|
|
'body': [
|
|
{
|
|
{
|
|
- 'type': 'ExpressionStatement',
|
|
|
|
|
|
+ 'type': NodeType.ExpressionStatement,
|
|
'expression': {
|
|
'expression': {
|
|
- 'type': 'AssignmentExpression',
|
|
|
|
|
|
+ 'type': NodeType.AssignmentExpression,
|
|
'operator': '=',
|
|
'operator': '=',
|
|
'left': {
|
|
'left': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'temp'
|
|
'name': 'temp'
|
|
},
|
|
},
|
|
'right': {
|
|
'right': {
|
|
- 'type': 'CallExpression',
|
|
|
|
|
|
+ 'type': NodeType.CallExpression,
|
|
'callee': {
|
|
'callee': {
|
|
- 'type': 'MemberExpression',
|
|
|
|
|
|
+ 'type': NodeType.MemberExpression,
|
|
'computed': true,
|
|
'computed': true,
|
|
'object': {
|
|
'object': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'array'
|
|
'name': 'array'
|
|
},
|
|
},
|
|
'property': {
|
|
'property': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'name': 'shift',
|
|
'name': 'shift',
|
|
'x-verbatim-property': Utils.stringToUnicode('shift')
|
|
'x-verbatim-property': Utils.stringToUnicode('shift')
|
|
}
|
|
}
|
|
@@ -274,25 +276,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- 'type': 'ExpressionStatement',
|
|
|
|
|
|
+ 'type': NodeType.ExpressionStatement,
|
|
'expression': {
|
|
'expression': {
|
|
- 'type': 'CallExpression',
|
|
|
|
|
|
+ 'type': NodeType.CallExpression,
|
|
'callee': {
|
|
'callee': {
|
|
- 'type': 'MemberExpression',
|
|
|
|
|
|
+ 'type': NodeType.MemberExpression,
|
|
'computed': true,
|
|
'computed': true,
|
|
'object': {
|
|
'object': {
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'array'
|
|
'name': 'array'
|
|
},
|
|
},
|
|
'property': {
|
|
'property': {
|
|
- 'type': 'Literal',
|
|
|
|
|
|
+ 'type': NodeType.Literal,
|
|
'name': 'push',
|
|
'name': 'push',
|
|
'x-verbatim-property': Utils.stringToUnicode('push')
|
|
'x-verbatim-property': Utils.stringToUnicode('push')
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'arguments': [
|
|
'arguments': [
|
|
{
|
|
{
|
|
- 'type': 'Identifier',
|
|
|
|
|
|
+ 'type': NodeType.Identifier,
|
|
'name': 'temp'
|
|
'name': 'temp'
|
|
}
|
|
}
|
|
]
|
|
]
|