Guest User

Untitled

a guest
May 20th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. # babel-plugin
  2.  
  3. three stage of Babel:
  4.  
  5. parse => transform => generate
  6.  
  7.  
  8.  
  9. #### parse
  10.  
  11. Lexical Analysis => syntactic Analysis
  12.  
  13.  
  14.  
  15. Lexical Analysis: string to tokens.
  16.  
  17. ```
  18. {
  19. type: {
  20. label: 'name',
  21. keyword: undefined,
  22. beforeExpr: false,
  23. startsExpr: true,
  24. rightAssociative: false,
  25. isLoop: false,
  26. isAssign: false,
  27. prefix: false,
  28. postfix: false,
  29. binop: null,
  30. updateContext: null
  31. },
  32. ...
  33. }
  34. ```
  35.  
  36.  
  37.  
  38. syntactic Analysis: tokens to AST
  39.  
  40. ```
  41. "body": [
  42. {
  43. "type": "ExpressionStatement",
  44. "start": 0,
  45. "end": 1,
  46. "loc": {
  47. "start": {
  48. "line": 1,
  49. "column": 0
  50. },
  51. "end": {
  52. "line": 1,
  53. "column": 1
  54. }
  55. },
  56. "expression": {
  57. "type": "Identifier",
  58. "start": 0,
  59. "end": 1,
  60. "loc": {
  61. "start": {
  62. "line": 1,
  63. "column": 0
  64. },
  65. "end": {
  66. "line": 1,
  67. "column": 1
  68. },
  69. "identifierName": "n"
  70. },
  71. "name": "n"
  72. }
  73. }
  74. ],
  75. ```
  76.  
  77.  
  78.  
  79.  
  80.  
  81. #### transform
  82.  
  83. traverse AST, adding、updating、removing
  84.  
  85.  
  86.  
  87. #### generate
  88.  
  89. traverse AST and building a string that represents the transformed code.
  90.  
  91.  
  92.  
  93. - babel-core
  94. - babel-types
  95.  
  96.  
  97.  
  98. create AST tree
  99.  
  100. - VariableDeclaration
  101. - template
  102. - replaceWithSourceString
Add Comment
Please, Sign In to add comment