extract-react-intl-messages icon indicating copy to clipboard operation
extract-react-intl-messages copied to clipboard

Getting an error for using FormattedHTMLMessage

Open udayrajMT opened this issue 5 years ago • 1 comments

  • version:
  • node version: 12
  • yarn version: 1.22
  • react-intl version: 2.9.0

Do you want to request a feature or report a bug?: bug. (would be a feature if this functionality is missing altogether)

What is the current behavior?: When using FormattedHTMLMessage to parse the following string - Sample message string : Hello <span class='bold'>'{name}'</span>

I'm getting an 'unexpected token' error.

yarn run v1.22.4
$ extract-messages -l=messages -o dist -d en './src/components/**/!(*.test).js'
SyntaxError: [React Intl] Message failed to parse. See: https://formatjs.io/docs/icu-syntax
SyntaxError: Expected "#", "'", "\n", "{", argumentElement, double apostrophes, end of input, or tagElement but "<" found. (This is an error on an internal node. Probably an internal error.)
    at File.buildCodeFrameError (/project/node_modules/@babel/core/lib/transformation/file/file.js:248:12)
    at NodePath.buildCodeFrameError (/project/node_modules/@babel/traverse/lib/path/index.js:144:21)
    at getICUMessageValue (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:66:27)
    at evaluateMessageDescriptor (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:113:26)
    at processMessageObject (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:388:38)
    at Array.forEach (<anonymous>)
    at PluginPass.CallExpression (/project/node_modules/extract-react-intl-messages/node_modules/babel-plugin-react-intl/dist/index.js:415:38)
    at newFn (/project/node_modules/@babel/traverse/lib/visitors.js:179:21)
    at NodePath._call (/project/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (/project/node_modules/@babel/traverse/lib/path/context.js:42:17)
error Command failed with exit code 1.

What is the expected behavior?: Expecting this to be extracted like the other messages.

Suggested solution:

udayrajMT avatar Jul 01 '20 16:07 udayrajMT

Had a simular issue, this can be solved by marking the HTML as escaped

Example: Hello '<span class="bold">'{name}'</span>'

TriPSs avatar Mar 30 '21 10:03 TriPSs