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: satisfies expressions are parsed as TsSatisfiesExpression #6354

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Expand Up @@ -717,6 +717,7 @@ jobs:
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update
kdy1 marked this conversation as resolved.
Show resolved Hide resolved

- name: Cache
uses: actions/cache@v3
Expand Down Expand Up @@ -777,6 +778,7 @@ jobs:
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update

- name: Prepare
run: |
Expand Down
8 changes: 4 additions & 4 deletions crates/swc_ecma_ast/src/expr.rs
Expand Up @@ -22,7 +22,7 @@ use crate::{
prop::Prop,
stmt::BlockStmt,
typescript::{
TsAsExpr, TsConstAssertion, TsInstantiation, TsNonNullExpr, TsSatisfactionExpr, TsTypeAnn,
TsAsExpr, TsConstAssertion, TsInstantiation, TsNonNullExpr, TsSatisfiesExpr, TsTypeAnn,
TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation,
},
ComputedPropName, Id, Invalid,
Expand Down Expand Up @@ -157,8 +157,8 @@ pub enum Expr {
#[tag("TsInstantiation")]
TsInstantiation(TsInstantiation),

#[tag("TsSatisfactionExpr")]
TsSatisfaction(TsSatisfactionExpr),
#[tag("TsSatisfiesExpression")]
TsSatisfies(TsSatisfiesExpr),
Copy link
Contributor

Choose a reason for hiding this comment

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

I will no longer have Benny Benassi stuck in my head while working with this. Thank you!


#[tag("PrivateName")]
PrivateName(PrivateName),
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Clone for Expr {
PrivateName(e) => PrivateName(e.clone()),
OptChain(e) => OptChain(e.clone()),
Invalid(e) => Invalid(e.clone()),
TsSatisfaction(e) => TsSatisfaction(e.clone()),
TsSatisfies(e) => TsSatisfies(e.clone()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_ast/src/lib.rs
Expand Up @@ -68,7 +68,7 @@ pub use self::{
TsKeywordType, TsKeywordTypeKind, TsLit, TsLitType, TsMappedType, TsMethodSignature,
TsModuleBlock, TsModuleDecl, TsModuleName, TsModuleRef, TsNamespaceBody, TsNamespaceDecl,
TsNamespaceExportDecl, TsNonNullExpr, TsOptionalType, TsParamProp, TsParamPropParam,
TsParenthesizedType, TsPropertySignature, TsQualifiedName, TsRestType, TsSatisfactionExpr,
TsParenthesizedType, TsPropertySignature, TsQualifiedName, TsRestType, TsSatisfiesExpr,
TsSetterSignature, TsThisType, TsThisTypeOrIdent, TsTplLitType, TsTupleElement,
TsTupleType, TsType, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeElement, TsTypeLit,
TsTypeOperator, TsTypeOperatorOp, TsTypeParam, TsTypeParamDecl, TsTypeParamInstantiation,
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_ast/src/typescript.rs
Expand Up @@ -1055,10 +1055,10 @@ pub struct TsNonNullExpr {
pub expr: Box<Expr>,
}

#[ast_node("TsSatisfactionExpr")]
#[ast_node("TsSatisfiesExpression")]
#[derive(Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TsSatisfactionExpr {
pub struct TsSatisfiesExpr {
pub span: Span,
#[serde(rename = "expression")]
pub expr: Box<Expr>,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Expand Up @@ -794,7 +794,7 @@ where
Expr::TsInstantiation(ref n) => emit!(n),
Expr::OptChain(ref n) => emit!(n),
Expr::Invalid(ref n) => emit!(n),
Expr::TsSatisfaction(n) => {
Expr::TsSatisfies(n) => {
emit!(n)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/typescript.rs
Expand Up @@ -40,7 +40,7 @@ where
}

#[emitter]
fn emit_ts_satisfaction_expr(&mut self, n: &TsSatisfactionExpr) -> Result {
fn emit_ts_satisfies_expr(&mut self, n: &TsSatisfiesExpr) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

emit!(n.expr);
Expand Down
4 changes: 1 addition & 3 deletions crates/swc_ecma_codegen/src/util.rs
Expand Up @@ -142,9 +142,7 @@ impl StartsWithAlphaNum for Expr {
| Expr::TsAs(TsAsExpr { ref expr, .. })
| Expr::TsConstAssertion(TsConstAssertion { ref expr, .. })
| Expr::TsInstantiation(TsInstantiation { ref expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { ref expr, .. }) => {
expr.starts_with_alpha_num()
}
| Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => expr.starts_with_alpha_num(),

Expr::OptChain(OptChainExpr {
base: OptChainBase::Member(MemberExpr { obj: expr, .. }),
Expand Down
Expand Up @@ -1451,7 +1451,7 @@ where
| Expr::TsNonNull(_)
| Expr::TsAs(_)
| Expr::TsInstantiation(_)
| Expr::TsSatisfaction(_) => false,
| Expr::TsSatisfies(_) => false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/util/size.rs
Expand Up @@ -198,7 +198,7 @@ impl SizeWithCtxt for Expr {
Expr::TsNonNull(_) => TODO,
Expr::TsAs(_) => TODO,
Expr::TsInstantiation(_) => TODO,
Expr::TsSatisfaction(_) => TODO,
Expr::TsSatisfies(_) => TODO,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/parser/expr/ops.rs
Expand Up @@ -122,7 +122,7 @@ impl<I: Tokens> Parser<I> {
let expr = left;
let node = {
let type_ann = self.next_then_parse_ts_type()?;
Box::new(Expr::TsAs(TsAsExpr {
Box::new(Expr::TsSatisfies(TsSatisfiesExpr {
span: span!(self, start),
expr,
type_ann,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/parser/util.rs
Expand Up @@ -315,7 +315,7 @@ pub(super) trait ExprExt {
| Expr::TsTypeAssertion(TsTypeAssertion { ref expr, .. })
| Expr::TsAs(TsAsExpr { ref expr, .. })
| Expr::TsInstantiation(TsInstantiation { ref expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { ref expr, .. }) => {
| Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => {
expr.is_valid_simple_assignment_target(strict)
}

Expand Down
16 changes: 8 additions & 8 deletions crates/swc_ecma_parser/tests/tsc/typeSatisfaction.json
Expand Up @@ -290,7 +290,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 110,
"end": 131,
Expand Down Expand Up @@ -382,7 +382,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 150,
"end": 177,
Expand Down Expand Up @@ -497,7 +497,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 199,
"end": 215,
Expand Down Expand Up @@ -591,7 +591,7 @@
}
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 242,
"end": 265,
Expand Down Expand Up @@ -683,7 +683,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 284,
"end": 318,
Expand Down Expand Up @@ -827,7 +827,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 338,
"end": 371,
Expand Down Expand Up @@ -1021,7 +1021,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 413,
"end": 438,
Expand Down Expand Up @@ -1113,7 +1113,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 449,
"end": 485,
Expand Down
Expand Up @@ -167,7 +167,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 71,
"end": 153,
Expand Down
Expand Up @@ -133,7 +133,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 68,
"end": 198,
Expand Down
Expand Up @@ -35,7 +35,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 71,
"end": 92,
Expand Down
Expand Up @@ -147,7 +147,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 103,
"end": 139,
Expand Down
Expand Up @@ -137,7 +137,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 47,
"end": 163,
Expand Down
Expand Up @@ -137,7 +137,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 47,
"end": 154,
Expand Down
Expand Up @@ -681,7 +681,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 476,
"end": 523,
Expand Down
Expand Up @@ -681,7 +681,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 457,
"end": 504,
Expand Down
Expand Up @@ -203,7 +203,7 @@
"typeAnnotation": null
},
"init": {
"type": "TsAsExpression",
"type": "TsSatisfiesExpression",
"span": {
"start": 150,
"end": 323,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_quote_macros/src/ast/expr.rs
Expand Up @@ -38,7 +38,7 @@ impl_enum!(
TsNonNull,
TsAs,
TsInstantiation,
TsSatisfaction,
TsSatisfies,
PrivateName,
OptChain,
Invalid
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_quote_macros/src/ast/typescript.rs
Expand Up @@ -19,4 +19,4 @@ fail_todo!(TsTypeParamDecl);
fail_todo!(TsExprWithTypeArgs);
fail_todo!(TsIndexSignature);
fail_todo!(TsParamProp);
fail_todo!(TsSatisfactionExpr);
fail_todo!(TsSatisfiesExpr);
Expand Up @@ -1210,7 +1210,7 @@ fn can_be_null(e: &Expr) -> bool {
| Expr::TsTypeAssertion(TsTypeAssertion { ref expr, .. })
| Expr::TsConstAssertion(TsConstAssertion { ref expr, .. })
| Expr::TsInstantiation(TsInstantiation { ref expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { ref expr, .. }) => can_be_null(expr),
| Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => can_be_null(expr),

Expr::Invalid(..) => unreachable!(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_typescript/src/strip.rs
Expand Up @@ -437,7 +437,7 @@ where
| Expr::TsTypeAssertion(TsTypeAssertion { expr, .. })
| Expr::TsConstAssertion(TsConstAssertion { expr, .. })
| Expr::TsInstantiation(TsInstantiation { expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { expr, .. }) => {
| Expr::TsSatisfies(TsSatisfiesExpr { expr, .. }) => {
expr.visit_mut_with(self);
let expr = *expr.take();
*n = expr;
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_utils/src/lib.rs
Expand Up @@ -1489,7 +1489,7 @@ pub trait ExprExt {
| Expr::TsNonNull(TsNonNullExpr { ref expr, .. })
| Expr::TsTypeAssertion(TsTypeAssertion { ref expr, .. })
| Expr::TsInstantiation(TsInstantiation { ref expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { ref expr, .. }) => {
| Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => {
expr.may_have_side_effects(ctx)
}

Expand Down Expand Up @@ -2454,7 +2454,7 @@ impl ExprCtx {
| Expr::TsAs(TsAsExpr { expr, .. })
| Expr::TsConstAssertion(TsConstAssertion { expr, .. })
| Expr::TsInstantiation(TsInstantiation { expr, .. })
| Expr::TsSatisfaction(TsSatisfactionExpr { expr, .. }) => {
| Expr::TsSatisfies(TsSatisfiesExpr { expr, .. }) => {
self.extract_side_effects_to(to, *expr)
}
Expr::OptChain(OptChainExpr { base: child, .. }) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_visit/src/lib.rs
Expand Up @@ -660,7 +660,7 @@ define!({
TsConstAssertion(TsConstAssertion),
TsNonNull(TsNonNullExpr),
TsAs(TsAsExpr),
TsSatisfaction(TsSatisfactionExpr),
TsSatisfies(TsSatisfiesExpr),
TsInstantiation(TsInstantiation),
PrivateName(PrivateName),
OptChain(OptChainExpr),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_estree_compat/src/babelify/expr.rs
Expand Up @@ -157,7 +157,7 @@ impl Babelify for Expr {
"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
&self
),
Expr::TsSatisfaction(_) => panic!(
Expr::TsSatisfies(_) => panic!(
"illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
&self
),
Expand Down
4 changes: 2 additions & 2 deletions node-swc/__tests__/transform/issue_4730_test.mjs
Expand Up @@ -37,9 +37,9 @@ Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
const _interopRequireWildcard = require(\\"@swc/helpers/lib/_interop_require_wildcard.js\\").default;
const _b = require(\\"../packages/b/src/index\\");
const _b = require(\\"../packages/b/src/index.ts\\");
async function display() {
const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require(\\"../packages/a/src/index\\"))).then((c)=>c.displayA);
const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require(\\"../packages/a/src/index.ts\\"))).then((c)=>c.displayA);
Comment on lines +40 to +42
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After applying patch dependencies correctly, this test failed. I seem #6339 causes this issue. Therefore, I updated snapshot.

console.log(displayA());
console.log((0, _b.displayB)());
}
Expand Down