Skip to content

fix(angular): preserve block-body functions in decorator providers#205

Merged
Brooooooklyn merged 5 commits intomainfrom
fix/203-use-factory-block-body-preserved
Apr 2, 2026
Merged

fix(angular): preserve block-body functions in decorator providers#205
Brooooooklyn merged 5 commits intomainfrom
fix/203-use-factory-block-body-preserved

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Apr 2, 2026

Block-body arrow functions and function expressions in decorator properties
(e.g., useFactory) were silently having unsupported statements dropped.
Only return and expression statements survived, corrupting the function body
and causing runtime errors.

Add RawSource fallback: when convert_oxc_expression encounters a block-body
arrow with unsupported statement types (const, if, for, try/catch, etc.) or
a function expression, it preserves the complete source text verbatim via
span slicing instead of silently dropping statements.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com


Note

Medium Risk
Touches core expression conversion/emission paths and introduces verbatim source emission (RawSource), which could affect correctness and escaping/formatting for previously-converted expressions.

Overview
Fixes metadata/codegen loss where complex expressions inside Angular decorator properties (notably providers.useFactory) had unsupported statements silently dropped, producing corrupted runtime factories.

This threads optional source_text through metadata extraction and expression conversion, and introduces a new OutputExpression::RawSource fallback that preserves the original expression text (with TypeScript types stripped) when the output AST cannot represent constructs like block-body arrows with const/if/loops or function expressions. Emission, cloning, visitors, and optimization passes are updated to treat RawSource as an opaque leaf, with new unit/integration tests covering the regression (#203).

Written by Cursor Bugbot for commit 3b9955e. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 557ff9a92f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Block-body arrow functions and function expressions in decorator properties
(e.g., useFactory) were silently having unsupported statements dropped.
Only return and expression statements survived, corrupting the function body
and causing runtime errors.

Add RawSource fallback: when convert_oxc_expression encounters a block-body
arrow with unsupported statement types (const, if, for, try/catch, etc.) or
a function expression, it preserves the complete source text verbatim via
span slicing instead of silently dropping statements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn force-pushed the fix/203-use-factory-block-body-preserved branch from 557ff9a to fa2c703 Compare April 2, 2026 08:14
Thread source_text into class metadata builder so decorator arguments
containing block-body arrows/function expressions are preserved via
RawSource fallback instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa2c7030e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6eabfac5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- build_ctor_params_metadata: pass source_text so @Inject(...) args
  with complex expressions are preserved in ɵsetClassMetadata
- build_prop_decorators_metadata: pass source_text so @input({...})
  with complex transform functions are preserved
- extract_provided_in: propagate source_text from parent
  extract_injectable_metadata into forwardRef extraction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90ccab0a13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…back, thread source_text through property decorators

Three reviewer fixes:

1. P1 - RawSource now strips TypeScript type annotations via
   parse-transform-codegen pipeline, preventing invalid JS output
   like `(dep: Dep) => { ... }` in generated code.

2. Medium - Expression-body arrows with unsupported inner expressions
   (e.g., `() => someUnsupportedExpr`) now fall back to RawSource
   instead of returning None.

3. P2 - Thread source_text through property_decorators.rs so
   @input({transform}), @ViewChild, @ContentChild arguments with
   complex expressions are preserved via RawSource fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d70418d613

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Use SourceType::ts().with_module(true) instead of script-mode ts()
  so import.meta and ESM-only syntax parse correctly in RawSource
  fallback expressions.

- Add fast path: try parsing as .mjs first. If the expression is
  already valid JavaScript (no type annotations), return it as-is
  without running the heavier semantic→transform→codegen pipeline.
  Only expressions with actual TypeScript syntax pay the full cost.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn merged commit 9724ae5 into main Apr 2, 2026
9 checks passed
@Brooooooklyn Brooooooklyn deleted the fix/203-use-factory-block-body-preserved branch April 2, 2026 10:59
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b9955ebe4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +750 to +752
if let Some(rest) = code.strip_prefix("0, (").or_else(|| code.strip_prefix("0,(")) {
if let Some(inner) = rest.strip_suffix(");") {
return inner.to_string();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Parse wrapper output without fixed 0,(...) formatting

This unwrapping assumes codegen always returns exactly 0, (expr);, but oxc_codegen can emit forms like 0, function(...) {} or 0, (x) => x; where the wrapper parentheses are normalized away. When that happens, this branch misses and falls back to expr_source, so TypeScript annotations are not stripped and RawSource can re-emit invalid JS (for example useFactory: function(dep: Dep) { ... } keeps : Dep in output).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant