Git Product home page Git Product logo

babel-blog's Introduction

babel-blog

babel 学习笔记

babel-help 函数

常见 path 的方法

  • inList(): 判断节点是否在数组中
  • get(key): 获取某个属性的 path
  • set(key, node):设置某个属性的值
  • getSibling(key):获取某个下标的兄弟节点
  • getNextSibling():获取下一个兄弟节点
  • getPrevSibling():获取上一个兄弟节点
  • getAllPrevSiblings(): 获取之前的所有兄弟节点
  • getAllNextSiblings(): 获取之后的所有兄弟节点
  • find(callback): 从当前节点到根节点来查找节点(包括当前节点),调用 callback(传入 path)来决定是否终止查找
  • findParent(callback): 从当前节点到根节点来查找节点(不包括当前节点),调用 callback(传入 path)来决定是否终止查找
  • isXxx(opts): 判断当前节点是否是某个类型,可以传入属性和属性值进一步判断,比如path.isIdentifier({name: 'a'})
  • assertXxx(opts): 同 isXxx,但是不返回布尔值,而是抛出异常
  • insertBefore(nodes): 在之前插入节点,可以是单个节点或者节点数组
  • insertAfter(nodes): 在之后插入节点,可以是单个节点或者节点数组
  • replaceWith(replacement): 用某个节点替换当前节点
  • replaceWithMultiple(nodes): 用多个节点替换当前节点
  • replaceWithSourceString(replacement): 解析源码成 AST,然后替换当前节点
  • remove(): 删除当前节点
  • traverse(visitor, state): 遍历当前节点的子节点,传入 visitor 和 state(state 是不同节点间传递数据的方式)
  • skip(): 跳过当前节点的子节点的遍历
  • stop(): 结束所有遍历

部分用法可查看babel-handbook

未完,待续 ing...

babel-blog's People

Contributors

senfish avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.