{"record":{"id":"b2eeea3660804f88","repo":"sinelaw/fresh","slug":"typescript-parse-errors","errorCode":null,"errorMessage":"TypeScript parse errors: {}","messagePattern":"TypeScript parse errors: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-parser-js/src/lib.rs","lineNumber":27,"sourceCode":"use oxc_codegen::Codegen;\nuse oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};\nuse oxc_parser::Parser;\nuse oxc_semantic::SemanticBuilder;\nuse oxc_span::SourceType;\nuse oxc_transformer::{TransformOptions, Transformer};\nuse std::collections::HashSet;\nuse std::path::{Path, PathBuf};\n\n/// Transpile TypeScript source code to JavaScript\npub fn transpile_typescript(source: &str, filename: &str) -> Result<String> {\n    let allocator = Allocator::default();\n    let source_type = SourceType::from_path(filename).unwrap_or_default();\n\n    // Parse\n    let parser_ret = Parser::new(&allocator, source, source_type).parse();\n    if !parser_ret.errors.is_empty() {\n        let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect();\n        return Err(anyhow!(\"TypeScript parse errors: {}\", errors.join(\"; \")));\n    }\n\n    let mut program = parser_ret.program;\n\n    // Semantic analysis (required for transformer)\n    let semantic_ret = SemanticBuilder::new().build(&program);\n\n    if !semantic_ret.errors.is_empty() {\n        let errors: Vec<String> = semantic_ret.errors.iter().map(|e| e.to_string()).collect();\n        return Err(anyhow!(\"Semantic errors: {}\", errors.join(\"; \")));\n    }\n\n    // Get scoping info for transformer\n    let scoping = semantic_ret.semantic.into_scoping();\n\n    // Transform (strip TypeScript types)\n    let transform_options = TransformOptions::default();\n    let transformer_ret = Transformer::new(&allocator, Path::new(filename), &transform_options)","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-parser-js/src/lib.rs#L9-L45","documentation":"`transpile_typescript` parses the given source with an oxc-based parser; if the parser reports any syntax errors the transpiler aborts with this message containing all parse errors joined by '; '. No JavaScript is produced until the source parses cleanly.","triggerScenarios":"Passing TypeScript (or JS) source that is syntactically invalid to `transpile_typescript(source, filename)` — e.g. plugin bundles containing a typo, unbalanced braces, or unsupported syntax for the source type inferred from `filename`.","commonSituations":"Bundling a plugin whose .ts file has a syntax error; giving a filename whose extension makes oxc parse TS as plain JS (or vice versa); pasting partial/snippet code into a plugin loader.","solutions":["Read the joined error list in the message and fix each syntax error at the reported line/column in the .ts source.","Pass a correct filename/extension (e.g. plugin.ts) so SourceType::from_path picks the right parser mode.","Run tsc or a local parser on the source before submitting it to the bundler to catch errors early."],"exampleFix":"// before\ntranspile_typescript(broken_src, \"plugin.js\")?; // parsed as JS, syntax errors\n// after\ntranspile_typescript(broken_src, \"plugin.ts\")?; // parsed as TypeScript","handlingStrategy":"validation","validationCode":"// Pre-check with tsc or parse locally before transpiling\nlet ok = tsc_no_errors(path); // external or oxc pre-pass\nif !ok { bail!(\"fix TypeScript syntax before bundling\"); }","typeGuard":null,"tryCatchPattern":"match transpile_typescript(src, \"plugin.ts\") {\n    Err(e) if e.to_string().starts_with(\"TypeScript parse errors\") => show_editor_diagnostics(&e.to_string()),\n    other => other?,\n}","preventionTips":["Run tsc/eslint in CI on all plugin sources.","Always pass accurate filenames with correct extensions.","Surface parse errors inline in the editor before bundling."],"tags":["typescript","parser","syntax-error","plugins"],"backgroundTag":"schema-validation-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}