Registry / testing / acorn-hammerhead

acorn-hammerhead

JSON →
library0.6.3jsnpmunverified

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.

npm install acorn-hammerhead
INSTALL
IMPORT
SIG · ACORN-HAMMERHEAD
A
acorn-hammerhead
testingjavascriptv0.6.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'acorn-hammerhead'
const { parse } = require('acorn-hammerhead')
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.
Node
import type { Node } from 'acorn-hammerhead'
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.
* as acorn
import * as acorn from 'acorn-hammerhead'
const acorn = require('acorn-hammerhead')
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.

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.

import { parse } from 'acorn-hammerhead'; const code = ` function greeting(name) { if (name?.length > 0) { console.log(`Hello, ${name}!`); } else { console.log('Hello, stranger!'); } } greeting('World'); greeting(); `; try { const ast = parse(code, { ecmaVersion: 2020, locations: true, sourceType: 'module' }); console.log('Successfully parsed AST top-level nodes:'); ast.body.forEach(node => console.log(`- ${node.type}`)); console.log('\nFirst node details:'); console.log(JSON.stringify(ast.body[0], null, 2)); } catch (error) { console.error('Parsing failed:', error); }
Debug
Known issues
gotchaacorn-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.
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.
affects: >=0.1.0
gotchaThe 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.
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`.
affects: >=0.1.0
breakingCodeQL 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.
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.
affects: <0.6.3
Errors
Common errors & fixes
SyntaxError: Unexpected token
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.
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.
TypeError: parse is not a function
Incorrect import statement or attempting to call a non-existent export. Common in mixed ESM/CJS environments or when destructuring incorrectly.
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.
Upgrade
Version history
0.6.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
63 hits · last 30 days
node
52
OpenAI (training)
1
Resources
acorn-hammerhead — npm install acorn-hammerhead · libregistry