Skip to content

fix: tarball bundling - import assertion replacement - #6928

Merged
mrstork merged 17 commits into
mainfrom
import-assertion-replacement
Feb 17, 2026
Merged

mrstork merged 17 commits into
mainfrom
import-assertion-replacement

Conversation

@mrstork

@mrstork mrstork commented Feb 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of FRB-2115

  • Converts import assert -> import with in user code and vendor code
  • Also handles dynamic import assertions

Note: When the syntax is unrecognized / fails being parsed into an AST, the input code is returned as is (e.g. when using JSX syntax)


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@github-actions

Copy link
Copy Markdown
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@mrstork
mrstork marked this pull request as ready for review February 17, 2026 14:06
@mrstork
mrstork requested a review from a team as a code owner February 17, 2026 14:06
.forEach((node) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
const statement = source.slice((node as any).source.end, node.end)
const newStatement = statement.replace('assert', 'with')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What example statement looks like in those AST nodes?

Will this be something like assert { type: 'json' }?

If so I think this is fine for what deno actually supports - because it's just type property with values being just "json" or "bytes" and "text" (some of them seems to need some flag to enable) (ref https://github.com/denoland/deno/blob/8871ade7aa09eb907a04ee61a427f5ba14c54014/runtime/worker.rs#L97-L114 )

If this would be entire import/export statement - like say import assert from "./assert.json" assert { type: "json" } this would replace just first assert text occurrence which would not be correct change. Can we add this weird import statement as one of test inputs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will be assert { type: 'json' }
I added import assert from './assert.json' with { type: 'json' }; and console.assert(true, 'should be true'); to cover the case of "over capturing"

@mrstork
mrstork marked this pull request as draft February 17, 2026 15:03
@mrstork
mrstork marked this pull request as ready for review February 17, 2026 16:26
@mrstork
mrstork merged commit 7a5a649 into main Feb 17, 2026
76 of 81 checks passed
@mrstork
mrstork deleted the import-assertion-replacement branch February 17, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants