🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

unbash

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unbash - npm Package Compare versions

Comparing version
4.0.0
to
4.0.1
+3
-2
package.json
{
"name": "unbash",
"version": "4.0.0",
"version": "4.0.1",
"description": "Fast 0-deps bash parser written in TypeScript",

@@ -44,3 +44,4 @@ "keywords": [

"test": "node --test test/*.test.ts",
"playground": "npx rolldown src/parser.ts -f esm -m -o playground/parser.js && npx rolldown src/printer.ts -f esm -m -o playground/printer.js && sed -i 's/id=\"version\">[^<]*/id=\"version\">'\"$(node -p \"require('.\\x2fpackage.json').version\")\"'/' playground/index.html"
"playground": "pnpx rolldown src/parser.ts -f esm -m -o playground/parser.js && pnpx rolldown src/printer.ts -f esm -m -o playground/printer.js && sed -i 's/id=\"version\">[^<]*/id=\"version\">'\"$(node -p \"require('.\\x2fpackage.json').version\")\"'/' playground/index.html",
"bench": "node bench/all.ts"
},

@@ -47,0 +48,0 @@ "devDependencies": {

+19
-24

@@ -32,20 +32,6 @@ # unbash

## Source offsets
Every node carries `pos`/`end` as absolute offsets into the original source, so `source.slice(node.pos, node.end)` yields that node's text at any nesting depth — including inside command, process, arithmetic, and `${ }` substitutions, and parameter-expansion sub-fields. No need to track inner offsets while traversing.
```ts
const source = 'echo "$(date -u) $(whoami)"';
const ast = parse(source);
const sub = ast.commands[0].command.suffix[0].parts[0].parts[0]; // the $(date -u)
source.slice(sub.script.pos, sub.script.end); // → "date -u"
```
`parts` is computed lazily — accessing it resolves a word's substitutions in place. Every word's `text` equals its source span (`source.slice(pos, end)`); `value` carries the interpreted form (quotes resolved).
The one exception to absolute offsets: legacy escaped backticks (`` `… \`…\` …` ``) rebuild their inner with the escapes removed, so it is no longer a verbatim substring of the source — the nested script's offsets stay relative to that rebuilt inner.
## Print
Basic opinionated printer, does not preserve whitespace or comments (except shebang):
Basic opinionated printer, does not preserve whitespace or comments (except
shebang):

@@ -74,3 +60,4 @@ ```ts

- CST output preserving all tokens and punctuation
- Granular error recovery that wraps errors in `ERROR` nodes and continues parsing
- Granular error recovery that wraps errors in `ERROR` nodes and continues
parsing

@@ -82,3 +69,4 @@ unbash might be a good fit if you prefer:

- A typed TypeScript API
- Built-in parsing for command/process substitutions, coproc, Bash 5.3 `${ cmd; }`, `[[ ]]`, `(( ))`, and extglob
- Built-in parsing for command/process substitutions, coproc, Bash 5.3 `${ cmd;
}`, `[[ ]]`, `(( ))`, and extglob
- Tolerant parsing that never throws and collects parse errors

@@ -88,3 +76,4 @@

[sh-syntax][2] is a WASM wrapper around the robust [mvdan/sh][3] Go parser. It is highly recommended if you need:
[sh-syntax][2] is a WASM wrapper around the robust [mvdan/sh][3] Go parser. It
is highly recommended if you need:

@@ -97,7 +86,10 @@ - Support for multiple shell dialects (bash, POSIX sh, mksh, Bats)

- A zero-dependency, synchronous API
- A detailed AST with structured word parts, parameter expansions, arithmetic expressions, and test expressions
- A detailed AST with structured word parts, parameter expansions, arithmetic
expressions, and test expressions
## unbash vs bash-parser
[bash-parser][4] (last publish: 2017) and its fork [@ericcornelissen/bash-parser][5] (community dependency maintenance fork ❤️ now archived) might be interesting if you need:
[bash-parser][4] (last publish: 2017) and its fork
[@ericcornelissen/bash-parser][5] (community dependency maintenance fork ❤️ now
archived) might be interesting if you need:

@@ -111,8 +103,11 @@ - A POSIX-only mode that rejects bash-specific syntax

- Tolerant parsing that never throws and collects parse errors
- Structured AST nodes for parameter expansions, arithmetic expressions, and `[[ ]]` test expressions
- Support for many additional syntax features (like herestrings, C-style for loops, `select`, process substitution, etc. etc.)
- Structured AST nodes for parameter expansions, arithmetic expressions, and `[[
]]` test expressions
- Support for many additional syntax features (like herestrings, C-style for
loops, `select`, process substitution, etc. etc.)
## Benchmarks
Relative performance comparison (on Apple M1 Pro/32GB), unbash is x times faster:
Relative performance comparison (on Apple M1 Pro/32GB), unbash is x times
faster:

@@ -119,0 +114,0 @@ | Parser | short | advanced | medium | large |