@@ -44,6 +44,8 @@ import {
44
44
isVariableDeclaration
45
45
} from "./packages/babel-types" ;
46
46
47
+ import { defineFunctionLength , defineFunctionName } from "./utils" ;
48
+
47
49
const visitors : EvaluateMap = {
48
50
File ( path ) {
49
51
evaluate ( path . createChild ( path . node . program ) ) ;
@@ -393,10 +395,8 @@ const visitors: EvaluateMap = {
393
395
func = visitors . FunctionExpression ( path . createChild ( node as any ) ) ;
394
396
}
395
397
396
- Object . defineProperties ( func , {
397
- length : { value : node . params . length || 0 } ,
398
- name : { value : functionName }
399
- } ) ;
398
+ defineFunctionLength ( func , node . params . length || 0 ) ;
399
+ defineFunctionName ( func , functionName ) ;
400
400
401
401
// Function can repeat declaration
402
402
scope . var ( functionName , func ) ;
@@ -855,10 +855,8 @@ const visitors: EvaluateMap = {
855
855
return result . value ;
856
856
}
857
857
} ;
858
- Object . defineProperties ( method , {
859
- length : { value : node . params . length } ,
860
- name : { value : methodName }
861
- } ) ;
858
+ defineFunctionLength ( method , node . params . length ) ;
859
+ defineFunctionName ( method , methodName ) ;
862
860
switch ( node . kind ) {
863
861
case "get" :
864
862
Object . defineProperty ( path . ctx . object , methodName , { get : method } ) ;
@@ -904,10 +902,8 @@ const visitors: EvaluateMap = {
904
902
}
905
903
} ;
906
904
907
- Object . defineProperties ( func , {
908
- length : { value : node . params . length } ,
909
- name : { value : node . id ? node . id . name : "" } // Anonymous function
910
- } ) ;
905
+ defineFunctionLength ( func , node . params . length ) ;
906
+ defineFunctionName ( func , node . id ? node . id . name : "" ) ; // Anonymous function
911
907
912
908
return func ;
913
909
} ,
@@ -1170,10 +1166,8 @@ const visitors: EvaluateMap = {
1170
1166
}
1171
1167
} ;
1172
1168
1173
- Object . defineProperties ( func , {
1174
- length : { value : node . params . length } ,
1175
- name : { value : node . id ? node . id . name : "" }
1176
- } ) ;
1169
+ defineFunctionLength ( func , node . params . length ) ;
1170
+ defineFunctionName ( func , node . id ? node . id . name : "" ) ;
1177
1171
1178
1172
return func ;
1179
1173
} ,
@@ -1266,11 +1260,12 @@ const visitors: EvaluateMap = {
1266
1260
return this ;
1267
1261
}
1268
1262
1269
- // define class name
1270
- Object . defineProperties ( ClassConstructor , {
1271
- name : { value : parentNode . id . name } ,
1272
- length : { value : constructor ? constructor . params . length : 0 }
1273
- } ) ;
1263
+ // define class name and length
1264
+ defineFunctionLength (
1265
+ ClassConstructor ,
1266
+ constructor ? constructor . params . length : 0
1267
+ ) ;
1268
+ defineFunctionName ( ClassConstructor , parentNode . id . name ) ;
1274
1269
1275
1270
const classMethods = methods
1276
1271
. map ( ( method : types . ClassMethod ) => {
@@ -1299,10 +1294,8 @@ const visitors: EvaluateMap = {
1299
1294
}
1300
1295
} ;
1301
1296
1302
- Object . defineProperties ( func , {
1303
- length : { value : method . params . length } ,
1304
- name : { value : method . id ? method . id . name : "" }
1305
- } ) ;
1297
+ defineFunctionLength ( func , method . params . length ) ;
1298
+ defineFunctionName ( func , method . id ? method . id . name : "" ) ;
1306
1299
1307
1300
return {
1308
1301
key : ( method . key as any ) . name ,
0 commit comments