UNPKG

@ordojs/core

Version:

Core compiler and runtime for OrdoJS framework

94 lines 2.59 kB
/** * @fileoverview Simplified OrdoJS Parser for testing */ import {} from '../types/index.js'; /** * Default parser options */ const DEFAULT_OPTIONS = { allowRecovery: true, maxErrors: 10, strictMode: false }; /** * Simplified OrdoJS Parser for testing */ export class OrdoJSParser { tokens; errors = []; options; filename; constructor(tokens, options = {}, filename) { this.tokens = tokens; this.options = { ...DEFAULT_OPTIONS, ...options }; this.filename = filename; } /** * Parse the token stream into a ComponentAST */ parse() { // Create a minimal component AST for testing const componentNode = { type: 'Component', name: 'SimpleComponent', props: [], markupBlock: this.createSimpleMarkupBlock(), range: this.createRange({ line: 1, column: 1, offset: 0 }, { line: 10, column: 1, offset: 100 }) }; return { component: componentNode, dependencies: [], exports: [], sourceMap: { version: 3, sources: [], names: [], mappings: '', sourcesContent: [] } }; } /** * Create a simple markup block for testing */ createSimpleMarkupBlock() { // Create a text node const textNode = { type: 'Text', content: 'Hello, World!', range: this.createRange({ line: 3, column: 10, offset: 30 }, { line: 3, column: 23, offset: 43 }) }; // Create an HTML element const element = { type: 'HTMLElement', tagName: 'div', attributes: [], children: [textNode], isSelfClosing: false, isVoidElement: false, range: this.createRange({ line: 3, column: 5, offset: 25 }, { line: 3, column: 30, offset: 50 }) }; // Create a markup block return { type: 'MarkupBlock', elements: [element], textNodes: [textNode], interpolations: [], range: this.createRange({ line: 2, column: 3, offset: 15 }, { line: 4, column: 3, offset: 55 }), children: [element] }; } /** * Create a source range */ createRange(start, end) { return { start, end }; } /** * Get parsing errors */ getErrors() { return this.errors; } } //# sourceMappingURL=parser-simplified.js.map