Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented Nov 19, 2025

Summary

Introduces global type definitions for the regex type.

This is a stepping stone towards resolving #8034.

Note that the regex types don't carry flags yet, which I think still needs to be done to resolve the issue.

Please be aware there are two regex types in our type inference engine: there are instances of the RegExp class (created when using new RegExp()), but there are also regex literals (/ab+c/).

Test Plan

Test added. Snapshots updated.

Docs

N/A

@arendjr arendjr requested a review from Netail November 19, 2025 12:51
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: 58d3249

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-Project Area: project L-JavaScript Language: JavaScript and super languages A-Type-Inference Area: type inference labels Nov 19, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

This pull request enhances RegExp type inference in Biome's JavaScript type system. Changes include reworking literal value formatting to include explicit type prefixes (e.g., "string:", "number:"), adding three new RegExp-related type IDs to the global type registry, extending the global resolver with RegExp class and method definitions, introducing a helper method to detect RegExp type references, and adding a corresponding test for regex literal type inference.

Suggested labels

L-JavaScript, A-Type-Inference

Suggested reviewers

  • ematipico

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: add regex globals' directly describes the main change—introducing global type definitions for regex types.
Description check ✅ Passed The description clearly relates to the changeset, explaining the purpose of adding global regex type definitions and their role as a stepping stone for issue #8034.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf1a836 and 58d3249.

⛔ Files ignored due to path filters (30)
  • crates/biome_js_type_info/tests/snapshots/infer_flattened_type_from_direct_promise_instance.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_flattened_type_from_static_promise_function.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_flattened_type_of_typeof_expression.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_resolved_type_from_direct_promise_instance.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_resolved_type_from_static_promise_function.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_type_of_binary_expression_eq.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_type_of_binary_expression_ne.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_type_of_literal.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/infer_type_of_regex.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_type_info/tests/snapshots/test_reference_to_falsy_subset_of.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_export_type_referencing_imported_type.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_export_types.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_exports.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_generic_mapped_value.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_generic_return_value.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_generic_return_value_with_multiple_modules.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_import_as_namespace.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_merged_types.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_multiple_reexports.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_promise_export.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_promise_from_imported_function_returning_imported_promise_type.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_promise_from_imported_function_returning_reexported_promise_type.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_recursive_looking_vfile.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_single_reexport.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_property_with_getter.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_this_in_class_assign.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_this_in_class_export.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_this_in_class_plain.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_this_in_class_wrong_scope.snap is excluded by !**/*.snap and included by **
  • crates/biome_module_graph/tests/snapshots/test_resolve_type_of_this_in_object.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • crates/biome_js_type_info/src/format_type_info.rs (1 hunks)
  • crates/biome_js_type_info/src/globals.rs (7 hunks)
  • crates/biome_js_type_info/src/type_data.rs (1 hunks)
  • crates/biome_js_type_info/tests/local_inference.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/type_data.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
🧬 Code graph analysis (3)
crates/biome_js_type_info/src/format_type_info.rs (3)
crates/biome_formatter/src/lib.rs (2)
  • write (1428-1435)
  • as_str (169-185)
crates/biome_formatter/src/builders.rs (3)
  • token (251-259)
  • space (606-608)
  • text (279-283)
crates/biome_js_type_info/src/type_data/literal.rs (4)
  • text (44-46)
  • as_bool (11-13)
  • as_str (39-41)
  • as_str (89-91)
crates/biome_js_type_info/tests/local_inference.rs (2)
crates/biome_js_type_info/tests/utils.rs (2)
  • get_expression (224-238)
  • assert_type_data_snapshot (22-55)
crates/biome_js_type_info/src/globals.rs (1)
  • default (184-410)
crates/biome_js_type_info/src/globals.rs (2)
crates/biome_js_type_info/src/type_data.rs (19)
  • new (39-43)
  • new (1436-1440)
  • new (1471-1481)
  • from (174-176)
  • from (180-182)
  • from (186-188)
  • from (192-194)
  • from (198-200)
  • from (204-206)
  • from (210-212)
  • from (216-218)
  • from (222-224)
  • from (228-230)
  • from (234-236)
  • from (240-242)
  • from (246-248)
  • from (721-723)
  • from (1020-1025)
  • instance_of (295-297)
crates/biome_rowan/src/text.rs (2)
  • new_static (182-186)
  • new_static (262-271)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: autofix
🔇 Additional comments (7)
crates/biome_js_type_info/src/format_type_info.rs (1)

789-837: LGTM! Consistent type-prefixed formatting for literals.

The rework to emit explicit type prefixes ("bigint:", "bool:", "number:", "regex:", "string:") for each Literal variant improves clarity in formatted output and snapshots. The pattern is applied uniformly across all variants.

crates/biome_js_type_info/tests/local_inference.rs (1)

37-46: LGTM! Well-structured test for regex type inference.

The new test follows established patterns in the file and validates type inference for regex literals, exercising the newly introduced RegExp global types.

crates/biome_js_type_info/src/type_data.rs (1)

1405-1414: LGTM! Consistent helper method for RegExp detection.

The new is_regex() method mirrors the existing is_array() and is_promise() patterns, maintaining consistency in the API. Documentation appropriately notes this is a semantic check after resolution, not a substitute for it.

crates/biome_js_type_info/src/globals.rs (4)

62-80: LGTM! RegExp type IDs properly integrated.

Three new predefined type IDs added (INSTANCEOF_REGEXP_ID, REGEXP_ID, REGEXP_EXEC_ID), with all subsequent IDs correctly shifted and NUM_PREDEFINED_TYPES updated from 41 to 44. The arithmetic is sound.


89-91: LGTM! Global constants and type names properly extended.

The new global RegExp constants and type name mappings are consistent with existing patterns. All indices in global_type_name() correctly updated to reflect the new type ID positions.

Also applies to: 149-169


227-235: LGTM! RegExp class and method definitions properly structured.

The regexp_method_definition helper mirrors the Promise pattern, and the RegExp class definition is appropriately constructed with an exec method. Correctly uses no type parameters, as RegExp is not generic.

Also applies to: 333-341


485-486: LGTM! RegExp qualifier resolution properly integrated.

The new condition in resolve_qualifier() follows the established pattern for Array and Promise, returning GLOBAL_REGEXP_ID for RegExp references without type parameters. Correctly placed in the resolution chain.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Netail
Copy link
Member

Netail commented Nov 19, 2025

Note that the regex types don't carry flags yet, which I think still needs to be done to resolve the issue.

Correct :)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #8166 will not alter performance

Comparing arendjr:add-regex-globals (58d3249) with main (bf1a836)1

Summary

✅ 58 untouched
⏩ 95 skipped2

Footnotes

  1. No successful run was found on main (12d5b42) during the generation of this report, so bf1a836 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@arendjr arendjr merged commit 7d963f3 into biomejs:main Nov 19, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants