wesl 0.7.21 → 0.7.23

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
  }
@@ -725,9 +726,13 @@ declare class LinkedWesl {
725
726
  * . lengthPrefixMangle constructs long but predictable names for every declaration
726
727
  */
727
728
  type ManglerFn = (/** global declaration that needs a name */
729
+
728
730
  decl: DeclIdent, /** module that contains the declaration */
731
+
729
732
  srcModule: SrcModule, /** name at use site (possibly import as renamed from declaration) */
733
+
730
734
  proposedName: string, /** current set of mangled root level names for the linked result (read only) */
735
+
731
736
  globalNames: Set<string>) => string;
732
737
  /**
733
738
  * Construct a globally unique name based on the declaration
@@ -972,11 +977,15 @@ interface BindIdentsParams extends Pick<LinkRegistryParams, "resolver" | "condit
972
977
  virtuals?: VirtualLibrarySet;
973
978
  /** If true, accumulate unbound identifiers into BindResults.unbound instead of throwing. */
974
979
  accumulateUnbound?: true;
980
+ /** Visit all conditional branches (for dependency discovery). */
981
+ discoveryMode?: boolean;
975
982
  }
976
983
  /** Bind ref idents to declarations and mangle global declaration names. */
977
984
  declare function bindIdents(params: BindIdentsParams): BindResults;
978
985
  /** Find all conditionally valid declarations at the root level. */
979
986
  declare function findValidRootDecls(rootScope: Scope, conditions: Conditions): DeclIdent[];
987
+ /** Find all declarations at the root level, ignoring conditions. */
988
+ declare function findAllRootDecls(rootScope: Scope): DeclIdent[];
980
989
  /** Find a public declaration with the given original name. */
981
990
  declare function publicDecl(scope: Scope, name: string, conditions: Conditions): DeclIdent | undefined;
982
991
  /** State used during the recursive scope tree walk to bind references to declarations. */
@@ -1000,6 +1009,8 @@ interface BindContext {
1000
1009
  unbound?: UnboundRef[];
1001
1010
  /** Don't follow references from declarations (for library dependency detection). */
1002
1011
  dontFollowDecls?: boolean;
1012
+ /** Visit all conditional branches (for dependency discovery). */
1013
+ discoveryMode?: boolean;
1003
1014
  }
1004
1015
  /**
1005
1016
  * Recursively bind references to declarations in this scope and child scopes.
@@ -1008,6 +1019,17 @@ interface BindContext {
1008
1019
  */
1009
1020
  declare function bindIdentsRecursive(scope: Scope, bindContext: BindContext, liveDecls: LiveDecls): DeclIdent[];
1010
1021
  //#endregion
1022
+ //#region src/Conditions.d.ts
1023
+ /**
1024
+ * Filter elements based on @if/@else conditional logic.
1025
+ * This function processes elements sequentially to handle @if/@else chains correctly.
1026
+ *
1027
+ * @param elements Array of elements at the same scope level
1028
+ * @param conditions Current conditional compilation settings
1029
+ * @return Array of valid elements after applying @if/@else logic
1030
+ */
1031
+ declare function filterValidElements<T extends AbstractElem>(elements: readonly T[], conditions: Conditions): T[];
1032
+ //#endregion
1011
1033
  //#region src/debug/ASTtoString.d.ts
1012
1034
  declare function astToString(elem: AbstractElem, indent?: number): string;
1013
1035
  /** @return string representation of an attribute (for test/debug) */
@@ -1035,6 +1057,23 @@ declare function identToString(ident?: Ident): string;
1035
1057
  declare function findUnboundIdents(resolver: BatchModuleResolver): string[][];
1036
1058
  /** Find unbound references with full position info. */
1037
1059
  declare function findUnboundRefs(resolver: BatchModuleResolver): UnboundRef[];
1060
+ /** Thin decorator that records which modules were resolved. */
1061
+ declare class TrackingResolver implements ModuleResolver {
1062
+ #private;
1063
+ readonly visited: Set<string>;
1064
+ constructor(inner: ModuleResolver);
1065
+ resolveModule(modulePath: string): WeslAST | undefined;
1066
+ }
1067
+ /**
1068
+ * Discover reachable modules and unbound external refs from a single root.
1069
+ *
1070
+ * Traces the import graph from `rootModuleName`, returning only the reachable
1071
+ * local modules in `weslSrc` and unresolved external references in `unbound`.
1072
+ */
1073
+ declare function discoverModules(weslSrc: Record<string, string>, resolver: ModuleResolver, rootModuleName: string, packageName?: string): {
1074
+ weslSrc: Record<string, string>;
1075
+ unbound: string[][];
1076
+ };
1038
1077
  //#endregion
1039
1078
  //#region src/discovery/PackageNameUtils.d.ts
1040
1079
  /** Package name sanitization for WESL.
@@ -1131,6 +1170,9 @@ declare const textureStorageTypes = "\n texture_storage_1d texture_storage_2d t
1131
1170
  declare const stdTypes: string[];
1132
1171
  /** https://www.w3.org/TR/WGSL/#predeclared-enumerants */
1133
1172
  declare const stdEnumerants: string[];
1173
+ /** WGSL standard attributes whose params need binding (e.g., @workgroup_size).
1174
+ * See: https://www.w3.org/TR/WGSL/#attributes */
1175
+ declare const wgslStandardAttributes: Set<string>;
1134
1176
  /** return true if the name is for a built in type (not a user struct) */
1135
1177
  declare function stdType(name: string): boolean;
1136
1178
  /** return true if the name is for a built in fn (not a user function) */
@@ -1233,4 +1275,4 @@ declare function offsetToLineNumber(offset: number, text: string): [lineNum: num
1233
1275
  */
1234
1276
  declare function errorHighlight(source: string, span: Span): [string, string];
1235
1277
  //#endregion
1236
- 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, 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 };
1278
+ 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, 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 };