From 895f754369726ed04c8be8f7c4269e8cb6ea145e Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Fri, 8 Nov 2024 16:15:10 +0100 Subject: [PATCH 1/4] Fix global declaration processing --- .../dev/buildTools/src/generateDeclaration.ts | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/dev/buildTools/src/generateDeclaration.ts b/packages/dev/buildTools/src/generateDeclaration.ts index 5fdeccdc1e6..2d95a15034f 100644 --- a/packages/dev/buildTools/src/generateDeclaration.ts +++ b/packages/dev/buildTools/src/generateDeclaration.ts @@ -418,14 +418,46 @@ function getPackageDeclaration( processedSource = processedSource.replace(/export const enum/g, "export enum"); - processedSource = processedSource.replace( - / global {([^}]*)}/gm, - ` + /* + deal with + global { + interface Window { + "pointer-events-capture-debug": boolean | null; + } } -$1 -declare module ${thisFileModuleName} { - ` - ); + - remove the declare global and the last } + */ + // find the index of global { + const globalIndex = processedSource.indexOf(" global {"); + console.log("found global", globalIndex); + if (globalIndex !== -1) { + console.log(processedSource); + // find where the ending } is. What we do is we count +1 if we find a { and -1 if we find a }. when we get to 0, this is the end of the global + let count = 1; + let i = -1; + for (i = globalIndex + 9; i < processedSource.length; i++) { + if (processedSource[i] === "{") { + count++; + } else if (processedSource[i] === "}") { + count--; + } + if (count === 0) { + break; + } + } + const nextIndex = i; + console.log("found next", nextIndex); + if (nextIndex !== -1) { + processedSource = + `} +` + + processedSource.substring(0, globalIndex) + + processedSource.substring(globalIndex + 9, nextIndex) + + `declare module ${thisFileModuleName} { + ` + + processedSource.substring(nextIndex + 2); + } + } if (defaultModuleName !== thisFileModuleName) { return ` From d8ea60225e9f428206ca111534c10adcfd378da2 Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Fri, 8 Nov 2024 16:17:30 +0100 Subject: [PATCH 2/4] small fix for the playground --- packages/tools/playground/public/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/tools/playground/public/index.js b/packages/tools/playground/public/index.js index 76735d1782e..eb4c604b238 100644 --- a/packages/tools/playground/public/index.js +++ b/packages/tools/playground/public/index.js @@ -55,9 +55,9 @@ var Versions = { "https://rawcdn.githack.com/BabylonJS/Extensions/f43ab677b4bca0a6ab77132d3f785be300382760/ClonerSystem/src/babylonx.cloner.js", "https://rawcdn.githack.com/BabylonJS/Extensions/785013ec55b210d12263c91f3f0a2ae70cf0bc8a/CompoundShader/src/babylonx.CompoundShader.js", ], - "5.71.1": [ + "5.57.1": [ "https://cdn.babylonjs.com/timestamp.js?t=" + Date.now(), - "https://cdn.babylonjs.com/v5.71.1/babylon.js", + "https://cdn.babylonjs.com/v5.57.1/babylon.js", "https://cdn.babylonjs.com/v5.57.1/gui/babylon.gui.min.js", "https://cdn.babylonjs.com/v5.57.1/inspector/babylon.inspector.bundle.js", "https://cdn.babylonjs.com/v5.57.1/nodeEditor/babylon.nodeEditor.js", @@ -77,7 +77,6 @@ var Versions = { "https://cdn.babylonjs.com/4.2.1/gui/babylon.gui.min.js", "https://cdn.babylonjs.com/4.2.1/inspector/babylon.inspector.bundle.js", "https://cdn.babylonjs.com/4.2.1/nodeEditor/babylon.nodeEditor.js", - "https://cdn.babylonjs.com/4.2.1/nodeGeometryEditor/babylon.nodeGeometryEditor.js", "https://cdn.babylonjs.com/4.2.1/materialsLibrary/babylonjs.materials.min.js", "https://cdn.babylonjs.com/4.2.1/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js", "https://cdn.babylonjs.com/4.2.1/postProcessesLibrary/babylonjs.postProcess.min.js", From 99253ed1f19e42d8d158294e120dbfd0d6e05dad Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Fri, 8 Nov 2024 16:39:31 +0100 Subject: [PATCH 3/4] In case global is at the end --- packages/dev/buildTools/src/generateDeclaration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/buildTools/src/generateDeclaration.ts b/packages/dev/buildTools/src/generateDeclaration.ts index 2d95a15034f..d3449d15e47 100644 --- a/packages/dev/buildTools/src/generateDeclaration.ts +++ b/packages/dev/buildTools/src/generateDeclaration.ts @@ -449,9 +449,9 @@ function getPackageDeclaration( console.log("found next", nextIndex); if (nextIndex !== -1) { processedSource = + processedSource.substring(0, globalIndex) + `} ` + - processedSource.substring(0, globalIndex) + processedSource.substring(globalIndex + 9, nextIndex) + `declare module ${thisFileModuleName} { ` + From a94188585696b62975808f47d5f63146ec7eadab Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Fri, 8 Nov 2024 16:40:18 +0100 Subject: [PATCH 4/4] cleanup --- packages/dev/buildTools/src/generateDeclaration.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/dev/buildTools/src/generateDeclaration.ts b/packages/dev/buildTools/src/generateDeclaration.ts index d3449d15e47..88a7c8e4063 100644 --- a/packages/dev/buildTools/src/generateDeclaration.ts +++ b/packages/dev/buildTools/src/generateDeclaration.ts @@ -431,7 +431,6 @@ function getPackageDeclaration( const globalIndex = processedSource.indexOf(" global {"); console.log("found global", globalIndex); if (globalIndex !== -1) { - console.log(processedSource); // find where the ending } is. What we do is we count +1 if we find a { and -1 if we find a }. when we get to 0, this is the end of the global let count = 1; let i = -1; @@ -446,7 +445,6 @@ function getPackageDeclaration( } } const nextIndex = i; - console.log("found next", nextIndex); if (nextIndex !== -1) { processedSource = processedSource.substring(0, globalIndex) +