{"record":{"id":"a54e31cc5d25e33e","repo":"BabylonJS/Babylon.js","slug":"consts-must-have-a-name-constline","errorCode":null,"errorMessage":"`Consts must have a name: '${constLine}'`","messagePattern":"`Consts must have a name: '(.+?)'`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts","lineNumber":222,"sourceCode":"            continue;\r\n        }\r\n\r\n        const constLine = matches[2];\r\n\r\n        if (!constLine) {\r\n            throw new Error(\"Const line not found\");\r\n        }\r\n\r\n        const constLineMatches = new RegExp(/^const\\s+(\\w+)\\s+(\\w+)\\s*=\\s*([^\\s;]+)\\s*;?\\s*$/gm).exec(constLine);\r\n        if (!constLineMatches || constLineMatches.length < 4) {\r\n            throw new Error(`Consts must have a name, type, and a default value: '${constLine}'`);\r\n        }\r\n        const type = constLineMatches[1];\r\n        const friendlyName = constLineMatches[2];\r\n        const defaultValue = constLineMatches[3];\r\n\r\n        if (!friendlyName) {\r\n            throw new Error(`Consts must have a name: '${constLine}'`);\r\n        }\r\n        if (defaultValue === null) {\r\n            throw new Error(`Consts must have a value: '${constLine}'`);\r\n        }\r\n\r\n        const constProperty: ConstPropertyMetadata | null =\r\n            type === \"float\"\r\n                ? {\r\n                      name: DecorateSymbol(friendlyName),\r\n                      friendlyName,\r\n                      type,\r\n                      defaultValue: parseFloat(defaultValue),\r\n                      options: annotation.property.options as ConstMetadataAnnotationFloatOptions | undefined,\r\n                  }\r\n                : null;\r\n\r\n        if (!constProperty) {\r\n            throw new Error(`Unsupported const property type: '${type}'`);\r","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts#L204-L240","documentation":"The regex for the const line captured a type and optional value but the friendly-name capture group (\\w+) is empty. Since (\\w+) cannot normally match empty, reaching this check usually indicates the const line was matched by an odd path or the captured name failed a truthiness check after decoration-adjacent processing. It guards that every exposed property const has an identifier name.","triggerScenarios":"ParseFragmentShader on a const line where the name token is absent or not a word character, e.g. `const float  = 0.5;` (missing identifier), or a shader where preprocessing stripped identifiers.","commonSituations":"Accidentally deleted variable name while editing a shader; code generators emitting placeholder consts with blank names; IDE refactor that removed a name.","solutions":["Give the const a valid GLSL identifier name: `const float exposure = 1.0;`.","Verify no macro/minifier step removed identifiers before conversion.","Check the const line for typos such as double spaces collapsing the name or a stray `=`."],"exampleFix":"// before\nconst float  = 0.5;\n// after\nconst float exposure = 0.5;","handlingStrategy":"validation","validationCode":"if ([...shader.matchAll(/const\\s+\\w+\\s+(?=\\s*=)/g)].length) throw new Error(\"Property const missing a variable name\");","typeGuard":"function constHasName(line: string): boolean {\n  const m = /^const\\s+\\w+\\s+(\\w+)\\s*=/.exec(line);\n  return !!m && !!m[1];\n}","tryCatchPattern":"try {\n  const info = ParseFragmentShader(blockName, namespace, shader);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Consts must have a name\")) {\n    // repair: give the const an identifier before retrying\n  } else throw e;\n}","preventionTips":["Never leave a const identifier blank, even temporarily.","Let the IDE complete const declarations instead of hand-typing the pattern.","Review shader diffs for edits around `const` lines."],"tags":["shader","parsing","glsl","naming"],"backgroundTag":"shader-const-syntax-invalid","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}