From 0601271b2c80a013bb0a82f465dc34cf5da7a875 Mon Sep 17 00:00:00 2001 From: tomoya yanagibashi <40194351+tbashiyy@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:28:48 +0900 Subject: [PATCH] fix(ast): Fix `StaticMemberExpression.get_first_object` (#6969) I think `get_first_object` does not return expected expression. For example, in case of `foo.bar.a`, it doesn't return `foo` but `foo.bar`. **Expected** ``` { "type": "Identifier", "start": 0, "end": 3, "name": "foo" } ``` **Actual** ``` { "type":"StaticMemberExpression", "start":0, "end":7, "object":{ "type":"Identifier", "start":0, "end":3, "name":"foo" }, "property":{ "type":"Identifier", "start":4, "end":7, "name":"bar" }, "optional":false } ``` --------- Co-authored-by: Dunqing --- crates/oxc_ast/src/ast_impl/js.rs | 8 +------- tasks/coverage/snapshots/transpile.snap | 18 ------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 29162b410..ad39dd06c 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -513,13 +513,7 @@ impl<'a> StaticMemberExpression<'a> { #[allow(missing_docs)] pub fn get_first_object(&self) -> &Expression<'a> { match &self.object { - Expression::StaticMemberExpression(member) => { - if let Expression::StaticMemberExpression(expr) = &member.object { - expr.get_first_object() - } else { - &self.object - } - } + Expression::StaticMemberExpression(member) => member.get_first_object(), Expression::ChainExpression(chain) => { if let ChainElement::StaticMemberExpression(expr) = &chain.expression { expr.get_first_object() diff --git a/tasks/coverage/snapshots/transpile.snap b/tasks/coverage/snapshots/transpile.snap index 07e29689e..323ed8b75 100644 --- a/tasks/coverage/snapshots/transpile.snap +++ b/tasks/coverage/snapshots/transpile.snap @@ -114,15 +114,6 @@ export {}; 3 | } `---- - x TS9014: Computed properties must be number or string literals, variables - | or dotted expressions with --isolatedDeclarations. - ,-[declarationComputedPropertyNames.d.ts:12:6] - 11 | [Symbol.iterator]: number, - 12 | [globalThis.Symbol.toStringTag]: number, - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 | [(globalThis.Symbol).unscopables]: number, - `---- - x TS9014: Computed properties must be number or string literals, variables | or dotted expressions with --isolatedDeclarations. ,-[declarationComputedPropertyNames.d.ts:13:6] @@ -150,15 +141,6 @@ export {}; 19 | }; `---- - x TS9014: Computed properties must be number or string literals, variables - | or dotted expressions with --isolatedDeclarations. - ,-[declarationComputedPropertyNames.d.ts:26:6] - 25 | [Symbol.iterator]: number, - 26 | [globalThis.Symbol.toStringTag]: number, - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 27 | [(globalThis.Symbol).unscopables]: number, - `---- - x TS9014: Computed properties must be number or string literals, variables | or dotted expressions with --isolatedDeclarations. ,-[declarationComputedPropertyNames.d.ts:27:6]