Skip to content

Implement top-level await functionality#156

Open
leizongmin wants to merge 2 commits intomainfrom
cursor/implement-top-level-await-functionality-8a35
Open

Implement top-level await functionality#156
leizongmin wants to merge 2 commits intomainfrom
cursor/implement-top-level-await-functionality-8a35

Conversation

@leizongmin
Copy link
Copy Markdown
Owner

Implement top-level await support for ES modules in jssh.

This feature allows the await keyword to be used directly at the top level of ES modules (.mjs files), enabling asynchronous initialization and data fetching without wrapping code in an async function. The implementation involves detecting top-level await usage, transforming ES module export syntax, and wrapping the module's code in an asynchronous IIFE for execution.

Co-authored-by: leizongmin <leizongmin@gmail.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: ES Module Loader Malforms Exported Functions

The enhanced ES module loader's transformation for export function statements generates invalid JavaScript syntax. The regex replacement incorrectly modifies the function signature, resulting in malformed code like const temp_func = function name(; exportNamed("name", temp_func); function name( which causes runtime syntax errors. Additionally, the conditional check for applying this transformation is unreliable, potentially preventing correct function export due to false positives if the function name appears elsewhere in the content.

example/es-modules/enhanced-es-module.js#L78-L88

);
transformedContent = transformedContent.replace(
/function\\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\\s*\\(/g,
(match, name) => {
if (!transformedContent.includes(\`exportNamed("\${name}"\`)) {
return match.replace('function', 'const temp_func = function') +
\`; exportNamed("\${name}", temp_func); function \${name}\`;
}
return match;
}
);

Fix in CursorFix in Web


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

Co-authored-by: leizongmin <leizongmin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants