@ordojs/core
Version:
Core compiler and runtime for OrdoJS framework
74 lines (58 loc) • 2.39 kB
text/typescript
/**
* @fileoverview Debug HTML element parsing step by step
*/
import { describe, expect, it } from 'vitest';
import { OrdoJSLexer } from './lexer.js';
import { OrdoJSParser } from './parser.js';
describe('Debug HTML Parsing', () => {
it('should trace HTML element parsing', () => {
const source = `
component TestComponent {
markup {
<div>Hello World</div>
}
}
`;
const lexer = new OrdoJSLexer(source, 'test.ordo');
const tokens = lexer.tokenize();
// Create a custom parser with debug logging
class DebugParser extends (OrdoJSParser as any) {
parseHTMLElement() {
console.log('\n=== Starting parseHTMLElement ===');
console.log('Current token position:', this.tokens.current);
console.log('Current token:', this.tokens.peek());
const result = super.parseHTMLElement();
console.log('=== Finished parseHTMLElement ===');
console.log('Final token position:', this.tokens.current);
console.log('Final token:', this.tokens.peek());
console.log('Parsed element:', { tagName: result.tagName, childrenCount: result.children.length });
return result;
}
checkClosingTag(tagName: string) {
const result = super.checkClosingTag(tagName);
console.log(`checkClosingTag("${tagName}") at position ${this.tokens.current}:`, result);
console.log(' Current token:', this.tokens.peek());
return result;
}
parseClosingTag(tagName: string) {
console.log(`\n--- parseClosingTag("${tagName}") ---`);
console.log('Before - position:', this.tokens.current, 'token:', this.tokens.peek());
super.parseClosingTag(tagName);
console.log('After - position:', this.tokens.current, 'token:', this.tokens.peek());
}
}
const parser = new DebugParser(tokens, { allowRecovery: true }, 'test.ordo');
// Advance to the HTML_TAG_OPEN token for <div>
tokens.current = 8; // Position at <div>
try {
const element = parser.parseHTMLElement();
console.log('\nParsing succeeded!');
console.log('Element:', element);
} catch (error) {
console.log('\nParsing failed:', error.message);
console.log('Final position:', tokens.current);
console.log('Final token:', tokens.peek());
}
expect(true).toBe(true);
});
});