Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Auto-wrapping is broken for non-textual children (fbt:*, template literals, etc) #35

Closed
jrwats opened this issue Jan 9, 2019 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jrwats
Copy link
Contributor

jrwats commented Jan 9, 2019

This is fully evident even in the example app:

    <fbt desc="...">
      <fbt:param name="name" gender={this.state.ex1Gender}>
        <b className="padRight">{this.state.ex1Name}</b>
      </fbt:param>
      has shared
      <a className="neatoLink" href="#">
        <fbt:plural
          many="photos"
          showCount="ifMany"
          count={this.state.ex1Count}>
          a photo
        </fbt:plural>
      </a>
      with you
    </fbt>

Extracts to

  {
      "hashToText": {
        "PqPPir8Kg9xSlqdednPFOg==": "{name} has shared {=a photo} with you"
      },
      "jsfbt": {
        "t": {
          "*": "{name} has shared {=a photo} with you"
        },
        "m": [
          {
            "token": "name",
            "type": 1
          }
        ]
      }
    },
    {
      "hashToText": {
        "/gj3gwqx1z8Xw233oZgOpQ==": "{number} photos",
        "8UZCD6gFUKN+U5UUo1I3/w==": " a photo"
      },
      "desc": "In the phrase: \"{=} has shared {=a photo} with you\"",
      "jsfbt": {
        "t": {
          "*": "{number} photos",
          "_1": " a photo"
        },
        "m": [
          {
            "token": "number",
            "type": 2,
            "singular": true
          }
        ]
      }
    }

Notice both the "{=}" token and the {=a photo} token in the description:

'In the phrase: "{=} has shared {= a photo} with you"'

So two things wrong here. {=} should be {name} AND the {number} photos variant of the <fbt:plural> instance needs its own description such that its token corresponds to the inner text:

'In the phrase: "{name} has shared {=[number] photos} with you"'

There should be two separate outer strings here (not one):

"{name} has shared {=a photo} with you"
"{name} has shared {=[number] photos} with you"

and inner-strings should have separate descriptions:

'In the phrase: "{name} has shared {=a photo} with you"'
'In the phrase: "{name} has shared {=[number] photos} with you"'
@jrwats jrwats self-assigned this Jan 9, 2019
@jrwats jrwats added the bug Something isn't working label Jan 9, 2019
@jrwats
Copy link
Contributor Author

jrwats commented Jan 30, 2019

Template literals are also hosed. Compare

<fbt desc="desc">
  Outer content and
  <Link>
    inner content
  </Link>.
</fbt>

with what-should-be equivalent in template-literal-speak:

<fbt desc="desc">
  {`Outer content and `}
  <Link>
    {`inner content`}
  </Link>
  {`.`}
</fbt>

The former collects texts as expected, where the latter is busted:

{
  "phrases": [
    {
      "hashToText": {
        "zoSwvN/MtdBi+P1krDf5qA==": "Outer content and {=}."
      },
      ...
      "jsfbt": "Outer content and {=}."
    },
    {
      "hashToText": {
        "HwRant9sTV66YQvuSS79qg==": "inner content"
      },
      "desc": "In the phrase: \"{=}\"",
      "jsfbt": "inner content"
    }
  ],
  "childParentMappings": {
    "1": 0
  }
}

@jrwats jrwats changed the title Auto-wrapping is broken for fbt:* children Auto-wrapping is broken for non-textual children (fbt:*, template literals, etc) Jan 30, 2019
@kayhadrin
Copy link
Collaborator

Interesting files:

babel-plugin-fbt/index.js
babel-plugin-fbt/getNamespacedArgs.js
babel-plugin-fbt/FbtUtil.js

@kayhadrin
Copy link
Collaborator

Done. See announcement: #356

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants