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

Move hoisted script analysis optimization as experimental #8011

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 9, 2023

Changes

Fix #7744
Supersedes and closes #7997

Move the feature in #7707 behind an experimental flag. And added extra comments to make the analysis easier to follow.

Testing

Updated hoisted script test to enable the experimental flags.

Docs

Added the jsdocs. cc @withastro/maintainers-docs for feedback!

@bluwy bluwy requested a review from a team as a code owner August 9, 2023 08:05
@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2023

🦋 Changeset detected

Latest commit: 9c775a5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 9, 2023
Comment on lines -39 to +46
walk(parentInfo.ast, {
enter(node) {
if (node.type === 'ImportDeclaration') {
imports.push(node as ImportDeclaration);
} else if (
node.type === 'ExportDefaultDeclaration' ||
node.type === 'ExportNamedDeclaration'
) {
exports.push(node as ExportNamedDeclaration | ExportDefaultDeclaration);
}
},
});
// All of the aliases the current component is imported as
for (const node of (parentInfo.ast as any).body) {
if (node.type === 'ImportDeclaration') {
imports.push(node);
} else if (node.type === 'ExportDefaultDeclaration' || node.type === 'ExportNamedDeclaration') {
exports.push(node);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Import and exports declarations are top level only, so use this optimization.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

One small suggestion to make this A++, @bluwy! (OK, to make my life easier in the future... but that still counts as A++ in my books!!) 😉

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
@bluwy bluwy merged commit 5b1e39e into main Aug 10, 2023
5 checks passed
@bluwy bluwy deleted the experimental-hoisted-script branch August 10, 2023 04:52
@astrobot-houston astrobot-houston mentioned this pull request Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The component js is lost after packaging.
5 participants