@@ -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' ,
7
+ 'PI' ,
8
+ 'SQRT2' ,
9
+ 'SQRT1_2' ,
10
+ 'LN2' ,
11
+ 'LN10' ,
12
+ 'LOG2E' ,
13
+ 'LOG10E' ,
14
+ ] ;
15
+
16
+ const mathFunctions = [
17
+ 'abs' ,
18
+ 'acos' ,
19
+ 'acosh' ,
20
+ 'asin' ,
21
+ 'asinh' ,
22
+ 'atan' ,
23
+ 'atan2' ,
24
+ 'atanh' ,
25
+ 'cbrt' ,
26
+ 'ceil' ,
27
+ 'clz32' ,
28
+ 'cos' ,
29
+ 'cosh' ,
30
+ 'expm1' ,
31
+ 'exp' ,
32
+ 'floor' ,
33
+ 'fround' ,
34
+ 'imul' ,
35
+ 'log' ,
36
+ 'log2' ,
37
+ 'log10' ,
38
+ 'log1p' ,
39
+ 'max' ,
40
+ 'min' ,
41
+ 'pow' ,
42
+ 'random' ,
43
+ 'round' ,
44
+ 'sign' ,
45
+ 'sin' ,
46
+ 'sinh' ,
47
+ 'sqrt' ,
48
+ 'tan' ,
49
+ 'tanh' ,
50
+ 'trunc' ,
51
+ ] ;
52
+
53
+ const allowedExpressions = [
54
+ 'value' ,
55
+ 'value[]' ,
56
+ 'value[][]' ,
57
+ 'value[][][]' ,
58
+ 'value[][][][]' ,
59
+ 'value.value' ,
60
+ 'value.thread.value' ,
61
+ 'this.thread.value' ,
62
+ 'this.output.value' ,
63
+ 'this.constants.value' ,
64
+ 'this.constants.value[]' ,
65
+ 'this.constants.value[][]' ,
66
+ 'this.constants.value[][][]' ,
67
+ 'this.constants.value[][][][]' ,
68
+ 'fn()[]' ,
69
+ 'fn()[][]' ,
70
+ 'fn()[][][]' ,
71
+ '[][]' ,
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 . includes ( 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 . includes ( 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 . includes ( signatureString ) ) {
868
871
return signatureString ;
869
872
}
870
873
return null ;
0 commit comments