File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { namedTypes as n } from 'ast-types' ;
2+ import { NodePath } from 'ast-types/lib/node-path' ;
3+
4+ const IgnoreRules = ( path : NodePath < n . Expression > ) => {
5+ return {
6+ check : n . ObjectExpression . check ( path . node ) ,
7+ shouldSkip : ( ) => {
8+ if (
9+ n . VariableDeclarator . check ( path . parentPath . node ) &&
10+ n . VariableDeclaration . check ( path . parentPath . parentPath . node ) &&
11+ n . Program . check ( path . parentPath . parentPath . parentPath . parentPath . node )
12+ ) {
13+ return true ;
14+ }
15+ return false ;
16+ } ,
17+ } ;
18+ } ;
19+
20+ export default IgnoreRules ;
Original file line number Diff line number Diff line change 99import { builders as b , namedTypes as n } from 'ast-types' ;
1010import type { NodePath } from 'ast-types/lib/node-path' ;
1111import type { Transformer } from '../transform' ;
12+ import IgnoreRules from '../transform-ignore' ;
1213
1314// Walk up the AST and work out where the parent arrow function should go
1415const ensureParentArrow = ( path : NodePath < n . MemberExpression > ) => {
@@ -80,15 +81,9 @@ const isOpenFunction = (path: NodePath) => {
8081
8182function visitor ( path : NodePath < n . MemberExpression > ) {
8283 // if it was called for an ObjectExpression
83- if ( n . ObjectExpression . check ( path . node ) ) {
84- if (
85- n . VariableDeclarator . check ( path . parentPath . node ) &&
86- n . VariableDeclaration . check ( path . parentPath . parentPath . node ) &&
87- n . Program . check ( path . parentPath . parentPath . parentPath . parentPath . node )
88- ) {
89- return true ;
90- }
91- return false ;
84+ const ignoreRule = IgnoreRules ( path ) ;
85+ if ( ignoreRule . check ) {
86+ return ignoreRule . shouldSkip ( ) ;
9287 }
9388 let first = path . node . object ;
9489 while ( first . hasOwnProperty ( 'object' ) ) {
Original file line number Diff line number Diff line change 11import { namedTypes as n , builders as b } from 'ast-types' ;
22
33import type { NodePath } from 'ast-types/lib/node-path' ;
4+ import IgnoreRules from '../transform-ignore' ;
45
56const NO_DEFER_DECLARATION_ERROR = 'No defer declaration found' ;
67
@@ -146,6 +147,10 @@ const isTopScope = (path: NodePath<any>) => {
146147} ;
147148
148149const visitor = ( path : NodePath < n . CallExpression > ) => {
150+ const ignoreRule = IgnoreRules ( path ) ;
151+ if ( ignoreRule . check ) {
152+ return ignoreRule . shouldSkip ( ) ;
153+ }
149154 let root : NodePath < any > = path ;
150155 while ( ! n . Program . check ( root . node ) ) {
151156 root = root . parent ;
@@ -166,7 +171,7 @@ const visitor = (path: NodePath<n.CallExpression>) => {
166171
167172export default {
168173 id : 'promises' ,
169- types : [ 'CallExpression' ] ,
174+ types : [ 'CallExpression' , 'ObjectExpression' ] ,
170175 visitor,
171176 // this should run before top-level operations are moved into the exports array
172177 order : 0 ,
You can’t perform that action at this time.
0 commit comments