@@ -2,6 +2,75 @@ const acorn = require('acorn');
22const { utils } = require ( '../utils' ) ;
33const { FunctionTracer } = require ( './function-tracer' ) ;
44
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+
574/**
675 *
776 * @desc Represents a single function, inside JS, webGL, or openGL.
@@ -592,61 +661,15 @@ class FunctionNode {
592661 }
593662
594663 isAstMathVariable ( ast ) {
595- const mathProperties = [
596- 'E' ,
597- 'PI' ,
598- 'SQRT2' ,
599- 'SQRT1_2' ,
600- 'LN2' ,
601- 'LN10' ,
602- 'LOG2E' ,
603- 'LOG10E' ,
604- ] ;
605664 return ast . type === 'MemberExpression' &&
606665 ast . object && ast . object . type === 'Identifier' &&
607666 ast . object . name === 'Math' &&
608667 ast . property &&
609668 ast . property . type === 'Identifier' &&
610- mathProperties . indexOf ( ast . property . name ) > - 1 ;
669+ mathProperties . includes ( ast . property . name ) ;
611670 }
612671
613672 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- ] ;
650673 return ast . type === 'CallExpression' &&
651674 ast . callee &&
652675 ast . callee . type === 'MemberExpression' &&
@@ -655,7 +678,7 @@ class FunctionNode {
655678 ast . callee . object . name === 'Math' &&
656679 ast . callee . property &&
657680 ast . callee . property . type === 'Identifier' &&
658- mathFunctions . indexOf ( ast . callee . property . name ) > - 1 ;
681+ mathFunctions . includes ( ast . callee . property . name ) ;
659682 }
660683
661684 isAstVariable ( ast ) {
@@ -844,27 +867,7 @@ class FunctionNode {
844867 return signatureString ;
845868 }
846869
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 ) ) {
868871 return signatureString ;
869872 }
870873 return null ;
0 commit comments