swc-project / swc-project/swc-node
Mocha tests for React (jsx) aren't parsed as jsx if test filename has .js extension
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 95
- Avg merge
- 14d 11h
- Merged PRs (30d)
- 1
Description
Hi, This is a clone of an issue i've opened on the main SWC repo
It might be better suited for this repo than the main SWC one.
Repo - https://github.com/yairEO/swc-js-extension-fails-with-jsx-content
Describe the bug
Hi, I am trying to convert a large project from Mocha + babel to Mocha + SWC, but get errors if the test file extension ends with .js and not .jsx. I have hundreds of files like this.
Renaming one of them makes SWC compile it correctly, but I really prefer keeping the tests files with the .js extension.
the project is based on React v16, so every component and its test file has the React import:
import React from 'react';
I would assume SWC would be smart enough to automatically know the content of the file is JSX...
Input code
No response
Config
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true,
"dynamicImport": false,
"privateMethod": true,
"functionBind": false,
"exportDefaultFrom": true,
"exportNamespaceFrom": false,
"decorators": true,
"decoratorsBeforeExport": true,
"topLevelAwait": false,
"importMeta": false
},
"transform": {
"legacyDecorator": true,
"react": {
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false
},
"optimizer": {
"globals": {
"vars": {
"__DEBUG__": "true"
}
}
}
},
"target": "es5",
"loose": false,
"externalHelpers": false,
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
},
"minify": false
}
Expected behavior
Should transpile JSX for .js files automatically
Actual behavior
No response
Version
1.5.5
Additional context
Am using these packages:
"@swc-node/register": "1.5.5",
"swc": "1.0.11",
"mocha": "9.2.2",
Running the tests with this .mocharc:
{
"exit": true,
"color": true,
"require": ["@swc-node/register", "test/register.js", "test/setup.js"],
"ignore": "node_modules"
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with @swc-node/register and its handling of Mocha's .js test files; reproduce the report using the shown .mocharc and SWC parser configuration. Compare processing of .js and .jsx inputs, then add coverage for JSX in .js tests and verify the expected transpilation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100