Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-ES6-ESNext转ES5 #104

Open
yaofly2012 opened this issue Feb 13, 2020 · 0 comments
Open

JS-ES6-ESNext转ES5 #104

yaofly2012 opened this issue Feb 13, 2020 · 0 comments

Comments

@yaofly2012
Copy link
Owner

yaofly2012 commented Feb 13, 2020

ES6 代码转成 ES5 代码的实现思路是什么

1. ES6代码转AST

2. 对 AST 进行处理,在这个阶段可以对 ES6 代码进行相应转换,即转成 ES5 代码:

ES6转ES5分为以下两种情况

  1. 语法转换
    例如:let,const转换为var,箭头函数转换为function函数声明等
  2. API转换
    采用babel-polyfill等工具对ES5中不存在的API(包括Set等ES6中新的数据结构)做修复,例如:Array.prototype.includes Set Map等在ES5中不存在,需要用相应的ES5代码实现这些API

3. 根据处理后的 AST 再生成代码字符串

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant