Skip to content

fix(fast-build): support .length property on arrays in template expressions#7394

Merged
janechu merged 7 commits intomainfrom
users/janechu/fix-array-length-in-expressions
Apr 8, 2026
Merged

fix(fast-build): support .length property on arrays in template expressions#7394
janechu merged 7 commits intomainfrom
users/janechu/fix-array-length-in-expressions

Conversation

@janechu
Copy link
Copy Markdown
Collaborator

@janechu janechu commented Apr 6, 2026

Pull Request

📖 Description

Fixes two gaps in the microsoft-fast-build Rust renderer related to data access in template expressions:

  1. Array .length support{{items.length}} now resolves correctly. Previously, get_nested_property tried to parse "length" as a numeric array index, which always failed and returned a MissingState error. A special case now returns the array's length as a number.

  2. JSON literal attribute values — Custom element attributes can now accept JSON array and object literals directly (e.g. items='["a","b","c"]' or config='{"title":"Hello"}'). Previously, these were passed through as raw strings, causing child templates that iterated or accessed nested values to fail.

🎫 Issues

  • Helps unblock #7390 — deep-merge fixture uses {{users.length}} and {{user.orders.length}}
  • Helps unblock #7388 — observer-map fixture uses {{user.posts.length}}

📑 Test Plan

New Rust integration tests added:

  • tests/bindings.rstest_array_length, test_array_length_empty, test_array_length_nested
  • tests/f_when.rstest_when_array_length_gt_zero, test_when_array_length_zero
  • tests/custom_elements.rstest_custom_element_json_array_attr, test_custom_element_empty_array_attr, test_custom_element_json_object_attr

All existing and new tests pass (cargo test).

✅ Checklist

General

  • I have included a change request file using $ npm run change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

janechu and others added 3 commits April 6, 2026 08:42
…ssions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…te values

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…d README.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ay-length-in-expressions

# Conflicts:
#	crates/microsoft-fast-build/src/directive.rs
#	crates/microsoft-fast-build/tests/custom_elements.rs
@janechu janechu marked this pull request as ready for review April 8, 2026 22:14
janechu and others added 2 commits April 8, 2026 15:16
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@janechu janechu requested a review from Copilot April 8, 2026 22:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes two data-access gaps in the microsoft-fast-build Rust renderer: enabling {{items.length}} for arrays in template expressions, and allowing JSON array/object literals to be passed directly via custom element attribute values.

Changes:

  • Parse attribute values that look like JSON arrays/objects ([ / {) into JsonValue instead of always treating them as strings.
  • Add integration tests for JSON-literal attribute values passed into custom elements.
  • Update docs to describe .length support for arrays and the new attribute coercion rules.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/microsoft-fast-build/tests/custom_elements.rs Adds integration tests covering JSON array/object literals in custom element attributes.
crates/microsoft-fast-build/src/directive.rs Adds JSON-literal parsing branch to coerce attribute values into arrays/objects.
crates/microsoft-fast-build/README.md Documents .length and attribute value coercion order (including JSON literals).
crates/microsoft-fast-build/DESIGN.md Updates design notes for .length behavior and JSON-literal attribute coercion.
change/@microsoft-fast-build-fix-json-attrs-*.json Adds patch change record for JSON literal attribute parsing.
change/@microsoft-fast-build-fix-array-length-*.json Adds patch change record for array .length support.

…SON parse

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@janechu janechu merged commit 4329aca into main Apr 8, 2026
11 of 14 checks passed
@janechu janechu deleted the users/janechu/fix-array-length-in-expressions branch April 8, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants