๐Ÿงช Complete AST Node Type Test Suite

Click any code element below to verify AST path tracking is working correctly. Every node type should display its path, array path, and properties.

โœ… Control Flow Statements (All Loops & Conditionals)

Test: SwitchStatement, SwitchCase, ThrowStatement, TryStatement, CatchClause, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, WithStatement

๐Ÿ‘‰ Click: switch keyword, case values, throw, try/catch/finally, loop conditions, loop bodies

// Switch Statement switch (day) { case 'Monday': console.log('Start of week'); break; case 'Friday': console.log('TGIF!'); break; default: console.log('Mid week'); } // Try-Catch-Finally try { riskyOperation(); } catch (error) { console.error('Error:', error.message); throw new Error('Failed'); } finally { cleanup(); } // While Loop while (count < 10) { count++; } // Do-While Loop do { process(); } while (hasMore); // For Loop for (let i = 0; i < items.length; i++) { console.log(items[i]); } // For-In Loop for (const key in object) { console.log(key, object[key]); } // For-Of Loop for (const item of array) { console.log(item); } // For-Await-Of Loop for await (const data of asyncIterator) { await process(data); } // With Statement (deprecated but valid) // with (Math) { const result = cos(PI / 2); }

โœ… Expressions & Collections

Test: ChainExpression, SequenceExpression, ArrayExpression, ObjectExpression, Property, SpreadElement, RestElement

๐Ÿ‘‰ Click: optional chains, comma operators, array/object literals, spread operators, rest parameters

// Optional Chaining (ChainExpression) const value = obj?.prop?.nested?.deep; const result = func?.(); const item = array?.[0]; // Sequence Expression (comma operator) let a, b, c; const val = (a = 1, b = 2, c = 3, a + b + c); // Array Expression with Spread const arr1 = [1, 2, 3]; const arr2 = [0, ...arr1, 4, 5]; const sparse = [1, , , 4]; // Object Expression with Spread const obj1 = {x: 1, y: 2}; const obj2 = { ...obj1, z: 3, method() { return this.x + this.y; }, get value() { return this.x; }, set value(v) { this.x = v; } }; // Rest Parameters function sum(...numbers) { return numbers.reduce((a, b) => a + b, 0); }

โœ… Destructuring Patterns

Test: ArrayPattern, ObjectPattern with nested structures and defaults

๐Ÿ‘‰ Click: array destructuring, object destructuring, nested patterns, default values, rest elements

// Array Destructuring const [first, second, ...rest] = [1, 2, 3, 4, 5]; const [a, , c] = [1, 2, 3]; const [x = 10, y = 20] = [1]; // Object Destructuring const {name, age, city = 'Unknown'} = user; const {x: posX, y: posY} = coordinates; const {nested: {deep: {value}}} = data; // Function Parameter Destructuring function greet({name, greeting = 'Hello'}) { return `${greeting}, ${name}!`; } function process([first, ...rest]) { return {first, rest}; } // Complex Nested Patterns const { user: { profile: {name1, avatar}, settings: {theme = 'dark', ...otherSettings} }, posts: [firstPost, ...otherPosts] } = data;

โœ… Template Literals & Tagged Templates

Test: TemplateLiteral, TaggedTemplateExpression, TemplateElement

๐Ÿ‘‰ Click: template strings, interpolated expressions, template tags, template parts

// Template Literals const name = 'World'; const greeting = `Hello, ${name}!`; const multiline = ` Line 1 Line 2 Line 3 `; const nested = `Outer ${`inner ${value}`}`; // Tagged Template Expression function tag(strings, ...values) { return strings.raw[0] + values.join(''); } const styled = tag`color: ${color}; font-size: ${size}px`; // Complex Expressions in Templates const result = `Sum: ${a + b}, Product: ${a * b}`; const conditional = `Status: ${isActive ? 'Active' : 'Inactive'}`;

โœ… Async, Generators & Yield/Await

Test: YieldExpression, AwaitExpression in various contexts

