Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docs/
/styles/
coverage/
.vscode/
stats.html
67 changes: 66 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,70 @@ module.exports = {
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: ['@babel/proposal-object-rest-spread'],
plugins: [
[
'babel-plugin-react-compiler',
{
// Support React 17 as a minimum
target: '17',
logger: {
/**
* @param {string | null} filename
* @param {import('babel-plugin-react-compiler').LoggerEvent} event
*/
logEvent(filename, event) {
if (
event.kind === 'CompileError' ||
event.kind === 'CompileSkip' ||
event.kind === 'PipelineError'
) {
if (event.kind === 'CompileError') {
Copy link

Choose a reason for hiding this comment

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

[P2] Inconsistent Log Header: The current logging logic only prints a contextual header with the filename for CompileError events. For CompileSkip and PipelineError events, this header is omitted, which makes it difficult to determine which file the logged details refer to. To improve debuggability, a header should be logged for all handled event types.

Suggested change
if (event.kind === 'CompileError') {
if (event.kind === 'PipelineError') {
console.error(
`\n[React Compiler] \x1b[31mCompilation failed\x1b[0m: ${filename}`,
)
} else {
console.warn(
`\n[React Compiler] \x1b[33mCompilation skipped\x1b[0m: ${filename}`,
)
}

console.warn(
`\n[React Compiler] \x1b[33mCompilation skipped\x1b[0m: ${filename}`,
)
}

if (event.detail?.reason) {
console.error(`Reason: ${event.detail.reason}`)
}

if (event.detail?.description) {
console.error(`Details: ${event.detail.description}`)
}

if (event.detail.primaryLocation) {
Copy link

Choose a reason for hiding this comment

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

[P1] Potential Runtime Error: The event.detail property may be undefined for some event kinds, such as PipelineError. Accessing event.detail.primaryLocation directly can cause a TypeError and crash the logging utility. Using optional chaining (?.) here will prevent this potential runtime error.

Suggested change
if (event.detail.primaryLocation) {
if (event.detail?.primaryLocation) {

const sourceLocation = event.detail.primaryLocation()

if (sourceLocation?.start) {
console.error(
`Location: Line ${sourceLocation.start.line}, Column ${sourceLocation.start.column}`,
)
}
}

if (event.detail?.suggestions?.length) {
console.error('Suggestions:')
for (const suggestion of event.detail.suggestions) {
console.error(`• ${suggestion.description}`)
}
}

if (event.data) {
console.error(`Data: ${event.data}`)
}
}
},
},
},
],
'@babel/proposal-object-rest-spread',
[
'@babel/plugin-transform-runtime',
{
// Prevent helpers from being inlined in the output code
// https://babeljs.io/docs/babel-plugin-transform-runtime#version
version: '^7.28.4',
},
],
],
}
Loading