ããBabelæ¯ä¸ä¸ªè½¬æ¢ç¼è¯å¨ï¼å®è½å°ES6转æ¢æå¯ä»¥å¨æµè§å¨ä¸è¿è¡ç代ç ãBabelç±æ¥èªæ¾³å¤§å©äºçå¼åè
Sebastian McKenzieå建ãä»çç®æ æ¯ä½¿Babelå¯ä»¥å¤çES6çæææ°è¯æ³ï¼å¹¶ä¸ºå®å
ç½®äºReact JSXæ©å±åFlowç±»å注解æ¯æã
ããæ®codemixåå§äººCharles Pickä»ç»ï¼Babelæ¯ææES6转æ¢ç¼è¯å¨ä¸ä¸ES6è§èå
¼å®¹åº¦æé«çï¼çè³è¶
è¿äºè°·æå建已ä¹
çTraceurç¼è¯å¨ãBabelå
许å¼åè
使ç¨ES6çæææ°ç¹æ§ï¼èä¸ä¸ä¼å½±åä¸èçæ¬æµè§å¨çå
¼å®¹æ§ãæ¤å¤ï¼å®è¿æ¯æ许å¤ä¸åçæ建&æµè¯ç³»ç»ï¼ä½¿å¼åè
å¾å®¹æå°å®éæå°èªå·±çå·¥å
·é¾ä¸ã
ããCharles认为ï¼Babelä»æ ¹æ¬ä¸è®²æ¯ä¸ä¸ªå¹³å°ï¼è¿æ¯å®ä¸compile-to-JSè¯è¨CoffeeScriptåTypeScriptæ大çä¸åãBabelçæ件系ç»å
许å¼åè
èªå®ä¹ä»£ç 转æ¢å¨å¹¶æå
¥å°ç¼è¯è¿ç¨ãè¿äºè½¬æ¢å¨ä¼æ¥æ¶ä¸æ£µæ½è±¡è¯æ³æ ï¼å¹¶å¨ä»£ç 转æ¢æå¯æ§è¡çJavaScriptä¹å对å
¶è¿è¡æä½ãcodemixå·²ç»å°è¯å¼åäºéæ&è¿è¡æ¶ç±»åæ£æ¥ãéå
æ¶é¤ãJavaScriptâå¥åº·å®ï¼hygienic macrosï¼âçæ件ã
ããBabelä¸ä»
è·è¸ªES6çè¿å±æ
åµï¼èä¸è¿æ¯ES7æES2016çè¯éªåºãæ¯å¦ï¼å®å·²ç»æ¯æasync/awaitï¼ ä½¿å¼åè
æ´å®¹æç¼åå¼æ¥JavaScript代ç ï¼èä¸ä¸ä½¿ç¨åè°æPromisesç¸æ¯ï¼ä»£ç æ´ç®æ´ææãè½ç¶ä¸»æµæµè§å¨å¯è½è¿éè¦å å¹´çæ¶é´æè½æ¯æ è¿ç§å¼æ¥JavaScript代ç ç¼åæ¹å¼ï¼ä½Babel使å¼åè
ç°å¨å°±å¯ä»¥ç¨ä¸å®ãè¿å¾çäºBabelä¸JavaScriptææ¯å§åä¼ï¼TC39ï¼ä¿æçé«åº¦ä¸è´ï¼è½å¤å¨ECMAScriptæ°ç¹æ§æ ååä¹å为å¼åè
æä¾ç°å®ä¸çå¯ç¨çå®ç°ãèåæ¶ï¼è¿ä¹æå©äºJavaScriptçè¿ä¸æ¥åå±ï¼å 为å
¶å¢éå¯ä»¥å¨ECMAScriptè§èæåå®ç¨¿åå°±è·å¾æ¥èªç°å®ä¸ççåé¦ã
ããBabelè¿è½æåJavaScriptçæ§è¡é度ãç±äºJavaScript æ件å è½½åæ§è¡é度æ
¢ä¼ä¸¥éå½±åç¨æ·ä½éªï¼æ以JIT没ææ¶é´å¨è¿è¡æ¶æ§è¡ææææ¯ä¸å¯è¡çä¼åãç¸æ¯ä¹ä¸ï¼Babelæ¯å¨ç¼è¯æ¶è¿è¡ï¼æ²¡æè¿ä¹ä¸¥æ ¼çæ¶ é´éå¶ãåå©å¼ºå¤§çä½ç¨åè·è¸ªåç±»åæ¨æåè½åæ件系ç»ï¼å¼åè
å¯ä»¥æ建转æ¢å¨æ¥æ§è¡æ¤ç±»ä¼åï¼æ¯å¦ä¸ææå°çéå
æ¶é¤å¯ä»¥å°éå
转æ¢æ平常çå½æ°ã Babelæ¬èº«ä¹å
ç½®äºä¸äºä¼åï¼æ¯å¦éè¿utility.deadCodeElimination转æ¢å¨æ§è¡å¸¸éå并/常éä¼ æãå¨æ¥ä¸æ¥çå 个æéï¼æ们è¿ææçå°å¦ä¸æ件ï¼
ããä»»æå½æ°å
èï¼å°å½æ°å
èè³è°ç¨ç¹ï¼å®ç°æ§è½æ大åï¼é¿å
å¤æåå½æ°è°ç¨å¼éï¼
ããå½æ°å¤å¶ï¼å¨JavaScriptä¸ï¼å¤ææ¯å¯¼è´ä»£ç æ§è¡æ
¢çä¸ä¸ªå¸¸è§åå ãå æ¤ï¼å¨å½æ°æ æ³å
èçå°æ¹ï¼åºè¯¥çæä¸ä¸ªå½æ°å¯æ¬ï¼ç¡®ä¿å½æ°ä¿æåæï¼
ãã循ç¯å
ä¸å代ç å¤æï¼å°å¾ªç¯ä½å
ä¸åç代ç 移è³å¾ªç¯ä½å¤ï¼
ãã循ç¯å±å¼ï¼å¦æ循ç¯æ¬¡æ°Nåºå®ï¼å移é¤å¾ªç¯ï¼å°å¾ªç¯ä½å¤å¶N份ã
ããcodemixåç»å°åå¸å¤ä¸ªæ§è¡æ¤ç±»ä¼åçæ件ï¼æå
´è¶£ç读è
å¯ä»¥èç³»ä»ä»¬æè
å
³æ³¨å
¶Twitterãå
³äºJavaScriptå¼æå¯ä»¥ååªäºä¸åçä¼åï¼å¯ä»¥æ¥çè¿éã
ããBabelæ件并å±éäºæ§è½æåï¼æ¯å¦ï¼è¿å¯ä»¥åä¸é¢è¿äºäºæ
ï¼
ããi18n/ç¿»è¯è½¬æ¢å¨ï¼ç¿»è¯ç¹å®å符串并æ¿æ¢ï¼
ããèªå®ä¹æ¥å¿ç³»ç»ï¼éè¿ç¯å¢åé设置æ¥å¿çº§å«ï¼æ§å¶æ¥å¿ç²åº¦ï¼
ããé¢åå¯é模æ¿ç³»ç»ï¼å¦MustacheæHandlebarsï¼çç¼è¯æ¶è½¬æ¢å¨ï¼å°æ ç¾æ¨¡æ¿å符串ç´æ¥è½¬æ¢æJavaScript代ç ï¼
ããææ¡£çæå¨ï¼å©ç¨Flowç±»å注解åç±»åæ¨æçæææ¡£ã
ããä¸è¿°æ件ï¼æä¸é¨åå·²ç»å®ç°ã
ããæ»ä¹ï¼Charles认为ï¼Babelæ¯ä¸æ¬¾ä¼ç§ç软件ï¼å¿
å°æ为æ¯ä¸ªWebå¼åè
å·¥å
·ç®±çä¸é¨åï¼èä½ä¸ºECMAScriptçè¯éªåºï¼å®å¨ä¸è¿çå°æ¥å¾å¯è½ä¼æ为æ¨å¨ES6åESNextåºç¨ååå±ç主è¦å¨åã
ãã
温馨提示:答案为网友推荐,仅供参考