@@ -2,6 +2,75 @@ const acorn = require('acorn');
2
2
const { utils } = require ( '../utils' ) ;
3
3
const { FunctionTracer } = require ( './function-tracer' ) ;
4
4
5
+ const mathProperties = {
6
+ 'E' : true ,
7
+ 'PI' : true ,
8
+ 'SQRT2' : true ,
9
+ 'SQRT1_2' : true ,
10
+ 'LN2' : true ,
11
+ 'LN10' : true ,
12
+ 'LOG2E' : true ,
13
+ 'LOG10E' : true ,
14
+ } ;
15
+
16
+ const mathFunctions = {
17
+ 'abs' : true ,
18
+ 'acos' : true ,
19
+ 'acosh' : true ,
20
+ 'asin' : true ,
21
+ 'asinh' : true ,
22
+ 'atan' : true ,
23
+ 'atan2' : true ,
24
+ 'atanh' : true ,
25
+ 'cbrt' : true ,
26
+ 'ceil' : true ,
27
+ 'clz32' : true ,
28
+ 'cos' : true ,
29
+ 'cosh' : true ,
30
+ 'expm1' : true ,
31
+ 'exp' : true ,
32
+ 'floor' : true ,
33
+ 'fround' : true ,
34
+ 'imul' : true ,
35
+ 'log' : true ,
36
+ 'log2' : true ,
37
+ 'log10' : true ,
38
+ 'log1p' : true ,
39
+ 'max' : true ,
40
+ 'min' : true ,
41
+ 'pow' : true ,
42
+ 'random' : true ,
43
+ 'round' : true ,
44
+ 'sign' : true ,
45
+ 'sin' : true ,
46
+ 'sinh' : true ,
47
+ 'sqrt' : true ,
48
+ 'tan' : true ,
49
+ 'tanh' : true ,
50
+ 'trunc' : true ,
51
+ } ;
52
+
53
+ const allowedExpressions = {
54
+ 'value' : true ,
55
+ 'value[]' : true ,
56
+ 'value[][]' : true ,
57
+ 'value[][][]' : true ,
58
+ 'value[][][][]' : true ,
59
+ 'value.value' : true ,
60
+ 'value.thread.value' : true ,
61
+ 'this.thread.value' : true ,
62
+ 'this.output.value' : true ,
63
+ 'this.constants.value' : true ,
64
+ 'this.constants.value[]' : true ,
65
+ 'this.constants.value[][]' : true ,
66
+ 'this.constants.value[][][]' : true ,
67
+ 'this.constants.value[][][][]' : true ,
68
+ 'fn()[]' : true ,
69
+ 'fn()[][]' : true ,
70
+ 'fn()[][][]' : true ,
71
+ '[][]' : true ,
72
+ } ;
73
+
5
74
/**
6
75
*
7
76
* @desc Represents a single function, inside JS, webGL, or openGL.
@@ -592,61 +661,15 @@ class FunctionNode {
592
661
}
593
662
594
663
isAstMathVariable ( ast ) {
595
- const mathProperties = [
596
- 'E' ,
597
- 'PI' ,
598
- 'SQRT2' ,
599
- 'SQRT1_2' ,
600
- 'LN2' ,
601
- 'LN10' ,
602
- 'LOG2E' ,
603
- 'LOG10E' ,
604
- ] ;
605
664
return ast . type === 'MemberExpression' &&
606
665
ast . object && ast . object . type === 'Identifier' &&
607
666
ast . object . name === 'Math' &&
608
667
ast . property &&
609
668
ast . property . type === 'Identifier' &&
610
- mathProperties . indexOf ( ast . property . name ) > - 1 ;
669
+ ! ! mathProperties [ ast . property . name ] ;
611
670
}
612
671
613
672
isAstMathFunction ( ast ) {
614
- const mathFunctions = [
615
- 'abs' ,
616
- 'acos' ,
617
- 'acosh' ,
618
- 'asin' ,
619
- 'asinh' ,
620
- 'atan' ,
621
- 'atan2' ,
622
- 'atanh' ,
623
- 'cbrt' ,
624
- 'ceil' ,
625
- 'clz32' ,
626
- 'cos' ,
627
- 'cosh' ,
628
- 'expm1' ,
629
- 'exp' ,
630
- 'floor' ,
631
- 'fround' ,
632
- 'imul' ,
633
- 'log' ,
634
- 'log2' ,
635
- 'log10' ,
636
- 'log1p' ,
637
- 'max' ,
638
- 'min' ,
639
- 'pow' ,
640
- 'random' ,
641
- 'round' ,
642
- 'sign' ,
643
- 'sin' ,
644
- 'sinh' ,
645
- 'sqrt' ,
646
- 'tan' ,
647
- 'tanh' ,
648
- 'trunc' ,
649
- ] ;
650
673
return ast . type === 'CallExpression' &&
651
674
ast . callee &&
652
675
ast . callee . type === 'MemberExpression' &&
@@ -655,7 +678,7 @@ class FunctionNode {
655
678
ast . callee . object . name === 'Math' &&
656
679
ast . callee . property &&
657
680
ast . callee . property . type === 'Identifier' &&
658
- mathFunctions . indexOf ( ast . callee . property . name ) > - 1 ;
681
+ ! ! mathFunctions [ ast . callee . property . name ] ;
659
682
}
660
683
661
684
isAstVariable ( ast ) {
@@ -844,27 +867,7 @@ class FunctionNode {
844
867
return signatureString ;
845
868
}
846
869
847
- const allowedExpressions = [
848
- 'value' ,
849
- 'value[]' ,
850
- 'value[][]' ,
851
- 'value[][][]' ,
852
- 'value[][][][]' ,
853
- 'value.value' ,
854
- 'value.thread.value' ,
855
- 'this.thread.value' ,
856
- 'this.output.value' ,
857
- 'this.constants.value' ,
858
- 'this.constants.value[]' ,
859
- 'this.constants.value[][]' ,
860
- 'this.constants.value[][][]' ,
861
- 'this.constants.value[][][][]' ,
862
- 'fn()[]' ,
863
- 'fn()[][]' ,
864
- 'fn()[][][]' ,
865
- '[][]' ,
866
- ] ;
867
- if ( allowedExpressions . indexOf ( signatureString ) > - 1 ) {
870
+ if ( ! ! allowedExpressions [ signatureString ] ) {
868
871
return signatureString ;
869
872
}
870
873
return null ;
0 commit comments