{"record":{"id":"b1bd73eb70f3d7b6","repo":"SeleniumHQ/selenium","slug":"unexpected-compiled-output-format-expected-it-to-b1bd73","errorCode":null,"errorMessage":"Unexpected compiled output format. Expected it to start with \"(function (\", got: ${input.slice(0, 80)}","messagePattern":"Unexpected compiled output format\\. Expected it to start with \"\\(function \\(\", got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/atoms/typescript/wrap-get-attribute-as-global.js","lineNumber":59,"sourceCode":"// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied.  See the License for the\n// specific language governing permissions and limitations\n// under the License.`;\n\nconst preamble = `\nwindow.bot = window.bot || {};\nwindow.bot.dom = window.bot.dom || {};\nwindow.bot.dom.typescript = window.bot.dom.typescript || {};\nwindow.bot.dom.typescript.getAttribute = `;\n\nconst input = fs.readFileSync(inputPath, 'utf8');\n\n// The compiled TypeScript output begins with \"(function (\". Prepend the\n// browser-global assignment so the atom is accessible as\n// window.bot.dom.typescript.getAttribute in test pages.\nif (!input.trimStart().startsWith('(function (')) {\n  throw new Error(\n    `Unexpected compiled output format. Expected it to start with \"(function (\", got: ${input.slice(0, 80)}`\n  );\n}\n\nconst output = licenseHeader + preamble + input.trimStart();\nfs.writeFileSync(outputPath, output);\n","sourceCodeStart":41,"sourceCodeEnd":66,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/atoms/typescript/wrap-get-attribute-as-global.js#L41-L66","documentation":"wrap-get-attribute-as-global.js asserts the compiled getAttribute output starts with '(function (' (note the open paren after 'function', reflecting an anonymous-IIFE-with-params shape) before prepending window.bot.dom.typescript.getAttribute =. This differs slightly from the isShown/findElements wrapper, which checks '(function ' — the getAttribute compiled form uses an anonymous function with destructured/parenthesized params. Any other output envelope (ESM, named function, class, bare statement) fails fast to avoid emitting invalid JS.","triggerScenarios":"A tsconfig/module change causing getAttribute to compile to a named IIFE '(function getAttribute(' or ESM instead of '(function ('. Feeding the wrong compiled file. A transform step altering the function signature shape. Manual edits to the compiled output.","commonSituations":"TypeScript compiler upgrades that change emitted function naming (e.g. preserving the function name vs. anonymizing). Bazel rule pointing at the wrong artifact. Module format changes.","solutions":["Ensure the getAttribute compile step emits output starting with '(function (' (anonymous IIFE).","Feed the correct compiled getAttribute artifact as input.","If the compiler now names the function, adjust the guard or the compile options to match the expected shape.","Diff the input against the last-known-good output to see the signature change."],"exampleFix":"// before (compiler emits named IIFE)\n(function getAttribute(elem, name) { ... })\n\n// after (anonymous IIFE matching the guard)\n(function (elem, name) { ... })","handlingStrategy":"validation","validationCode":"const input = fs.readFileSync(inputPath, 'utf8')\nif (!input.trimStart().startsWith('(function (')) {\n  console.error('Compiled getAttribute output must start with (function (; check signature/module format')\n  process.exit(2)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the compile step emits an anonymous IIFE '(function ('.","Feed the correct compiled getAttribute artifact.","Adjust compile options if function naming changes after an upgrade.","Diff generated input against last-good output."],"tags":["build","nodejs","bazel","atoms","typescript","compiler","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}