diff --git a/src/domain/javascript/javascriptAstValues.test.ts b/src/domain/javascript/javascriptAstValues.test.ts index 43e7400f8af..9e8a30680c5 100644 --- a/src/domain/javascript/javascriptAstValues.test.ts +++ b/src/domain/javascript/javascriptAstValues.test.ts @@ -13,6 +13,13 @@ import { unwrapPureJavaScriptSequenceExpression, } from "./javascriptAstValues.js"; +const emptyObjectMethod = ( + kind: "method" | "get", + name: string, + computed = false, +) => + t.objectMethod(kind, t.identifier(name), [], t.blockStatement([]), computed); + it("keeps string spread indices separate from named descriptor fields", () => { for (const text of ["", "x", "😀", "x".repeat(1_000_000)]) { const original = t.objectProperty( @@ -97,20 +104,7 @@ it("keeps literal array indices, holes and unknown iterable suffixes separate fr }); it("preserves ordinary method data values without executing getter effects", () => { - const method = (name: string, computed = false) => - t.objectMethod( - "method", - t.identifier(name), - [], - t.blockStatement([]), - computed, - ); - const getter = t.objectMethod( - "get", - t.identifier("helper"), - [], - t.blockStatement([]), - ); + const getter = emptyObjectMethod("get", "helper"); const setter = t.objectMethod( "set", t.identifier("helper"), @@ -118,11 +112,11 @@ it("preserves ordinary method data values without executing getter effects", () t.blockStatement([]), ); for (const [member, status] of [ - [method("helper"), "explicit"], + [emptyObjectMethod("method", "helper"), "explicit"], [setter, "explicit"], - [method("stdio"), "explicit"], + [emptyObjectMethod("method", "stdio"), "explicit"], [getter, "dynamic"], - [method("key", true), "dynamic"], + [emptyObjectMethod("method", "key", true), "dynamic"], ] as const) { const object = t.objectExpression([ t.objectProperty(t.identifier("stdio"), t.stringLiteral("inherit")), @@ -199,12 +193,7 @@ it("leaves only the keys a conditional literal spread can copy unresolved", () = property: preload, value: preload.value, }); - const method = t.objectMethod( - "method", - t.identifier("run"), - [], - t.blockStatement([]), - ); + const method = emptyObjectMethod("method", "run"); const branch = (name: string) => t.spreadElement( t.logicalExpression( @@ -247,9 +236,7 @@ it("keeps fallback and unresolved conditional spreads unknown", () => { t.logicalExpression( "&&", comparison, - t.objectExpression([ - t.objectMethod("get", t.identifier("frame"), [], t.blockStatement([])), - ]), + t.objectExpression([emptyObjectMethod("get", "frame")]), ), t.logicalExpression( "&&", @@ -381,16 +368,7 @@ it("keeps key enumeration unknown when object membership is unresolved", () => { t.objectProperty(t.identifier("direct"), t.objectExpression([])), ]), t.objectExpression([ - t.spreadElement( - t.objectExpression([ - t.objectMethod( - "get", - t.identifier("query"), - [], - t.blockStatement([]), - ), - ]), - ), + t.spreadElement(t.objectExpression([emptyObjectMethod("get", "query")])), ]), ]; for (const object of cases) @@ -465,12 +443,7 @@ it("excludes prototype setters from own keys but preserves other __proto__ forms false, true, ), - t.objectMethod( - "method", - t.identifier("__proto__"), - [], - t.blockStatement([]), - ), + emptyObjectMethod("method", "__proto__"), ]; for (const member of ownForms) expect(staticObjectPropertyNames(t.objectExpression([member]))).toEqual({ @@ -559,18 +532,8 @@ it("shares static member paths and stops before unadmitted path expansion", () = }); it("retains exact ordinary method data nodes while keeping accessors unknown", () => { - const method = t.objectMethod( - "method", - t.identifier("value"), - [], - t.blockStatement([]), - ); - const getter = t.objectMethod( - "get", - t.identifier("value"), - [], - t.blockStatement([]), - ); + const method = emptyObjectMethod("method", "value"); + const getter = emptyObjectMethod("get", "value"); expect(staticObjectProperty(t.objectExpression([method]), "value")).toEqual({ status: "explicit", property: method,