4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.6.4
8
- * @date Tue Jan 21 2020 08:05:29 GMT-0500 (Eastern Standard Time)
7
+ * @version 2.6.5
8
+ * @date Thu Jan 23 2020 07:17:48 GMT-0500 (Eastern Standard Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
@@ -6948,6 +6948,7 @@ module.exports = {
6948
6948
fragmentShader
6949
6949
} ;
6950
6950
} , { } ] , 37 :[ function ( require , module , exports ) {
6951
+ const { utils } = require ( '../../utils' ) ;
6951
6952
const { FunctionNode } = require ( '../function-node' ) ;
6952
6953
6953
6954
class WebGLFunctionNode extends FunctionNode {
@@ -7033,11 +7034,11 @@ class WebGLFunctionNode extends FunctionNode {
7033
7034
if ( ! type ) {
7034
7035
throw this . astErrorOutput ( 'Unexpected expression' , ast ) ;
7035
7036
}
7036
-
7037
+ const name = utils . sanitizeName ( argumentName ) ;
7037
7038
if ( type === 'sampler2D' || type === 'sampler2DArray' ) {
7038
- retArr . push ( `${ type } user_${ argumentName } ,ivec2 user_${ argumentName } Size,ivec3 user_${ argumentName } Dim` ) ;
7039
+ retArr . push ( `${ type } user_${ name } ,ivec2 user_${ name } Size,ivec3 user_${ name } Dim` ) ;
7039
7040
} else {
7040
- retArr . push ( `${ type } user_${ argumentName } ` ) ;
7041
+ retArr . push ( `${ type } user_${ name } ` ) ;
7041
7042
}
7042
7043
}
7043
7044
}
@@ -7479,16 +7480,17 @@ class WebGLFunctionNode extends FunctionNode {
7479
7480
7480
7481
const type = this . getType ( idtNode ) ;
7481
7482
7483
+ const name = utils . sanitizeName ( idtNode . name ) ;
7482
7484
if ( idtNode . name === 'Infinity' ) {
7483
7485
retArr . push ( '3.402823466e+38' ) ;
7484
7486
} else if ( type === 'Boolean' ) {
7485
- if ( this . argumentNames . indexOf ( idtNode . name ) > - 1 ) {
7486
- retArr . push ( `bool(user_${ idtNode . name } )` ) ;
7487
+ if ( this . argumentNames . indexOf ( name ) > - 1 ) {
7488
+ retArr . push ( `bool(user_${ name } )` ) ;
7487
7489
} else {
7488
- retArr . push ( `user_${ idtNode . name } ` ) ;
7490
+ retArr . push ( `user_${ name } ` ) ;
7489
7491
}
7490
7492
} else {
7491
- retArr . push ( `user_${ idtNode . name } ` ) ;
7493
+ retArr . push ( `user_${ name } ` ) ;
7492
7494
}
7493
7495
7494
7496
return retArr ;
@@ -7682,7 +7684,7 @@ class WebGLFunctionNode extends FunctionNode {
7682
7684
throw new Error ( 'Unhandled declaration' ) ;
7683
7685
}
7684
7686
lastType = type ;
7685
- declarationResult . push ( `user_${ declaration . id . name } =` ) ;
7687
+ declarationResult . push ( `user_${ utils . sanitizeName ( declaration . id . name ) } =` ) ;
7686
7688
declarationResult . push ( 'float(' ) ;
7687
7689
this . astGeneric ( init , declarationResult ) ;
7688
7690
declarationResult . push ( ')' ) ;
@@ -7696,7 +7698,7 @@ class WebGLFunctionNode extends FunctionNode {
7696
7698
declarationResult . push ( `${ markupType } ` ) ;
7697
7699
}
7698
7700
lastType = type ;
7699
- declarationResult . push ( `user_${ declaration . id . name } =` ) ;
7701
+ declarationResult . push ( `user_${ utils . sanitizeName ( declaration . id . name ) } =` ) ;
7700
7702
if ( actualType === 'Number' && type === 'Integer' ) {
7701
7703
if ( init . left && init . left . type === 'Literal' ) {
7702
7704
this . astGeneric ( init , declarationResult ) ;
@@ -7932,18 +7934,19 @@ class WebGLFunctionNode extends FunctionNode {
7932
7934
retArr . push ( Math [ name ] ) ;
7933
7935
return retArr ;
7934
7936
}
7937
+ const cleanName = utils . sanitizeName ( name ) ;
7935
7938
switch ( property ) {
7936
7939
case 'r' :
7937
- retArr . push ( `user_${ name } .r` ) ;
7940
+ retArr . push ( `user_${ cleanName } .r` ) ;
7938
7941
return retArr ;
7939
7942
case 'g' :
7940
- retArr . push ( `user_${ name } .g` ) ;
7943
+ retArr . push ( `user_${ cleanName } .g` ) ;
7941
7944
return retArr ;
7942
7945
case 'b' :
7943
- retArr . push ( `user_${ name } .b` ) ;
7946
+ retArr . push ( `user_${ cleanName } .b` ) ;
7944
7947
return retArr ;
7945
7948
case 'a' :
7946
- retArr . push ( `user_${ name } .a` ) ;
7949
+ retArr . push ( `user_${ cleanName } .a` ) ;
7947
7950
return retArr ;
7948
7951
}
7949
7952
break ;
@@ -8225,7 +8228,7 @@ class WebGLFunctionNode extends FunctionNode {
8225
8228
case 'Array(4)' :
8226
8229
if ( targetType === argumentType ) {
8227
8230
if ( argument . type === 'Identifier' ) {
8228
- retArr . push ( `user_${ argument . name } ` ) ;
8231
+ retArr . push ( `user_${ utils . sanitizeName ( argument . name ) } ` ) ;
8229
8232
} else if ( argument . type === 'ArrayExpression' || argument . type === 'MemberExpression' ) {
8230
8233
this . astGeneric ( argument , retArr ) ;
8231
8234
} else {
@@ -8247,7 +8250,8 @@ class WebGLFunctionNode extends FunctionNode {
8247
8250
if ( targetType === argumentType ) {
8248
8251
if ( argument . type !== 'Identifier' ) throw this . astErrorOutput ( `Unhandled argument type ${ argument . type } ` , ast ) ;
8249
8252
this . triggerImplyArgumentBitRatio ( this . name , argument . name , functionName , i ) ;
8250
- retArr . push ( `user_${ argument . name } ,user_${ argument . name } Size,user_${ argument . name } Dim` ) ;
8253
+ const name = utils . sanitizeName ( argument . name ) ;
8254
+ retArr . push ( `user_${ name } ,user_${ name } Size,user_${ name } Dim` ) ;
8251
8255
continue ;
8252
8256
}
8253
8257
break ;
@@ -8345,7 +8349,7 @@ const operatorMap = {
8345
8349
module . exports = {
8346
8350
WebGLFunctionNode
8347
8351
} ;
8348
- } , { "../function-node" :9 } ] , 38 :[ function ( require , module , exports ) {
8352
+ } , { "../../utils" : 113 , "../ function-node" :9 } ] , 38 :[ function ( require , module , exports ) {
8349
8353
const { WebGLKernelValueBoolean } = require ( './kernel-value/boolean' ) ;
8350
8354
const { WebGLKernelValueFloat } = require ( './kernel-value/float' ) ;
8351
8355
const { WebGLKernelValueInteger } = require ( './kernel-value/integer' ) ;
@@ -9967,7 +9971,7 @@ class WebGLKernel extends GLKernel {
9967
9971
9968
9972
for ( let index = 0 ; index < args . length ; index ++ ) {
9969
9973
const value = args [ index ] ;
9970
- const name = this . argumentNames [ index ] ;
9974
+ const name = utils . sanitizeName ( this . argumentNames [ index ] ) ;
9971
9975
let type ;
9972
9976
if ( needsArgumentTypes ) {
9973
9977
type = utils . getVariableType ( value , this . strictIntegers ) ;
@@ -10016,7 +10020,8 @@ class WebGLKernel extends GLKernel {
10016
10020
}
10017
10021
this . constantBitRatios = { } ;
10018
10022
let textureIndexes = 0 ;
10019
- for ( const name in this . constants ) {
10023
+ for ( const p in this . constants ) {
10024
+ const name = utils . sanitizeName ( p ) ;
10020
10025
const value = this . constants [ name ] ;
10021
10026
let type ;
10022
10027
if ( needsConstantTypes ) {
@@ -11463,6 +11468,7 @@ module.exports = {
11463
11468
fragmentShader
11464
11469
} ;
11465
11470
} , { } ] , 72 :[ function ( require , module , exports ) {
11471
+ const { utils } = require ( '../../utils' ) ;
11466
11472
const { WebGLFunctionNode } = require ( '../web-gl/function-node' ) ;
11467
11473
11468
11474
class WebGL2FunctionNode extends WebGLFunctionNode {
@@ -11477,16 +11483,17 @@ class WebGL2FunctionNode extends WebGLFunctionNode {
11477
11483
11478
11484
const type = this . getType ( idtNode ) ;
11479
11485
11486
+ const name = utils . sanitizeName ( idtNode . name ) ;
11480
11487
if ( idtNode . name === 'Infinity' ) {
11481
11488
retArr . push ( 'intBitsToFloat(2139095039)' ) ;
11482
11489
} else if ( type === 'Boolean' ) {
11483
- if ( this . argumentNames . indexOf ( idtNode . name ) > - 1 ) {
11484
- retArr . push ( `bool(user_${ idtNode . name } )` ) ;
11490
+ if ( this . argumentNames . indexOf ( name ) > - 1 ) {
11491
+ retArr . push ( `bool(user_${ name } )` ) ;
11485
11492
} else {
11486
- retArr . push ( `user_${ idtNode . name } ` ) ;
11493
+ retArr . push ( `user_${ name } ` ) ;
11487
11494
}
11488
11495
} else {
11489
- retArr . push ( `user_${ idtNode . name } ` ) ;
11496
+ retArr . push ( `user_${ name } ` ) ;
11490
11497
}
11491
11498
11492
11499
return retArr ;
@@ -11496,7 +11503,7 @@ class WebGL2FunctionNode extends WebGLFunctionNode {
11496
11503
module . exports = {
11497
11504
WebGL2FunctionNode
11498
11505
} ;
11499
- } , { "../web-gl/function-node" :37 } ] , 73 :[ function ( require , module , exports ) {
11506
+ } , { "../../utils" : 113 , "../ web-gl/function-node" :37 } ] , 73 :[ function ( require , module , exports ) {
11500
11507
const { WebGL2KernelValueBoolean } = require ( './kernel-value/boolean' ) ;
11501
11508
const { WebGL2KernelValueFloat } = require ( './kernel-value/float' ) ;
11502
11509
const { WebGL2KernelValueInteger } = require ( './kernel-value/integer' ) ;
@@ -14539,8 +14546,23 @@ const utils = {
14539
14546
throw new Error ( 'Unrecognized function type. Please use `() => yourFunctionVariableHere` or function() { return yourFunctionVariableHere; }' ) ;
14540
14547
}
14541
14548
} ,
14549
+ sanitizeName : function ( name ) {
14550
+ if ( dollarSign . test ( name ) ) {
14551
+ name = name . replace ( dollarSign , 'S_S' ) ;
14552
+ }
14553
+ if ( doubleUnderscore . test ( name ) ) {
14554
+ name = name . replace ( doubleUnderscore , 'U_U' ) ;
14555
+ } else if ( singleUnderscore . test ( name ) ) {
14556
+ name = name . replace ( singleUnderscore , 'u_u' ) ;
14557
+ }
14558
+ return name ;
14559
+ }
14542
14560
} ;
14543
14561
14562
+ const dollarSign = / \$ / ;
14563
+ const doubleUnderscore = / _ _ / ;
14564
+ const singleUnderscore = / _ / ;
14565
+
14544
14566
const _systemEndianness = utils . getSystemEndianness ( ) ;
14545
14567
14546
14568
module . exports = {
0 commit comments