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

fix(es/typescript): Handle shebang with jsx pragma #8318

Merged

Conversation

dsherret
Copy link
Contributor

@dsherret dsherret commented Nov 20, 2023

Description:

This handles a shebang with a jsx prag. Previously h would be removed as an import in this case.

Related issue:

@dsherret dsherret requested a review from a team as a code owner November 20, 2023 16:50
.span
.with_lo(n.body.first().map(|s| s.span_lo()).unwrap_or(n.span.lo)),
false => n.span,
};
Copy link
Contributor Author

@dsherret dsherret Nov 20, 2023

Choose a reason for hiding this comment

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

FWIW, I think probably a better solution would be to consolidate the jsx prag detection code, but I believe the jsx prag detection code in swc_ecma_transforms_react is doing too much work as it checks every module item instead of just the top of the file:

self.parse_directives(module.span);
for item in &module.body {
let span = item.span();
if self.parse_directives(span) {
break;
}
}

Copy link
Member

Choose a reason for hiding this comment

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

#2992 (comment)

It's due to mdxjs

@dsherret
Copy link
Contributor Author

A potential fix to CI issues: actions/setup-node#899 (comment)

@kdy1 kdy1 added this to the Planned milestone Nov 20, 2023
@dsherret dsherret requested a review from kdy1 November 20, 2023 23:55
@kdy1 kdy1 changed the title fix(transforms/typescript): ImportsNotUsedAsValues - Handle shebang with jsx prag fix(es/typescript): Handle shebang with jsx pragma Nov 21, 2023
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thanks!

swc-bump:

  • swc_ecma_transforms_typescript

@kdy1 kdy1 enabled auto-merge (squash) November 21, 2023 08:46
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

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

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit c25601d into swc-project:main Nov 21, 2023
142 checks passed
@dsherret dsherret deleted the fix_imports_not_used_as_values_shebang_jsx_prag branch November 22, 2023 17:44
@kdy1 kdy1 modified the milestones: Planned, v1.3.100 Nov 30, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants