es6-plato icon indicating copy to clipboard operation
es6-plato copied to clipboard

`SyntaxError: Unexpected token` when encountering React Fragment shorthand syntax

Open jasonbarry opened this issue 6 years ago • 12 comments

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, <>.

jasonbarry avatar Nov 22 '18 19:11 jasonbarry

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!!

the-simian avatar Nov 23 '18 00:11 the-simian

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

luckykun avatar Jan 18 '19 07:01 luckykun

@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 avatar Jan 18 '19 22:01 the-simian

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

the-simian avatar Feb 05 '19 01:02 the-simian

(possibly duplicate of #79 )

the-simian avatar Feb 05 '19 01:02 the-simian

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

the-simian avatar Aug 01 '19 05:08 the-simian

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

rayno avatar Dec 09 '19 14:12 rayno

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

the-simian avatar Dec 09 '19 20:12 the-simian

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)

rayno avatar Dec 10 '19 11:12 rayno

@rayno, thank you!

the-simian avatar Dec 11 '19 20:12 the-simian

I have the same problem

Num142857 avatar Sep 10 '21 01:09 Num142857

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

HenriqueDerosa avatar Dec 10 '21 12:12 HenriqueDerosa