{"id":12785,"library":"acorn-hammerhead","title":"Acorn.js Parser for TestCafe Hammerhead","description":"acorn-hammerhead is a specialized JavaScript parser derived from Acorn.js, specifically adapted for use within the TestCafe Hammerhead project. It is not intended as a general-purpose Acorn.js replacement, but rather provides a subset of Acorn's features tailored to Hammerhead's requirements. The current stable version is 0.6.3. Its release cadence appears irregular, driven by the needs and updates of the TestCafe Hammerhead project rather than independent feature development. Key differentiators include enhanced Unicode support and tighter integration with the Esotope library, alongside a deliberate reduction in the overall feature set compared to a full Acorn.js distribution, focusing only on the syntax elements pertinent to TestCafe's proxying and instrumentation logic. This package ships with TypeScript type definitions, enabling robust usage in TypeScript projects.","status":"active","version":"0.6.3","language":"javascript","source_language":"en","source_url":"https://github.com/miherlosev/acorn-hammerhead","tags":["javascript","typescript"],"install":[{"cmd":"npm install acorn-hammerhead","lang":"bash","label":"npm"},{"cmd":"yarn add acorn-hammerhead","lang":"bash","label":"yarn"},{"cmd":"pnpm add acorn-hammerhead","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS `require` works, but ESM `import` is preferred for modern Node.js and TypeScript environments. The `parse` function is the primary entry point for parsing code.","wrong":"const { parse } = require('acorn-hammerhead')","symbol":"parse","correct":"import { parse } from 'acorn-hammerhead'"},{"note":"Importing types like `Node` for Abstract Syntax Tree (AST) nodes should use `import type` for clarity and to avoid bundling type information in runtime code.","symbol":"Node","correct":"import type { Node } from 'acorn-hammerhead'"},{"note":"While `import * as` works, typically you'd destructure specific functions like `parse` directly. This pattern is less common for `acorn-hammerhead` as it exposes a limited API.","wrong":"const acorn = require('acorn-hammerhead')","symbol":"* as acorn","correct":"import * as acorn from 'acorn-hammerhead'"}],"quickstart":{"code":"import { parse } from 'acorn-hammerhead';\n\nconst code = `\n  function greeting(name) {\n    if (name?.length > 0) {\n      console.log(`Hello, ${name}!`);\n    } else {\n      console.log('Hello, stranger!');\n    }\n  }\n\n  greeting('World');\n  greeting();\n`;\n\ntry {\n  const ast = parse(code, { \n    ecmaVersion: 2020, \n    locations: true, \n    sourceType: 'module' \n  });\n  console.log('Successfully parsed AST top-level nodes:');\n  ast.body.forEach(node => console.log(`- ${node.type}`));\n  console.log('\\nFirst node details:');\n  console.log(JSON.stringify(ast.body[0], null, 2));\n} catch (error) {\n  console.error('Parsing failed:', error);\n}","lang":"typescript","description":"This quickstart demonstrates parsing a simple JavaScript code snippet using `acorn-hammerhead`'s `parse` function, logging the top-level AST nodes and details of the first node."},"warnings":[{"fix":"Ensure the code being parsed adheres to the subset of features supported by TestCafe Hammerhead. If you need full Acorn.js functionality, use the original `acorn` package instead.","message":"acorn-hammerhead is a heavily customized and feature-limited fork of Acorn.js. It does not support all Acorn.js options or all ECMAScript features that a standard Acorn.js parser might. Consult the TestCafe Hammerhead codebase if unexpected parsing issues occur with advanced syntax.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Only use `acorn-hammerhead` if you are specifically integrating with TestCafe's internal architecture or have confirmed its feature set meets your limited parsing needs. For general-purpose JavaScript parsing, use `acorn` or `@babel/parser`.","message":"The package's primary purpose is for TestCafe Hammerhead. Using it in contexts outside of TestCafe's internal proxying or transformation logic may lead to unexpected behavior or missing features compared to a general-purpose JavaScript parser.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to `acorn-hammerhead@0.6.3` or newer to incorporate the security fixes. Review any custom parser logic you might have that relies on specific Acorn.js internal behaviors if upgrading from very old versions.","message":"CodeQL vulnerabilities were fixed in v0.6.3. While not explicitly a breaking API change, upgrading is critical for security if your application processes untrusted code through this parser.","severity":"breaking","affected_versions":"<0.6.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the `ecmaVersion` option passed to `parse` (e.g., `{ ecmaVersion: 2020 }`) matches or exceeds the features used in your code. If the feature is very recent or experimental, `acorn-hammerhead` might not support it at all due to its specialized nature.","cause":"The parsed code uses an ECMAScript feature or syntax that is not supported by the `acorn-hammerhead` version or the `ecmaVersion` option provided to the `parse` function.","error":"SyntaxError: Unexpected token"},{"fix":"Use `import { parse } from 'acorn-hammerhead';` for ESM, or `const { parse } = require('acorn-hammerhead');` for CommonJS. Verify that `parse` is indeed exported by the module in your environment.","cause":"Incorrect import statement or attempting to call a non-existent export. Common in mixed ESM/CJS environments or when destructuring incorrectly.","error":"TypeError: parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null}