-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: TsImportType - support import attributes #9796
base: main
Are you sure you want to change the base?
feat: TsImportType - support import attributes #9796
Conversation
|
@@ -546,6 +546,8 @@ pub struct TsImportType { | |||
pub qualifier: Option<TsEntityName>, | |||
#[cfg_attr(feature = "serde-impl", serde(rename = "typeArguments"))] | |||
pub type_args: Option<Box<TsTypeParamInstantiation>>, | |||
#[cfg_attr(feature = "serde-impl", serde(default))] | |||
pub with: Option<Box<ObjectLit>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this name because this is the full { with: { "module-resolution": "import" } }
(which I need for dprint-plugin-typescript). Maybe something else would be better here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll wait to update the failing tests until getting feedback on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So annotation
? I think we may need to use separate type for this kind of annotations. How do you think? cc @swc-project/core-es
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is with
hardcoded?
I hope there is no situation like { with: { "foo": "bar" }, other: "value" }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html
The expected type of that second argument is defined by a type called
ImportCallOptions
, which by default just expects a property calledwith
.
And typescript playground throws Object literal may only specify known properties, and 'xxx' does not exist in type 'ImportCallOptions'.
So I think some names related to ImportCallOptions
or just attributes
are ok as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a breaking change anyway if there's a situation like { with: { "foo": "bar" }, other: "value" }
, and I like the idea of
ImportCallOptions or just attributes
@@ -316,6 +316,18 @@ impl<I: Tokens> Parser<I> { | |||
} | |||
}; | |||
|
|||
// the "assert" keyword is deprecated and this syntax is niche, so | |||
// don't support it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should support the "assert" keyword for these reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was difficult to figure out how to run (cargo run --package generate-code -- --input-dir crates/swc_ecma_ast --output crates/swc_ecma_visit/src/generated.rs
). It might be good to add instructions somewhere.
Also, running that command generates a bunch of other things that I reverted because they were unrelated to this PR. I think maybe this file is out of date on main. It might be good to add some CI verification to ensure it stays up to date.
CodSpeed Performance ReportMerging #9796 will improve performances by 3.81%Comparing Summary
Benchmarks breakdown
|
Description:
This parses, emits, and visits import attributes in TsImportType.
BREAKING CHANGE:
Adds an additional property to
TsImportType
Related issue (if exists): #9377