herb 0.10.3-aarch64-linux-gnu → 0.11.0-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +16 -6
- data/README.md +36 -119
- data/Rakefile +2 -11
- data/config/action_view_helpers/actioncable/action_cable_helper/action_cable_meta_tag.yml +12 -8
- data/config/action_view_helpers/actionpack/content_security_policy/content_security_policy?.yml +9 -6
- data/config/action_view_helpers/actionpack/content_security_policy/content_security_policy_nonce.yml +9 -6
- data/config/action_view_helpers/actionpack/polymorphic_routes/polymorphic_path.yml +20 -12
- data/config/action_view_helpers/actionpack/polymorphic_routes/polymorphic_url.yml +30 -18
- data/config/action_view_helpers/actionpack/request_forgery_protection/form_authenticity_token.yml +15 -9
- data/config/action_view_helpers/actionpack/request_forgery_protection/protect_against_forgery?.yml +9 -6
- data/config/action_view_helpers/actiontext/content_helper/render_action_text_content.yml +15 -9
- data/config/action_view_helpers/actiontext/content_helper/sanitize_action_text_content.yml +15 -9
- data/config/action_view_helpers/actiontext/tag_helper/rich_textarea_tag.yml +34 -22
- data/config/action_view_helpers/actionview/active_model_helper/error_message.yml +9 -6
- data/config/action_view_helpers/actionview/active_model_helper/error_wrapping.yml +9 -6
- data/config/action_view_helpers/actionview/active_model_helper/object.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/apply_stylesheet_media_default.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/audio_tag.yml +40 -27
- data/config/action_view_helpers/actionview/asset_tag_helper/auto_discovery_link_tag.yml +37 -23
- data/config/action_view_helpers/actionview/asset_tag_helper/auto_include_nonce.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/auto_include_nonce_for_scripts.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/auto_include_nonce_for_styles.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/favicon_link_tag.yml +32 -22
- data/config/action_view_helpers/actionview/asset_tag_helper/image_decoding.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/image_loading.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/image_tag.yml +67 -46
- data/config/action_view_helpers/actionview/asset_tag_helper/javascript_include_tag.yml +58 -39
- data/config/action_view_helpers/actionview/asset_tag_helper/picture_tag.yml +22 -14
- data/config/action_view_helpers/actionview/asset_tag_helper/preload_link_tag.yml +45 -30
- data/config/action_view_helpers/actionview/asset_tag_helper/preload_links_header.yml +9 -6
- data/config/action_view_helpers/actionview/asset_tag_helper/stylesheet_link_tag.yml +49 -30
- data/config/action_view_helpers/actionview/asset_tag_helper/video_tag.yml +53 -35
- data/config/action_view_helpers/actionview/asset_url_helper/asset_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/asset_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/audio_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/audio_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/compute_asset_extname.yml +9 -6
- data/config/action_view_helpers/actionview/asset_url_helper/compute_asset_host.yml +9 -6
- data/config/action_view_helpers/actionview/asset_url_helper/compute_asset_path.yml +9 -6
- data/config/action_view_helpers/actionview/asset_url_helper/font_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/font_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/image_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/image_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/javascript_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/javascript_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/public_compute_asset_path.yml +9 -6
- data/config/action_view_helpers/actionview/asset_url_helper/stylesheet_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/stylesheet_url.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/video_path.yml +16 -10
- data/config/action_view_helpers/actionview/asset_url_helper/video_url.yml +16 -10
- data/config/action_view_helpers/actionview/atom_feed_helper/atom_feed.yml +52 -27
- data/config/action_view_helpers/actionview/cache_helper/cache.yml +25 -15
- data/config/action_view_helpers/actionview/cache_helper/cache_fragment_name.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/cache_if.yml +20 -12
- data/config/action_view_helpers/actionview/cache_helper/cache_unless.yml +20 -12
- data/config/action_view_helpers/actionview/cache_helper/caching_predicate.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/digest_path_from_template.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/fragment_for.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/fragment_name_with_digest.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/read_fragment_for.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/uncacheable.yml +9 -6
- data/config/action_view_helpers/actionview/cache_helper/write_fragment_for.yml +9 -6
- data/config/action_view_helpers/actionview/capture_helper/capture.yml +9 -6
- data/config/action_view_helpers/actionview/capture_helper/content_for.yml +20 -12
- data/config/action_view_helpers/actionview/capture_helper/content_for_predicate.yml +15 -9
- data/config/action_view_helpers/actionview/capture_helper/provide.yml +15 -9
- data/config/action_view_helpers/actionview/capture_helper/with_output_buffer.yml +9 -6
- data/config/action_view_helpers/actionview/content_exfiltration_prevention_helper/prepend_content_exfiltration_prevention.yml +9 -6
- data/config/action_view_helpers/actionview/content_exfiltration_prevention_helper/prevent_content_exfiltration.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/action_name.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/assign_controller.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/controller.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/controller_name.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/controller_path.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/cookies.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/flash.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/headers.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/logger.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/params.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/request.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/request_forgery_protection_token.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/response.yml +9 -6
- data/config/action_view_helpers/actionview/controller_helper/session.yml +9 -6
- data/config/action_view_helpers/actionview/csp_helper/csp_meta_tag.yml +18 -11
- data/config/action_view_helpers/actionview/csrf_helper/csrf_meta_tags.yml +16 -10
- data/config/action_view_helpers/actionview/date_helper/date_select.yml +85 -51
- data/config/action_view_helpers/actionview/date_helper/datetime_select.yml +65 -39
- data/config/action_view_helpers/actionview/date_helper/distance_of_time_in_words.yml +30 -18
- data/config/action_view_helpers/actionview/date_helper/relative_time_in_words.yml +35 -21
- data/config/action_view_helpers/actionview/date_helper/select_date.yml +50 -30
- data/config/action_view_helpers/actionview/date_helper/select_datetime.yml +65 -39
- data/config/action_view_helpers/actionview/date_helper/select_day.yml +40 -24
- data/config/action_view_helpers/actionview/date_helper/select_hour.yml +50 -30
- data/config/action_view_helpers/actionview/date_helper/select_minute.yml +40 -24
- data/config/action_view_helpers/actionview/date_helper/select_month.yml +60 -36
- data/config/action_view_helpers/actionview/date_helper/select_second.yml +35 -21
- data/config/action_view_helpers/actionview/date_helper/select_time.yml +55 -33
- data/config/action_view_helpers/actionview/date_helper/select_year.yml +45 -27
- data/config/action_view_helpers/actionview/date_helper/time_ago_in_words.yml +21 -13
- data/config/action_view_helpers/actionview/date_helper/time_select.yml +60 -36
- data/config/action_view_helpers/actionview/date_helper/time_tag.yml +32 -20
- data/config/action_view_helpers/actionview/debug_helper/debug.yml +15 -9
- data/config/action_view_helpers/actionview/form_builder/button.yml +60 -0
- data/config/action_view_helpers/actionview/form_builder/submit.yml +48 -0
- data/config/action_view_helpers/actionview/form_helper/apply_form_for_options.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/checkbox.yml +41 -25
- data/config/action_view_helpers/actionview/form_helper/color_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/date_field.yml +35 -21
- data/config/action_view_helpers/actionview/form_helper/datetime_field.yml +41 -25
- data/config/action_view_helpers/actionview/form_helper/email_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/emitted_hidden_id.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/fields.yml +37 -18
- data/config/action_view_helpers/actionview/form_helper/fields_for.yml +33 -15
- data/config/action_view_helpers/actionview/form_helper/file_field.yml +45 -27
- data/config/action_view_helpers/actionview/form_helper/form_for.yml +45 -24
- data/config/action_view_helpers/actionview/form_helper/form_with.yml +56 -30
- data/config/action_view_helpers/actionview/form_helper/form_with_generates_ids.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/form_with_generates_remote_forms.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/hidden_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/label.yml +52 -27
- data/config/action_view_helpers/actionview/form_helper/month_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/multipart.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/multiple_file_field_include_hidden.yml +9 -6
- data/config/action_view_helpers/actionview/form_helper/number_field.yml +45 -27
- data/config/action_view_helpers/actionview/form_helper/password_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/radio_button.yml +30 -18
- data/config/action_view_helpers/actionview/form_helper/range_field.yml +45 -27
- data/config/action_view_helpers/actionview/form_helper/search_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/telephone_field.yml +26 -16
- data/config/action_view_helpers/actionview/form_helper/text_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/textarea.yml +31 -19
- data/config/action_view_helpers/actionview/form_helper/time_field.yml +40 -24
- data/config/action_view_helpers/actionview/form_helper/url_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_helper/week_field.yml +25 -15
- data/config/action_view_helpers/actionview/form_options_helper/collection_checkboxes.yml +58 -31
- data/config/action_view_helpers/actionview/form_options_helper/collection_radio_buttons.yml +57 -30
- data/config/action_view_helpers/actionview/form_options_helper/collection_select.yml +65 -39
- data/config/action_view_helpers/actionview/form_options_helper/grouped_collection_select.yml +65 -39
- data/config/action_view_helpers/actionview/form_options_helper/grouped_options_for_select.yml +35 -21
- data/config/action_view_helpers/actionview/form_options_helper/option_groups_from_collection_for_select.yml +40 -24
- data/config/action_view_helpers/actionview/form_options_helper/options_for_select.yml +20 -12
- data/config/action_view_helpers/actionview/form_options_helper/options_from_collection_for_select.yml +30 -18
- data/config/action_view_helpers/actionview/form_options_helper/select.yml +60 -36
- data/config/action_view_helpers/actionview/form_options_helper/time_zone_options_for_select.yml +25 -15
- data/config/action_view_helpers/actionview/form_options_helper/time_zone_select.yml +50 -30
- data/config/action_view_helpers/actionview/form_options_helper/weekday_options_for_select.yml +30 -18
- data/config/action_view_helpers/actionview/form_options_helper/weekday_select.yml +30 -18
- data/config/action_view_helpers/actionview/form_tag_helper/button_tag.yml +39 -21
- data/config/action_view_helpers/actionview/form_tag_helper/checkbox_tag.yml +33 -21
- data/config/action_view_helpers/actionview/form_tag_helper/color_field_tag.yml +26 -17
- data/config/action_view_helpers/actionview/form_tag_helper/date_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/datetime_field_tag.yml +28 -18
- data/config/action_view_helpers/actionview/form_tag_helper/default_enforce_utf8.yml +9 -6
- data/config/action_view_helpers/actionview/form_tag_helper/email_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/embed_authenticity_token_in_remote_forms.yml +9 -6
- data/config/action_view_helpers/actionview/form_tag_helper/field_id.yml +30 -18
- data/config/action_view_helpers/actionview/form_tag_helper/field_name.yml +30 -18
- data/config/action_view_helpers/actionview/form_tag_helper/field_set_tag.yml +23 -15
- data/config/action_view_helpers/actionview/form_tag_helper/file_field_tag.yml +35 -22
- data/config/action_view_helpers/actionview/form_tag_helper/form_tag.yml +38 -24
- data/config/action_view_helpers/actionview/form_tag_helper/hidden_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/image_submit_tag.yml +31 -21
- data/config/action_view_helpers/actionview/form_tag_helper/label_tag.yml +33 -17
- data/config/action_view_helpers/actionview/form_tag_helper/month_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/number_field_tag.yml +47 -29
- data/config/action_view_helpers/actionview/form_tag_helper/password_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/radio_button_tag.yml +32 -20
- data/config/action_view_helpers/actionview/form_tag_helper/range_field_tag.yml +47 -29
- data/config/action_view_helpers/actionview/form_tag_helper/search_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/select_tag.yml +47 -29
- data/config/action_view_helpers/actionview/form_tag_helper/submit_tag.yml +33 -21
- data/config/action_view_helpers/actionview/form_tag_helper/telephone_field_tag.yml +28 -18
- data/config/action_view_helpers/actionview/form_tag_helper/text_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/textarea_tag.yml +31 -20
- data/config/action_view_helpers/actionview/form_tag_helper/time_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/url_field_tag.yml +27 -17
- data/config/action_view_helpers/actionview/form_tag_helper/utf8_enforcer_tag.yml +9 -6
- data/config/action_view_helpers/actionview/form_tag_helper/week_field_tag.yml +28 -18
- data/config/action_view_helpers/actionview/javascript_helper/escape_javascript.yml +16 -10
- data/config/action_view_helpers/actionview/javascript_helper/javascript_cdata_section.yml +9 -6
- data/config/action_view_helpers/actionview/javascript_helper/javascript_tag.yml +41 -27
- data/config/action_view_helpers/actionview/number_helper/number_to_currency.yml +29 -18
- data/config/action_view_helpers/actionview/number_helper/number_to_human.yml +25 -15
- data/config/action_view_helpers/actionview/number_helper/number_to_human_size.yml +20 -12
- data/config/action_view_helpers/actionview/number_helper/number_to_percentage.yml +20 -12
- data/config/action_view_helpers/actionview/number_helper/number_to_phone.yml +33 -20
- data/config/action_view_helpers/actionview/number_helper/number_with_delimiter.yml +21 -13
- data/config/action_view_helpers/actionview/number_helper/number_with_precision.yml +25 -15
- data/config/action_view_helpers/actionview/output_safety_helper/raw.yml +15 -9
- data/config/action_view_helpers/actionview/output_safety_helper/safe_join.yml +20 -12
- data/config/action_view_helpers/actionview/output_safety_helper/to_sentence.yml +24 -15
- data/config/action_view_helpers/actionview/record_identifier/dom_class.yml +20 -12
- data/config/action_view_helpers/actionview/record_identifier/dom_id.yml +20 -12
- data/config/action_view_helpers/actionview/record_identifier/dom_target.yml +15 -9
- data/config/action_view_helpers/actionview/record_identifier/model_name_from_record_or_class.yml +9 -6
- data/config/action_view_helpers/actionview/rendering_helper/render.yml +108 -22
- data/config/action_view_helpers/actionview/sanitize_helper/sanitize.yml +25 -15
- data/config/action_view_helpers/actionview/sanitize_helper/sanitize_css.yml +15 -9
- data/config/action_view_helpers/actionview/sanitize_helper/sanitizer_vendor.yml +9 -6
- data/config/action_view_helpers/actionview/sanitize_helper/strip_links.yml +15 -9
- data/config/action_view_helpers/actionview/sanitize_helper/strip_tags.yml +15 -9
- data/config/action_view_helpers/actionview/tag_helper/cdata_section.yml +15 -9
- data/config/action_view_helpers/actionview/tag_helper/content_tag.yml +59 -38
- data/config/action_view_helpers/actionview/tag_helper/escape_once.yml +15 -9
- data/config/action_view_helpers/actionview/tag_helper/tag.yml +54 -31
- data/config/action_view_helpers/actionview/tag_helper/token_list.yml +16 -10
- data/config/action_view_helpers/actionview/text_helper/concat.yml +15 -9
- data/config/action_view_helpers/actionview/text_helper/current_cycle.yml +15 -9
- data/config/action_view_helpers/actionview/text_helper/cycle.yml +23 -14
- data/config/action_view_helpers/actionview/text_helper/excerpt.yml +33 -20
- data/config/action_view_helpers/actionview/text_helper/highlight.yml +37 -18
- data/config/action_view_helpers/actionview/text_helper/pluralize.yml +30 -18
- data/config/action_view_helpers/actionview/text_helper/reset_cycle.yml +15 -9
- data/config/action_view_helpers/actionview/text_helper/safe_concat.yml +9 -6
- data/config/action_view_helpers/actionview/text_helper/simple_format.yml +33 -20
- data/config/action_view_helpers/actionview/text_helper/truncate.yml +38 -23
- data/config/action_view_helpers/actionview/text_helper/word_wrap.yml +25 -15
- data/config/action_view_helpers/actionview/translation_helper/debug_missing_translation.yml +9 -6
- data/config/action_view_helpers/actionview/translation_helper/localize.yml +26 -16
- data/config/action_view_helpers/actionview/translation_helper/translate.yml +31 -19
- data/config/action_view_helpers/actionview/url_helper/button_to.yml +57 -33
- data/config/action_view_helpers/actionview/url_helper/button_to_generates_button_tag.yml +9 -6
- data/config/action_view_helpers/actionview/url_helper/current_page?.yml +25 -15
- data/config/action_view_helpers/actionview/url_helper/link_to.yml +76 -53
- data/config/action_view_helpers/actionview/url_helper/link_to_if.yml +54 -20
- data/config/action_view_helpers/actionview/url_helper/link_to_unless.yml +54 -20
- data/config/action_view_helpers/actionview/url_helper/link_to_unless_current.yml +49 -17
- data/config/action_view_helpers/actionview/url_helper/mail_to.yml +60 -34
- data/config/action_view_helpers/actionview/url_helper/phone_to.yml +40 -22
- data/config/action_view_helpers/actionview/url_helper/sms_to.yml +45 -25
- data/config/action_view_helpers/actionview/url_helper/url_for.yml +15 -9
- data/config/action_view_helpers/importmap-rails/importmap_tags_helper/javascript_import_module_tag.yml +32 -0
- data/config/action_view_helpers/importmap-rails/importmap_tags_helper/javascript_importmap_module_preload_tags.yml +39 -0
- data/config/action_view_helpers/importmap-rails/importmap_tags_helper/javascript_importmap_tags.yml +35 -0
- data/config/action_view_helpers/importmap-rails/importmap_tags_helper/javascript_inline_importmap_tag.yml +32 -0
- data/config/action_view_helpers/importmap-rails/importmap_tags_helper/javascript_module_preload_tag.yml +35 -0
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_exempts_page_from_cache.yml +9 -6
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_exempts_page_from_cache_tag.yml +12 -8
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_exempts_page_from_preview.yml +9 -6
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_exempts_page_from_preview_tag.yml +12 -8
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_page_requires_reload.yml +9 -6
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_page_requires_reload_tag.yml +12 -8
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_refresh_method_tag.yml +17 -11
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_refresh_scroll_tag.yml +17 -11
- data/config/action_view_helpers/turbo-rails/drive_helper/turbo_refreshes_with.yml +20 -12
- data/config/action_view_helpers/turbo-rails/frames_helper/turbo_frame_tag.yml +54 -33
- data/config/action_view_helpers/turbo-rails/includes_helper/turbo_include_tags.yml +9 -6
- data/config/action_view_helpers/turbo-rails/streams_action_helper/turbo_stream_action_tag.yml +32 -20
- data/config/action_view_helpers/turbo-rails/streams_action_helper/turbo_stream_refresh_tag.yml +18 -11
- data/config/action_view_helpers/turbo-rails/streams_helper/turbo_stream.yml +9 -6
- data/config/action_view_helpers/turbo-rails/streams_helper/turbo_stream_from.yml +28 -18
- data/config/html_elements.yml +597 -0
- data/config/options.yml +1 -0
- data/config/slots/components.yml +52 -0
- data/config/state/kind.yml +61 -0
- data/config/state/operators.yml +27 -0
- data/config/state/predicates.yml +39 -0
- data/config/state/transforms.yml +18 -0
- data/config/view_context_methods/actionview/base/annotate_rendered_view_with_filenames.yml +4 -4
- data/config/view_context_methods/actionview/base/assign.yml +4 -4
- data/config/view_context_methods/actionview/base/assigns.yml +4 -4
- data/config/view_context_methods/actionview/base/automatically_disable_submit_tag.yml +4 -4
- data/config/view_context_methods/actionview/base/compiled_method_container.yml +4 -4
- data/config/view_context_methods/actionview/base/config.yml +4 -4
- data/config/view_context_methods/actionview/base/default_form_builder.yml +4 -4
- data/config/view_context_methods/actionview/base/default_formats.yml +4 -4
- data/config/view_context_methods/actionview/base/field_error_proc.yml +4 -4
- data/config/view_context_methods/actionview/base/formats.yml +4 -4
- data/config/view_context_methods/actionview/base/in_rendering_context.yml +4 -4
- data/config/view_context_methods/actionview/base/locale.yml +4 -4
- data/config/view_context_methods/actionview/base/lookup_context.yml +4 -4
- data/config/view_context_methods/actionview/base/output_buffer.yml +4 -4
- data/config/view_context_methods/actionview/base/prefix_partial_path_with_controller_namespace.yml +4 -4
- data/config/view_context_methods/actionview/base/remove_hidden_field_autocomplete.yml +4 -4
- data/config/view_context_methods/actionview/base/streaming_completion_on_exception.yml +4 -4
- data/config/view_context_methods/actionview/base/view_flow.yml +4 -4
- data/config/view_context_methods/actionview/base/view_paths.yml +4 -4
- data/config/view_context_methods/actionview/base/view_renderer.yml +4 -4
- data/config/view_context_methods/actionview/template/local_assigns.yml +4 -4
- data/config/view_context_methods/activemodel/conversion/convert_to_model.yml +4 -4
- data/config/view_context_methods/activesupport/benchmarkable/benchmark.yml +4 -4
- data/config.yml +1240 -790
- data/exe/herb +2 -0
- data/ext/herb/error_helpers.c +355 -17
- data/ext/herb/error_helpers.h +1 -1
- data/ext/herb/extconf.rb +4 -2
- data/ext/herb/extension.c +137 -89
- data/ext/herb/extension_helpers.c +81 -42
- data/ext/herb/extension_helpers.h +4 -1
- data/ext/herb/nodes.c +826 -358
- data/ext/herb/nodes.h +3 -2
- data/ext/herb/parser_options_helpers.c +151 -0
- data/ext/herb/parser_options_helpers.h +14 -0
- data/herb.gemspec +2 -2
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/4.0/herb.so +0 -0
- data/lib/herb/action_view/helper_registry.rb +1358 -62
- data/lib/herb/analysis/partial_declaration.rb +140 -0
- data/lib/herb/analysis/partial_index.rb +189 -0
- data/lib/herb/analysis/partial_resolution.rb +161 -0
- data/lib/herb/analysis/partial_resolver.rb +144 -0
- data/lib/herb/analysis/project_index.rb +152 -0
- data/lib/herb/{action_view → analysis}/render_analyzer.rb +287 -77
- data/lib/herb/analysis/render_graph/ancestor_chain.rb +27 -0
- data/lib/herb/analysis/render_graph/builder.rb +376 -0
- data/lib/herb/analysis/render_graph/call_frame.rb +9 -0
- data/lib/herb/analysis/render_graph/call_site_location.rb +23 -0
- data/lib/herb/analysis/render_graph/inferred_signature.rb +21 -0
- data/lib/herb/analysis/render_graph/partial_call_site.rb +40 -0
- data/lib/herb/analysis/render_graph/partial_context.rb +46 -0
- data/lib/herb/analysis/render_graph/template_roots.rb +31 -0
- data/lib/herb/analysis/render_graph.rb +285 -0
- data/lib/herb/analysis/ruby_locals_index/local.rb +25 -0
- data/lib/herb/analysis/ruby_locals_index/named_reference.rb +22 -0
- data/lib/herb/analysis/ruby_locals_index/offset_table.rb +44 -0
- data/lib/herb/analysis/ruby_locals_index/reference_collector.rb +80 -0
- data/lib/herb/analysis/ruby_locals_index/state_locals.rb +49 -0
- data/lib/herb/analysis/ruby_locals_index.rb +165 -0
- data/lib/herb/analysis/ruby_reference.rb +67 -0
- data/lib/herb/analysis/template_dependencies/dependency_collector.rb +179 -0
- data/lib/herb/analysis/template_dependencies/node_dependency_collector.rb +309 -0
- data/lib/herb/analysis/template_dependencies.rb +562 -0
- data/lib/herb/ast/erb_render_node.rb +26 -94
- data/lib/herb/ast/helpers.rb +90 -10
- data/lib/herb/ast/herb_directive_node.rb +18 -0
- data/lib/herb/ast/node.rb +32 -2
- data/lib/herb/ast/nodes.rb +1342 -105
- data/lib/herb/backend.rb +73 -0
- data/lib/herb/bootstrap.rb +3 -7
- data/lib/herb/cli.rb +550 -32
- data/lib/herb/colors.rb +14 -0
- data/lib/herb/configuration.rb +71 -35
- data/lib/herb/defaults.yml +2 -1
- data/lib/herb/dev/assets.rb +57 -0
- data/lib/herb/dev/classifier.rb +84 -0
- data/lib/herb/dev/embedded.rb +27 -0
- data/lib/herb/dev/pipeline.rb +305 -0
- data/lib/herb/dev/protocol.rb +221 -0
- data/lib/herb/dev/runner.rb +175 -175
- data/lib/herb/dev/server.rb +89 -26
- data/lib/herb/dev/server_entry.rb +41 -6
- data/lib/herb/dev/watcher.rb +181 -0
- data/lib/herb/dev.rb +163 -0
- data/lib/herb/diagnostic/formatter.rb +88 -0
- data/lib/herb/diagnostic.rb +172 -0
- data/lib/herb/diff/operation.rb +36 -0
- data/lib/herb/diff/result.rb +62 -0
- data/lib/herb/diff.rb +10 -0
- data/lib/herb/engine/collector.rb +62 -0
- data/lib/herb/engine/compiler.rb +346 -108
- data/lib/herb/engine/component_tags/constant_resolver.rb +28 -0
- data/lib/herb/engine/component_tags/partial_resolver.rb +54 -0
- data/lib/herb/engine/component_tags/resolver.rb +32 -0
- data/lib/herb/engine/component_tags/visitor.rb +231 -0
- data/lib/herb/engine/css_inliner/inliner.rb +101 -0
- data/lib/herb/engine/css_inliner/visitor.rb +174 -0
- data/lib/herb/engine/errors.rb +122 -0
- data/lib/herb/engine/helpers.rb +82 -0
- data/lib/herb/engine/inline_render/inliner.rb +122 -0
- data/lib/herb/engine/inline_render/visitor.rb +267 -0
- data/lib/herb/engine/runtime/entry.rb +62 -0
- data/lib/herb/engine/runtime/error_page.rb +362 -0
- data/lib/herb/engine/runtime/html_safe_assertions.rb +217 -0
- data/lib/herb/engine/runtime/journal/summary.rb +227 -0
- data/lib/herb/engine/runtime/journal.rb +379 -0
- data/lib/herb/engine/runtime/middleware.rb +212 -0
- data/lib/herb/engine/runtime/observations.rb +73 -0
- data/lib/herb/engine/runtime/report.rb +204 -0
- data/lib/herb/engine/runtime/session.rb +437 -0
- data/lib/herb/engine/runtime.rb +21 -0
- data/lib/herb/engine/scoped_style/channel.rb +66 -0
- data/lib/herb/engine/scoped_style/collector.rb +74 -0
- data/lib/herb/engine/scoped_style/visitor.rb +533 -0
- data/lib/herb/engine/slots/annotation.rb +98 -0
- data/lib/herb/engine/slots/bindings.rb +61 -0
- data/lib/herb/engine/slots/callee.rb +118 -0
- data/lib/herb/engine/slots/component_definitions.rb +67 -0
- data/lib/herb/engine/slots/components/async.rb +24 -0
- data/lib/herb/engine/slots/components/base.rb +132 -0
- data/lib/herb/engine/slots/components/deferred.rb +81 -0
- data/lib/herb/engine/slots/components/fallback.rb +27 -0
- data/lib/herb/engine/slots/components/fragment.rb +99 -0
- data/lib/herb/engine/slots/components/lazy.rb +24 -0
- data/lib/herb/engine/slots/components.rb +52 -0
- data/lib/herb/engine/slots/dependencies/channel.rb +72 -0
- data/lib/herb/engine/slots/dependencies.rb +269 -0
- data/lib/herb/engine/slots/dynamics_compiler.rb +854 -0
- data/lib/herb/engine/slots/identifier.rb +35 -0
- data/lib/herb/engine/slots/manifest/channel.rb +74 -0
- data/lib/herb/engine/slots/manifest/collector.rb +75 -0
- data/lib/herb/engine/slots/markers.rb +128 -0
- data/lib/herb/engine/slots/render_bindings.rb +141 -0
- data/lib/herb/engine/slots/schema_compiler.rb +94 -0
- data/lib/herb/engine/slots/state_anchor.rb +94 -0
- data/lib/herb/engine/slots/state_compiler.rb +1326 -0
- data/lib/herb/engine/slots/state_directives.rb +854 -0
- data/lib/herb/engine/slots/state_kinds.rb +54 -0
- data/lib/herb/engine/slots/state_operators.rb +36 -0
- data/lib/herb/engine/slots/state_overrides.rb +79 -0
- data/lib/herb/engine/slots/state_predicates.rb +65 -0
- data/lib/herb/engine/slots/state_transforms.rb +42 -0
- data/lib/herb/engine/slots/statics.rb +185 -0
- data/lib/herb/engine/slots/subtree.rb +82 -0
- data/lib/herb/engine/slots/subtree_compiler.rb +255 -0
- data/lib/herb/engine/slots/types.rb +42 -0
- data/lib/herb/engine/slots/visitor.rb +2256 -0
- data/lib/herb/engine/validators/accessibility_validator.rb +3 -3
- data/lib/herb/engine/validators/base.rb +36 -0
- data/lib/herb/engine/validators/generator_template_validator.rb +39 -0
- data/lib/herb/engine/validators/nesting_validator.rb +3 -3
- data/lib/herb/engine/validators/render_validator.rb +13 -33
- data/lib/herb/engine/validators/security_validator.rb +3 -17
- data/lib/herb/engine/validators.rb +43 -0
- data/lib/herb/engine/visitors/auto_close_omitted_tags_visitor.rb +48 -0
- data/lib/herb/engine/visitors/content_for_visitor.rb +127 -0
- data/lib/herb/engine/{debug_visitor.rb → visitors/debug_visitor.rb} +121 -93
- data/lib/herb/engine/visitors/html_safe_assertions_visitor.rb +281 -0
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +290 -0
- data/lib/herb/engine/visitors/optimize_visitor.rb +728 -0
- data/lib/herb/engine/visitors/remove_comments_visitor.rb +106 -0
- data/lib/herb/engine/visitors/source_attribution_visitor.rb +177 -0
- data/lib/herb/engine.rb +218 -257
- data/lib/herb/ensure_installed.rb +43 -0
- data/lib/herb/errors.rb +646 -157
- data/lib/herb/fingerprint.rb +82 -0
- data/lib/herb/html/elements.rb +18 -0
- data/lib/herb/html/util.rb +21 -2
- data/lib/herb/lex_result.rb +0 -10
- data/lib/herb/locate.rb +163 -0
- data/lib/herb/location.rb +20 -0
- data/lib/herb/parse_result.rb +17 -11
- data/lib/herb/parser_options.rb +65 -46
- data/lib/herb/position.rb +19 -0
- data/lib/herb/prism_inspect.rb +1 -4
- data/lib/herb/project.rb +31 -18
- data/lib/herb/range.rb +5 -0
- data/lib/herb/result.rb +2 -2
- data/lib/herb/ruby_program.rb +110 -0
- data/lib/herb/source_path.rb +232 -0
- data/lib/herb/token.rb +14 -3
- data/lib/herb/version.rb +1 -1
- data/lib/herb/visitor/context/origin.rb +52 -0
- data/lib/herb/visitor/context/replacements.rb +59 -0
- data/lib/herb/visitor/context.rb +169 -0
- data/lib/herb/visitor/context_aware.rb +45 -0
- data/lib/herb/visitor/diagnostics.rb +148 -0
- data/lib/herb/visitor/experimental.rb +33 -0
- data/lib/herb/visitor/parser_option_requirements.rb +151 -0
- data/lib/herb/visitor/stack.rb +192 -0
- data/lib/herb/visitor.rb +47 -1
- data/lib/herb/warnings.rb +25 -0
- data/lib/herb.rb +74 -63
- data/sig/herb/action_view/helper_registry.rbs +82 -10
- data/sig/herb/analysis/partial_declaration.rbs +80 -0
- data/sig/herb/analysis/partial_index.rbs +66 -0
- data/sig/herb/analysis/partial_resolution.rbs +57 -0
- data/sig/herb/analysis/partial_resolver.rbs +76 -0
- data/sig/herb/analysis/project_index.rbs +57 -0
- data/sig/herb/{action_view → analysis}/render_analyzer.rbs +25 -4
- data/sig/herb/analysis/render_graph/ancestor_chain.rbs +22 -0
- data/sig/herb/analysis/render_graph/builder.rbs +180 -0
- data/sig/herb/analysis/render_graph/call_frame.rbs +26 -0
- data/sig/herb/analysis/render_graph/call_site_location.rbs +28 -0
- data/sig/herb/analysis/render_graph/inferred_signature.rbs +27 -0
- data/sig/herb/analysis/render_graph/partial_call_site.rbs +36 -0
- data/sig/herb/analysis/render_graph/partial_context.rbs +31 -0
- data/sig/herb/analysis/render_graph/template_roots.rbs +32 -0
- data/sig/herb/analysis/render_graph.rbs +83 -0
- data/sig/herb/analysis/ruby_locals_index/local.rbs +21 -0
- data/sig/herb/analysis/ruby_locals_index/named_reference.rbs +20 -0
- data/sig/herb/analysis/ruby_locals_index/offset_table.rbs +26 -0
- data/sig/herb/analysis/ruby_locals_index/reference_collector.rbs +40 -0
- data/sig/herb/analysis/ruby_locals_index/state_locals.rbs +19 -0
- data/sig/herb/analysis/ruby_locals_index.rbs +62 -0
- data/sig/herb/analysis/ruby_reference.rbs +28 -0
- data/sig/herb/analysis/template_dependencies/dependency_collector.rbs +52 -0
- data/sig/herb/analysis/template_dependencies/node_dependency_collector.rbs +81 -0
- data/sig/herb/analysis/template_dependencies.rbs +125 -0
- data/sig/herb/ast/erb_render_node.rbs +10 -2
- data/sig/herb/ast/helpers.rbs +31 -1
- data/sig/herb/ast/herb_directive_node.rbs +13 -0
- data/sig/herb/ast/node.rbs +9 -0
- data/sig/herb/ast/nodes.rbs +662 -89
- data/sig/herb/backend.rbs +52 -0
- data/sig/herb/colors.rbs +3 -0
- data/sig/herb/configuration.rbs +27 -3
- data/sig/herb/dev/assets.rbs +27 -0
- data/sig/herb/dev/classifier.rbs +57 -0
- data/sig/herb/dev/embedded.rbs +21 -0
- data/sig/herb/dev/pipeline.rbs +118 -0
- data/sig/herb/dev/protocol.rbs +78 -0
- data/sig/herb/dev/runner.rbs +61 -23
- data/sig/herb/dev/server.rbs +49 -22
- data/sig/herb/dev/server_entry.rbs +46 -21
- data/sig/herb/dev/watcher.rbs +84 -0
- data/sig/herb/dev.rbs +58 -0
- data/sig/herb/diagnostic/formatter.rbs +28 -0
- data/sig/herb/diagnostic.rbs +88 -0
- data/sig/herb/diff/operation.rbs +36 -0
- data/sig/herb/diff/result.rbs +36 -0
- data/sig/herb/diff.rbs +6 -0
- data/sig/herb/engine/collector.rbs +48 -0
- data/sig/herb/engine/compiler.rbs +62 -23
- data/sig/herb/engine/component_tags/constant_resolver.rbs +19 -0
- data/sig/herb/engine/component_tags/partial_resolver.rbs +30 -0
- data/sig/herb/engine/component_tags/resolver.rbs +25 -0
- data/sig/herb/engine/component_tags/visitor.rbs +69 -0
- data/sig/herb/engine/css_inliner/inliner.rbs +65 -0
- data/sig/herb/engine/css_inliner/visitor.rbs +87 -0
- data/sig/herb/engine/errors.rbs +68 -0
- data/sig/herb/engine/helpers.rbs +28 -0
- data/sig/herb/engine/inline_render/inliner.rbs +39 -0
- data/sig/herb/engine/inline_render/visitor.rbs +104 -0
- data/sig/herb/engine/runtime/entry.rbs +43 -0
- data/sig/herb/engine/runtime/error_page.rbs +115 -0
- data/sig/herb/engine/runtime/html_safe_assertions.rbs +99 -0
- data/sig/herb/engine/runtime/journal/summary.rbs +172 -0
- data/sig/herb/engine/runtime/journal.rbs +126 -0
- data/sig/herb/engine/runtime/middleware.rbs +96 -0
- data/sig/herb/engine/runtime/observations.rbs +38 -0
- data/sig/herb/engine/runtime/report.rbs +97 -0
- data/sig/herb/engine/runtime/session.rbs +233 -0
- data/sig/herb/engine/runtime.rbs +14 -0
- data/sig/herb/engine/scoped_style/channel.rbs +45 -0
- data/sig/herb/engine/scoped_style/collector.rbs +45 -0
- data/sig/herb/engine/scoped_style/visitor.rbs +220 -0
- data/sig/herb/engine/slots/annotation.rbs +72 -0
- data/sig/herb/engine/slots/bindings.rbs +34 -0
- data/sig/herb/engine/slots/callee.rbs +62 -0
- data/sig/herb/engine/slots/component_definitions.rbs +19 -0
- data/sig/herb/engine/slots/components/async.rbs +20 -0
- data/sig/herb/engine/slots/components/base.rbs +60 -0
- data/sig/herb/engine/slots/components/deferred.rbs +29 -0
- data/sig/herb/engine/slots/components/fallback.rbs +21 -0
- data/sig/herb/engine/slots/components/fragment.rbs +34 -0
- data/sig/herb/engine/slots/components/lazy.rbs +20 -0
- data/sig/herb/engine/slots/components.rbs +30 -0
- data/sig/herb/engine/slots/dependencies/channel.rbs +51 -0
- data/sig/herb/engine/slots/dependencies.rbs +94 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +349 -0
- data/sig/herb/engine/slots/identifier.rbs +19 -0
- data/sig/herb/engine/slots/manifest/channel.rbs +49 -0
- data/sig/herb/engine/slots/manifest/collector.rbs +45 -0
- data/sig/herb/engine/slots/markers.rbs +85 -0
- data/sig/herb/engine/slots/render_bindings.rbs +69 -0
- data/sig/herb/engine/slots/schema_compiler.rbs +62 -0
- data/sig/herb/engine/slots/state_anchor.rbs +41 -0
- data/sig/herb/engine/slots/state_compiler.rbs +258 -0
- data/sig/herb/engine/slots/state_directives.rbs +278 -0
- data/sig/herb/engine/slots/state_kinds.rbs +24 -0
- data/sig/herb/engine/slots/state_operators.rbs +19 -0
- data/sig/herb/engine/slots/state_overrides.rbs +33 -0
- data/sig/herb/engine/slots/state_predicates.rbs +16 -0
- data/sig/herb/engine/slots/state_transforms.rbs +15 -0
- data/sig/herb/engine/slots/statics.rbs +67 -0
- data/sig/herb/engine/slots/subtree.rbs +49 -0
- data/sig/herb/engine/slots/subtree_compiler.rbs +130 -0
- data/sig/herb/engine/slots/types.rbs +46 -0
- data/sig/herb/engine/slots/visitor.rbs +599 -0
- data/sig/herb/engine/validators/accessibility_validator.rbs +1 -1
- data/sig/herb/engine/validators/base.rbs +28 -0
- data/sig/herb/engine/validators/generator_template_validator.rbs +19 -0
- data/sig/herb/engine/validators/nesting_validator.rbs +1 -1
- data/sig/herb/engine/validators/render_validator.rbs +2 -6
- data/sig/herb/engine/validators/security_validator.rbs +1 -3
- data/sig/herb/engine/validators.rbs +21 -0
- data/sig/herb/engine/visitors/auto_close_omitted_tags_visitor.rbs +26 -0
- data/sig/herb/engine/visitors/content_for_visitor.rbs +52 -0
- data/sig/herb/engine/{debug_visitor.rbs → visitors/debug_visitor.rbs} +26 -15
- data/sig/herb/engine/visitors/html_safe_assertions_visitor.rbs +100 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +111 -0
- data/sig/herb/engine/visitors/optimize_visitor.rbs +246 -0
- data/sig/herb/engine/visitors/remove_comments_visitor.rbs +66 -0
- data/sig/herb/engine/visitors/source_attribution_visitor.rbs +90 -0
- data/sig/herb/engine.rbs +47 -41
- data/sig/herb/ensure_installed.rbs +9 -0
- data/sig/herb/errors.rbs +293 -0
- data/sig/herb/fingerprint.rbs +37 -0
- data/sig/herb/html/elements.rbs +19 -0
- data/sig/herb/html/util.rbs +15 -1
- data/sig/herb/lex_result.rbs +0 -6
- data/sig/herb/locate.rbs +89 -0
- data/sig/herb/location.rbs +12 -0
- data/sig/herb/parse_result.rbs +10 -8
- data/sig/herb/parser_options.rbs +47 -21
- data/sig/herb/position.rbs +11 -0
- data/sig/herb/range.rbs +3 -0
- data/sig/herb/ruby_program.rbs +51 -0
- data/sig/herb/source_path.rbs +132 -0
- data/sig/herb/token.rbs +5 -2
- data/sig/herb/visitor/context/origin.rbs +51 -0
- data/sig/herb/visitor/context/replacements.rbs +39 -0
- data/sig/herb/visitor/context.rbs +83 -0
- data/sig/herb/visitor/context_aware.rbs +32 -0
- data/sig/herb/visitor/diagnostics.rbs +82 -0
- data/sig/herb/visitor/experimental.rbs +23 -0
- data/sig/herb/visitor/parser_option_requirements.rbs +76 -0
- data/sig/herb/visitor/stack.rbs +91 -0
- data/sig/herb/visitor.rbs +22 -0
- data/sig/herb/warnings.rbs +10 -0
- data/sig/herb.rbs +27 -10
- data/sig/serialized_ast_errors.rbs +58 -1
- data/sig/serialized_ast_nodes.rbs +58 -2
- data/src/analyze/action_view/attribute_extraction_helpers.c +73 -36
- data/src/analyze/action_view/generated_handlers.c +37 -1
- data/src/analyze/action_view/generated_handlers.h +2 -1
- data/src/analyze/action_view/helper_registry.c +1353 -58
- data/src/analyze/action_view/registry.c +10 -17
- data/src/analyze/action_view/stylesheet_link_tag.c +40 -0
- data/src/analyze/action_view/tag_helper_node_builders.c +57 -0
- data/src/analyze/action_view/tag_helpers.c +423 -93
- data/src/analyze/analyze.c +301 -64
- data/src/analyze/analyze_helpers.c +420 -23
- data/src/analyze/builders.c +79 -51
- data/src/analyze/conditional_elements.c +13 -8
- data/src/analyze/conditional_open_tags.c +11 -5
- data/src/analyze/control_type.c +16 -1
- data/src/analyze/herb_directives.c +701 -0
- data/src/analyze/invalid_structures.c +11 -7
- data/src/analyze/iteration_nodes.c +306 -0
- data/src/analyze/missing_end.c +116 -32
- data/src/analyze/parse_errors.c +8 -3
- data/src/analyze/postfix_conditionals.c +98 -63
- data/src/analyze/prism_annotate.c +13 -4
- data/src/analyze/render_nodes.c +345 -123
- data/src/analyze/strict_locals.c +30 -26
- data/src/analyze/ternary_conditionals.c +95 -70
- data/src/analyze/transform.c +43 -1
- data/src/ast/ast_node.c +3 -13
- data/src/ast/ast_nodes.c +911 -112
- data/src/ast/ast_pretty_print.c +161 -2
- data/src/diff/herb_diff.c +8 -0
- data/src/diff/herb_diff_attributes.c +1 -0
- data/src/diff/herb_diff_children.c +4 -3
- data/src/diff/herb_diff_helpers.c +7 -1
- data/src/diff/herb_diff_nodes.c +186 -71
- data/src/diff/herb_hash_tree.c +99 -1
- data/src/errors.c +1096 -128
- data/src/extract.c +30 -8
- data/src/herb.c +30 -11
- data/src/include/analyze/action_view/attribute_extraction_helpers.h +1 -1
- data/src/include/analyze/action_view/helper_registry.h +28 -4
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +7 -0
- data/src/include/analyze/analyze.h +11 -0
- data/src/include/analyze/builders.h +16 -0
- data/src/include/analyze/helpers.h +23 -2
- data/src/include/analyze/herb_directive_kinds.h +41 -0
- data/src/include/analyze/herb_directives.h +14 -0
- data/src/include/analyze/iteration_nodes.h +11 -0
- data/src/include/analyze/prism_annotate.h +3 -3
- data/src/include/analyze/ternary_conditionals.h +2 -0
- data/src/include/ast/ast_node.h +1 -5
- data/src/include/ast/ast_nodes.h +76 -2
- data/src/include/ast/ast_pretty_print.h +1 -1
- data/src/include/diff/herb_diff.h +11 -0
- data/src/include/errors.h +156 -39
- data/src/include/extract.h +11 -0
- data/src/include/herb.h +6 -0
- data/src/include/lexer/erb_openers.h +29 -0
- data/src/include/lexer/lexer_peek_helpers.h +8 -1
- data/src/include/lexer/lexer_struct.h +4 -0
- data/src/include/lexer/token.h +3 -0
- data/src/include/lexer/token_struct.h +8 -6
- data/src/include/lib/hb_allocator.h +2 -1
- data/src/include/lib/hb_array.h +2 -0
- data/src/include/lib/hb_foreach.h +1 -1
- data/src/include/lib/hb_string.h +7 -0
- data/src/include/parser/dot_notation.h +1 -1
- data/src/include/parser/foreign_content_elements.h +32 -0
- data/src/include/parser/parser.h +16 -30
- data/src/include/parser/parser_helpers.h +13 -11
- data/src/include/parser/parser_options.h +41 -0
- data/src/include/prism/ruby_parser.h +6 -0
- data/src/include/util/html_elements.h +85 -0
- data/src/include/util/html_util.h +1 -0
- data/src/include/version.h +1 -1
- data/src/lexer/lexer_peek_helpers.c +15 -1
- data/src/lexer/token.c +83 -1
- data/src/lexer.c +196 -12
- data/src/lib/hb_allocator.c +2 -0
- data/src/lib/hb_array.c +26 -0
- data/src/lib/hb_string.c +26 -0
- data/src/main.c +1 -1
- data/src/parser/dot_notation.c +4 -3
- data/src/parser/match_tags.c +66 -1
- data/src/parser/parser_helpers.c +69 -37
- data/src/parser.c +606 -383
- data/src/parser_options_defaults.c +30 -0
- data/src/prism/prism_helpers.c +3 -0
- data/src/prism/ruby_parser.c +49 -0
- data/src/util/html_util.c +11 -58
- data/src/visitor.c +77 -1
- data/templates/ext/herb/error_helpers.c.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +18 -13
- data/templates/ext/herb/nodes.h.erb +2 -1
- data/templates/ext/herb/parser_options_helpers.c.erb +69 -0
- data/templates/ext/herb/parser_options_helpers.h.erb +11 -0
- data/templates/java/nodes.c.erb +20 -16
- data/templates/java/nodes.h.erb +3 -2
- data/templates/java/org/herb/ParserOptions.java.erb +24 -0
- data/templates/java/org/herb/ast/HelperRegistry.java.erb +67 -31
- data/templates/java/org/herb/ast/HelperType.java.erb +29 -0
- data/templates/java/org/herb/ast/Nodes.java.erb +11 -7
- data/templates/java/parser_options_helpers.c.erb +45 -0
- data/templates/java/parser_options_helpers.h.erb +10 -0
- data/templates/javascript/packages/client/src/state-kinds.ts.erb +49 -0
- data/templates/javascript/packages/client/src/state-operators.ts.erb +15 -0
- data/templates/javascript/packages/client/src/state-predicates.ts.erb +27 -0
- data/templates/javascript/packages/client/src/state-transforms.ts.erb +19 -0
- data/templates/javascript/packages/core/src/action-view-helpers.ts.erb +47 -0
- data/templates/javascript/packages/core/src/built-in-components.ts.erb +67 -0
- data/templates/javascript/packages/core/src/errors.ts.erb +9 -3
- data/templates/javascript/packages/core/src/foreign-content-elements.ts.erb +18 -0
- data/templates/javascript/packages/core/src/html-constants.ts.erb +32 -0
- data/templates/javascript/packages/core/src/html-elements.ts.erb +41 -0
- data/templates/javascript/packages/core/src/node-type-guards.ts.erb +11 -7
- data/templates/javascript/packages/core/src/nodes.ts.erb +82 -19
- data/templates/javascript/packages/core/src/parser-options.ts.erb +41 -0
- data/templates/javascript/packages/core/src/visitor.ts.erb +1 -1
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +3 -3
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +17 -12
- data/templates/javascript/packages/node/extension/nodes.h.erb +3 -3
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +41 -0
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +12 -0
- data/templates/lib/herb/action_view/helper_registry.rb.erb +77 -3
- data/templates/lib/herb/ast/nodes.rb.erb +16 -6
- data/templates/lib/herb/engine/slots/component_definitions.rb.erb +38 -0
- data/templates/lib/herb/engine/slots/state_kinds.rb.erb +37 -0
- data/templates/lib/herb/engine/slots/state_operators.rb.erb +26 -0
- data/templates/lib/herb/engine/slots/state_predicates.rb.erb +39 -0
- data/templates/lib/herb/engine/slots/state_transforms.rb.erb +27 -0
- data/templates/lib/herb/errors.rb.erb +34 -6
- data/templates/lib/herb/html/elements.rb.erb +12 -0
- data/templates/lib/herb/parser_options.rb.erb +32 -0
- data/templates/lib/herb/visitor.rb.erb +7 -1
- data/templates/rust/herb-printer/src/printer_visitor.rs.erb +14 -0
- data/templates/rust/src/action_view_helpers.rs.erb +38 -0
- data/templates/rust/src/ast/nodes.rs.erb +24 -31
- data/templates/rust/src/errors.rs.erb +1 -1
- data/templates/rust/src/nodes.rs.erb +58 -26
- data/templates/rust/src/parser_options.rs.erb +16 -0
- data/templates/rust/src/prism/generated_deserialize.rs.erb +109 -0
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +153 -0
- data/templates/rust/src/union_types.rs.erb +7 -1
- data/templates/rust/src/visitor.rs.erb +1 -1
- data/templates/src/analyze/action_view/helper_registry.c.erb +22 -0
- data/templates/src/analyze/missing_end.c.erb +13 -5
- data/templates/src/ast/ast_nodes.c.erb +41 -2
- data/templates/src/diff/herb_diff_nodes.c.erb +44 -8
- data/templates/src/errors.c.erb +8 -3
- data/templates/src/include/analyze/action_view/helper_registry.h.erb +19 -0
- data/templates/src/include/analyze/herb_directive_kinds.h.erb +25 -0
- data/templates/src/include/errors.h.erb +3 -1
- data/templates/src/include/parser/foreign_content_elements.h.erb +23 -0
- data/templates/src/include/parser/parser_options.h.erb +21 -0
- data/templates/src/include/util/html_elements.h.erb +28 -0
- data/templates/src/parser_options_defaults.c.erb +9 -0
- data/templates/template.rb +564 -9
- data/templates/wasm/error_helpers.cpp.erb +4 -4
- data/templates/wasm/nodes.cpp.erb +12 -12
- data/templates/wasm/nodes.h.erb +3 -3
- data/templates/wasm/parser_options_helpers.cpp.erb +25 -0
- data/templates/wasm/parser_options_helpers.h.erb +12 -0
- metadata +306 -27
- data/config/action_view_helpers/actionview/form_helper/button.yml +0 -38
- data/config/action_view_helpers/actionview/form_helper/submit.yml +0 -35
- data/lib/herb/ast.rb +0 -7
- data/lib/herb/diff_operation.rb +0 -34
- data/lib/herb/diff_result.rb +0 -59
- data/lib/herb/engine/error_formatter.rb +0 -432
- data/lib/herb/engine/parser_error_overlay.rb +0 -773
- data/lib/herb/engine/validation_error_overlay.rb +0 -182
- data/lib/herb/engine/validation_errors.rb +0 -65
- data/lib/herb/engine/validator.rb +0 -80
- data/sig/herb/ast.rbs +0 -6
- data/sig/herb/diff_operation.rbs +0 -34
- data/sig/herb/diff_result.rbs +0 -34
- data/sig/herb/engine/debug.rbs +0 -38
- data/sig/herb/engine/error_formatter.rbs +0 -47
- data/sig/herb/engine/parser_error_overlay.rbs +0 -41
- data/sig/herb/engine/validation_error_overlay.rbs +0 -35
- data/sig/herb/engine/validation_errors.rbs +0 -45
- data/sig/herb/engine/validator.rbs +0 -41
- data/sig/herb_c_extension.rbs +0 -10
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
require "prism"
|
|
5
|
+
|
|
6
|
+
require_relative "state_anchor"
|
|
7
|
+
require_relative "state_kinds"
|
|
8
|
+
require_relative "state_operators"
|
|
9
|
+
require_relative "state_predicates"
|
|
10
|
+
require_relative "state_transforms"
|
|
11
|
+
|
|
12
|
+
module Herb
|
|
13
|
+
class Engine
|
|
14
|
+
module Slots
|
|
15
|
+
# Parses `<%# herb:state (name: default, …) %>` directives and classifies how the body
|
|
16
|
+
# reads the states they declare.
|
|
17
|
+
#
|
|
18
|
+
class StateDirectives
|
|
19
|
+
BARE = /\A[a-z_][a-zA-Z0-9_]*\z/ #: Regexp
|
|
20
|
+
|
|
21
|
+
KINDS = StateKinds::PRISM #: Hash[String, Symbol]
|
|
22
|
+
|
|
23
|
+
NODE_KINDS = StateKinds::NODE #: Hash[String, Symbol]
|
|
24
|
+
|
|
25
|
+
Declaration = Data.define(
|
|
26
|
+
:name, #: String
|
|
27
|
+
:kind, #: Symbol
|
|
28
|
+
:default, #: String
|
|
29
|
+
:derived, #: untyped
|
|
30
|
+
:line, #: Integer?
|
|
31
|
+
:column #: Integer?
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
Read = Data.define(
|
|
35
|
+
:name, #: String
|
|
36
|
+
:comparand, #: String?
|
|
37
|
+
:kind, #: Symbol?
|
|
38
|
+
:operator, #: String?
|
|
39
|
+
:against, #: String?
|
|
40
|
+
:transform, #: String?
|
|
41
|
+
:against_transform #: String?
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
Combo = Data.define(
|
|
45
|
+
:op, #: String
|
|
46
|
+
:parts #: Array[untyped]
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
FoldIncrement = Data.define(
|
|
50
|
+
:name, #: String
|
|
51
|
+
:by #: Integer
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
ORDERED_OPERATORS = StateOperators::ORDERED #: Array[Symbol]
|
|
55
|
+
MIRRORED_OPERATORS = StateOperators::MIRRORED #: Hash[String, String]
|
|
56
|
+
NEGATED_OPERATORS = StateOperators::NEGATED #: Hash[String, String]
|
|
57
|
+
|
|
58
|
+
FALSY_OPERATOR = "falsy" #: String
|
|
59
|
+
|
|
60
|
+
PREDICATES = StatePredicates::TABLE #: Hash[String, Hash[Symbol, untyped]]
|
|
61
|
+
|
|
62
|
+
UNARY_OPERATORS = StatePredicates::UNARY #: Hash[String, String]
|
|
63
|
+
|
|
64
|
+
NEGATED_UNARY = StatePredicates::NEGATED #: Hash[String, String]
|
|
65
|
+
|
|
66
|
+
TRANSFORMS = StateTransforms::TABLE #: Hash[String, Hash[Symbol, untyped]]
|
|
67
|
+
|
|
68
|
+
TRANSFORM_SPELLINGS = StateTransforms::SPELLINGS #: Hash[String, String]
|
|
69
|
+
|
|
70
|
+
Parsing = Data.define(
|
|
71
|
+
:locals, #: Hash[String, Symbol]
|
|
72
|
+
:declared, #: Hash[String, Declaration]
|
|
73
|
+
:names, #: Array[String]
|
|
74
|
+
:enclosing, #: Hash[String, Declaration]
|
|
75
|
+
:visitor, #: untyped
|
|
76
|
+
:location #: Herb::Location?
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
module Silent
|
|
80
|
+
#: (String, Herb::Location?, Symbol, **untyped) -> nil
|
|
81
|
+
def self.slot_error(_message, _location, _family, **_options)
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#: (?Symbol?) -> Integer
|
|
86
|
+
def self.diagnostic_count(_severity = nil)
|
|
87
|
+
0
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class << self
|
|
92
|
+
#: (untyped, Hash[String, Symbol], visitor: untyped, ?enclosing: Hash[String, Declaration]) -> Array[Declaration]
|
|
93
|
+
def parse(node, locals, visitor:, enclosing: {})
|
|
94
|
+
states = node.states
|
|
95
|
+
|
|
96
|
+
return [] if states.empty?
|
|
97
|
+
|
|
98
|
+
declared = {} #: Hash[String, Declaration]
|
|
99
|
+
|
|
100
|
+
parsing = Parsing.new(
|
|
101
|
+
locals: locals,
|
|
102
|
+
declared: declared,
|
|
103
|
+
names: states.map { |state| state.name&.value.to_s },
|
|
104
|
+
enclosing: enclosing,
|
|
105
|
+
visitor: visitor,
|
|
106
|
+
location: node.location
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
states.map { |state|
|
|
110
|
+
declaration = declaration_for(state, parsing)
|
|
111
|
+
declared[declaration.name] = declaration
|
|
112
|
+
|
|
113
|
+
declaration
|
|
114
|
+
}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#: (String, Hash[String, Declaration], untyped, (StateAnchor | Herb::Location)?, ?untyped) -> (Read | Combo | Symbol)?
|
|
118
|
+
def condition_read(expression, states, visitor, anchor, resolved = nil)
|
|
119
|
+
anchor = StateAnchor.new(anchor) unless anchor.is_a?(StateAnchor)
|
|
120
|
+
source = expression.strip
|
|
121
|
+
resolved_node = resolved_expression(resolved, source)
|
|
122
|
+
parsed = resolved_node || expression_node(source)
|
|
123
|
+
anchor = anchor.rebased(resolved_node.location.start_offset) if resolved_node
|
|
124
|
+
|
|
125
|
+
return mentions_any?(source, states) ? :computed : nil if parsed.nil?
|
|
126
|
+
|
|
127
|
+
said = visitor.diagnostic_count
|
|
128
|
+
read = tree_read(parsed, states, visitor, anchor)
|
|
129
|
+
|
|
130
|
+
return :reported if visitor.diagnostic_count > said
|
|
131
|
+
return read if read
|
|
132
|
+
|
|
133
|
+
mentions?(parsed, states) ? :computed : nil
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
#: (untyped, Hash[String, Declaration], untyped, (StateAnchor | Herb::Location)?) -> (Read | Combo | Symbol)?
|
|
137
|
+
def tree_read(node, states, visitor, anchor)
|
|
138
|
+
anchor = StateAnchor.new(anchor) unless anchor.is_a?(StateAnchor)
|
|
139
|
+
node = unwrap_parentheses(node)
|
|
140
|
+
|
|
141
|
+
read = bare_read(node, states, visitor, anchor)
|
|
142
|
+
return read if read
|
|
143
|
+
|
|
144
|
+
predicate = predicate_read(node, states, visitor, anchor)
|
|
145
|
+
return predicate if predicate
|
|
146
|
+
|
|
147
|
+
transform = transform_read(node, states, visitor, anchor)
|
|
148
|
+
return transform if transform
|
|
149
|
+
|
|
150
|
+
negated = negated_read(node, states, visitor, anchor)
|
|
151
|
+
return negated if negated
|
|
152
|
+
|
|
153
|
+
equality = equality_read(node, states, visitor, anchor)
|
|
154
|
+
return equality if equality
|
|
155
|
+
|
|
156
|
+
combo_read(node, states, visitor, anchor)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#: (untyped) -> untyped
|
|
160
|
+
def unwrap_parentheses(node)
|
|
161
|
+
return node unless node.is_a?(Prism::ParenthesesNode)
|
|
162
|
+
|
|
163
|
+
body = node.body
|
|
164
|
+
|
|
165
|
+
return node unless body.is_a?(Prism::StatementsNode) && body.body.one?
|
|
166
|
+
|
|
167
|
+
unwrap_parentheses(body.body.first)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> (Combo | Symbol)?
|
|
171
|
+
def combo_read(node, states, visitor, anchor)
|
|
172
|
+
op = case node
|
|
173
|
+
when Prism::AndNode then "all"
|
|
174
|
+
when Prism::OrNode then "any"
|
|
175
|
+
else return nil
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
said = visitor.diagnostic_count
|
|
179
|
+
branches = flatten_combo(node, node.class)
|
|
180
|
+
parts = branches.map { |part| tree_read(part, states, visitor, anchor) }
|
|
181
|
+
|
|
182
|
+
return nil if parts.none? { |part| part.is_a?(Read) || part.is_a?(Combo) }
|
|
183
|
+
return :reported if visitor.diagnostic_count > said
|
|
184
|
+
|
|
185
|
+
server = branches.zip(parts).find { |_, part| part.nil? || part == :computed }&.first
|
|
186
|
+
|
|
187
|
+
return :computed if server && !anchor.condition?
|
|
188
|
+
|
|
189
|
+
if server
|
|
190
|
+
read = branches.zip(parts).find { |_, part| part.is_a?(Read) || part.is_a?(Combo) }&.last
|
|
191
|
+
|
|
192
|
+
return mixed_combo(node, server, read, visitor, anchor)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
Combo.new(op: op, parts: parts)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
#: (untyped, untyped, untyped, untyped, StateAnchor) -> nil
|
|
199
|
+
def mixed_combo(node, server, read, visitor, anchor)
|
|
200
|
+
named = read && read_names(read).first
|
|
201
|
+
reads = named ? "the state `#{named}`" : "a state"
|
|
202
|
+
|
|
203
|
+
visitor.slot_error(
|
|
204
|
+
"`#{server.slice}` is server Ruby inside a condition that also reads #{reads}. The client resolves each side of `#{node.is_a?(Prism::AndNode) ? "&&" : "||"}` itself and has no value for this one.",
|
|
205
|
+
anchor.locate(server),
|
|
206
|
+
:read,
|
|
207
|
+
suggestion: "Move `#{server.slice}` into its own conditional around this one, or declare a state for it and set it from app code."
|
|
208
|
+
)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#: (untyped, untyped) -> Array[untyped]
|
|
212
|
+
def flatten_combo(node, klass)
|
|
213
|
+
return [node] unless node.is_a?(klass)
|
|
214
|
+
|
|
215
|
+
flatten_combo(node.left, klass) + flatten_combo(node.right, klass)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
#: (Read | Combo) -> Array[String]
|
|
219
|
+
def read_names(read)
|
|
220
|
+
return [read.name, read.against].compact if read.is_a?(Read)
|
|
221
|
+
|
|
222
|
+
read.parts.flat_map { |part| read_names(part) }
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
#: (Read | Combo) -> untyped
|
|
226
|
+
def condition_entry(read)
|
|
227
|
+
return { read.op => read.parts.map { |part| condition_entry(part) } } if read.is_a?(Combo)
|
|
228
|
+
|
|
229
|
+
comparand = comparand_entry(read)
|
|
230
|
+
|
|
231
|
+
if read.transform
|
|
232
|
+
return [read.name, comparand, read.operator || (comparand ? "==" : nil), read.transform]
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
read.operator ? [read.name, comparand, read.operator] : [read.name, comparand]
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
#: (Read) -> untyped
|
|
239
|
+
def comparand_entry(read)
|
|
240
|
+
if read.against
|
|
241
|
+
entry = { "state" => read.against } #: Hash[String, untyped]
|
|
242
|
+
entry["transform"] = read.against_transform if read.against_transform
|
|
243
|
+
|
|
244
|
+
return entry
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
return nil unless read.comparand
|
|
248
|
+
|
|
249
|
+
{ "value" => literal_value(read.comparand) }
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
#: (String) -> untyped
|
|
253
|
+
def literal_value(source)
|
|
254
|
+
node = expression_node(source)
|
|
255
|
+
|
|
256
|
+
case node
|
|
257
|
+
when Prism::TrueNode then true
|
|
258
|
+
when Prism::FalseNode then false
|
|
259
|
+
when Prism::NilNode then nil
|
|
260
|
+
when Prism::IntegerNode then node.value
|
|
261
|
+
when Prism::StringNode, Prism::SymbolNode then node.unescaped
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
#: (String) -> bool
|
|
266
|
+
def literal?(source)
|
|
267
|
+
node = expression_node(source)
|
|
268
|
+
|
|
269
|
+
!node.nil? && KINDS.key?(node.class.name)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
#: (Read | Combo) -> String
|
|
273
|
+
def condition_source(read)
|
|
274
|
+
if read.is_a?(Read)
|
|
275
|
+
spelled = UNARY_OPERATORS[read.operator.to_s]
|
|
276
|
+
subject = read.transform ? "#{read.name}.#{TRANSFORM_SPELLINGS.fetch(read.transform)}" : read.name
|
|
277
|
+
|
|
278
|
+
return "#{subject}.#{spelled}" if spelled
|
|
279
|
+
return "!#{subject}" if read.operator == FALSY_OPERATOR
|
|
280
|
+
return subject if read.comparand.nil? && read.against.nil?
|
|
281
|
+
|
|
282
|
+
against = read.against && read.against_transform ? "#{read.against}.#{TRANSFORM_SPELLINGS.fetch(read.against_transform)}" : read.against
|
|
283
|
+
|
|
284
|
+
"#{subject} #{read.operator || "=="} #{against || read.comparand}"
|
|
285
|
+
else
|
|
286
|
+
joiner = read.op == "all" ? " && " : " || "
|
|
287
|
+
|
|
288
|
+
"(#{read.parts.map { |part| condition_source(part) }.join(joiner)})"
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
#: (String) -> FoldIncrement?
|
|
293
|
+
def fold_increment(source)
|
|
294
|
+
result = Prism.parse(source.to_s.strip)
|
|
295
|
+
|
|
296
|
+
return nil if result.failure?
|
|
297
|
+
|
|
298
|
+
body = result.value.statements.body
|
|
299
|
+
|
|
300
|
+
return nil unless body.one?
|
|
301
|
+
|
|
302
|
+
node = body.first
|
|
303
|
+
|
|
304
|
+
case node
|
|
305
|
+
when Prism::LocalVariableOperatorWriteNode
|
|
306
|
+
return nil unless node.binary_operator == :+
|
|
307
|
+
|
|
308
|
+
step = node.value
|
|
309
|
+
|
|
310
|
+
return nil unless step.is_a?(Prism::IntegerNode)
|
|
311
|
+
|
|
312
|
+
FoldIncrement.new(name: node.name.to_s, by: step.value)
|
|
313
|
+
when Prism::LocalVariableWriteNode
|
|
314
|
+
value = node.value
|
|
315
|
+
|
|
316
|
+
return nil unless value.is_a?(Prism::CallNode) && value.name == :+
|
|
317
|
+
|
|
318
|
+
receiver = value.receiver
|
|
319
|
+
|
|
320
|
+
return nil unless receiver.is_a?(Prism::LocalVariableReadNode) && receiver.name == node.name
|
|
321
|
+
|
|
322
|
+
arguments = value.arguments&.arguments
|
|
323
|
+
|
|
324
|
+
return nil unless arguments&.one?
|
|
325
|
+
|
|
326
|
+
step = arguments.first
|
|
327
|
+
|
|
328
|
+
return nil unless step.is_a?(Prism::IntegerNode)
|
|
329
|
+
|
|
330
|
+
FoldIncrement.new(name: node.name.to_s, by: step.value)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
#: (String, Hash[String, Declaration]) -> Array[String]
|
|
335
|
+
def assigned_state_names(source, states)
|
|
336
|
+
result = Prism.parse(source)
|
|
337
|
+
|
|
338
|
+
return [] if result.failure?
|
|
339
|
+
|
|
340
|
+
names = [] #: Array[String]
|
|
341
|
+
queue = [] #: Array[untyped]
|
|
342
|
+
|
|
343
|
+
queue << result.value
|
|
344
|
+
|
|
345
|
+
while (node = queue.shift)
|
|
346
|
+
case node
|
|
347
|
+
when Prism::LocalVariableWriteNode, Prism::LocalVariableOperatorWriteNode, Prism::LocalVariableOrWriteNode, Prism::LocalVariableAndWriteNode, Prism::LocalVariableTargetNode
|
|
348
|
+
names << node.name.to_s if states.key?(node.name.to_s)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
queue.concat(node.child_nodes.compact) if node.respond_to?(:child_nodes)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
names.uniq
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
#: (String, Declaration) -> (Array[String] | Symbol)
|
|
358
|
+
def when_comparands(list, subject)
|
|
359
|
+
result = Prism.parse("[#{list}]")
|
|
360
|
+
|
|
361
|
+
return :computed if result.failure?
|
|
362
|
+
|
|
363
|
+
array = result.value.statements.body.first
|
|
364
|
+
|
|
365
|
+
return :computed unless array.is_a?(Prism::ArrayNode)
|
|
366
|
+
|
|
367
|
+
array.elements.map { |element|
|
|
368
|
+
kind = KINDS[element.class.name]
|
|
369
|
+
|
|
370
|
+
return :computed unless kind
|
|
371
|
+
return :mismatched unless kind == subject.kind || kind == :nil || subject.kind == :seeded
|
|
372
|
+
|
|
373
|
+
element.slice
|
|
374
|
+
}
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
#: (Symbol?, String) -> String
|
|
378
|
+
def predicate_advice(kind, name)
|
|
379
|
+
spellings = PREDICATES.filter_map { |predicate, entry| predicate if entry[:kinds]&.include?(kind) }
|
|
380
|
+
|
|
381
|
+
return "" if spellings.empty?
|
|
382
|
+
|
|
383
|
+
listed = spellings.each_with_index.map { |predicate, index| index.zero? ? "`#{name}.#{predicate}`" : "`.#{predicate}`" }
|
|
384
|
+
leading = listed[0..-2] #: Array[String]
|
|
385
|
+
|
|
386
|
+
"Ask #{listed.one? ? listed.last : "#{leading.join(", ")} or #{listed.last}"}, "
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
#: ((Read | Combo)) -> Read?
|
|
390
|
+
def never_falsy_read(read)
|
|
391
|
+
return nil unless read.is_a?(Read)
|
|
392
|
+
return nil unless read.operator.nil? && read.comparand.nil? && read.against.nil? && read.transform.nil?
|
|
393
|
+
return nil if StateKinds::FALSY.include?(read.kind)
|
|
394
|
+
|
|
395
|
+
read
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
#: (Declaration) -> bool
|
|
399
|
+
def literal_default?(declaration)
|
|
400
|
+
return false if declaration.derived
|
|
401
|
+
|
|
402
|
+
node = expression_node(declaration.default)
|
|
403
|
+
|
|
404
|
+
!node.nil? && KINDS.key?(node.class.name)
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
#: (Declaration, String) -> String
|
|
408
|
+
def default_example(declaration, spelling)
|
|
409
|
+
return "" unless literal_default?(declaration)
|
|
410
|
+
|
|
411
|
+
", like `#{spelling}#{declaration.default}`"
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
#: (Declaration) -> bool
|
|
415
|
+
def seeded?(declaration)
|
|
416
|
+
return false if declaration.derived
|
|
417
|
+
|
|
418
|
+
node = expression_node(declaration.default)
|
|
419
|
+
|
|
420
|
+
node.nil? || !KINDS.key?(node.class.name)
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
#: (Read) -> String
|
|
424
|
+
def subject_phrase(read)
|
|
425
|
+
return "the #{TRANSFORM_SPELLINGS.fetch(read.transform)} of the state `#{read.name}`" if read.transform
|
|
426
|
+
|
|
427
|
+
"the #{read.kind.to_s.capitalize} state `#{read.name}`"
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
#: ((Symbol | String)?) -> String
|
|
431
|
+
def kind_article(kind)
|
|
432
|
+
known = StateKinds::ARTICLES[kind.to_s]
|
|
433
|
+
|
|
434
|
+
return known if known
|
|
435
|
+
|
|
436
|
+
spelled = kind.to_s.capitalize
|
|
437
|
+
|
|
438
|
+
return "a value" if spelled.empty?
|
|
439
|
+
|
|
440
|
+
spelled.start_with?("A", "E", "I", "O", "U") ? "an #{spelled}" : "a #{spelled}"
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
#: (String, String, ?untyped) -> String
|
|
444
|
+
def rewrite_reads(source, name, resolved = nil)
|
|
445
|
+
splices = read_splices(source, name, resolved&.source == source ? resolved : nil)
|
|
446
|
+
|
|
447
|
+
return source if splices.empty?
|
|
448
|
+
|
|
449
|
+
rewritten = source.dup
|
|
450
|
+
|
|
451
|
+
splices.reverse_each { |start, finish, replacement| rewritten.bytesplice(start, finish - start, replacement) }
|
|
452
|
+
|
|
453
|
+
rewritten
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
#: (String, Hash[String, Declaration]) -> bool
|
|
457
|
+
def mentions_any?(source, states)
|
|
458
|
+
return false if states.empty?
|
|
459
|
+
|
|
460
|
+
reads_any?(expression_nodes(source), states)
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
#: (untyped, Hash[String, Declaration]) -> bool
|
|
464
|
+
def mentions?(node, states)
|
|
465
|
+
return false if states.empty? || node.nil?
|
|
466
|
+
|
|
467
|
+
reads_any?(descendants(node), states)
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
private
|
|
471
|
+
|
|
472
|
+
#: (untyped, String) -> untyped
|
|
473
|
+
def resolved_expression(resolved, source)
|
|
474
|
+
nodes = resolved&.nodes
|
|
475
|
+
|
|
476
|
+
return nil unless nodes&.one?
|
|
477
|
+
|
|
478
|
+
node = nodes.fetch(0)
|
|
479
|
+
|
|
480
|
+
node.slice == source ? node : nil
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
#: (Array[untyped], Hash[String, Declaration]) -> bool
|
|
484
|
+
def reads_any?(nodes, states)
|
|
485
|
+
nodes.any? { |node| states.key?(bare_name(node).to_s.delete_suffix("?")) }
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
#: (String, String, untyped) -> Array[[Integer, Integer, String]]
|
|
489
|
+
def read_splices(source, name, resolved = nil)
|
|
490
|
+
splices = [] #: Array[[Integer, Integer, String]]
|
|
491
|
+
nodes = resolved ? resolved.nodes.flat_map { |node| descendants(node) } : expression_nodes(source)
|
|
492
|
+
base = resolved ? resolved.offset : 0
|
|
493
|
+
|
|
494
|
+
nodes.each do |node|
|
|
495
|
+
next unless node.is_a?(Prism::CallNode) && node.arguments.nil? && node.block.nil?
|
|
496
|
+
|
|
497
|
+
rewrite = PREDICATES.dig(node.name.to_s, :rewrite)
|
|
498
|
+
|
|
499
|
+
if rewrite && bare_name(node.receiver) == name
|
|
500
|
+
splices << [node.location.start_offset - base, node.location.end_offset - base, "(#{name} #{rewrite})"]
|
|
501
|
+
elsif node.receiver.nil? && node.name.to_s == "#{name}?"
|
|
502
|
+
splices << [node.location.start_offset - base, node.location.end_offset - base, name]
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
splices.sort_by { |splice| splice[0] }
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
#: (String) -> Array[untyped]
|
|
510
|
+
def expression_nodes(source)
|
|
511
|
+
Prism.parse(source).value.statements.body.compact.flat_map { |node| descendants(node) }
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
#: (untyped) -> Array[untyped]
|
|
515
|
+
def descendants(node)
|
|
516
|
+
found = [] #: Array[untyped]
|
|
517
|
+
queue = [node] #: Array[untyped]
|
|
518
|
+
|
|
519
|
+
until queue.empty?
|
|
520
|
+
current = queue.shift
|
|
521
|
+
found << current
|
|
522
|
+
queue.concat(current.compact_child_nodes)
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
found
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
#: (untyped) -> String?
|
|
529
|
+
def bare_name(node)
|
|
530
|
+
return node.name.to_s if node.is_a?(Prism::LocalVariableReadNode)
|
|
531
|
+
return nil unless node.is_a?(Prism::CallNode) && node.receiver.nil? && node.arguments.nil? && node.block.nil?
|
|
532
|
+
|
|
533
|
+
node.name.to_s
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
#: (untyped, Parsing) -> Declaration
|
|
537
|
+
def declaration_for(state, parsing)
|
|
538
|
+
spot = state.name&.location&.start
|
|
539
|
+
declaration = classify(state, parsing)
|
|
540
|
+
|
|
541
|
+
spot ? declaration.with(line: spot.line, column: spot.column) : declaration
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
#: (untyped, Parsing) -> Declaration
|
|
545
|
+
def classify(state, parsing)
|
|
546
|
+
name = state.name&.value.to_s
|
|
547
|
+
visitor = parsing.visitor
|
|
548
|
+
default = state.default_value
|
|
549
|
+
location = default&.location || state.name&.location || parsing.location
|
|
550
|
+
|
|
551
|
+
if state.kind == "missing" || default.nil?
|
|
552
|
+
return refused(name, "The state `#{name}` has no default. The server renders a value for every state, so there is nothing to render or to seed the client with.", visitor, state.name&.location || parsing.location, suggestion: "Give it a default, like `(#{name}: false)`.")
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
source = default.content.to_s
|
|
556
|
+
kind = NODE_KINDS[state.kind]
|
|
557
|
+
|
|
558
|
+
return Declaration.new(name: name, kind: kind, default: source, derived: nil, line: nil, column: nil) if kind
|
|
559
|
+
|
|
560
|
+
case state.kind
|
|
561
|
+
when "float"
|
|
562
|
+
refused(name, "The state `#{name}` has a Float default. Ruby and JavaScript disagree on how to print a float, so the server and the client would render different text.", visitor, location, default: source, suggestion: "Declare it as an Integer or a String instead.")
|
|
563
|
+
when "array"
|
|
564
|
+
refused(name, "The state `#{name}` has an Array default. A list on the page is a collection of items, not one state holding many values.", visitor, location, default: source, suggestion: "Declare an item-scoped state inside the loop instead.")
|
|
565
|
+
when "hash"
|
|
566
|
+
refused(name, "The state `#{name}` has a Hash default. A state holds one value the client can write and read back.", visitor, location, default: source, suggestion: "Declare each leaf as its own state, like `(#{name}_title: \"\")`.")
|
|
567
|
+
when "bare"
|
|
568
|
+
derived_default(name, source, location, parsing) || bare_default(name, source, location, parsing)
|
|
569
|
+
else
|
|
570
|
+
derived_default(name, source, location, parsing) ||
|
|
571
|
+
Declaration.new(name: name, kind: :seeded, default: source, derived: nil, line: nil, column: nil)
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
#: (String, String, untyped, Herb::Location?, **untyped) -> Declaration
|
|
576
|
+
def refused(name, message, visitor, location, **options)
|
|
577
|
+
default = options.fetch(:default, "nil") #: String
|
|
578
|
+
|
|
579
|
+
visitor.slot_error(message, location, :declaration, suggestion: options[:suggestion])
|
|
580
|
+
|
|
581
|
+
Declaration.new(name: name, kind: :seeded, default: default, derived: nil, line: nil, column: nil)
|
|
582
|
+
end
|
|
583
|
+
|
|
584
|
+
#: (String, String, Herb::Location?, Parsing) -> Declaration?
|
|
585
|
+
def derived_default(name, source, location, parsing)
|
|
586
|
+
declared = parsing.declared
|
|
587
|
+
visitor = parsing.visitor
|
|
588
|
+
value = expression_node(source)
|
|
589
|
+
|
|
590
|
+
return nil if value.nil?
|
|
591
|
+
|
|
592
|
+
said = visitor.diagnostic_count
|
|
593
|
+
read = tree_read(value, declared, visitor, StateAnchor.new(location, context: :default)) #: untyped
|
|
594
|
+
|
|
595
|
+
return Declaration.new(name: name, kind: :seeded, default: source, derived: nil, line: nil, column: nil) if visitor.diagnostic_count > said
|
|
596
|
+
|
|
597
|
+
if read == :computed
|
|
598
|
+
return refused(name, "The state `#{name}` defaults to `#{source}`, which mixes state reads with other Ruby. A derived state reads only other states and a seed reads none.", visitor, location, default: source, suggestion: "Split the two apart, so `#{name}` derives from states only.")
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
if read.nil?
|
|
602
|
+
later = {} #: Hash[String, untyped]
|
|
603
|
+
(parsing.names - declared.keys - [name]).each { |candidate| later[candidate] = true }
|
|
604
|
+
|
|
605
|
+
if mentions_any?(source, later)
|
|
606
|
+
return refused(name, "The state `#{name}` reads a state declared after it. A derived state reads only states declared before it.", visitor, location, suggestion: "Move `#{name}` after the states it reads.")
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
if mentions_any?(source, declared)
|
|
610
|
+
return refused(name, "The state `#{name}` defaults to `#{source}`, which mixes state reads with other Ruby. A derived state reads only other states and a seed reads none.", visitor, location, default: source, suggestion: "Split the two apart, so `#{name}` derives from states only.")
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
return nil
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
Declaration.new(name: name, kind: derived_kind(read), default: source, derived: read, line: nil, column: nil)
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
#: (Read | Combo) -> Symbol
|
|
620
|
+
def derived_kind(read)
|
|
621
|
+
return read.kind || :seeded if read.is_a?(Read) && read.comparand.nil? && read.against.nil? && read.operator.nil?
|
|
622
|
+
|
|
623
|
+
:boolean
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
#: (String, String, Herb::Location?, Parsing) -> Declaration
|
|
627
|
+
def bare_default(name, identifier, location, parsing)
|
|
628
|
+
visitor = parsing.visitor
|
|
629
|
+
|
|
630
|
+
unless BARE.match?(identifier)
|
|
631
|
+
return Declaration.new(name: name, kind: :seeded, default: identifier, derived: nil, line: nil, column: nil)
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
if parsing.enclosing.key?(identifier)
|
|
635
|
+
return refused(name, "The state `#{name}` reads `#{identifier}` from an enclosing scope. A derived state reads only states from its own signature.", visitor, location, suggestion: "Declare `#{name}` beside the states it reads.")
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
kind = parsing.locals[identifier]
|
|
639
|
+
|
|
640
|
+
unless kind
|
|
641
|
+
return refused(name, "The state `#{name}` defaults to `#{identifier}`, which is not a declared strict local. A name that was never passed raises at render.", visitor, location, suggestion: "Add `#{identifier}` to the `locals:` signature.")
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
Declaration.new(name: name, kind: kind, default: identifier, derived: nil, line: nil, column: nil)
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
#: (String) -> untyped
|
|
648
|
+
def expression_node(source)
|
|
649
|
+
result = Prism.parse(source)
|
|
650
|
+
|
|
651
|
+
return nil if result.failure?
|
|
652
|
+
|
|
653
|
+
body = result.value.statements.body
|
|
654
|
+
|
|
655
|
+
body.one? ? body.first : nil
|
|
656
|
+
end
|
|
657
|
+
|
|
658
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> Read?
|
|
659
|
+
def bare_read(node, states, _visitor, _anchor)
|
|
660
|
+
if node.is_a?(Prism::LocalVariableReadNode)
|
|
661
|
+
declaration = states[node.name.to_s]
|
|
662
|
+
|
|
663
|
+
return nil unless declaration
|
|
664
|
+
|
|
665
|
+
return Read.new(name: node.name.to_s, comparand: nil, kind: declaration.kind, operator: nil, against: nil, transform: nil, against_transform: nil)
|
|
666
|
+
end
|
|
667
|
+
|
|
668
|
+
return nil unless node.is_a?(Prism::CallNode) && node.receiver.nil? && node.arguments.nil? && node.block.nil?
|
|
669
|
+
|
|
670
|
+
spelled = node.name.to_s
|
|
671
|
+
predicate = spelled.end_with?("?")
|
|
672
|
+
name = predicate ? spelled.delete_suffix("?") : spelled
|
|
673
|
+
declaration = states[name]
|
|
674
|
+
|
|
675
|
+
return nil unless declaration
|
|
676
|
+
|
|
677
|
+
Read.new(name: name, comparand: nil, kind: declaration.kind, operator: nil, against: nil, transform: nil, against_transform: nil)
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> Read?
|
|
681
|
+
def operand_read(node, states, visitor, anchor)
|
|
682
|
+
bare_read(node, states, visitor, anchor) || transform_read(node, states, visitor, anchor)
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> Read?
|
|
686
|
+
def transform_read(node, states, visitor, anchor)
|
|
687
|
+
return nil unless node.is_a?(Prism::CallNode)
|
|
688
|
+
|
|
689
|
+
transform = TRANSFORMS[node.name.to_s]
|
|
690
|
+
|
|
691
|
+
return nil unless transform
|
|
692
|
+
return nil unless node.arguments.nil? && node.block.nil?
|
|
693
|
+
|
|
694
|
+
receiver = node.receiver
|
|
695
|
+
|
|
696
|
+
return nil unless receiver
|
|
697
|
+
|
|
698
|
+
read = bare_read(receiver, states, visitor, anchor)
|
|
699
|
+
|
|
700
|
+
return nil unless read.is_a?(Read)
|
|
701
|
+
|
|
702
|
+
kinds = transform.fetch(:kinds)
|
|
703
|
+
|
|
704
|
+
if kinds && read.kind != :seeded && !kinds.include?(read.kind)
|
|
705
|
+
return visitor.slot_error("`#{node.slice}` reads the #{read.kind.to_s.capitalize} state `#{read.name}` with `#{node.name}`. Only #{transform.fetch(:only)} can be read with `#{node.name}`.", anchor.locate(node), :read, suggestion: "Compare `#{read.name}` itself instead#{default_example(states.fetch(read.name), "#{read.name} == ")}.")
|
|
706
|
+
end
|
|
707
|
+
|
|
708
|
+
Read.new(name: read.name, comparand: nil, kind: transform.fetch(:returns), operator: nil, against: nil, transform: transform.fetch(:operation), against_transform: nil)
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> Read?
|
|
712
|
+
def predicate_read(node, states, visitor, anchor)
|
|
713
|
+
return nil unless node.is_a?(Prism::CallNode)
|
|
714
|
+
|
|
715
|
+
predicate = PREDICATES[node.name.to_s]
|
|
716
|
+
|
|
717
|
+
return nil unless predicate
|
|
718
|
+
return nil unless node.arguments.nil? && node.block.nil?
|
|
719
|
+
|
|
720
|
+
receiver = node.receiver
|
|
721
|
+
|
|
722
|
+
return nil unless receiver
|
|
723
|
+
|
|
724
|
+
read = bare_read(receiver, states, visitor, anchor)
|
|
725
|
+
|
|
726
|
+
return nil unless read.is_a?(Read)
|
|
727
|
+
|
|
728
|
+
kinds = predicate[:kinds]
|
|
729
|
+
|
|
730
|
+
if kinds && read.kind != :seeded && !kinds.include?(read.kind)
|
|
731
|
+
return visitor.slot_error("`#{node.slice}` reads the #{read.kind.to_s.capitalize} state `#{read.name}` with `#{node.name}`. Only #{predicate.fetch(:only)} can be read with `#{node.name}`.", anchor.locate(node), :read, suggestion: "Compare `#{read.name}` to a literal instead, or declare it as #{kind_article(predicate.fetch(:kinds)&.first)} state.")
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
if predicate[:comparand] == "nil" && !StateKinds::NILABLE.include?(read.kind)
|
|
735
|
+
return nil_check_error(node, read, visitor, anchor, consequence: "can never match", example: default_example(states.fetch(read.name), "#{read.name} == "))
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
Read.new(name: read.name, comparand: predicate[:comparand], kind: read.kind, operator: predicate[:operator], against: nil, transform: nil, against_transform: nil)
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
#: (untyped, Read, untyped, StateAnchor, **untyped) -> nil
|
|
742
|
+
def nil_check_error(node, read, visitor, anchor, **options)
|
|
743
|
+
consequence = options.fetch(:consequence) #: String
|
|
744
|
+
example = options.fetch(:example) #: String
|
|
745
|
+
|
|
746
|
+
visitor.slot_error(
|
|
747
|
+
"`#{node.slice}` reads #{subject_phrase(read)} as a nil check. Only a Nil state can be nil, so it #{consequence}.",
|
|
748
|
+
anchor.locate(node),
|
|
749
|
+
:compare,
|
|
750
|
+
suggestion: "#{predicate_advice(read.kind, read.name)}compare it to a literal#{example}, or declare it with a `nil` default."
|
|
751
|
+
)
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> (Read | Combo)?
|
|
755
|
+
def negated_read(node, states, visitor, anchor)
|
|
756
|
+
return nil unless node.is_a?(Prism::CallNode) && node.name == :!
|
|
757
|
+
return nil unless node.receiver && node.arguments.nil? && node.block.nil?
|
|
758
|
+
|
|
759
|
+
inner = tree_read(unwrap_parentheses(node.receiver), states, visitor, anchor)
|
|
760
|
+
|
|
761
|
+
return nil unless inner.is_a?(Read) || inner.is_a?(Combo)
|
|
762
|
+
|
|
763
|
+
negate(inner)
|
|
764
|
+
end
|
|
765
|
+
|
|
766
|
+
#: (Read | Combo) -> (Read | Combo)
|
|
767
|
+
def negate(read)
|
|
768
|
+
return Combo.new(op: read.op == "all" ? "any" : "all", parts: read.parts.map { |part| negate(part) }) if read.is_a?(Combo)
|
|
769
|
+
|
|
770
|
+
return read.with(operator: NEGATED_UNARY.fetch(read.operator), kind: :boolean) if NEGATED_UNARY.key?(read.operator.to_s)
|
|
771
|
+
return read.with(operator: nil, kind: :boolean) if read.operator == FALSY_OPERATOR
|
|
772
|
+
return read.with(operator: FALSY_OPERATOR, kind: :boolean) if read.operator.nil? && read.comparand.nil? && read.against.nil?
|
|
773
|
+
|
|
774
|
+
read.with(operator: NEGATED_OPERATORS.fetch(read.operator || "=="), kind: :boolean)
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
#: (untyped, Hash[String, Declaration], untyped, StateAnchor) -> Read?
|
|
778
|
+
def equality_read(node, states, visitor, anchor)
|
|
779
|
+
return nil unless node.is_a?(Prism::CallNode)
|
|
780
|
+
return nil unless node.name == :== || node.name == :!= || ORDERED_OPERATORS.include?(node.name)
|
|
781
|
+
|
|
782
|
+
left = node.receiver
|
|
783
|
+
right = node.arguments&.arguments&.first
|
|
784
|
+
|
|
785
|
+
return nil unless left && right && node.arguments&.arguments&.one?
|
|
786
|
+
|
|
787
|
+
left_read = operand_read(left, states, visitor, anchor)
|
|
788
|
+
right_read = operand_read(right, states, visitor, anchor)
|
|
789
|
+
read = left_read || right_read
|
|
790
|
+
|
|
791
|
+
return nil unless read
|
|
792
|
+
|
|
793
|
+
if left_read && right_read
|
|
794
|
+
return state_pair_read(node, left_read, right_read, visitor, anchor)
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
literal = left_read ? right : left
|
|
798
|
+
kind = KINDS[literal.class.name]
|
|
799
|
+
|
|
800
|
+
unless kind
|
|
801
|
+
return visitor.slot_error("`#{node.slice}` compares the state `#{read.name}` against `#{literal.slice}`, which is not a literal. The client resolves a comparison by looking the state up, so it has no value for the other side.", anchor.locate(literal), :compare, suggestion: "Compare `#{read.name}` to a literal#{default_example(states.fetch(read.name), "#{read.name} == ")}, or declare a state for `#{literal.slice}` and set it from app code.")
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
operator = node.name == :== ? nil : node.name.to_s
|
|
805
|
+
operator = MIRRORED_OPERATORS.fetch(operator) if operator && operator != "!=" && right_read
|
|
806
|
+
ordered = operator && operator != "!="
|
|
807
|
+
|
|
808
|
+
if ordered && read.kind != :integer && read.kind != :seeded
|
|
809
|
+
return visitor.slot_error("`#{node.slice}` orders #{subject_phrase(read)}. Ordering compares numbers.", anchor.locate(node), :compare, suggestion: "Declare `#{read.name}` as an Integer, like `(#{read.name}: 0)`, or compare it with `==` instead.")
|
|
810
|
+
end
|
|
811
|
+
|
|
812
|
+
if ordered && kind != :integer
|
|
813
|
+
return visitor.slot_error("`#{node.slice}` orders the state `#{read.name}` against #{kind_article(kind)} literal. Ordering compares numbers.", anchor.locate(literal), :compare, suggestion: "Compare `#{read.name}` against an Integer literal, like `#{read.name} > 0`.")
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
if !ordered && kind == :nil && !StateKinds::NILABLE.include?(read.kind)
|
|
817
|
+
return nil_check_error(node, read, visitor, anchor, consequence: operator == "!=" ? "always matches" : "can never match", example: default_example(states.fetch(read.name), "#{read.name} == "))
|
|
818
|
+
end
|
|
819
|
+
|
|
820
|
+
unless ordered || kind == read.kind || kind == :nil || read.kind == :seeded
|
|
821
|
+
consequence = operator == "!=" ? "so it always matches" : "so it can never match"
|
|
822
|
+
|
|
823
|
+
return visitor.slot_error("`#{node.slice}` compares #{subject_phrase(read)} against #{kind_article(kind)} literal, #{consequence}.", anchor.locate(literal), :compare, suggestion: "Compare it against #{kind_article(read.kind)} literal#{default_example(states.fetch(read.name), "#{read.name} == ")}.")
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
Read.new(name: read.name, comparand: literal.slice, kind: read.kind, operator: operator, against: nil, transform: read.transform, against_transform: nil)
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
#: (untyped, Read, Read, untyped, StateAnchor) -> Read?
|
|
830
|
+
def state_pair_read(node, left, right, visitor, anchor)
|
|
831
|
+
operator = node.name == :== ? nil : node.name.to_s
|
|
832
|
+
|
|
833
|
+
if right.transform && !left.transform
|
|
834
|
+
left, right = right, left
|
|
835
|
+
operator = MIRRORED_OPERATORS.fetch(operator) if operator && operator != "!="
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
ordered = operator && operator != "!="
|
|
839
|
+
|
|
840
|
+
if ordered && (left.kind != :integer || right.kind != :integer) && left.kind != :seeded && right.kind != :seeded
|
|
841
|
+
return visitor.slot_error("`#{node.slice}` orders #{subject_phrase(left)} against #{subject_phrase(right)}. Ordering compares numbers.", anchor.locate(node), :compare, suggestion: "Make both sides Integers, or compare them with `==` instead.")
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
if !ordered && left.kind != right.kind && left.kind != :seeded && right.kind != :seeded
|
|
845
|
+
return visitor.slot_error("`#{node.slice}` compares #{subject_phrase(left)} with #{subject_phrase(right)}, so it can never match.", anchor.locate(node), :compare, suggestion: "Compare values of the same kind, or redeclare one of the two states.")
|
|
846
|
+
end
|
|
847
|
+
|
|
848
|
+
Read.new(name: left.name, comparand: nil, kind: left.kind, operator: operator, against: right.name, transform: left.transform, against_transform: right.transform)
|
|
849
|
+
end
|
|
850
|
+
end
|
|
851
|
+
end
|
|
852
|
+
end
|
|
853
|
+
end
|
|
854
|
+
end
|