javascript-obfuscator-lite 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/LICENSE +21 -0
- package/README.md +470 -2
- package/bin/cli.js +325 -0
- package/lib/index.d.ts +57 -0
- package/lib/index.js +140 -0
- package/lib/options.js +159 -0
- package/lib/transforms.js +757 -0
- package/lib/utils.js +452 -0
- package/package.json +56 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## 1.0.0 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
Initial release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Public npm package name, package metadata, MIT license, and English
|
|
12
|
+
documentation.
|
|
13
|
+
- `javascript-obfuscator-lite` and `jso-lite` CLI binaries with file,
|
|
14
|
+
stdin/stdout, flag, and error handling support.
|
|
15
|
+
- Programmatic API: `obfuscate()`, `obfuscateFile()`, `normalizeOptions()`,
|
|
16
|
+
`defaultOptions`, and `version`.
|
|
17
|
+
- TypeScript declarations in `lib/index.d.ts`.
|
|
18
|
+
- Behavioral test suite covering every transform, CLI behavior, module exports,
|
|
19
|
+
CommonJS, JSX, async functions, and regression cases.
|
|
20
|
+
- GitHub Actions CI workflow for Node.js 12, 18, 20, and 22.
|
|
21
|
+
- Batched, binding-aware identifier renaming. Renaming is now roughly linear
|
|
22
|
+
instead of quadratic for global bindings.
|
|
23
|
+
- Automatic protection for exported ES module bindings and CommonJS modules.
|
|
24
|
+
- Detection of `with` statements; risky transforms are skipped to preserve
|
|
25
|
+
dynamic-scope semantics.
|
|
26
|
+
- Clear rejection of TypeScript, Flow, and ESTree parser plugins.
|
|
27
|
+
- `--parser-plugins` support for JSX and import attributes.
|
|
28
|
+
- Website link in the README and CLI output.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Node.js 12 is now the minimum supported runtime.
|
|
33
|
+
- `eval` encoding is disabled by default and must be enabled with `--eval` /
|
|
34
|
+
`eval: true`.
|
|
35
|
+
- Removed unused runtime dependencies (`express`, `sync-request`, and
|
|
36
|
+
`@babel/code-frame` as a direct dependency).
|
|
37
|
+
- Removed the `figlet` dependency; the CLI uses a lightweight text banner.
|
|
38
|
+
- `obfuscateFile()` creates missing output directories.
|
|
39
|
+
- Errors produce a non-zero exit code in the CLI.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- **String transforms corrupted module syntax.** Strings in `import`/`export`
|
|
44
|
+
sources and import/export specifiers could be replaced with expressions,
|
|
45
|
+
producing invalid modules. These positions are now preserved.
|
|
46
|
+
- **String reversal corrupted non-BMP characters.** Emoji and other surrogate
|
|
47
|
+
pairs are no longer reversed by UTF-16 code unit.
|
|
48
|
+
- **Unicode escaping produced invalid escapes for non-BMP characters.**
|
|
49
|
+
Astral characters are now emitted as valid surrogate pairs.
|
|
50
|
+
- **JSX attribute strings were rewritten as JavaScript escapes.** JSX attribute
|
|
51
|
+
values are raw text, so they are now left untouched.
|
|
52
|
+
- **Hex property encoding could produce invalid escapes.** Hex escapes are now
|
|
53
|
+
padded to two digits, and non-Latin-1 identifiers use `\u`/surrogate escapes.
|
|
54
|
+
- **Class and object numeric keys were replaced with expressions.** Numeric
|
|
55
|
+
and boolean transforms now skip property-key positions.
|
|
56
|
+
- **`eval` encoding replaced expressions with statements.** This produced
|
|
57
|
+
invalid ASTs and broken output. Expressions are now replaced with call
|
|
58
|
+
expressions, and UTF-16 code units are used for astral characters.
|
|
59
|
+
- **`eval` encoding broke on shadowed `eval`/`String` bindings.** Shadowed
|
|
60
|
+
scopes are skipped, as are strict-mode classes, modules, and `with` blocks.
|
|
61
|
+
- **Renaming crashed on destructuring declarations and anonymous default
|
|
62
|
+
exports.** Non-identifier bindings and anonymous functions are now handled.
|
|
63
|
+
- **Renaming could capture references across scopes.** New names are unique
|
|
64
|
+
across the whole file, preventing shadowing/capture.
|
|
65
|
+
- **Renaming broke exported and CommonJS APIs.** Exported bindings are skipped
|
|
66
|
+
and CommonJS modules disable global renaming.
|
|
67
|
+
- **Renaming broke block-level function declarations.** Only declarations
|
|
68
|
+
directly in a program or function body are renamed.
|
|
69
|
+
- **Renaming mis-resolved function names shadowed by parameters, local `var`
|
|
70
|
+
declarations, or duplicate declarations.** Declaration identifiers are
|
|
71
|
+
matched by node identity, and all declaration nodes for a binding are
|
|
72
|
+
updated.
|
|
73
|
+
- **Renaming missed destructuring assignment, `for-in`/`for-of`, and
|
|
74
|
+
shorthand-property targets.** These positions are now renamed while
|
|
75
|
+
preserving object property keys.
|
|
76
|
+
- **Control-flow flattening checked the wrong body length and moved unsafe
|
|
77
|
+
declarations.** It now skips empty/single-statement bodies, lexical
|
|
78
|
+
declarations, classes, nested function declarations, imports/exports, and
|
|
79
|
+
files containing `with`.
|
|
80
|
+
- **String array name collisions with nested scopes.** The array name is now
|
|
81
|
+
chosen from a file-wide identifier set.
|
|
82
|
+
- **Zombie code could be inserted into invalid statement positions.** Insertion
|
|
83
|
+
is limited to statement-list positions.
|
|
84
|
+
- **Assignment junk mutated AST nodes in place.** Nodes are rebuilt safely.
|
|
85
|
+
- **The CLI keeps the process alive with per-character timers.** Output is
|
|
86
|
+
written directly instead.
|
|
87
|
+
- **Parse errors and I/O errors were swallowed.** They now surface with a
|
|
88
|
+
non-zero exit code.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wang Yinzhen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,471 @@
|
|
|
1
|
-
#
|
|
1
|
+
# javascript-obfuscator-lite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/javascript-obfuscator-lite)
|
|
4
|
+
[](https://www.npmjs.com/package/javascript-obfuscator-lite)
|
|
5
|
+
[](https://www.npmjs.com/package/javascript-obfuscator-lite)
|
|
6
|
+
[](https://www.npmjs.com/package/javascript-obfuscator-lite)
|
|
7
|
+
|
|
8
|
+
Website: [https://js-obfuscator.github.io/](https://js-obfuscator.github.io/)
|
|
9
|
+
|
|
10
|
+
A lightweight, AST-based JavaScript obfuscator with a friendly CLI and a
|
|
11
|
+
programmatic API. It rewrites JavaScript into code that is harder for humans to
|
|
12
|
+
read while preserving the original runtime behavior.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **String protection** — string arrays, reversal expressions, and Unicode
|
|
17
|
+
escaping.
|
|
18
|
+
- **Expression protection** — hexadecimal property access, XOR-encoded
|
|
19
|
+
numbers, wrapped binary expressions, encoded booleans, and junk assignments.
|
|
20
|
+
- **Code-shape protection** — zombie declarations and switch-based
|
|
21
|
+
control-flow flattening.
|
|
22
|
+
- **Identifier renaming** — configurable global/local renaming with
|
|
23
|
+
collision-safe, file-wide unique names.
|
|
24
|
+
- **Optional eval encoding** — opt-in `eval(String.fromCharCode(...))`
|
|
25
|
+
expression encoding.
|
|
26
|
+
- **Safety checks** — exported names, CommonJS globals, JSX, module specifiers,
|
|
27
|
+
class/object keys, destructuring, and `with` statements are handled
|
|
28
|
+
conservatively.
|
|
29
|
+
- **CLI + API** — file, stdin/stdout, JSON-style options, TypeScript type
|
|
30
|
+
definitions, and zero configuration to get started.
|
|
31
|
+
|
|
32
|
+
## Requirements
|
|
33
|
+
|
|
34
|
+
- Node.js **12** or newer.
|
|
35
|
+
- The obfuscator runs in Node.js. The generated JavaScript can target any
|
|
36
|
+
runtime that supports the syntax used by the input.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
Install it as a project dependency:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install --save-dev javascript-obfuscator-lite
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or run it without installing:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx javascript-obfuscator-lite --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
### CLI
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx javascript-obfuscator-lite input.js -o output.js
|
|
58
|
+
node output.js
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Use `-` for stdin or stdout:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cat input.js | npx javascript-obfuscator-lite - > output.js
|
|
65
|
+
npx javascript-obfuscator-lite input.js --quiet | node
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Programmatic API
|
|
69
|
+
|
|
70
|
+
CommonJS:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const fs = require('node:fs');
|
|
74
|
+
const { obfuscate } = require('javascript-obfuscator-lite');
|
|
75
|
+
|
|
76
|
+
const source = fs.readFileSync('input.js', 'utf8');
|
|
77
|
+
const output = obfuscate(source, {
|
|
78
|
+
controlFlow: true,
|
|
79
|
+
stringArray: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync('output.js', output);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
ES modules:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
89
|
+
import { obfuscate } from 'javascript-obfuscator-lite';
|
|
90
|
+
|
|
91
|
+
const output = obfuscate(readFileSync('input.js', 'utf8'), {
|
|
92
|
+
renameGlobals: false,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
writeFileSync('output.js', output);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Obfuscate a file directly:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const { obfuscateFile } = require('javascript-obfuscator-lite');
|
|
102
|
+
|
|
103
|
+
obfuscateFile('src/app.js', 'dist/app.js', {
|
|
104
|
+
compact: true,
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## CLI reference
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
Usage: javascript-obfuscator-lite [options] <input> [output]
|
|
112
|
+
|
|
113
|
+
Arguments:
|
|
114
|
+
input Input file, or "-" for stdin
|
|
115
|
+
output Output file, or "-" for stdout (default: "-")
|
|
116
|
+
|
|
117
|
+
Options:
|
|
118
|
+
-o, --output <file> Write output to <file>
|
|
119
|
+
-c, --compact Emit compact code
|
|
120
|
+
-k, --comments Preserve comments
|
|
121
|
+
--parser-plugins <p> Comma-separated Babel parser plugins (e.g. jsx)
|
|
122
|
+
--eval Enable eval-based expression encoding
|
|
123
|
+
--no-string-array Disable the string array transform
|
|
124
|
+
--no-string-reverse Disable string reversal
|
|
125
|
+
--no-string-unicode Disable unicode string escaping
|
|
126
|
+
--no-member-expression
|
|
127
|
+
Disable computed property encoding
|
|
128
|
+
--no-numeric-literal Disable numeric literal encoding
|
|
129
|
+
--no-binary-expression
|
|
130
|
+
Disable binary expression wrapping
|
|
131
|
+
--no-boolean-literal Disable boolean literal encoding
|
|
132
|
+
--no-assignment-junk Disable assignment junk code
|
|
133
|
+
--no-zombie-code Disable zombie code injection
|
|
134
|
+
--no-control-flow Disable control-flow flattening
|
|
135
|
+
--no-rename-globals Keep top-level variable/function names
|
|
136
|
+
--no-rename-locals Keep function-scoped names
|
|
137
|
+
-q, --quiet Suppress banner and status messages
|
|
138
|
+
--verbose Print diagnostic details to stderr
|
|
139
|
+
-h, --help Show this help
|
|
140
|
+
-v, --version Show the version
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The positive forms of the transform flags are accepted too, for example
|
|
144
|
+
`--string-array` or `--rename-globals`. For long flags, the last occurrence
|
|
145
|
+
wins.
|
|
146
|
+
|
|
147
|
+
### CLI examples
|
|
148
|
+
|
|
149
|
+
Obfuscate a single file with the defaults:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx javascript-obfuscator-lite src/app.js -o dist/app.js
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Use a compact build and keep license comments:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx javascript-obfuscator-lite -c -k src/app.js -o dist/app.js
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Turn off the most invasive transforms:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npx javascript-obfuscator-lite \
|
|
165
|
+
--no-control-flow \
|
|
166
|
+
--no-rename-globals \
|
|
167
|
+
--no-zombie-code \
|
|
168
|
+
src/app.js -o dist/app.js
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Process JSX:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
npx javascript-obfuscator-lite --parser-plugins jsx src/App.jsx -o dist/App.js
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Read from stdin and write to stdout:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
cat src/app.js | npx javascript-obfuscator-lite - --quiet > dist/app.js
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Exit codes
|
|
184
|
+
|
|
185
|
+
- `0` — success.
|
|
186
|
+
- `1` — invalid arguments, I/O error, parse error, or obfuscation error.
|
|
187
|
+
|
|
188
|
+
Status messages and the banner are written to **stderr**, so stdout contains
|
|
189
|
+
only generated code. Use `--quiet` to suppress all non-error output.
|
|
190
|
+
|
|
191
|
+
## API reference
|
|
192
|
+
|
|
193
|
+
### `obfuscate(source, options?)`
|
|
194
|
+
|
|
195
|
+
Returns the obfuscated code as a string.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
const { obfuscate } = require('javascript-obfuscator-lite');
|
|
199
|
+
|
|
200
|
+
const output = obfuscate('console.log("hello");', {
|
|
201
|
+
stringArray: false,
|
|
202
|
+
compact: true,
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
| Parameter | Type | Description |
|
|
207
|
+
| --- | --- | --- |
|
|
208
|
+
| `source` | `string` | JavaScript source code. A leading BOM is removed. |
|
|
209
|
+
| `options` | `object` | Optional overrides for the defaults. |
|
|
210
|
+
|
|
211
|
+
Throws `TypeError` for non-string input or invalid options, and `SyntaxError`
|
|
212
|
+
for invalid JavaScript.
|
|
213
|
+
|
|
214
|
+
### `obfuscateFile(inputPath, outputPath?, options?)`
|
|
215
|
+
|
|
216
|
+
Reads a file, obfuscates it, and optionally writes the result. Parent
|
|
217
|
+
directories for the output are created automatically. Returns the generated
|
|
218
|
+
code.
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// Write the result.
|
|
222
|
+
obfuscateFile('input.js', 'dist/output.js', { compact: true });
|
|
223
|
+
|
|
224
|
+
// Only return the result.
|
|
225
|
+
const code = obfuscateFile('input.js', { compact: true });
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### `normalizeOptions(options?)`
|
|
229
|
+
|
|
230
|
+
Validates options, applies aliases, and fills in defaults.
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
const { normalizeOptions } = require('javascript-obfuscator-lite');
|
|
234
|
+
|
|
235
|
+
const options = normalizeOptions({ string_array: false });
|
|
236
|
+
// { stringArray: false, ...all other defaults }
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### `defaultOptions`
|
|
240
|
+
|
|
241
|
+
A frozen object containing every default value.
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
const { defaultOptions } = require('javascript-obfuscator-lite');
|
|
245
|
+
|
|
246
|
+
console.log(defaultOptions.eval); // false
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### `version`
|
|
250
|
+
|
|
251
|
+
The installed package version.
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
const { version } = require('javascript-obfuscator-lite');
|
|
255
|
+
console.log(version);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Options
|
|
259
|
+
|
|
260
|
+
All options are optional. The defaults are aggressive, with one deliberate
|
|
261
|
+
exception: the `eval` transform is disabled by default.
|
|
262
|
+
|
|
263
|
+
| Option | Type | Default | Description |
|
|
264
|
+
| --- | --- | --- | --- |
|
|
265
|
+
| `stringArray` | `boolean` | `true` | Move string literals into a file-level array and reference them by index. |
|
|
266
|
+
| `stringReverse` | `boolean` | `true` | Replace strings with reverse/split/join expressions. Strings containing surrogate pairs are skipped. |
|
|
267
|
+
| `stringUnicode` | `boolean` | `true` | Escape string literals as `\uXXXX` sequences, including valid surrogate pairs. |
|
|
268
|
+
| `memberExpression` | `boolean` | `true` | Convert `object.property` to `object['\x...']`. |
|
|
269
|
+
| `numericLiteral` | `boolean` | `true` | Replace small integer literals with XOR expressions. |
|
|
270
|
+
| `binaryExpression` | `boolean` | `true` | Wrap binary variable initializers in an IIFE call. |
|
|
271
|
+
| `booleanLiteral` | `boolean` | `true` | Replace booleans with `!![]` / `![]`. |
|
|
272
|
+
| `assignmentJunk` | `boolean` | `true` | Wrap literal assignment values in an IIFE. |
|
|
273
|
+
| `zombieCode` | `boolean` | `true` | Insert dead variable declarations and assignments. |
|
|
274
|
+
| `controlFlow` | `boolean` | `true` | Flatten eligible function bodies into switch-based dispatchers. |
|
|
275
|
+
| `eval` | `boolean` | `false` | Encode expressions with `eval(String.fromCharCode(...))`. |
|
|
276
|
+
| `renameGlobals` | `boolean` | `true` | Rename top-level variables and functions. |
|
|
277
|
+
| `renameLocals` | `boolean` | `true` | Rename function-scoped variables and functions. |
|
|
278
|
+
| `compact` | `boolean` | `false` | Emit compact output. |
|
|
279
|
+
| `comments` | `boolean` | `false` | Preserve comments. |
|
|
280
|
+
| `parserPlugins` | `string[]` | `[]` | Extra Babel parser plugins, for example `['jsx']`. |
|
|
281
|
+
|
|
282
|
+
### Example configuration
|
|
283
|
+
|
|
284
|
+
```js
|
|
285
|
+
const { obfuscate } = require('javascript-obfuscator-lite');
|
|
286
|
+
|
|
287
|
+
const output = obfuscate(source, {
|
|
288
|
+
// Strong string and expression protection.
|
|
289
|
+
stringArray: true,
|
|
290
|
+
stringReverse: true,
|
|
291
|
+
stringUnicode: true,
|
|
292
|
+
memberExpression: true,
|
|
293
|
+
numericLiteral: true,
|
|
294
|
+
binaryExpression: true,
|
|
295
|
+
booleanLiteral: true,
|
|
296
|
+
assignmentJunk: true,
|
|
297
|
+
|
|
298
|
+
// Code-shape protection.
|
|
299
|
+
zombieCode: true,
|
|
300
|
+
controlFlow: true,
|
|
301
|
+
|
|
302
|
+
// Rename local names but keep the public global API stable.
|
|
303
|
+
renameGlobals: false,
|
|
304
|
+
renameLocals: true,
|
|
305
|
+
|
|
306
|
+
// Do not require eval at runtime.
|
|
307
|
+
eval: false,
|
|
308
|
+
|
|
309
|
+
// Readable output for debugging.
|
|
310
|
+
compact: false,
|
|
311
|
+
comments: true,
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## What it does
|
|
316
|
+
|
|
317
|
+
The obfuscator parses source with [Babel](https://babeljs.io/), applies AST
|
|
318
|
+
transforms, and generates JavaScript again. It does not execute the input and
|
|
319
|
+
does not send source code anywhere.
|
|
320
|
+
|
|
321
|
+
Transform order:
|
|
322
|
+
|
|
323
|
+
1. String reversal
|
|
324
|
+
2. Zombie declarations
|
|
325
|
+
3. Member-expression encoding
|
|
326
|
+
4. Assignment junk
|
|
327
|
+
5. Numeric literal encoding
|
|
328
|
+
6. Binary expression wrapping
|
|
329
|
+
7. Boolean literal encoding
|
|
330
|
+
8. Unicode string escaping
|
|
331
|
+
9. Control-flow flattening
|
|
332
|
+
10. String array construction
|
|
333
|
+
11. Identifier renaming
|
|
334
|
+
12. Eval encoding (only when `eval: true`)
|
|
335
|
+
|
|
336
|
+
Illustrative input:
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
function greet(name) {
|
|
340
|
+
const greeting = "Hello, ";
|
|
341
|
+
return greeting + name + "!";
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
console.log(greet("World"));
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Illustrative output (actual output is randomized):
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
var _0 = ["Hello, ", "!", "log"];
|
|
351
|
+
|
|
352
|
+
function _1(name) {
|
|
353
|
+
var _3 = _0[0];
|
|
354
|
+
return _3 + name + _0[1];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
console[_0[2]](_1("World"));
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Safety and limitations
|
|
361
|
+
|
|
362
|
+
### Obfuscation is not encryption
|
|
363
|
+
|
|
364
|
+
Obfuscation raises the cost of reading and copying code. It cannot make code
|
|
365
|
+
impossible to recover, and it is not a place to hide secrets, API keys, or
|
|
366
|
+
credentials. Anything shipped to a client can eventually be inspected.
|
|
367
|
+
|
|
368
|
+
### Global renaming can break external references
|
|
369
|
+
|
|
370
|
+
`renameGlobals` is enabled by default. It can break code that is accessed from
|
|
371
|
+
outside the obfuscated file, including:
|
|
372
|
+
|
|
373
|
+
- other scripts that read `window.someName` or `globalThis.someName`;
|
|
374
|
+
- inline HTML event handlers;
|
|
375
|
+
- names referenced from `eval("...")` or `new Function("...")` strings;
|
|
376
|
+
- string-based global lookups.
|
|
377
|
+
|
|
378
|
+
Exported ES module bindings and CommonJS export patterns are detected
|
|
379
|
+
automatically and protected from global renaming. For libraries, browser
|
|
380
|
+
globals, or code that must keep a stable top-level API, disable global renaming:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
npx javascript-obfuscator-lite --no-rename-globals input.js -o output.js
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Local renaming can also affect code that inspects function names, stack traces,
|
|
387
|
+
or `Function.prototype.toString()`. This is expected for obfuscation.
|
|
388
|
+
|
|
389
|
+
### `eval` is opt-in
|
|
390
|
+
|
|
391
|
+
The `eval` transform is disabled by default because:
|
|
392
|
+
|
|
393
|
+
- it requires `eval` to be allowed (for example, strict Content Security Policy
|
|
394
|
+
configurations often block it);
|
|
395
|
+
- it is slower at runtime;
|
|
396
|
+
- it produces larger output.
|
|
397
|
+
|
|
398
|
+
Enable it explicitly:
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
npx javascript-obfuscator-lite --eval input.js -o output.js
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
It is skipped in strict-mode code, ES modules, class bodies, `with` statements,
|
|
405
|
+
and scopes where `eval` or `String` is shadowed. It is not a security boundary.
|
|
406
|
+
|
|
407
|
+
### Dynamic code and `with`
|
|
408
|
+
|
|
409
|
+
Code that relies on dynamic name resolution can be incompatible with renaming.
|
|
410
|
+
This includes `eval("variableName")`, `new Function("return variableName")`, and
|
|
411
|
+
similar patterns. Disable `renameGlobals`/`renameLocals` for such code.
|
|
412
|
+
|
|
413
|
+
When a `with` statement is present, the obfuscator skips zombie code,
|
|
414
|
+
control-flow flattening, string arrays, and renaming for that file. The other
|
|
415
|
+
transforms still apply.
|
|
416
|
+
|
|
417
|
+
### TypeScript and Flow
|
|
418
|
+
|
|
419
|
+
TypeScript and Flow syntax are **not** supported. Transpile to JavaScript first
|
|
420
|
+
(for example with `tsc`, `esbuild`, or Babel) and then obfuscate the output.
|
|
421
|
+
Passing the `typescript`, `flow`, or `estree` parser plugin is rejected with a
|
|
422
|
+
clear error.
|
|
423
|
+
|
|
424
|
+
### JSX
|
|
425
|
+
|
|
426
|
+
JSX is supported when the parser plugin is enabled:
|
|
427
|
+
|
|
428
|
+
```js
|
|
429
|
+
obfuscate(source, { parserPlugins: ['jsx'] });
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
npx javascript-obfuscator-lite --parser-plugins jsx src/App.jsx -o dist/App.js
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
JSX attribute strings are preserved as raw text. JSX component names are
|
|
437
|
+
renamed consistently with their bindings. The obfuscator parses and emits JSX
|
|
438
|
+
as-is; it does not convert JSX to `React.createElement`. Keep your normal JSX
|
|
439
|
+
transpilation step in the build pipeline, or transpile JSX before obfuscating.
|
|
440
|
+
|
|
441
|
+
### Import attributes
|
|
442
|
+
|
|
443
|
+
Use the `importAttributes` parser plugin. Generated code uses the modern
|
|
444
|
+
`with { ... }` attribute syntax, so make sure the target runtime supports it.
|
|
445
|
+
|
|
446
|
+
### Randomized output
|
|
447
|
+
|
|
448
|
+
Names, XOR keys, control-flow layout, and other details are randomized on every
|
|
449
|
+
run. Two runs on the same input will produce different files. This is useful
|
|
450
|
+
for builds, but means output is not byte-for-byte reproducible.
|
|
451
|
+
|
|
452
|
+
### Output size and performance
|
|
453
|
+
|
|
454
|
+
Control-flow flattening and zombie code increase output size and can add a
|
|
455
|
+
small runtime cost. Disable them for size-sensitive bundles:
|
|
456
|
+
|
|
457
|
+
```bash
|
|
458
|
+
npx javascript-obfuscator-lite --no-control-flow --no-zombie-code input.js -o output.js
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
There are no source maps. Comments are removed unless `comments: true` /
|
|
462
|
+
`--comments` is used, so keep license headers with `--comments`.
|
|
463
|
+
|
|
464
|
+
## License
|
|
465
|
+
|
|
466
|
+
[MIT](https://opensource.org/licenses/MIT) © 2026 Wang Yinzhen
|
|
467
|
+
|
|
468
|
+
## Acknowledgements
|
|
469
|
+
|
|
470
|
+
Built with [Babel](https://babeljs.io/) for parsing, AST traversal, code
|
|
471
|
+
generation, and types.
|