wesl 0.6.2 → 0.6.7

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.
package/dist/index.js CHANGED
@@ -437,7 +437,7 @@ function parserArg(arg) {
437
437
  function fn(fn2) {
438
438
  const parser2 = new Parser({
439
439
  fn: function _fn(state) {
440
- let generatedParser = fn2();
440
+ const generatedParser = fn2();
441
441
  if (!fn2) {
442
442
  const before = state.stream.checkpoint();
443
443
  throw new ParseError(`fn parser called before definition`, [
@@ -1117,13 +1117,13 @@ function mapValues(obj, fn2) {
1117
1117
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn2(v)]));
1118
1118
  }
1119
1119
  function offsetToLineNumber(offset, text2) {
1120
- offset = Math.min(text2.length, Math.max(0, offset));
1120
+ const safeOffset = Math.min(text2.length, Math.max(0, offset));
1121
1121
  let lineStartOffset = 0;
1122
1122
  let lineNum = 1;
1123
1123
  while (true) {
1124
1124
  const lineEnd = text2.indexOf("\n", lineStartOffset);
1125
- if (lineEnd === -1 || offset <= lineEnd) {
1126
- const linePos = 1 + (offset - lineStartOffset);
1125
+ if (lineEnd === -1 || safeOffset <= lineEnd) {
1126
+ const linePos = 1 + (safeOffset - lineStartOffset);
1127
1127
  return [lineNum, linePos];
1128
1128
  } else {
1129
1129
  lineStartOffset = lineEnd + 1;
@@ -1173,19 +1173,20 @@ function encodeVlq(value) {
1173
1173
  }
1174
1174
  function encode_integer(num) {
1175
1175
  let result = "";
1176
+ let enc;
1176
1177
  if (num < 0) {
1177
- num = -num << 1 | 1;
1178
+ enc = -num << 1 | 1;
1178
1179
  } else {
1179
- num <<= 1;
1180
+ enc = num << 1;
1180
1181
  }
1181
1182
  do {
1182
- let clamped = num & 31;
1183
- num >>>= 5;
1184
- if (num > 0) {
1183
+ let clamped = enc & 31;
1184
+ enc >>>= 5;
1185
+ if (enc > 0) {
1185
1186
  clamped |= 32;
1186
1187
  }
1187
1188
  result += integer_to_char[clamped];
1188
- } while (num > 0);
1189
+ } while (enc > 0);
1189
1190
  return result;
1190
1191
  }
1191
1192
  function throwClickableError(params) {
@@ -1889,7 +1890,7 @@ const memberRefCollect = collectElem(
1889
1890
  }
1890
1891
  );
1891
1892
  function nameCollect(cc) {
1892
- const { start, end, src, app } = cc;
1893
+ const { start, end, src } = cc;
1893
1894
  const name2 = src.slice(start, end);
1894
1895
  const elem = { kind: "name", start, end, name: name2 };
1895
1896
  addToOpenElem(cc, elem);
@@ -2109,6 +2110,7 @@ const weslMatcher = new RegexMatchers({
2109
2110
  blankspaces,
2110
2111
  commentStart,
2111
2112
  symbol: matchOneOf(symbolSet),
2113
+ // biome-ignore lint/correctness/noEmptyCharacterClassInRegex: TODO
2112
2114
  invalid: /[^]/
2113
2115
  });
2114
2116
  function weslExtension(combinator) {
@@ -2162,7 +2164,8 @@ class WeslStream {
2162
2164
  return this.eolPattern.lastIndex;
2163
2165
  }
2164
2166
  }
2165
- skipBlockComment(position) {
2167
+ skipBlockComment(start) {
2168
+ let position = start;
2166
2169
  while (true) {
2167
2170
  this.blockCommentPattern.lastIndex = position;
2168
2171
  const result = this.blockCommentPattern.exec(this.src);
@@ -2552,10 +2555,7 @@ const struct_member = tagScope(
2552
2555
  ).collect(collectStructMember)
2553
2556
  ).ctag("members");
2554
2557
  const struct_decl = seq(
2555
- weslExtension(opt_attributes).collect(
2556
- (cc) => cc.tags.attribute,
2557
- "attributes"
2558
- ),
2558
+ weslExtension(opt_attributes).collect((cc) => cc.tags.attribute, "attributes"),
2559
2559
  "struct",
2560
2560
  req(globalTypeNameDecl, "invalid struct, expected name"),
2561
2561
  seq(
@@ -2860,10 +2860,7 @@ const global_value_decl = or(
2860
2860
  ).collect(collectVarLike("const"))
2861
2861
  ).collect(partialScopeCollect);
2862
2862
  const global_alias = seq(
2863
- weslExtension(opt_attributes).collect(
2864
- (cc) => cc.tags.attribute,
2865
- "attributes"
2866
- ),
2863
+ weslExtension(opt_attributes).collect((cc) => cc.tags.attribute, "attributes"),
2867
2864
  "alias",
2868
2865
  req(word, "invalid alias, expected name").collect(
2869
2866
  globalDeclCollect,
@@ -3039,7 +3036,7 @@ class WeslParseError extends Error {
3039
3036
  this.src = opts.src;
3040
3037
  }
3041
3038
  }
3042
- function parseSrcModule(srcModule, srcMap) {
3039
+ function parseSrcModule(srcModule) {
3043
3040
  const stream = new WeslStream(srcModule.src);
3044
3041
  const appState = blankWeslParseState(srcModule);
3045
3042
  const init = { stream, appState };
@@ -3210,7 +3207,7 @@ function findUnboundIdents(registry) {
3210
3207
  unbound: [],
3211
3208
  dontFollowDecls: true
3212
3209
  };
3213
- Object.entries(registry.modules).map(([module, ast]) => {
3210
+ Object.entries(registry.modules).map(([_module, ast]) => {
3214
3211
  const rootDecls = findValidRootDecls(ast.rootScope, {});
3215
3212
  const declEntries = rootDecls.map((d) => [d.originalName, d]);
3216
3213
  const liveDecls = { decls: new Map(declEntries), parent: null };
@@ -3551,9 +3548,7 @@ function emitAttributes(attributes, ctx) {
3551
3548
  function emitStruct(e, ctx) {
3552
3549
  const { name: name2, members, start, end } = e;
3553
3550
  const { srcBuilder } = ctx;
3554
- const validMembers = members.filter(
3555
- (m) => conditionsValid(m, ctx.conditions)
3556
- );
3551
+ const validMembers = members.filter((m) => conditionsValid(m, ctx.conditions));
3557
3552
  const validLength = validMembers.length;
3558
3553
  if (validLength === 0) {
3559
3554
  warnEmptyStruct(e);
@@ -4147,15 +4142,16 @@ function selectModule(parsed, selectPath, packageName = "package") {
4147
4142
  return parsed.modules[modulePath];
4148
4143
  }
4149
4144
  function parseIntoRegistry(srcFiles, registry, packageName = "package", debugWeslRoot) {
4150
- if (debugWeslRoot === void 0) {
4151
- debugWeslRoot = "";
4152
- } else if (!debugWeslRoot.endsWith("/")) {
4153
- debugWeslRoot += "/";
4145
+ let weslRoot2 = debugWeslRoot;
4146
+ if (weslRoot2 === void 0) {
4147
+ weslRoot2 = "";
4148
+ } else if (!weslRoot2.endsWith("/")) {
4149
+ weslRoot2 += "/";
4154
4150
  }
4155
4151
  const srcModules = Object.entries(srcFiles).map(
4156
4152
  ([filePath, src]) => {
4157
4153
  const modulePath = fileToModulePath(filePath, packageName);
4158
- return { modulePath, debugFilePath: debugWeslRoot + filePath, src };
4154
+ return { modulePath, debugFilePath: weslRoot2 + filePath, src };
4159
4155
  }
4160
4156
  );
4161
4157
  srcModules.forEach((mod) => {
@@ -4424,7 +4420,7 @@ function transformBindingStruct(s, globalNames) {
4424
4420
  member.mangledVarName = varName;
4425
4421
  globalNames.add(varName);
4426
4422
  const attributes = ((_a = member.attributes) == null ? void 0 : _a.map(attributeToString).join(" ")) ?? "";
4427
- const varTypes = lowerPtrMember(member, typeName, typeParameters) ?? lowerStdTypeMember(typeName, typeParameters) ?? lowerStorageTextureMember(typeName, typeParameters);
4423
+ const varTypes = lowerPtrMember(typeName, typeParameters) ?? lowerStdTypeMember(typeName, typeParameters) ?? lowerStorageTextureMember(typeName, typeParameters);
4428
4424
  if (!varTypes) {
4429
4425
  console.log("unhandled case transforming member", typeName);
4430
4426
  return syntheticVar(attributes, varName, "", "??");
@@ -4433,7 +4429,7 @@ function transformBindingStruct(s, globalNames) {
4433
4429
  return syntheticVar(attributes, varName, storageType, varType);
4434
4430
  });
4435
4431
  }
4436
- function lowerPtrMember(member, typeName, typeParameters, varName) {
4432
+ function lowerPtrMember(typeName, typeParameters) {
4437
4433
  if (typeName.originalName === "ptr") {
4438
4434
  const origParams = typeParameters ?? [];
4439
4435
  const newParams = [origParams[0]];