2
0
Эх сурвалжийг харах

Build: transform private class properties in the build script (#22441)

* Build: transform private class properties in esmodule build

* Build: add further private property transform
Marco Fugaro 3 жил өмнө
parent
commit
f69814c15a

+ 30 - 0
utils/build/rollup.config.js

@@ -277,6 +277,35 @@ ${ code }`;
 
 
 }
 }
 
 
+// Transform #properties to _properties until they're supported in bundlers
+function privateProperties() {
+
+	return {
+
+		transform( code, id ) {
+
+			if ( /\.glsl.js$/.test( id ) === true ) return;
+
+			// replace `#property =` with `_property =`
+			code = code.replace( /#(\w+) =/g, ( match, p1 ) => `_${p1} =` );
+
+			// replace `#property;` with `_property;`
+			code = code.replace( /#(\w+);/g, ( match, p1 ) => `_${p1};` );
+
+			// replace `this.#property` with `this._property`
+			code = code.replace( /this\.#(\w+)/g, ( match, p1 ) => `this._${p1}` );
+
+			return {
+				code: code,
+				map: null
+			};
+
+		}
+
+	};
+
+}
+
 export default [
 export default [
 	{
 	{
 		input: 'src/Three.js',
 		input: 'src/Three.js',
@@ -284,6 +313,7 @@ export default [
 			addons(),
 			addons(),
 			glconstants(),
 			glconstants(),
 			glsl(),
 			glsl(),
+			privateProperties(),
 			header()
 			header()
 		],
 		],
 		output: [
 		output: [