evenchange4 / react-intl-cra

🔧 Extract messages of Creact React App from the command line.
MIT License
67 stars 11 forks source link

React.Fragment Short Syntax fails to extract, SyntaxError unexpected token #59

Open 18steps opened 6 years ago

18steps commented 6 years ago

Do you want to request a feature or report a bug?: Bug

What is the current behavior?:

Fragment short syntax breaks the parser.

yarn run v1.6.0
$ yarn run extract:messages && yarn run extract:pot-c
$ react-intl-cra ./src/**/*.js -o translations/generated-translations.json
C:\src\legacy-invoice-view-app\node_modules\babel-core\lib\transformation\file\index.js:558
      throw err;
      ^

SyntaxError: unknown: Unexpected token (19:5)
  17 | function App({ username, userToken, customerNumber }) {
  18 |   return (
> 19 |     <>
     |      ^
  20 |       <DoWhenAppMounts />
  21 |       <global-header
  22 |         consumer={'legacy-invoice-view'}
    at Parser.pp$5.raise (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp$9.jsxParseIdentifier (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7029:10)
    at Parser.pp$9.jsxParseNamespacedName (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7040:19)
    at Parser.pp$9.jsxParseElementName (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7055:19)
    at Parser.pp$9.jsxParseOpeningElementAt (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7145:20)
    at Parser.pp$9.jsxParseElementAt (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7169:29)
    at Parser.pp$9.jsxParseElement (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7224:15)
    at Parser.parseExprAtom (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:7236:21)
    at Parser.pp$3.parseExprSubscripts (C:\src\legacy-invoice-view-app\node_modules\babylon\lib\index.js:3494:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What is the expected behavior?: Extract messages works even if the solution uses the shorthand syntax for React Fragments.

Suggested solution: Update dependencies? No idea. Babylon package says it's now at "babel/babel as @babel/parser" -- don't know if that one works with the shorter syntax though.

arvinsim commented 5 years ago

I got the same Unexpected token issue. Although my problem is that it wasn't parsing Typescript interface properly without semicolons.

fffan64 commented 4 years ago

any update on this ? will the shorthand syntax be supported ? thanks !