-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Import Attributes (Stage 3) #53656
Comments
Given the Stage 3 -> 2 regression on the original proposal, we might hold off on this until it's more like Stage 3.5 |
Regarding the stability of the proposal, the reason we changed the proposal so much after Stage 3 was because we found problems integrating it with the web platform. We reached broad consensus on the current semantics, which mach what HTML folks needed from the proposal. You might have noticed that this "back to stage 2 and again to 3" dance has been very quick (3->2 in January, and 2->3 1 in March): it's because engines were very eager to ship this proposal, and we had to solve its problems very quickly. I would expect import attributes to be available in browsers very soon. There is only one part of the proposal around which there is uncertainty: what will happen to the
Footnotes
|
Given that import attributes actually do influence resolution, would we have to specify more semantics based on the |
Import attributes can influence module resolution, but the currently planned attributes (i.e., just However, if for example one day Node.js implements an attribute that does affect module resolution, I would expect TS's Additionally, the |
Although it could be useful to consider as a follow-up to have some support for declare module '*' with {type: 'x-url'} {
const url: string;
export default url;
} |
Is it required to continue to support the TypeScript/src/compiler/types.ts Line 3673 in ac55b29
TypeScript/src/compiler/types.ts Lines 3709 to 3714 in ac55b29
TypeScript/src/compiler/types.ts Line 2178 in ac55b29
Or can the export interface ImportDeclaration extends Statement {
...
readonly attributes?: NodeArray<ImportAttribute>;
// readonly attributes?: ImportAttributes; ?
} Could someone, please clarify if this change in terminology from assertions to attributes is correct or if I have misunderstood something? |
I think we could possibly mark |
(@rbuckton probably has opinions here though) |
We'd love to support using import attributes in Bun in both the bundler and the runtime for things like: // return a Uint8Array
import placeholderBytes from './placeholder.png' with {encoding: "binary"};
// return a data:image/png;base64, as a string
import placeholderUrl from './placeholder.png' with {encoding: "base64url"};
// note: no idea if "encoding" would be the attribute name used here nor what the specific values for these should be, just "some way for this to work" We have implemented parser support (through the transpiler, not in JSC) for the |
@nicolo-ribaudo can we get a clarification on the official status of the proposal? I noticed tc39/proposal-import-attributes#137 is closed with all boxes checked, but tc39/ecma262#3057 is still getting review activity. |
Remaining review items are just editorials about spec wording, the semantics are settled :) (unless there is significant implementation feedback, like for any stage 3 proposal) |
Are those review items pending stage 3, or is the proposal officially stage 3 and those review items are pending stage 4 / acceptance into the final spec? |
Officially stage 3, the editors approved the current proposal spec |
We can probably just mark it as deprecated and set it for both properties until some future time where we remove it in a major release. If we want to remove it sooner we could use |
@DanielRosenwasser @rbuckton Does that mean the implementation for |
Are you talking about the runtime implementation, or the TypeScript compiler implementation? Until everyone has moved off of |
Suggestion
π Search Terms
import attributes, import assertions, esnext
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
https://github.com/tc39/proposal-import-attributes
In January 2023, Import Assertions proposal was demoted back to Stage 2 to investigate a solution for the web platform's needs. In March 2023, the proposal was renamed to Import Attributes and moved back to Stage 3 (with conditional consensus - pending spec text review).
TypeScript should support the new syntax. The most relevant change for TypeScript is that the keyword changed from
assert
towith
.The minimal option here is just to add the
with
syntax. Ideally there would also be two enhancements:assert
: For compatibility with existing implementations, theassert
keyword is still allowed by the spec until it's safe to remove it. Chrome will explore removing it. Babel is deprecating the syntax with a plan to eventually remove it in Babel 8. TypeScript could follow something similar to the 5-release deprecation process by initially suggesting migration via warnings and quick fixes - though we recognise that the deprecation process was originally intended only for flags.import()
right now. This could be expanded to also work for attributes in static declarations.π Motivating Example
This will be new ECMAScript syntax so motivation is to be compatible with the language. The champion group considers this to be stable, even though it just changed: this is what re-promoting to Stage 3 represents.
It sounds like this would also unblock #49055 (comment).
π» Use Cases
https://github.com/tc39/proposal-import-attributes#motivation
In addition, we have an internal use case in Bloomberg to use Import Attributes as an annotation to achieve lazy-loading by deferring module evaluation. This is an early implementation of the TC39 proposal for Deferring Module Evaluation.
This issue is raised only for awareness. At this point we are not planning to implement.
The text was updated successfully, but these errors were encountered: