feat: render invalid ICU placeholders as plain text#10
Open
bdshadow wants to merge 1 commit into
Open
Conversation
Invalid ICU expressions like `{placeholder:space}` used to parse as a
partial `{placeholder` Expression plus trailing text. In RTL editors the
two halves ended up in different bidi-isolation runs, scrambling the token.
They now parse leniently as a single Expression with no styled child
tokens, so they render as plain text — no chip, no highlighting — and stay
intact in RTL. Valid placeholders are unchanged. Adds `getInvalidPlaceholders`
to detect them.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Invalid ICU expressions like
{placeholder:space}(a colon isn't valid ICU) parsed as a partial{placeholderExpressionplus trailing:space}text. In an RTL editor,htmlIsolatesPluginputs theExpressionin an LTR isolate and the trailing text in an RTL isolate, splitting the single token across two bidi boundaries and scrambling it.Fix
Invalid
{...}contents now parse leniently as a singleExpressioncontaining anInvalidExpressionBody(noParam, no styled tokens):getPlaceholdersskips it (inner node isn'tFormatExpression).Param/styled child tokens.{...}stays one node, so RTL bidi isolation keeps it intact.Mechanism: an
extend: trueexternal tokenizer forks the parse, andInvalidExpressionBody's@dynamicPrecedence=-1makes a real format/select parse win whenever one exists. ICU validity itself is still reported by the formatjs-based linter.Adds
getInvalidPlaceholders(text, nested?)to detect such expressions (used by the platform to warn the user).Tests
166 tests pass, including new parser cases and a
getInvalidPlaceholderssuite.tsc,eslint, andvite buildare clean.