{"id":"493e94d6449874d5","repo":"rollup/rollup","slug":"not-implemented-cannot-convert-expr-tsas","errorCode":null,"errorMessage":"not implemented: Cannot convert Expr::TsAs","messagePattern":"not implemented: Cannot convert Expr::TsAs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/parse_ast/src/convert_ast/converter.rs","lineNumber":418,"sourceCode":"      Expr::Update(update_expression) => {\n        self.store_update_expression(update_expression);\n      }\n      Expr::Yield(yield_expression) => {\n        self.store_yield_expression(yield_expression);\n      }\n      Expr::JSXMember(_) => unimplemented!(\"Cannot convert Expr::JSXMember\"),\n      Expr::JSXNamespacedName(_) => unimplemented!(\"Cannot convert Expr::JSXNamespacedName\"),\n      Expr::JSXEmpty(_) => unimplemented!(\"Cannot convert Expr::JSXEmpty\"),\n      Expr::JSXElement(jsx_element) => {\n        self.store_jsx_element(jsx_element);\n      }\n      Expr::JSXFragment(jsx_fragment) => {\n        self.store_jsx_fragment(jsx_fragment);\n      }\n      Expr::TsTypeAssertion(_) => unimplemented!(\"Cannot convert Expr::TsTypeAssertion\"),\n      Expr::TsConstAssertion(_) => unimplemented!(\"Cannot convert Expr::TsConstAssertion\"),\n      Expr::TsNonNull(_) => unimplemented!(\"Cannot convert Expr::TsNonNull\"),\n      Expr::TsAs(_) => unimplemented!(\"Cannot convert Expr::TsAs\"),\n      Expr::TsInstantiation(_) => unimplemented!(\"Cannot convert Expr::TsInstantiation\"),\n      Expr::TsSatisfies(_) => unimplemented!(\"Cannot convert Expr::TsSatisfies\"),\n      Expr::Invalid(_) => unimplemented!(\"Cannot convert Expr::Invalid\"),\n    }\n  }\n\n  pub(crate) fn convert_expression_or_spread(&mut self, expression_or_spread: &ExprOrSpread) {\n    match expression_or_spread.spread {\n      Some(spread_span) => self.store_spread_element(&spread_span, &expression_or_spread.expr),\n      None => {\n        self.convert_expression(&expression_or_spread.expr);\n      }\n    }\n  }\n\n  pub(crate) fn convert_for_head(&mut self, for_head: &ForHead) {\n    match for_head {\n      ForHead::VarDecl(variable_declaration) => {","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/rollup/rollup/blob/ddc4ffab628944e45dbb8d66d58aae818015440f/rust/parse_ast/src/convert_ast/converter.rs#L400-L436","documentation":"convert_expression (converter.rs:322) has an unimplemented! arm at line 418 for Expr::TsAs. TsAs is TypeScript's `as` assertion `value as Type`, the most common TS cast form. The native parser is TS-tolerant (Syntax::Es, lib.rs:23) so SWC produces TsAs, but the buffer format cannot represent it and the converter panics; this is thrown to JS as a Rollup parse error.","triggerScenarios":"Source fed to Rollup's native parser contains `x as T`, `obj as unknown as T`, or `fn() as Promise<X>`. The Expr::TsAs node has no store arm in convert_expression. This is one of the most frequently hit arms for raw TypeScript bundles.","commonSituations":"Bundling .ts/.tsx source without a transform plugin that strips types. `.d.ts`-adjacent code or type tests copied into bundled source. Migration from tsc-only builds to Rollup without adding a TS plugin.","solutions":["Add a TypeScript transform plugin (@rollup/plugin-typescript, @rollup/plugin-swc, or rollup-plugin-esbuild) so `as` is removed before the native parser runs.","If only one module is affected, pre-transpile that module to JS and import the built file.","As a last resort rewrite the assertion away, though this is impractical across a real TS codebase."],"exampleFix":"// before\nconst len = (arr as number[]).length;\n\n// after (post TS strip)\nconst len = arr.length;","handlingStrategy":"validation","validationCode":"// Detect TS `as` assertions.\nfunction hasTsAs(src) {\n  return /\\)\\s*as\\s+[A-Z]|\\bas\\s+(const|unknown|[A-Z])/.test(src);\n}\nif (hasTsAs(code)) {\n  throw new Error('Source uses `as` assertions; strip TS with a transform plugin.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await rollup({ input });\n} catch (err) {\n  if (String(err.message).includes('Expr::TsAs')) {\n    throw new Error('Raw TS `as` assertion reached the native parser; add a TS plugin.');\n  }\n  throw err;\n}","preventionTips":["Always configure a TS transform plugin when bundling `.ts`/`.tsx`.","Confirm the plugin actually runs the transform hook before parsing.","Keep type-only code out of bundled runtime source."],"tags":["typescript","ast","native-parser","type-assertion"],"analyzedSha":"ddc4ffab628944e45dbb8d66d58aae818015440f","analyzedAt":"2026-08-03T19:42:57.546Z","schemaVersion":2}