Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global declaration processing #15792

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions packages/dev/buildTools/src/generateDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,44 @@ 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) {
// 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;
if (nextIndex !== -1) {
processedSource =
processedSource.substring(0, globalIndex) +
`}
` +
processedSource.substring(globalIndex + 9, nextIndex) +
`declare module ${thisFileModuleName} {
` +
processedSource.substring(nextIndex + 2);
}
}

if (defaultModuleName !== thisFileModuleName) {
return `
Expand Down
5 changes: 2 additions & 3 deletions packages/tools/playground/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down