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

SyntaxError: Unexpected token when encountering React Fragment shorthand syntax #73

Open
jasonbarry opened this issue Nov 22, 2018 · 12 comments
Assignees
Labels

Comments

@jasonbarry
Copy link

SyntaxError: Unexpected token (112:13)
    at Parser.pp$5.raise (./node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (./node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$9.jsxParseIdentifier (./node_modules/babylon/lib/index.js:7029:10)
    at Parser.pp$9.jsxParseNamespacedName (./node_modules/babylon/lib/index.js:7040:19)
    at Parser.pp$9.jsxParseElementName (./node_modules/babylon/lib/index.js:7055:19)
    at Parser.pp$9.jsxParseOpeningElementAt (./node_modules/babylon/lib/index.js:7145:20)
    at Parser.pp$9.jsxParseElementAt (./node_modules/babylon/lib/index.js:7169:29)
    at Parser.pp$9.jsxParseElement (./node_modules/babylon/lib/index.js:7224:15)
    at Parser.parseExprAtom (./node_modules/babylon/lib/index.js:7236:21)
    at Parser.pp$3.parseExprSubscripts (./node_modules/babylon/lib/index.js:3494:19)

when it encounters Babel 7's shorthand of React.Fragment, <>.

@the-simian
Copy link
Owner

Interesting! I probably need to update some dependencies. looks like the break is way down there in babylon. Can you show me the code it was trying to parse it that broke it, or maybe throw up a repo that reproduces this? man that could really help me fix this! Especially that second thing!!

@luckykun
Copy link

@the-simian hello, I have the same problem. Can you fix it? THX ^_^

@the-simian
Copy link
Owner

@luckykun can you post me a snippet of code you got that's breaking so I can use it to test? It might be in the underlying parser also.

@the-simian the-simian self-assigned this Feb 5, 2019
@the-simian
Copy link
Owner

@luckykun I'll be updating the underlying parser very soon might fix this.

@the-simian the-simian added the bug label Feb 5, 2019
@the-simian
Copy link
Owner

the-simian commented Feb 5, 2019

(possibly duplicate of #79 )

@the-simian
Copy link
Owner

I updated the underlying parser, lets see if this is still an issue @luckykun

@rayno
Copy link

rayno commented Dec 9, 2019

Yes, still an issue. It throws the error for each file.

@the-simian
Copy link
Owner

thanks for the update @rayno , can you post a snippet that throws so I can reproduce your exact usecase?

@rayno
Copy link

rayno commented Dec 10, 2019

Environment: Windows 10 64-bit
NodeJS: v10.15.0

file: test.js

import React from 'react'

function Comp() {
  return (
    <>
      <h1>Hello</h1>
      <p>Text</p>
    </>
  )
}

file: test-plato.js (taken from npm page)

let plato = require('es6-plato')
let src = './test.js'
let outputDir = './plato'

let lintRules = {
  rules: {
    indent: [2, 'tab'],
    quotes: [2, 'single'],
    semi: [2, 'always'],
    'no-console': [1],
    curly: ['error'],
    'no-dupe-keys': 2,
    'func-names': [1, 'always'],
  },
  env: {
    es6: true,
  },
  globals: ['require'],
  parserOptions: {
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      modules: true,
    },
  },
}

let complexityRules = {}

let platoArgs = {
  title: 'example',
  eslint: lintRules,
  complexity: complexityRules,
}

return plato.inspect(src, outputDir, platoArgs)

Console output from node ./test-plato.js (same with no lintRules):

Processing  1  files
Error reading file test.js:  SyntaxError: Unexpected token (5:5)
SyntaxError: Unexpected token (5:5)
    at Parser.pp$5.raise (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp$9.jsxParseIdentifier (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7029:10)
    at Parser.pp$9.jsxParseNamespacedName (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7040:19)
    at Parser.pp$9.jsxParseElementName (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7055:19)
    at Parser.pp$9.jsxParseOpeningElementAt (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7145:20)
    at Parser.pp$9.jsxParseElementAt (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7169:29)
    at Parser.pp$9.jsxParseElement (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7224:15)
    at Parser.parseExprAtom (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:7236:21)
    at Parser.pp$3.parseExprSubscripts (C:\Users\rarshinkov\projects\test-project\node_modules\babylon\lib\index.js:3494:19)

@the-simian
Copy link
Owner

@rayno, thank you!

@Fantasy9527
Copy link

I have the same problem

@HenriqueDerosa
Copy link

I have the same problem. Any chance this is going to be fixed? Or an alternative? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants