wesl 0.7.22 → 0.7.24

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.d.ts CHANGED
@@ -171,6 +171,7 @@ interface SrcModule {
171
171
  }
172
172
  /** a src declaration or reference to an ident */
173
173
  type Ident = DeclIdent | RefIdent;
174
+ type ScopeItem = Ident | Scope;
174
175
  /** LATER change this to a Map, so that `toString` isn't accidentally a condition */
175
176
  type Conditions = Record<string, boolean>;
176
177
  interface IdentBase {
@@ -229,7 +230,7 @@ interface ScopeBase {
229
230
  id: number;
230
231
  /** null for root scope in a module */
231
232
  parent: Scope | null;
232
- contents: (Ident | Scope)[];
233
+ contents: ScopeItem[];
233
234
  /** Conditional attribute (@if or @else) for this scope */
234
235
  condAttribute?: IfAttribute | ElifAttribute | ElseAttribute;
235
236
  }
@@ -820,6 +821,13 @@ declare class BundleResolver implements ModuleResolver {
820
821
  private moduleToFilePath;
821
822
  private modulePathToDebugPath;
822
823
  }
824
+ /** Wrap a resolver so each resolveModule call returns a freshly parsed AST.
825
+ * Use this when reusing a resolver across multiple link() calls, since binding
826
+ * mutates ASTs in place. Each wrapper instance caches within itself, so within
827
+ * a single link pass the same module path returns the same AST object.
828
+ * Re-parsing is faster than structuredClone due to cycle-tracking overhead
829
+ * from Scope.parent backpointers. */
830
+ declare function freshResolver(inner: ModuleResolver): ModuleResolver;
823
831
  /** Convert file path to module path (e.g., "foo/bar.wesl" to "package::foo::bar"). */
824
832
  declare function fileToModulePath(filePath: string, packageName: string, treatLibAsRoot: boolean): string;
825
833
  //#endregion
@@ -976,6 +984,8 @@ interface BindIdentsParams extends Pick<LinkRegistryParams, "resolver" | "condit
976
984
  virtuals?: VirtualLibrarySet;
977
985
  /** If true, accumulate unbound identifiers into BindResults.unbound instead of throwing. */
978
986
  accumulateUnbound?: true;
987
+ /** Visit all conditional branches (for dependency discovery). */
988
+ discoveryMode?: boolean;
979
989
  }
980
990
  /** Bind ref idents to declarations and mangle global declaration names. */
981
991
  declare function bindIdents(params: BindIdentsParams): BindResults;
@@ -1016,6 +1026,17 @@ interface BindContext {
1016
1026
  */
1017
1027
  declare function bindIdentsRecursive(scope: Scope, bindContext: BindContext, liveDecls: LiveDecls): DeclIdent[];
1018
1028
  //#endregion
1029
+ //#region src/Conditions.d.ts
1030
+ /**
1031
+ * Filter elements based on @if/@else conditional logic.
1032
+ * This function processes elements sequentially to handle @if/@else chains correctly.
1033
+ *
1034
+ * @param elements Array of elements at the same scope level
1035
+ * @param conditions Current conditional compilation settings
1036
+ * @return Array of valid elements after applying @if/@else logic
1037
+ */
1038
+ declare function filterValidElements<T extends AbstractElem>(elements: readonly T[], conditions: Conditions): T[];
1039
+ //#endregion
1019
1040
  //#region src/debug/ASTtoString.d.ts
1020
1041
  declare function astToString(elem: AbstractElem, indent?: number): string;
1021
1042
  /** @return string representation of an attribute (for test/debug) */
@@ -1043,6 +1064,23 @@ declare function identToString(ident?: Ident): string;
1043
1064
  declare function findUnboundIdents(resolver: BatchModuleResolver): string[][];
1044
1065
  /** Find unbound references with full position info. */
1045
1066
  declare function findUnboundRefs(resolver: BatchModuleResolver): UnboundRef[];
1067
+ /** Thin decorator that records which modules were resolved. */
1068
+ declare class TrackingResolver implements ModuleResolver {
1069
+ #private;
1070
+ readonly visited: Set<string>;
1071
+ constructor(inner: ModuleResolver);
1072
+ resolveModule(modulePath: string): WeslAST | undefined;
1073
+ }
1074
+ /**
1075
+ * Discover reachable modules and unbound external refs from a single root.
1076
+ *
1077
+ * Traces the import graph from `rootModuleName`, returning only the reachable
1078
+ * local modules in `weslSrc` and unresolved external references in `unbound`.
1079
+ */
1080
+ declare function discoverModules(weslSrc: Record<string, string>, resolver: ModuleResolver, rootModuleName: string, packageName?: string): {
1081
+ weslSrc: Record<string, string>;
1082
+ unbound: string[][];
1083
+ };
1046
1084
  //#endregion
1047
1085
  //#region src/discovery/PackageNameUtils.d.ts
1048
1086
  /** Package name sanitization for WESL.
@@ -1139,6 +1177,9 @@ declare const textureStorageTypes = "\n texture_storage_1d texture_storage_2d t
1139
1177
  declare const stdTypes: string[];
1140
1178
  /** https://www.w3.org/TR/WGSL/#predeclared-enumerants */
1141
1179
  declare const stdEnumerants: string[];
1180
+ /** WGSL standard attributes whose params need binding (e.g., @workgroup_size).
1181
+ * See: https://www.w3.org/TR/WGSL/#attributes */
1182
+ declare const wgslStandardAttributes: Set<string>;
1142
1183
  /** return true if the name is for a built in type (not a user struct) */
1143
1184
  declare function stdType(name: string): boolean;
1144
1185
  /** return true if the name is for a built in fn (not a user function) */
@@ -1241,4 +1282,4 @@ declare function offsetToLineNumber(offset: number, text: string): [lineNum: num
1241
1282
  */
1242
1283
  declare function errorHighlight(source: string, span: Span): [string, string];
1243
1284
  //#endregion
1244
- export { AbstractElem, AbstractElemBase, AliasElem, Attribute, AttributeElem, BatchModuleResolver, BinaryExpression, BinaryOperator, BindIdentsParams, BindResults, BindingAST, BindingStructElem, BlockStatement, BoundAndTransformed, BuiltinAttribute, BundleResolver, ComponentExpression, ComponentMemberExpression, CompositeResolver, ConditionalAttribute, Conditions, ConstAssertElem, ConstElem, ContainerElem, ContinuingElem, DeclIdent, DeclIdentElem, DeclarationElem, DiagnosticAttribute, DiagnosticDirective, DiagnosticRule, DirectiveElem, DirectiveVariant, ElemKindMap, ElemWithAttributes, ElemWithContentsBase, ElifAttribute, ElseAttribute, EmittableElem, EnableDirective, ExpressionElem, ExtendedGPUValidationError, FnElem, FnParamElem, FunctionCallExpression, GlobalDeclarationElem, GlobalVarElem, GrammarElem, HasAttributes, Ident, IfAttribute, ImportCollection, ImportElem, ImportItem, ImportSegment, ImportStatement, InterpolateAttribute, LetElem, LexicalScope, LinkConfig, LinkParams, LinkRegistryParams, LinkedWesl, LinkerTransform, Literal, LiveDecls, ManglerFn, ModuleElem, ModuleResolver, NameElem, OpenElem, OverrideElem, ParenthesizedExpression, ParseError, type ParseOptions, PartialScope, RecordResolver, RecordResolverOptions, RefIdent, RefIdentElem, RequiresDirective, Scope, SimpleMemberRef, Span, SrcMap, SrcMapBuilder, SrcMapEntry, SrcModule, SrcPosition, SrcWithPath, StableState, StandardAttribute, StatementElem, StructElem, StructMemberElem, StuffElem, SwitchClauseElem, SyntheticElem, TerminalElem, TextElem, TransformedAST, TranslateTimeExpressionElem, TypeRefElem, TypeTemplateParameter, TypedDeclElem, UnaryExpression, UnaryOperator, UnboundRef, UnknownExpressionElem, VarElem, VirtualLibrary, VirtualLibraryFn, VirtualLibrarySet, WeslAST, WeslBundle, WeslDevice, WeslGPUCompilationInfo, WeslGPUCompilationMessage, WeslJsPlugin, WeslParseContext, WeslParseError, WeslParseState, WeslStream, _linkSync, astToString, attributeToString, bindAndTransform, bindIdents, bindIdentsRecursive, bindingStructsPlugin, childIdent, childScope, containsScope, debug, debugContentsToString, emptyScope, errorHighlight, fileToModulePath, filterMap, findAllRootDecls, findMap, findRefsToBindingStructs, findUnboundIdents, findUnboundRefs, findValidRootDecls, flatImports, groupBy, grouped, identToString, last, lengthPrefixMangle, link, linkRegistry, liveDeclsToString, log, lowerBindingStructs, makeLiveDecls, makeWeslDevice, mapForward, mapValues, markBindingStructs, markEntryTypes, mergeScope, minimalMangle, minimallyMangledName, modulePartsToRelativePath, moduleToRelativePath, multiKeySet, multisampledTextureTypes, nextIdentId, noSuffix, normalize, normalizeDebugRoot, normalizeModuleName, npmNameVariations, offsetToLineNumber, overlapTail, parseSrcModule, partition, publicDecl, replaceWords, requestWeslDevice, resetScopeIds, resolveModulePath, sampledTextureTypes, sanitizePackageName, scan, scopeToString, scopeToStringLong, srcLog, stdEnumerant, stdEnumerants, stdFn, stdFns, stdType, stdTypes, textureStorageTypes, transformBindingReference, transformBindingStruct, underscoreMangle, validation, withLoggerAsync };
1285
+ export { AbstractElem, AbstractElemBase, AliasElem, Attribute, AttributeElem, BatchModuleResolver, BinaryExpression, BinaryOperator, BindIdentsParams, BindResults, BindingAST, BindingStructElem, BlockStatement, BoundAndTransformed, BuiltinAttribute, BundleResolver, ComponentExpression, ComponentMemberExpression, CompositeResolver, ConditionalAttribute, Conditions, ConstAssertElem, ConstElem, ContainerElem, ContinuingElem, DeclIdent, DeclIdentElem, DeclarationElem, DiagnosticAttribute, DiagnosticDirective, DiagnosticRule, DirectiveElem, DirectiveVariant, ElemKindMap, ElemWithAttributes, ElemWithContentsBase, ElifAttribute, ElseAttribute, EmittableElem, EnableDirective, ExpressionElem, ExtendedGPUValidationError, FnElem, FnParamElem, FunctionCallExpression, GlobalDeclarationElem, GlobalVarElem, GrammarElem, HasAttributes, Ident, IfAttribute, ImportCollection, ImportElem, ImportItem, ImportSegment, ImportStatement, InterpolateAttribute, LetElem, LexicalScope, LinkConfig, LinkParams, LinkRegistryParams, LinkedWesl, LinkerTransform, Literal, LiveDecls, ManglerFn, ModuleElem, ModuleResolver, NameElem, OpenElem, OverrideElem, ParenthesizedExpression, ParseError, type ParseOptions, PartialScope, RecordResolver, RecordResolverOptions, RefIdent, RefIdentElem, RequiresDirective, Scope, ScopeItem, SimpleMemberRef, Span, SrcMap, SrcMapBuilder, SrcMapEntry, SrcModule, SrcPosition, SrcWithPath, StableState, StandardAttribute, StatementElem, StructElem, StructMemberElem, StuffElem, SwitchClauseElem, SyntheticElem, TerminalElem, TextElem, TrackingResolver, TransformedAST, TranslateTimeExpressionElem, TypeRefElem, TypeTemplateParameter, TypedDeclElem, UnaryExpression, UnaryOperator, UnboundRef, UnknownExpressionElem, VarElem, VirtualLibrary, VirtualLibraryFn, VirtualLibrarySet, WeslAST, WeslBundle, WeslDevice, WeslGPUCompilationInfo, WeslGPUCompilationMessage, WeslJsPlugin, WeslParseContext, WeslParseError, WeslParseState, WeslStream, _linkSync, astToString, attributeToString, bindAndTransform, bindIdents, bindIdentsRecursive, bindingStructsPlugin, childIdent, childScope, containsScope, debug, debugContentsToString, discoverModules, emptyScope, errorHighlight, fileToModulePath, filterMap, filterValidElements, findAllRootDecls, findMap, findRefsToBindingStructs, findUnboundIdents, findUnboundRefs, findValidRootDecls, flatImports, freshResolver, groupBy, grouped, identToString, last, lengthPrefixMangle, link, linkRegistry, liveDeclsToString, log, lowerBindingStructs, makeLiveDecls, makeWeslDevice, mapForward, mapValues, markBindingStructs, markEntryTypes, mergeScope, minimalMangle, minimallyMangledName, modulePartsToRelativePath, moduleToRelativePath, multiKeySet, multisampledTextureTypes, nextIdentId, noSuffix, normalize, normalizeDebugRoot, normalizeModuleName, npmNameVariations, offsetToLineNumber, overlapTail, parseSrcModule, partition, publicDecl, replaceWords, requestWeslDevice, resetScopeIds, resolveModulePath, sampledTextureTypes, sanitizePackageName, scan, scopeToString, scopeToStringLong, srcLog, stdEnumerant, stdEnumerants, stdFn, stdFns, stdType, stdTypes, textureStorageTypes, transformBindingReference, transformBindingStruct, underscoreMangle, validation, wgslStandardAttributes, withLoggerAsync };