Skip to content

Commit 9853e38

Browse files
feat: a new unassertCode function that returns the modified code and sourcemap
1 parent be91c60 commit 9853e38

File tree

5 files changed

+467
-40
lines changed

5 files changed

+467
-40
lines changed

package-lock.json

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
],
1717
"dependencies": {
18-
"estraverse": "^5.0.0"
18+
"estraverse": "^5.0.0",
19+
"magic-string": "^0.30.0"
1920
},
2021
"devDependencies": {
2122
"@twada/benchmark-commits": "^0.1.0",

src/index.d.mts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type MagicString, { SourceMap, SourceMapOptions } from "magic-string";
2+
import type { Node } from "acorn";
3+
import type { Visitor } from "estraverse";
4+
5+
export type UnassertAstOptions = Partial<{
6+
modules: string[];
7+
variables: string[];
8+
}>;
9+
10+
export type UnassertCodeOptions = UnassertAstOptions &
11+
Partial<{
12+
sourceMap: boolean | SourceMapOptions;
13+
}>;
14+
15+
export type CreateVisitorOptions = UnassertAstOptions &
16+
Partial<{
17+
code: MagicString;
18+
sourceMap: boolean
19+
}>;
20+
21+
export type UnassertCodeResult = {
22+
code: string;
23+
map: SourceMap | null;
24+
};
25+
26+
export function unassertAst(ast: Node, options?: UnassertAstOptions): Node;
27+
28+
export function unassertCode(
29+
code: string,
30+
ast: Node,
31+
options?: UnassertCodeOptions
32+
): UnassertCodeResult;
33+
export function unassertCode(
34+
code: MagicString,
35+
ast: Node,
36+
options?: UnassertCodeOptions
37+
): void;
38+
export function unassertCode(
39+
code: string | MagicString,
40+
ast: Node,
41+
options?: UnassertCodeOptions
42+
): void | UnassertCodeResult;
43+
44+
export function defaultOptions(): UnassertAstOptions;
45+
46+
export function createVisitor(options?: CreateVisitorOptions): Visitor;

0 commit comments

Comments
 (0)