Repository navigation
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
from
October 22, 2026 01:19
0b9eeb5 to
74a4005
Compare
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
4 times, most recently
from
October 25, 2026 22:05
dd94f08 to
9bf4298
Compare
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
2 times, most recently
from
October 26, 2026 09:06
17471b2 to
07d12e5
Compare
Member
Author
|
/ecosystem-ci run |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
2 times, most recently
from
October 29, 2026 06:54
225fa0d to
abbdcfb
Compare
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
2 times, most recently
from
October 29, 2026 08:17
bd6245c to
5e51a9a
Compare
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
from
October 29, 2026 09:50
5e51a9a to
36a8ef4
Compare
shulaoda
force-pushed
the
feat/import-attributes-poc
branch
from
November 3, 2026 13:19
36a8ef4 to
71c9831
Compare
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
… import record (#11301) Part 1 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. Adds the data model for import attributes, aligned with Rollup 5. Nothing reads the new option yet, so builds behave as before, except for the legacy `assert` keyword below. - `ImportAttributes`: the attributes of one import, kept in the order `JSON.stringify` emits them, so equal attributes always compare and hash the same. - `ModuleId::with_attributes`: builds the Rollup 5 id `rawId?attributes=<encoded JSON>` and keeps `raw_id()` for path operations. - `ResolvedId.attributes` and `ImportRecord.attributes`: carry the attributes through resolution and keep what the scanner read from a `with` clause. - `experimental.importAttributes`: accepted by the Rust options, used by the next PRs. - Tests: `configVariants` accept `importAttributes`, so a fixture can run in both modes. Until now Rolldown supported import attributes only partially: the `ImportAttribute` side table (#5794, #9796, #11100) kept the `with` clause of an external import as written and picked one clause per chunk, while attributes took no part in module identity. That side table is gone. In this PR the `with` clause of an external is rendered from the import record's attributes instead, so the output does not change, except that keys are sorted and duplicates are removed. #11303 then renders it from the module's own attributes. The legacy `assert` keyword is deprecated. It is treated as `with`, so its attributes are kept and an external renders a `with` clause. The build warns with the new `DEPRECATED_IMPORT_ASSERTION` code (`checks.deprecatedImportAssertion`). Use `with` instead. Earlier versions kept the `assert` clause as written, which Node 22 rejects.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…ty (#11302) Part 2 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. With `experimental.importAttributes`, the same file imported with different attributes becomes different modules. Without the option, ids and output stay the same. Plugin hooks do not see the attributes yet. - `import()`: the scanner also reads the static `{ with: { ... } }` options of a dynamic import. The legacy `assert` key is read like `with`. - Resolution: the attributes travel through resolution into `ResolvedId`, and `finalize_attributes` turns the id into `rawId?attributes=...`. Dependencies are deduplicated by `(specifier, kind, attributes)`. - Raw id: everything that touches a file or names one uses `raw_id()`. That covers reading and watching the module, tsconfig lookup, `treeshake.moduleSideEffects`, `output.paths`, chunk and `preserveModules` file names, and the file name the transformer sees. - Module type: a `type` attribute of `json`, `text` or `bytes` selects the built-in module type. It beats the file extension and `moduleTypes`, but not the `moduleType` returned by a load hook. - Diagnostics: module comments and the "Could not load" error show a module with attributes as `dep.js with { kind: "x" }`. - Warnings: the new `INVALID_IMPORT_ATTRIBUTE` code (`checks.invalidImportAttribute`) reports `import()` options that cannot be read statically, the same cases Rollup uses it for. They warn only with the option on, because without it the options are left as written. An `assert` key in the options warns `DEPRECATED_IMPORT_ASSERTION`, also only with the option on here (#11303 changes that).
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…om their module identity (#11303) Part 3 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. External modules now render their `with` clause from their own attributes. Externals carry their attributes in their module id with or without `experimental.importAttributes`, so the clause is always kept. - ESM output: every static import and re-export of an external renders `ExternalModule.attributes`, including the `import * as` emitted for a namespace re-export. The record based search in `esm.rs` is removed. - `import()`: the options of `import()` of an external are rewritten to the final attributes, so a `resolveId` override shows up in the output. - `import()` path: `import()` of an external gets the same path as a static import, and stays an `import()` while it has options, because `require()` cannot carry them. - `assert` in `import()` options: engines ignore it, so every `import()` left in the output gets the key rewritten to `with`, including one with a computed specifier. It warns `DEPRECATED_IMPORT_ASSERTION` with or without the option, like a static `assert` clause. - Raw id: `output.globals` and the CJS `require()` of a re-exported external use the raw id. The old behavior (#5794, #9796, #11100) had no module identity. Two imports of one external with different attributes were one module, and only one clause survived. For example, `import 'ext'; import 'ext' with { type: 'json' }` rendered only the second import. Now they are two externals, each with its own clause. Without the option, an external with attributes now has a composite id in `getModuleInfo()` and `moduleIds`.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…he module id helpers to JS (#11304) Part 4 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. Exposes the option and the module id helpers to JS. Plugin hooks still get ids only, the next PRs add the attributes hook by hook. - `experimental.importAttributes`: accepted by the JS options and the validator, and passed to the binding. - `stringifyModuleId` and `parseModuleId` in `rolldown/utils`: build and split `rawId?attributes=...` ids with the same bytes as the Rust side. `parseModuleId` only accepts a suffix it would produce itself, so ids that only look similar stay as they are. - `UniqueModuleId`: a module id, or `{ rawId, attributes }`. - `PluginContextData.toModuleId`: composes ids on the JS side the same way as Rust, when the option is on or the module is external, so module options such as `meta` are stored under the right id.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…d `resolveDynamicImport` hooks (#11305) Part 5 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. `resolveId` and `resolveDynamicImport` see the attributes of an import and can change them, in Rust and in JS. The arguments are filled with or without `experimental.importAttributes`. - Arguments: both hooks get `attributes`, `importerRawId` and `importerAttributes`. `resolveDynamicImport` gets only these three, as in Rollup 5. `resolveId` keeps `isEntry`, `kind` and `custom`. - Return value: `attributes` replaces the attributes of the import. `{}` removes them, and leaving it out keeps the ones written in the source. For an external, the result is what ends up in its `with` clause. Without the option, the returned attributes only apply to externals. - Module options: `meta` and `moduleSideEffects` returned by the hook are stored under the composed id, also for an external without the option. - Binding: empty attributes and a raw id equal to the importer are left out, and the JS side fills in the defaults. Not covered: builtin plugins called from JS through `BindingCallableBuiltinPlugin` get the importer's attributes, but not the attributes of the import itself.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…nd `this.load` (#11306) Part 6 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. `this.resolve` and `this.load` accept import attributes. - `this.resolve(source, importer, { attributes })`: resolves a simulated import with attributes and returns `{ id: rawId, attributes }`. `importer` can also be `{ rawId, attributes }`. - `this.load(...)`: takes a module id or `{ rawId, attributes }`. A module id that contains attributes is split again. As in Rollup 5, the attributes only come from `id`, so a `this.resolve` result passed as is loads the module without them. Pass `{ ...resolved, id: { rawId: resolved.id, attributes: resolved.attributes } }` instead. - `this.resolve(source, null)` keeps working, like in Rollup. - Rust: `PluginContextResolveOptions.attributes` and `PluginContext::load(raw_id, attributes, ...)`. - Builtin plugins: `vite_alias` forwards the attributes of the import it resolves for and returns the resolved ones, and `isolated_declaration` loads with the resolved attributes. `lazy_compilation` skips an `import()` with attributes for now, so it is bundled as usual.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…11307) Part 7 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. `load` gets the raw id and the attributes of the module. Without `experimental.importAttributes`, `rawId` equals `id` and `attributes` is `{}`. - `load(id, { rawId, attributes })`: with the option on, `id` contains the attributes, so read the file from `rawId`. - Binding: the extra argument is sent only for a module with attributes, and the JS side fills in `{ rawId: id, attributes: {} }`. - Source maps returned by `load` are resolved against `rawId`. - The builtin data URL plugin looks its modules up by the raw id. Known: Vite's `load(id, options?: { ssr?: boolean })` hook type does not extend this signature (TS2430), so Vite needs to widen its options type.
shulaoda
added a commit
that referenced
this pull request
Nov 3, 2026
…ok (#11308) Part 8 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. `transform` gets the same two fields as `load`. - `transform(code, id, { rawId, attributes, ... })`: without `experimental.importAttributes`, `rawId` equals `id` and `attributes` is `{}`. - Binding: both fields are left out for a module without attributes, and the JS side fills in the defaults. - Rust: `HookTransformArgs` gets `raw_id` and `attributes`, and `PluginDriver::transform` takes the `ModuleId` and its attributes.
shulaoda
added a commit
that referenced
this pull request
Nov 4, 2026
…pes` in the asset and copy plugins (#11309) Part 9 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. A `type` attribute also beats `moduleTypes` in the builtin asset and copy plugins. With `experimental.importAttributes`, `import x from './a.txt' with { type: 'json' }` loads as JSON even when `moduleTypes` maps `.txt` to `asset` or `copy`. This matches how the core picks the module type. A `type` without a built-in meaning, like `css`, leaves the module to `moduleTypes`, and so does a build without the option. The copy plugin forwards the attributes of the import to `this.resolve` and checks the resolved ones, so a `resolveId` override counts.
shulaoda
added a commit
that referenced
this pull request
Nov 4, 2026
…11381) Part 10 of 11 of the import attributes stack. RFC: #11217. Full proof of concept: #11254. Enables the related Rollup tests, as asked in #11310 (comment). None of Rollup's own import attributes tests in `packages/rollup-tests` pass as they are. The `rollup` submodule is on Rollup 4, whose tests expect the old behavior (the `assert` keyword by default, a warning for conflicting attributes), and the suite runs without `experimental.importAttributes`. So the Rollup 5 versions are ported instead. - 17 Rollup 5 tests are ported to `packages/rolldown/tests/fixtures/topics/import-attributes/rollup-5/`, with the option on. The folders mirror Rollup's `test/function/samples` and `test/form/samples`. The folder should be deleted once the submodule moves to Rollup 5. - Form tests check the lines with attributes instead of the whole output. - A few parts differ from Rollup 5, each with a comment: Rolldown sorts attribute keys in the output, warns about the `assert` keyword, gives `type: 'json'` its built-in meaning, and only supports `this.load` while modules are loading. - In `packages/rollup-tests`, the Rollup 4 originals of the ported tests are listed in `ignored-tests.js`. The rest are grouped in `ignored-by-unsupported-features.md` by the feature they really miss, such as `output.importAttributesKey` or `resolveDynamicImport` with a non-string specifier. Three stale test names are dropped. Parts of Rollup 5 tests that need an API Rolldown does not have yet are left out: - `ModuleInfo.rawId` and `ModuleInfo.attributes` - the 4th argument of the `external` function, and `{ attributes }` for the `output.globals` and `output.paths` functions - `this.getModuleInfo` and `this.emitFile` chunks with attributes - `attributes` of `resolveFileUrl`, and `resolveImportMeta` - the deprecated `importerAttributes` option of `this.resolve`
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PoC of the import attributes RFC behind
experimental.importAttributes. Refs #2758.