@nudojs/parser 0.1.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 +31 -0
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.d.ts +51 -7
- package/dist/index.js +337 -14603
- package/package.json +24 -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,36 @@
|
|
|
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
|
+
|
|
19
|
+
## 0.2.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 6c38283: docs and ci
|
|
24
|
+
- 9f7f819: fix pkg info
|
|
25
|
+
- c175f71: version
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [6c38283]
|
|
30
|
+
- Updated dependencies [9f7f819]
|
|
31
|
+
- Updated dependencies [c175f71]
|
|
32
|
+
- @nudojs/core@0.2.0
|
|
33
|
+
|
|
3
34
|
## 0.1.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nudo Contributors
|
|
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
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 };
|