Skip to content

Commit 4dcfbf5

Browse files
committed
Add same alias test
1 parent ea68863 commit 4dcfbf5

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

packages/babel-plugin-component-annotate/test/__snapshots__/test-plugin.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,22 @@ export default function TestComponent() {
168168
}"
169169
`;
170170

171+
exports[`Fragment Performance Benchmarks handles Fragment aliased correctly when used by other non-Fragment components in a different scope 1`] = `
172+
"import { Fragment as OriginalF } from 'react';
173+
import { OtherComponent } from 'some-library';
174+
function TestComponent() {
175+
const F = OriginalF;
176+
177+
// Use Fragment alias - should be ignored
178+
return /*#__PURE__*/React.createElement(F, null, /*#__PURE__*/React.createElement(\\"div\\", null, \\"This should NOT have data-sentry-element (Fragment)\\"));
179+
}
180+
function AnotherComponent() {
181+
// Different component with same alias name in different function scope
182+
const F = OtherComponent;
183+
return /*#__PURE__*/React.createElement(F, null, /*#__PURE__*/React.createElement(\\"div\\", null, \\"This SHOULD have data-sentry-element (not Fragment)\\"));
184+
}"
185+
`;
186+
171187
exports[`arrow snapshot matches 1`] = `
172188
"import React, { Component } from 'react';
173189
const componentName = () => {

packages/babel-plugin-component-annotate/test/test-plugin.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,4 +1884,43 @@ export default function Component${i}() {
18841884

18851885
expect(memoryDelta).toBeLessThan(50);
18861886
});
1887+
1888+
it("handles Fragment aliased correctly when used by other non-Fragment components in a different scope", () => {
1889+
const result = transform(
1890+
`import { Fragment as OriginalF } from 'react';
1891+
import { OtherComponent } from 'some-library';
1892+
1893+
function TestComponent() {
1894+
const F = OriginalF;
1895+
1896+
// Use Fragment alias - should be ignored
1897+
return (
1898+
<F>
1899+
<div>This should NOT have data-sentry-element (Fragment)</div>
1900+
</F>
1901+
);
1902+
}
1903+
1904+
function AnotherComponent() {
1905+
// Different component with same alias name in different function scope
1906+
const F = OtherComponent;
1907+
1908+
return (
1909+
<F>
1910+
<div>This SHOULD have data-sentry-element (not Fragment)</div>
1911+
</F>
1912+
);
1913+
}
1914+
`,
1915+
{
1916+
filename: "/variable-assignment-test.js",
1917+
configFile: false,
1918+
presets: ["@babel/preset-react"],
1919+
plugins: [plugin],
1920+
}
1921+
);
1922+
1923+
expect(result?.code).not.toContain('"data-sentry-element": "F"');
1924+
expect(result?.code).toMatchSnapshot();
1925+
});
18871926
});

0 commit comments

Comments
 (0)