AST 구문 type 모음

joy·2025년 1월 21일

AST란?

AST(Abstract Syntax Tree, 추상 구문 트리)는 소스 코드를 분해하여 계층 구조로 표현한 객체입니다.
이 구조는 코드를 정적 분석하거나 트랜스파일(예: Babel), 린트(ESLint), 코드 포매팅(Prettier) 등에 사용됩니다.


// 1. FunctionDeclaration (함수 선언문)
function sayHello(name) {
  return `Hello ${name}`;
}

// 2. VariableDeclaration (변수 선언문)
const age = 25;
let name = "John";
var score = 100;

// 3. ArrowFunctionExpression (화살표 함수 표현식)
const greet = (name) => {
  console.log(`Hello ${name}`);
}

// 4. FunctionExpression (함수 표현식)
const calculate = function(x, y) {
  return x + y;
}

// 5. BlockStatement (블록문)
{
  const x = 1;
  console.log(x);
}

// 6. ExpressionStatement (표현식 문장)
console.log("Hello");
myFunction();
x + y;

// 7. CallExpression (호출 표현식)
alert("Warning!");
Math.max(1, 2, 3);
myFunction("param");

// 8. MemberExpression (멤버 접근 표현식)
console.log
object.property
array[0]

// 9. Identifier (식별자)
let userName;
function calculateTotal() {}
console.log(userName);

// 10. ThisExpression (this 표현식)
const person = {
  name: "John",
  sayHi() {
    console.log(this.name);
  }
}

// 11. ReturnStatement (반환문)
function multiply(x, y) {
  return x * y;
}

// 12. AssignmentExpression (할당 표현식)
x = 5;
y += 10;
obj.prop = "value";
profile
꾸준히

0개의 댓글