babel / website

:globe_with_meridians: The Babel documentation website
https://babeljs.io/docs/en/index.html
MIT License
746 stars 1.3k forks source link

@babel/plugin-syntax-jsx and @babel/plugin-syntax-typescript on REPL does not respect tsx contents #2285

Open alex-kinokon opened 4 years ago

alex-kinokon commented 4 years ago

Bug Report

Current behavior

/repl.js: Unexpected token, expected "," (4:14)

  2 | 
  3 | export function A() {
> 4 |   return <div />
    |               ^
  5 | }
  6 | 

Input Code

Minimum reproduction sample on REPL.

import React from "react"

export function A() {
  return <div />
}

Expected behavior Nothing happens.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

{
  "plugins": [
    "@babel/plugin-syntax-jsx",
    "@babel/plugin-syntax-typescript"
  ]
}

Environment

babel-bot commented 4 years ago

Hey @proteriax! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

babel-bot commented 4 years ago

Hey @proteriax! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

JLHwung commented 4 years ago

The REPL does not add filename: "test.tsx" option, required by @babel/plugin-syntax-typescript. As a workaround, please use the presets > typescript option.

alex-kinokon commented 4 years ago

You can reproduce it even with filename set on Node.js. Please see this example.

JLHwung commented 4 years ago

In Babel 7 you have to enable the isTSX option: https://babeljs.io/docs/en/babel-plugin-syntax-typescript#istsx

We acknowledge that

{
  "plugins": [
    "@babel/plugin-syntax-jsx",
    "@babel/plugin-syntax-typescript"
  ]
}

is more natural and it is now supported on Babel 8.