File tree Expand file tree Collapse file tree 3 files changed +37
-9
lines changed
Expand file tree Collapse file tree 3 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -94,15 +94,9 @@ export function extractCurrentScope(
9494 if ( currentPath . node . type === 'BlockStatement' ) {
9595 scopes . push ( '{}' )
9696 }
97- if (
98- [ 'FunctionDeclaration' , 'FunctionExpression' , 'ArrowFunctionExpression' ] . includes (
99- currentPath . node . type
100- )
101- ) {
97+ if ( [ 'FunctionDeclaration' , 'FunctionExpression' ] . includes ( currentPath . node . type ) ) {
10298 let scopeName : string
103- if ( currentPath . node . type === 'ArrowFunctionExpression' ) {
104- scopeName = extractFunctionName ( currentPath . parent as VariableDeclarator | ObjectProperty )
105- } else if ( currentPath . node . type === 'FunctionExpression' ) {
99+ if ( currentPath . node . type === 'FunctionExpression' ) {
106100 if ( currentPath . node . id ?. type === 'Identifier' ) {
107101 scopeName = extractFunctionName ( currentPath . node as FunctionExpression )
108102 } else {
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ describe('extractCurrentScope', () => {
131131 foo()
132132 }
133133 ` ,
134- scopes : [ 'arrowFuncScope' , ' {}']
134+ scopes : [ '{}' ]
135135 } ,
136136 {
137137 name : 'function expression scope' ,
Original file line number Diff line number Diff line change 1+ import { flytrapTransformArtifacts } from '../src/transform/index'
2+ import { describe , it } from 'vitest'
3+ import { extractArtifacts } from '../src/transform/artifacts/artifacts'
4+
5+ describe ( 'Regression' , ( ) => {
6+ it ( 'regression #1 > generates correct artifacts that match the transformed code' , async ( ) => {
7+ const fixture = `
8+ export const useRequestAccess = create((set) => ({
9+ setOpen: (open: boolean) => set((state) => ({ open }))
10+ }))
11+ `
12+
13+ const transformedCode = await flytrapTransformArtifacts ( fixture , '/stores.ts' ) . code
14+ const artifacts = extractArtifacts ( fixture , '/stores.ts' )
15+
16+ const functionOrCallIds = artifacts . map ( ( a ) => a . functionOrCallId )
17+ const missingIds = new Set < string > ( [ ] )
18+ for ( let i = 0 ; i < functionOrCallIds . length ; i ++ ) {
19+ if ( ! transformedCode . includes ( functionOrCallIds [ i ] ) ) {
20+ missingIds . add ( functionOrCallIds [ i ] )
21+ }
22+ }
23+
24+ if ( missingIds . size > 0 ) {
25+ throw new Error (
26+ `Transformed code is missing ${ missingIds . size } IDs. Following are missing: ${ new Array (
27+ ...missingIds
28+ )
29+ . map ( ( m ) => `"${ m } "` )
30+ . join ( ', ' ) } `
31+ )
32+ }
33+ } )
34+ } )
You can’t perform that action at this time.
0 commit comments