@nudojs/parser 0.2.0 → 0.3.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 +16 -0
- package/README.md +25 -0
- package/dist/index.d.ts +51 -7
- package/dist/index.js +337 -14603
- package/package.json +14 -2
- package/src/__tests__/directives-inline.test.ts +95 -0
- package/src/__tests__/directives-phase3.test.ts +0 -18
- package/src/__tests__/directives.test.ts +285 -3
- package/src/__tests__/mock-directive.test.ts +115 -0
- package/src/__tests__/sinon-directive.test.ts +200 -0
- package/src/directives.ts +458 -16
- package/src/index.ts +11 -1
- package/src/parse.ts +12 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @nudojs/parser
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5786fa5: Improve `@nudo:mock` parsing for sinon-style stubs and share parse/strip with core.
|
|
8
|
+
|
|
9
|
+
- Support `stub().onFirstCall()`, `stub().callsFake(fn)`, and `sinon.`-prefixed chains as the same MockHelper shape TypeValue/Abs already consume.
|
|
10
|
+
- Drop the unused `ReturnsDirective` / `@nudo:returns` directive type (contracts use `@nudo:refine`).
|
|
11
|
+
- `parse()` now strips types unconditionally via core `parseSource` (shared AST cache).
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [5786fa5]
|
|
16
|
+
- Updated dependencies [5786fa5]
|
|
17
|
+
- @nudojs/core@0.3.0
|
|
18
|
+
|
|
3
19
|
## 0.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @nudojs/parser
|
|
2
|
+
|
|
3
|
+
Babel-based parser and directive extraction for [Nudo](https://github.com/nudojs/nudo).
|
|
4
|
+
|
|
5
|
+
## What is Nudo?
|
|
6
|
+
|
|
7
|
+
Nudo is a type inference engine for JavaScript. Instead of a separate type system, it runs your code with symbolic type values via abstract interpretation — no TypeScript, no build step.
|
|
8
|
+
|
|
9
|
+
## This package
|
|
10
|
+
|
|
11
|
+
`@nudojs/parser` handles source code parsing and Nudo directive extraction:
|
|
12
|
+
|
|
13
|
+
- **Parsing** — wraps Babel parser for JavaScript/TypeScript source files
|
|
14
|
+
- **Directives** — extracts `@nudo:case`, `@nudo:mock`, `@nudo:pure`, `@nudo:skip`, `@nudo:sample`, `@nudo:env`, `@nudo:mock-module`, `@nudo:as`, and `@nudo:replace` from comments. `@nudo:refine` / `@nudo:import` are parsed in `@nudojs/core` (`algebra/refine.ts`).
|
|
15
|
+
- **Type expressions** — parses inline type value expressions used in directives
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @nudojs/parser
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
[MIT](https://github.com/nudojs/nudo/blob/main/LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { File, Node } from '@babel/types';
|
|
2
|
-
import { TypeValue } from '@nudojs/core';
|
|
2
|
+
import { TypeValue, MockHelper } from '@nudojs/core';
|
|
3
|
+
export { stripTypes } from '@nudojs/core';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 与 core `parseSource` 同一实现与 AST LRU:
|
|
7
|
+
* 决策:parse() 统一做 TS 剥除(不按 .ts 路径开关)。理由:parse() 的产物被
|
|
8
|
+
* CLI/service/LSP/evaluator 全链消费,按调用方 opt-in 会漏掉无法感知文件扩展名
|
|
9
|
+
* 的消费方(analyzer 的模块解析、LSP 等);对纯 JS 源码剥除是结构性 no-op,
|
|
10
|
+
* 默认行为不变,因此无条件执行可让 .ts 输入在所有入口零接线生效。
|
|
11
|
+
*
|
|
12
|
+
* errorRecovery 走 core 的非缓存路径,避免污染会话 AST。
|
|
13
|
+
*/
|
|
14
|
+
declare function parse(source: string, opts?: {
|
|
15
|
+
errorRecovery?: boolean;
|
|
16
|
+
}): File;
|
|
5
17
|
|
|
6
18
|
type CaseDirective = {
|
|
7
19
|
kind: "case";
|
|
@@ -15,6 +27,19 @@ type MockDirective = {
|
|
|
15
27
|
name: string;
|
|
16
28
|
expression?: string;
|
|
17
29
|
fromPath?: string;
|
|
30
|
+
arrowFn?: {
|
|
31
|
+
params: string[];
|
|
32
|
+
body: Node;
|
|
33
|
+
paramPatterns: Node[];
|
|
34
|
+
};
|
|
35
|
+
sinonExpr?: SinonExpression;
|
|
36
|
+
nudoMock?: MockHelper;
|
|
37
|
+
};
|
|
38
|
+
type SinonExpression = {
|
|
39
|
+
type: "stub" | "spy" | "mock";
|
|
40
|
+
returnValue?: TypeValue;
|
|
41
|
+
resolvedValue?: TypeValue;
|
|
42
|
+
rejectedValue?: TypeValue;
|
|
18
43
|
};
|
|
19
44
|
type PureDirective = {
|
|
20
45
|
kind: "pure";
|
|
@@ -27,11 +52,28 @@ type SampleDirective = {
|
|
|
27
52
|
kind: "sample";
|
|
28
53
|
count: number;
|
|
29
54
|
};
|
|
30
|
-
type
|
|
31
|
-
kind: "
|
|
32
|
-
|
|
55
|
+
type EnvDirective = {
|
|
56
|
+
kind: "env";
|
|
57
|
+
envs: string[];
|
|
58
|
+
};
|
|
59
|
+
type MockModuleDirective = {
|
|
60
|
+
kind: "mock-module";
|
|
61
|
+
source: string;
|
|
62
|
+
names?: string[];
|
|
63
|
+
fromPath: string;
|
|
64
|
+
};
|
|
65
|
+
type AsDirective = {
|
|
66
|
+
kind: "as";
|
|
67
|
+
typeExpr: TypeValue;
|
|
68
|
+
};
|
|
69
|
+
type ReplaceDirective = {
|
|
70
|
+
kind: "replace";
|
|
71
|
+
targetSource: string;
|
|
72
|
+
typeExpr: TypeValue;
|
|
33
73
|
};
|
|
34
|
-
type
|
|
74
|
+
type InlineDirective = AsDirective | ReplaceDirective;
|
|
75
|
+
type FileDirective = EnvDirective | MockModuleDirective;
|
|
76
|
+
type Directive = CaseDirective | MockDirective | PureDirective | SkipDirective | SampleDirective;
|
|
35
77
|
type FunctionWithDirectives = {
|
|
36
78
|
node: Node;
|
|
37
79
|
name: string;
|
|
@@ -39,5 +81,7 @@ type FunctionWithDirectives = {
|
|
|
39
81
|
};
|
|
40
82
|
declare function parseTypeValueExpr(expr: string): TypeValue;
|
|
41
83
|
declare function extractDirectives(ast: Node): FunctionWithDirectives[];
|
|
84
|
+
declare function extractInlineDirectives(node: Node): InlineDirective[];
|
|
85
|
+
declare function extractFileDirectives(ast: Node): FileDirective[];
|
|
42
86
|
|
|
43
|
-
export { type CaseDirective, type Directive, type FunctionWithDirectives, type MockDirective, type PureDirective, type
|
|
87
|
+
export { type AsDirective, type CaseDirective, type Directive, type EnvDirective, type FileDirective, type FunctionWithDirectives, type InlineDirective, type MockDirective, type MockModuleDirective, type PureDirective, type ReplaceDirective, type SampleDirective, type SinonExpression, type SkipDirective, extractDirectives, extractFileDirectives, extractInlineDirectives, parse, parseTypeValueExpr };
|