๐Ÿ‘‰ Click: yield, yield*, await, async keywords in different positions

// Generator Function with Yield function* fibonacci() { let a = 0, b = 1; while (true) { yield a; [a, b] = [b, a + b]; } } // Yield with Delegation function* delegateGenerator() { yield* fibonacci(); yield* otherGenerator(); } // Async Generator async function* asyncGenerator() { for (let i = 0; i < 10; i++) { await delay(100); yield i; } } // Await Expressions async function fetchData() { const response = await fetch(url); const data = await response.json(); const processed = await process(data); return processed; } // Await in Various Positions const result = await promise; const arr = [await p1, await p2]; const obj = {data: await fetchData()};

โœ… Meta Properties

Test: MetaProperty (import.meta, new.target)

๐Ÿ‘‰ Click: import.meta, new.target, their properties

// import.meta const moduleUrl = import.meta.url; const modulePath = import.meta.resolve('./module.js'); // new.target in constructor class MyClass { constructor() { if (new.target === MyClass) { console.log('Direct instantiation'); } else { console.log('Subclass instantiation'); } } } function Constructor() { if (!new.target) { throw new Error('Must use new'); } }

โœ… Module Imports & Exports

Test: ImportExpression, ImportDeclaration, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportAttribute, ExportNamedDeclaration, ExportSpecifier, ExportDefaultDeclaration, ExportAllDeclaration

๐Ÿ‘‰ Click: import, export keywords, module specifiers, import assertions, named/default exports

// Dynamic Import const module = await import('./module.js'); // Import Statements import defaultExport from './module.js'; import {named1, named2} from './utils.js'; import {original as renamed} from './lib.js'; import * as namespace from './all.js'; import React, {useState, useEffect} from 'react'; // Import with Attributes // Export Named export const PI = 3.14159; export function calculate(x) { return x * 2; } /// export {func1, func2}; // export {original as renamed}; // Export Default //export default class MyClass {} // export default function() {} //export default 42; // Re-exports export {item1, item2} from './other.js'; export * from './all.js'; export * as utilities from './utils.js';

โœ… Edge Cases & Special Syntax

Test: ParenthesizedExpression, complex nested structures

๐Ÿ‘‰ Click: parenthesized expressions, deeply nested structures

// Parenthesized Expressions const result = (a + b) * (c - d); const obj = ({x: 1, y: 2}); const arrow = (x) => (y) => x + y; // Complex Nested Expression const complex = ( (a && b) || (c ?? d) || (e?.f?.g) ); // IIFE with Parentheses (function() { console.log('IIFE'); })(); ((x) => { console.log(x); })(42);

๐ŸŽฏ Complete Integration Test

Test: All node types combined in realistic code

๐Ÿ‘‰ Click any part of this complex example to verify complete AST path tracking

// Complete test of all features class DataService extends BaseService { static #instances = new Map(); #cache = new WeakMap(); static { console.log('DataService initialized'); } static getInstance(key) { if (!this.#instances.has(key)) { this.#instances.set(key, new this(key)); } return this.#instances.get(key); } constructor(endpoint) { super(); this.endpoint = endpoint; } async *fetchPages() { let page = 1; while (true) { try { const response = await fetch(`${this.endpoint}?page=${page}`); switch (response.status) { case 200: const data = await response.json(); yield* data.items; break; case 404: throw new Error('Not found'); default: console.warn('Unexpected status:', response.status); } page++; } catch (error) { console.error('Fetch error:', error); break; } finally { await this.cleanup(); } } } async process({items, options = {}}) { const results = []; for await (const item of this.fetchPages()) { const processed = await this.transform(item); if (processed?.valid && processed?.data) { results.push(processed); } if (results.length >= (options.limit ?? 100)) { break; } } return { results, count: results.length, metadata: { timestamp: Date.now(), endpoint: this.endpoint } }; } } export default DataService; export {DataService}; export * from './types.js';

โœ… Testing Checklist

For each code section above, verify:

๐ŸŽ‰ If all checks pass, ALL 65+ AST node types are working perfectly!