wgsl-edit 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/wgsl-edit.js +22 -21
  2. package/package.json +4 -4
package/dist/wgsl-edit.js CHANGED
@@ -22045,9 +22045,8 @@ function flatImports(ast, conditions) {
22045
22045
  //#region ../wesl/src/BindIdents.ts
22046
22046
  /** Bind ref idents to declarations and mangle global declaration names. */
22047
22047
  function bindIdents(params) {
22048
- const { rootAst, resolver, virtuals, accumulateUnbound } = params;
22048
+ const { rootAst, resolver, virtuals, accumulateUnbound, discoveryMode } = params;
22049
22049
  const { conditions = {}, mangler = minimalMangle } = params;
22050
- const { discoveryMode } = params;
22051
22050
  const packageName = rootAst.srcModule.modulePath.split("::")[0];
22052
22051
  const rootDecls = discoveryMode ? findAllRootDecls(rootAst.rootScope) : findValidRootDecls(rootAst.rootScope, conditions);
22053
22052
  const { globalNames, knownDecls } = initRootDecls(rootDecls);
@@ -22058,6 +22057,7 @@ function bindIdents(params) {
22058
22057
  virtuals,
22059
22058
  mangler,
22060
22059
  packageName,
22060
+ rootModulePath: rootAst.srcModule.modulePath,
22061
22061
  foundScopes: /* @__PURE__ */ new Set(),
22062
22062
  globalNames,
22063
22063
  globalStatements: /* @__PURE__ */ new Map(),
@@ -22068,8 +22068,9 @@ function bindIdents(params) {
22068
22068
  decls: new Map(rootDecls.map((d) => [d.originalName, d])),
22069
22069
  parent: null
22070
22070
  };
22071
- const fromRootDecls = rootDecls.flatMap((decl) => processDependentScope(decl, bindContext));
22072
- const fromRefs = bindIdentsRecursive(rootAst.rootScope, bindContext, liveDecls);
22071
+ const fromRootDecls = rootDecls.flatMap((d) => processDependentScope(d, bindContext));
22072
+ const { rootScope } = rootAst;
22073
+ const fromRefs = bindIdentsRecursive(rootScope, bindContext, liveDecls);
22073
22074
  const newStatements = [...bindContext.globalStatements.values()];
22074
22075
  return {
22075
22076
  decls: [...fromRootDecls, ...fromRefs],
@@ -22114,11 +22115,7 @@ function findAllRootDecls(rootScope) {
22114
22115
  function publicDecl(scope, name, conditions) {
22115
22116
  return getValidRootDecls(scope, conditions).find((d) => d.originalName === name);
22116
22117
  }
22117
- /**
22118
- * Recursively bind references to declarations in this scope and child scopes.
22119
- * Tracks @else state to ensure filtered @else blocks don't pull in unused declarations.
22120
- * @return new declarations found
22121
- */
22118
+ /** Recursively bind refs to decls in this scope and children. @return new declarations found */
22122
22119
  function bindIdentsRecursive(scope, bindContext, liveDecls) {
22123
22120
  const { dontFollowDecls, foundScopes } = bindContext;
22124
22121
  if (foundScopes.has(scope)) return [];
@@ -22156,11 +22153,7 @@ function processDependentScope(decl, ctx) {
22156
22153
  if (!rootDecls) return [];
22157
22154
  return bindIdentsRecursive(dependentScope, ctx, makeLiveDecls(rootDecls));
22158
22155
  }
22159
- /**
22160
- * Trace references to their declarations.
22161
- * Mutates to mangle declarations and mark std references.
22162
- * @return found declaration, or undefined if already processed
22163
- */
22156
+ /** Resolve a ref to its declaration, mangling globals and marking std refs. */
22164
22157
  function handleRef(ident, liveDecls, bindContext) {
22165
22158
  if (ident.refersTo || ident.std) return;
22166
22159
  if (ident.conditionRef) return;
@@ -22240,7 +22233,8 @@ function findExport(pathParts, srcModule, ctx) {
22240
22233
  const modulePath = resolveModulePath(pathParts, srcModule.modulePath.split("::")).slice(0, -1).join("::");
22241
22234
  const moduleAst = ctx.resolver.resolveModule(modulePath) ?? virtualModule(pathParts[0], ctx);
22242
22235
  if (!moduleAst) return void 0;
22243
- const decl = publicDecl(moduleAst.rootScope, last(pathParts), ctx.conditions);
22236
+ const name = last(pathParts);
22237
+ const decl = publicDecl(moduleAst.rootScope, name, ctx.conditions);
22244
22238
  if (decl) return {
22245
22239
  decl,
22246
22240
  moduleAst
@@ -22251,9 +22245,14 @@ function virtualModule(moduleName, ctx) {
22251
22245
  const found = ctx.virtuals?.[moduleName];
22252
22246
  if (!found) return void 0;
22253
22247
  if (found.ast) return found.ast;
22254
- const src = found.fn(ctx.conditions);
22248
+ const { conditions, rootModulePath, packageName } = ctx;
22249
+ const src = found.fn({
22250
+ conditions,
22251
+ rootModulePath,
22252
+ packageName
22253
+ });
22255
22254
  found.ast = parseSrcModule({
22256
- modulePath: ctx.packageName + "::" + moduleName,
22255
+ modulePath: packageName + "::" + moduleName,
22257
22256
  debugFilePath: moduleName,
22258
22257
  src
22259
22258
  });
@@ -22273,8 +22272,8 @@ function rootLiveDecls(decl, conditions) {
22273
22272
  assertThatDebug(scope.kind === "scope");
22274
22273
  const root = scope;
22275
22274
  if (!root._scopeDecls) {
22276
- const rootDecls = findValidRootDecls(scope, conditions);
22277
- root._scopeDecls = { decls: new Map(rootDecls.map((d) => [d.originalName, d])) };
22275
+ const decls = findValidRootDecls(scope, conditions);
22276
+ root._scopeDecls = { decls: new Map(decls.map((d) => [d.originalName, d])) };
22278
22277
  }
22279
22278
  return root._scopeDecls;
22280
22279
  }
@@ -22799,8 +22798,9 @@ function flattenLibraryTree(libs) {
22799
22798
  * that share some sources.)
22800
22799
  */
22801
22800
  function linkRegistry(params) {
22802
- const { transformedAst, newDecls, newStatements } = bindAndTransform(params);
22803
- return SrcMapBuilder.build(emitWgsl(transformedAst.moduleElem, transformedAst.srcModule, newDecls, newStatements, params.conditions));
22801
+ const { transformedAst: ast, newDecls, newStatements } = bindAndTransform(params);
22802
+ const builders = emitWgsl(ast.moduleElem, ast.srcModule, newDecls, newStatements, params.conditions);
22803
+ return SrcMapBuilder.build(builders);
22804
22804
  }
22805
22805
  /** Bind identifiers and apply transform plugins */
22806
22806
  function bindAndTransform(params) {
@@ -22858,6 +22858,7 @@ function applyTransformPlugins(rootModule, globalNames, config) {
22858
22858
  };
22859
22859
  return filterMap(config?.plugins ?? [], (plugin) => plugin.transform).reduce((ast, transform) => transform(ast), startAst);
22860
22860
  }
22861
+ /** Assemble WGSL output from prologue statements, root module, and imported declarations. */
22861
22862
  function emitWgsl(rootModuleElem, srcModule, newDecls, newStatements, conditions = {}) {
22862
22863
  const prologueBuilders = newStatements.map((s) => emitStatement(s, conditions));
22863
22864
  const rootBuilder = new SrcMapBuilder({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wgsl-edit",
3
3
  "description": "Web component for editing WGSL/WESL with CodeMirror",
4
- "version": "0.0.24",
4
+ "version": "0.0.25",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -36,9 +36,9 @@
36
36
  "@codemirror/view": "^6.0.0",
37
37
  "@lezer/highlight": "^1.2.1",
38
38
  "codemirror": "^6.0.0",
39
- "wesl-fetch": "0.0.13",
40
- "wesl": "0.7.25",
41
- "lezer-wesl": "0.6.46"
39
+ "lezer-wesl": "0.6.47",
40
+ "wesl": "0.7.26",
41
+ "wesl-fetch": "0.0.14"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@playwright/test": "^1.53.2",