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

fix: strip comments for JSX pragma #29145

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: strip comments for JSX pragma",
"packageName": "@fluentui/react-jsx-runtime",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 6 additions & 1 deletion scripts/tasks/src/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ async function swcTransform(options: Options) {
outputPath,
});

// Strip @jsx comments, see https://github.com/microsoft/fluentui/issues/29126
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heads up that using @jsx in a comment without it actually being a jsx pragma directive is causing eslint-plugin-react to crash, which is something we need to fix. See jsx-eslint/eslint-plugin-react#3632.

Feel free in the meantime to avoid having @ and jsx next to each other in this comment if that ends up causing you any trouble :-)

const resultCode = result.code
.replace('/** @jsxRuntime automatic */', '')
.replace('/** @jsxImportSource @fluentui/react-jsx-runtime */', '');

const compiledFilePath = path.resolve(packageRoot, fileName.replace(`${sourceRootDirName}`, outputPath));

//Create directory folder for new compiled file(s) to live in.
await fs.promises.mkdir(compiledFilePath.replace(path.basename(compiledFilePath), ''), { recursive: true });

const compiledFilePathJS = `${compiledFilePath.replace(tsFileExtensionRegex, '.js')}`;

await fs.promises.writeFile(compiledFilePathJS, result.code);
await fs.promises.writeFile(compiledFilePathJS, resultCode);
if (result.map) {
await fs.promises.writeFile(`${compiledFilePathJS}.map`, result.map);
}
Expand Down
Loading