UnicodeArrayRotateFunctionCallNode.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. const estraverse = require('estraverse');
  3. const Node_1 = require('./Node');
  4. class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
  5. constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) {
  6. super();
  7. this.astTree = astTree;
  8. this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
  9. this.unicodeArrayName = unicodeArrayName;
  10. this.unicodeArrayRotateValue = unicodeArrayRotateValue;
  11. this.node = this.getNodeStructure();
  12. }
  13. appendNode() {
  14. estraverse.replace(this.astTree, {
  15. leave: (node, parent) => {
  16. switch (node.type) {
  17. case 'Program':
  18. node.body.unshift(this.getNode());
  19. break;
  20. default:
  21. break;
  22. }
  23. }
  24. });
  25. }
  26. getNodeStructure() {
  27. return {
  28. 'type': 'ExpressionStatement',
  29. 'expression': {
  30. 'type': 'CallExpression',
  31. 'callee': {
  32. 'type': 'Identifier',
  33. 'name': this.unicodeArrayRotateFunctionName
  34. },
  35. 'arguments': [
  36. {
  37. 'type': 'Identifier',
  38. 'name': this.unicodeArrayName
  39. },
  40. {
  41. 'type': 'Literal',
  42. 'value': this.unicodeArrayRotateValue,
  43. 'raw': `'${this.unicodeArrayRotateValue}'`
  44. },
  45. {
  46. 'type': 'Literal',
  47. 'value': true,
  48. 'raw': 'true'
  49. }
  50. ]
  51. }
  52. };
  53. }
  54. }
  55. exports.UnicodeArrayRotateFunctionCallNode = UnicodeArrayRotateFunctionCallNode;