/simple-babel

简易版babel工程实现,旨在深入了解词法分析以及其语法转换

Primary LanguageJavaScript

Description

simple babel。旨在深入理解babel的词法分析,替换等核心功能。

目前支持支持语法解析,语法转换以及代码生成

语法解析

Statement

  • VariableDeclaration
  • ClassDeclaration
  • FunctionDeclaration
  • ExpressionStatement
  • BlockStatement
  • LabeledStatement
  • SwitchStatement
  • BreakStatement
  • ContinueStatement
  • EmptyStatement
  • ThrowStatement
  • ReturnStatement
  • IfStatement
  • ForStatement
  • ForInStatement
  • ForOfStatement
  • WhileStatement
  • DoWhileStatement
  • TryStatement
  • DebuggerStatement

Expression

  • thisExpression
  • SequenceExpression
  • AssignmentExpression
  • UpdateExpression
  • UnaryExpression
  • MemberExpression
  • LogicalExpression
  • BinaryExpression
  • CallExpression
  • FunctionExpression
  • VariableDeclarator
  • ObjectExpression
  • ArrayExpression
  • ConditionalExpression
  • NewExpression
  • ArrowFunctionExpression
  • Property
  • Literal
  • Identifier
  • AssignmentPattern

语法转换以及代码生成

  • arrowFunctionExpression
  • block-bind
  • class
  • default-parameters
  • modules
  • property-method
  • spread
  • templateLiteral
  • forOf

How to test

npm install
npm run test

Usage

CLI

Compile the file a.js and output it to stdout

$ ./bin/babel ./example/a.js

Compile the file a.js and output it to a.compiled.js

$ ./bin/babel ./example/a.js -o ./example/a.compiled.js

Compile the file and output it to dist directory

$ ./bin/babel ./example/a.js -d dist

Compile the directory and output it to dist directory

$ ./bin/babel ./example -d dist