Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan forward until text tokens match #48294

Merged
merged 1 commit into from
May 24, 2023
Merged

Conversation

tenderlove
Copy link
Member

@tenderlove tenderlove commented May 24, 2023

Text tokens may be conditionally appended to the output buffer. For example if we have a template like this:

<h1>Oh no!</h1>
This template has a runtime error
<b>
  <% if true %>
    <%= method_that_does_not_exist %>
  <% end %>
</b>
Yikes!

In the above case, a string literal (" ") will be conditionally
appended to the output buffer with some code like below:

@output_buffer.safe_append='    '.freeze

This commit teaches text tokens (string literals) to scan forward in the compiled template until it finds the literal, thereby skipping the code generated for appending to the output buffer.

Related to:

Text tokens may be conditionally appended to the output buffer.  For
example if we have a template like this:

```erb
<h1>Oh no!</h1>
This template has a runtime error
<b>
  <% if true %>
    <%= method_that_does_not_exist %>
  <% end %>
</b>
Yikes!
```

In the above case, a string literal (`"    "`) will be conditionally
appended to the output buffer with some code like below:

```ruby
@output_buffer.safe_append='    '.freeze
```

This commit teaches text tokens (string literals) to scan forward in the
compiled template until it finds the literal, thereby skipping the code
generated for appending to the output buffer.

Related to:

* Bug: rails#48173
* PR: rails#48184
@tenderlove tenderlove merged commit 5513296 into rails:main May 24, 2023
9 checks passed
@tenderlove tenderlove deleted the fix-column-info branch May 24, 2023 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant