| 201 | } |
| 202 | |
| 203 | export function compile( |
| 204 | sourceCode: string, |
| 205 | fileName: string, |
| 206 | optionsOrRegistry?: CompileOptions | ComponentRegistry, |
| 207 | ): CompileResult { |
| 208 | // Backward compat: accept ComponentRegistry directly |
| 209 | const opts: CompileOptions = |
| 210 | optionsOrRegistry instanceof Map |
| 211 | ? { registry: optionsOrRegistry } |
| 212 | : optionsOrRegistry || {}; |
| 213 | const registry = opts.registry; |
| 214 | const resolvedStyles = opts.resolvedStyles; |
| 215 | const resolvedInlineStyles = opts.resolvedInlineStyles; |
| 216 | const useDefineForClassFields = opts.useDefineForClassFields ?? false; |
| 217 | const isPartial = opts.compilationMode === 'partial'; |
| 218 | const startTimeMs = debugCompile.enabled ? performance.now() : 0; |
| 219 | debugCompile( |
| 220 | 'compile %s (mode=%s, registry=%d entries)', |
| 221 | fileName, |
| 222 | isPartial ? 'partial' : 'full', |
| 223 | registry?.size ?? 0, |
| 224 | ); |
| 225 | const origSourceFile = ts.createSourceFile( |
| 226 | fileName, |
| 227 | sourceCode, |
| 228 | ts.ScriptTarget.Latest, |
| 229 | true, |
| 230 | ); |
| 231 | // OXC parse for metadata extraction (faster than TS for decorator/signal analysis) |
| 232 | const { program: oxcProgram } = parseSync(fileName, sourceCode); |
| 233 | const oxcClassMap = new Map<string, any>(); |
| 234 | for (const stmt of oxcProgram.body) { |
| 235 | const decl = |
| 236 | stmt.type === 'ExportNamedDeclaration' || |
| 237 | stmt.type === 'ExportDefaultDeclaration' |
| 238 | ? (stmt as any).declaration |
| 239 | : stmt; |
| 240 | if ( |
| 241 | decl && |
| 242 | (decl.type === 'ClassDeclaration' || decl.type === 'ClassExpression') && |
| 243 | decl.id?.name |
| 244 | ) { |
| 245 | oxcClassMap.set(decl.id.name, decl); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Collect module-level string constants so decorator metadata can resolve |
| 250 | // template-literal interpolations like `template: \`<div class="${tw}">x</div>\``. |
| 251 | const stringConsts = collectStringConstants(oxcProgram); |
| 252 | |
| 253 | const constantPool = new ConstantPool(); |
| 254 | const resourceDependencies: string[] = []; |
| 255 | const parseFile = new ParseSourceFile(sourceCode, fileName); |
| 256 | const parseLoc = new ParseLocation(parseFile, 0, 0, 0); |
| 257 | const typeSourceSpan = new ParseSourceSpan(parseLoc, parseLoc); |
| 258 | const typeOnlyImports = detectTypeOnlyImportNames(sourceCode); |
| 259 | const importSpecifierByName = new Map<string, string>(); |
| 260 | const importedNames = new Set<string>(); |