-
Notifications
You must be signed in to change notification settings - Fork 49.9k
[mcp] Make tool more reliable and fix integration issues with babel #33074
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
Merged
+48
−50
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
359dddc
Fix @babel usage and remove timeouts
jorge-cab 682fbcb
Fix @babel usage and remove timeouts
jorge-cab 47d4fc0
Minor style changes
jorge-cab b549ec0
Add more context to the tool
jorge-cab 3141c9f
Fix incorrect property access
jorge-cab 1900e35
prettier
jorge-cab 9e52151
Refactor babel functions and inline them
jorge-cab eea64bf
prettier
jorge-cab 6a3ca9c
Fine tunning tool context
jorge-cab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ export async function measurePerformance(code: any) { | |
| let options = { | ||
| configFile: false, | ||
| babelrc: false, | ||
| presets: [['@babel/preset-env'], '@babel/preset-react'], | ||
| presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')], | ||
| }; | ||
|
|
||
| const parsed = await babel.parseAsync(code, options); | ||
|
|
@@ -14,24 +14,21 @@ export async function measurePerformance(code: any) { | |
| throw new Error('Failed to parse code'); | ||
| } | ||
|
|
||
| const transpiled = await transformAsync(parsed); | ||
| const transpiled = await transformAsync(parsed, options); | ||
|
|
||
| if (!transpiled) { | ||
| throw new Error('Failed to transpile code'); | ||
| } | ||
|
|
||
| const browser = await puppeteer.launch({ | ||
| protocolTimeout: 600_000, | ||
| }); | ||
| const browser = await puppeteer.launch(); | ||
|
|
||
| const page = await browser.newPage(); | ||
| await page.setViewport({width: 1280, height: 720}); | ||
| const html = buildHtml(transpiled); | ||
| await page.setContent(html, {waitUntil: 'networkidle0'}); | ||
|
|
||
| await page.waitForFunction( | ||
| 'window.__RESULT__ !== undefined && (window.__RESULT__.renderTime !== null || window.__RESULT__.error !== null)', | ||
| {timeout: 600_000}, | ||
| 'window.__RESULT__ !== undefined && (window.__RESULT__.renderTime !== null || window.__RESULT__.error !== null)' | ||
| ); | ||
|
|
||
| const result = await page.evaluate(() => { | ||
|
|
@@ -48,10 +45,10 @@ export async function measurePerformance(code: any) { | |
| * @param {Object} opts - Transformation options | ||
| * @returns {Promise<string>} - The transpiled code | ||
| */ | ||
| async function transformAsync(ast: babel.types.Node) { | ||
| async function transformAsync(ast: babel.types.Node, options: any) { | ||
|
||
| const result = await babel.transformFromAstAsync(ast, undefined, { | ||
| ...options, | ||
| filename: 'file.jsx', | ||
| presets: [['@babel/preset-env'], '@babel/preset-react'], | ||
| plugins: [ | ||
| () => ({ | ||
| visitor: { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add something like "run this tool every time you propose a performance related change to verify if your suggestion actually improves performance"