Skip to content

Commit

Permalink
Refactor replaceExternalsInWgsl (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhawryluk authored Jan 15, 2025
1 parent 5d0718b commit 0142a4a
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/typegpu/src/core/resolve/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,12 @@ export function replaceExternalsInWgsl(
}

if (external !== null && typeof external === 'object') {
const regExp = new RegExp(
`${externalName}\\.(?<prop>.*?)(?![\\w_])`,
'g',
);

const foundProperties = [];
while (true) {
const found = regExp.exec(wgsl);
if (found === null) {
break;
}

foundProperties.push(found[1]);
}
const foundProperties =
[
...wgsl.matchAll(
new RegExp(`${externalName}\\.(?<prop>.*?)(?![\\w_])`, 'g'),
),
].map((found) => found[1]) ?? [];

return foundProperties.reduce(
(innerAcc: string, prop) =>
Expand Down

0 comments on commit 0142a4a

Please sign in to comment.