@opensip-cli/lang-rust 0.1.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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +31 -0
- package/dist/__tests__/adapter.test.d.ts +2 -0
- package/dist/__tests__/adapter.test.d.ts.map +1 -0
- package/dist/__tests__/adapter.test.js +97 -0
- package/dist/__tests__/adapter.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +9 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +27 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/strip.test.d.ts +15 -0
- package/dist/__tests__/strip.test.d.ts.map +1 -0
- package/dist/__tests__/strip.test.js +183 -0
- package/dist/__tests__/strip.test.js.map +1 -0
- package/dist/__tests__/substrate.test.d.ts +2 -0
- package/dist/__tests__/substrate.test.d.ts.map +1 -0
- package/dist/__tests__/substrate.test.js +79 -0
- package/dist/__tests__/substrate.test.js.map +1 -0
- package/dist/adapter.d.ts +6 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +13 -0
- package/dist/adapter.js.map +1 -0
- package/dist/enclosing.d.ts +16 -0
- package/dist/enclosing.d.ts.map +1 -0
- package/dist/enclosing.js +28 -0
- package/dist/enclosing.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/parse.d.ts +17 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +21 -0
- package/dist/parse.js.map +1 -0
- package/dist/predicates.d.ts +24 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +26 -0
- package/dist/predicates.js.map +1 -0
- package/dist/shared-tree.d.ts +10 -0
- package/dist/shared-tree.d.ts.map +1 -0
- package/dist/shared-tree.js +14 -0
- package/dist/shared-tree.js.map +1 -0
- package/dist/strip.d.ts +5 -0
- package/dist/strip.d.ts.map +1 -0
- package/dist/strip.js +157 -0
- package/dist/strip.js.map +1 -0
- package/package.json +50 -0
- package/wasm/tree-sitter-rust.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
OpenSIP CLI
|
|
2
|
+
Copyright 2026 opensip-ai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this software except in compliance with the License. A copy of the License is
|
|
6
|
+
included in the LICENSE file and is also available at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Generated by scripts/build-package-readmes.mjs — do not edit by hand.
|
|
2
|
+
Change the package's "description" (or the generator template) and run
|
|
3
|
+
`pnpm docs:readmes`. CI enforces sync via `pnpm docs:readmes:check`. -->
|
|
4
|
+
|
|
5
|
+
# @opensip-cli/lang-rust
|
|
6
|
+
|
|
7
|
+
> Rust language adapter for opensip-cli
|
|
8
|
+
|
|
9
|
+
This is an **internal library** of the opensip-cli toolkit. It is published so the CLI and tools can depend on it; most users will not install it directly.
|
|
10
|
+
|
|
11
|
+
Part of [**opensip-cli**](https://github.com/opensip-ai/opensip-cli) — an open-source codebase-analysis toolkit: fitness checks (`fit`), static call-graph analysis (`graph`), and simulation (`sim`).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Most users install the CLI, which bundles the first-party tools:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://opensip.ai/cli/install.sh | bash
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This package is published for the CLI and advanced plugin authors; most users should not install `@opensip-cli/lang-rust` directly.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
- 📚 Project docs: https://opensip.ai/docs/opensip-cli/
|
|
26
|
+
- 🧭 Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.0/docs/public/70-reference/02-package-catalog.md
|
|
27
|
+
- 📦 Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.0/packages/languages/lang-rust
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Apache-2.0 © opensip-ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/adapter.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { rustAdapter } from '../adapter.js';
|
|
3
|
+
import { stripComments, stripStrings } from '../strip.js';
|
|
4
|
+
describe('rustAdapter', () => {
|
|
5
|
+
it('declares the expected identity and extension', () => {
|
|
6
|
+
expect(rustAdapter.id).toBe('rust');
|
|
7
|
+
expect(rustAdapter.fileExtensions).toContain('.rs');
|
|
8
|
+
expect(rustAdapter.aliases).toContain('rs');
|
|
9
|
+
});
|
|
10
|
+
it('parse() returns a real tree-sitter tree + source', () => {
|
|
11
|
+
const src = 'fn main() {\n println!("hi");\n}';
|
|
12
|
+
const tree = rustAdapter.parse(src, 'foo.rs');
|
|
13
|
+
expect(tree).not.toBeNull();
|
|
14
|
+
expect(tree?.source).toBe(src);
|
|
15
|
+
expect(tree?.tree.rootNode.type).toBe('source_file');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('rust stripStrings', () => {
|
|
19
|
+
it('replaces regular string content but preserves length', () => {
|
|
20
|
+
const src = 'let x = "hello world";';
|
|
21
|
+
const out = stripStrings(src);
|
|
22
|
+
expect(out.length).toBe(src.length);
|
|
23
|
+
expect(out).not.toContain('hello');
|
|
24
|
+
expect(out).toContain('let x =');
|
|
25
|
+
expect(out).toContain('"');
|
|
26
|
+
});
|
|
27
|
+
it('handles raw strings r"..."', () => {
|
|
28
|
+
const src = String.raw `let p = r"C:\path\to\file";`;
|
|
29
|
+
const out = stripStrings(src);
|
|
30
|
+
expect(out.length).toBe(src.length);
|
|
31
|
+
expect(out).not.toContain('C:');
|
|
32
|
+
expect(out).not.toContain('path');
|
|
33
|
+
});
|
|
34
|
+
it('handles raw strings with hashes r#"..."#', () => {
|
|
35
|
+
const src = 'let s = r#"contains "quotes" inside"#;';
|
|
36
|
+
const out = stripStrings(src);
|
|
37
|
+
expect(out.length).toBe(src.length);
|
|
38
|
+
expect(out).not.toContain('quotes');
|
|
39
|
+
expect(out).toContain('let s =');
|
|
40
|
+
});
|
|
41
|
+
it('handles byte strings b"..."', () => {
|
|
42
|
+
const src = 'let b = b"binary";';
|
|
43
|
+
const out = stripStrings(src);
|
|
44
|
+
expect(out.length).toBe(src.length);
|
|
45
|
+
expect(out).not.toContain('binary');
|
|
46
|
+
});
|
|
47
|
+
it('preserves char literals (single chars are code, not strings)', () => {
|
|
48
|
+
const src = "let c = 'x';";
|
|
49
|
+
const out = stripStrings(src);
|
|
50
|
+
expect(out).toBe(src);
|
|
51
|
+
});
|
|
52
|
+
it('preserves lifetime annotations', () => {
|
|
53
|
+
const src = "fn foo<'a>(x: &'a str) {}";
|
|
54
|
+
// The outer "" string body is empty; lifetimes 'a should remain
|
|
55
|
+
const out = stripStrings(src);
|
|
56
|
+
expect(out).toContain("'a");
|
|
57
|
+
});
|
|
58
|
+
it('preserves newlines inside multi-line strings', () => {
|
|
59
|
+
const src = 'let x = "line1\nline2";';
|
|
60
|
+
const out = stripStrings(src);
|
|
61
|
+
expect(out.length).toBe(src.length);
|
|
62
|
+
// Newline must survive
|
|
63
|
+
expect(out.split('\n').length).toBe(src.split('\n').length);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('rust stripComments', () => {
|
|
67
|
+
it('replaces line comments', () => {
|
|
68
|
+
const src = 'let x = 1; // a line comment';
|
|
69
|
+
const out = stripComments(src);
|
|
70
|
+
expect(out.length).toBe(src.length);
|
|
71
|
+
expect(out).not.toContain('line comment');
|
|
72
|
+
expect(out).toContain('let x = 1;');
|
|
73
|
+
});
|
|
74
|
+
it('replaces block comments', () => {
|
|
75
|
+
const src = 'let x = /* inline */ 1;';
|
|
76
|
+
const out = stripComments(src);
|
|
77
|
+
expect(out.length).toBe(src.length);
|
|
78
|
+
expect(out).not.toContain('inline');
|
|
79
|
+
expect(out).toContain('let x =');
|
|
80
|
+
});
|
|
81
|
+
it('handles nested block comments', () => {
|
|
82
|
+
const src = 'let x = /* outer /* inner */ outer-end */ 1;';
|
|
83
|
+
const out = stripComments(src);
|
|
84
|
+
expect(out.length).toBe(src.length);
|
|
85
|
+
expect(out).not.toContain('outer');
|
|
86
|
+
expect(out).not.toContain('inner');
|
|
87
|
+
expect(out).toContain('let x =');
|
|
88
|
+
expect(out).toContain('1;');
|
|
89
|
+
});
|
|
90
|
+
it('also strips strings', () => {
|
|
91
|
+
const src = '// hi\nlet s = "secret";';
|
|
92
|
+
const out = stripComments(src);
|
|
93
|
+
expect(out).not.toContain('secret');
|
|
94
|
+
expect(out).not.toContain('hi');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=adapter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.test.js","sourceRoot":"","sources":["../../src/__tests__/adapter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,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E;QAC7B,MAAM,GAAG,GAAG,0BAA0B,CAAC;QACvC,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smoke test for the package barrel.
|
|
3
|
+
*
|
|
4
|
+
* The `src/index.ts` re-exports each public symbol. Importing through the
|
|
5
|
+
* barrel keeps the public surface honest: if a future refactor renames or
|
|
6
|
+
* forgets to re-export one of these, this test fails fast.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=index.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smoke test for the package barrel.
|
|
3
|
+
*
|
|
4
|
+
* The `src/index.ts` re-exports each public symbol. Importing through the
|
|
5
|
+
* barrel keeps the public surface honest: if a future refactor renames or
|
|
6
|
+
* forgets to re-export one of these, this test fails fast.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import * as pkg from '../index.js';
|
|
10
|
+
describe('@opensip-cli/lang-rust barrel', () => {
|
|
11
|
+
it('re-exports the rust adapter and adapters array', () => {
|
|
12
|
+
expect(pkg.rustAdapter).toBeDefined();
|
|
13
|
+
expect(pkg.rustAdapter.id).toBe('rust');
|
|
14
|
+
expect(Array.isArray(pkg.adapters)).toBe(true);
|
|
15
|
+
expect(pkg.adapters).toContain(pkg.rustAdapter);
|
|
16
|
+
});
|
|
17
|
+
it('re-exports parseRust', () => {
|
|
18
|
+
expect(typeof pkg.parseRust).toBe('function');
|
|
19
|
+
const tree = pkg.parseRust('fn main() {}', 'main.rs');
|
|
20
|
+
expect(tree?.tree.rootNode.type).toBe('source_file');
|
|
21
|
+
});
|
|
22
|
+
it('re-exports stripStrings and stripComments', () => {
|
|
23
|
+
expect(typeof pkg.stripStrings).toBe('function');
|
|
24
|
+
expect(typeof pkg.stripComments).toBe('function');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,CAAC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,OAAO,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,CAAC,OAAO,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge-case tests for the Rust string/comment stripper.
|
|
3
|
+
*
|
|
4
|
+
* The hand-written lexer in `strip.ts` has several state-machine branches
|
|
5
|
+
* that aren't exercised by the basic happy-path coverage in
|
|
6
|
+
* `adapter.test.ts`: unterminated literals, raw-string ambiguity, char
|
|
7
|
+
* literals with escapes, lifetime annotations next to weird tokens, and
|
|
8
|
+
* `\x` / `\u{...}` escape sequences inside regular strings.
|
|
9
|
+
*
|
|
10
|
+
* Each test in this file targets one of those branches so that a future
|
|
11
|
+
* regression — say, off-by-one on the unterminated-string fallback — gets
|
|
12
|
+
* caught by CI rather than discovered in a real Rust file.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=strip.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/strip.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge-case tests for the Rust string/comment stripper.
|
|
3
|
+
*
|
|
4
|
+
* The hand-written lexer in `strip.ts` has several state-machine branches
|
|
5
|
+
* that aren't exercised by the basic happy-path coverage in
|
|
6
|
+
* `adapter.test.ts`: unterminated literals, raw-string ambiguity, char
|
|
7
|
+
* literals with escapes, lifetime annotations next to weird tokens, and
|
|
8
|
+
* `\x` / `\u{...}` escape sequences inside regular strings.
|
|
9
|
+
*
|
|
10
|
+
* Each test in this file targets one of those branches so that a future
|
|
11
|
+
* regression — say, off-by-one on the unterminated-string fallback — gets
|
|
12
|
+
* caught by CI rather than discovered in a real Rust file.
|
|
13
|
+
*/
|
|
14
|
+
import { describe, expect, it } from 'vitest';
|
|
15
|
+
import { stripComments, stripStrings } from '../strip.js';
|
|
16
|
+
describe('rust stripStrings — unterminated literals', () => {
|
|
17
|
+
it('records an unterminated regular string up to EOF', () => {
|
|
18
|
+
const src = 'let s = "unterminated string';
|
|
19
|
+
const out = stripStrings(src);
|
|
20
|
+
expect(out.length).toBe(src.length);
|
|
21
|
+
// "unterminated" should be replaced by whitespace
|
|
22
|
+
expect(out).not.toContain('unterminated');
|
|
23
|
+
expect(out).not.toContain('string');
|
|
24
|
+
expect(out.startsWith('let s = "')).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
it('records an unterminated raw string up to EOF', () => {
|
|
27
|
+
// r#"..."# but the closing #" never appears
|
|
28
|
+
const src = 'let s = r#"never closes';
|
|
29
|
+
const out = stripStrings(src);
|
|
30
|
+
expect(out.length).toBe(src.length);
|
|
31
|
+
expect(out).not.toContain('never');
|
|
32
|
+
expect(out).not.toContain('closes');
|
|
33
|
+
});
|
|
34
|
+
it('records an unterminated raw string with multiple hashes', () => {
|
|
35
|
+
const src = 'let s = r##"opening but missing close';
|
|
36
|
+
const out = stripStrings(src);
|
|
37
|
+
expect(out.length).toBe(src.length);
|
|
38
|
+
expect(out).not.toContain('opening');
|
|
39
|
+
expect(out).not.toContain('missing');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('rust stripStrings — `r` ambiguity', () => {
|
|
43
|
+
// The lexer enters the raw-string branch whenever `r` is followed by `"`
|
|
44
|
+
// or `#`. If it then runs out of input before finding a `"`, it has to
|
|
45
|
+
// back out (treat the `r` as a normal identifier character) and advance
|
|
46
|
+
// by one. These inputs hit that fallback.
|
|
47
|
+
it('treats trailing `r#` (no quote) as identifier-like, not as a raw string', () => {
|
|
48
|
+
const src = 'let r###';
|
|
49
|
+
// Should not throw, should not hang, should not strip anything
|
|
50
|
+
const out = stripStrings(src);
|
|
51
|
+
expect(out).toBe(src);
|
|
52
|
+
});
|
|
53
|
+
it('treats `r##` followed by non-quote text as not-a-raw-string', () => {
|
|
54
|
+
const src = 'fn foo() { r##xyz }';
|
|
55
|
+
const out = stripStrings(src);
|
|
56
|
+
// Nothing was a string, so output equals input
|
|
57
|
+
expect(out).toBe(src);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('rust stripStrings — char literals and lifetimes', () => {
|
|
61
|
+
it(String.raw `handles char literal with escape: \n`, () => {
|
|
62
|
+
const src = String.raw `let c = '\n';`;
|
|
63
|
+
const out = stripStrings(src);
|
|
64
|
+
// Char literals are preserved as-is by the stripper
|
|
65
|
+
expect(out).toBe(src);
|
|
66
|
+
});
|
|
67
|
+
it(String.raw `handles char literal with escaped quote: \'`, () => {
|
|
68
|
+
const src = String.raw `let c = '\'';`;
|
|
69
|
+
const out = stripStrings(src);
|
|
70
|
+
expect(out).toBe(src);
|
|
71
|
+
});
|
|
72
|
+
it(String.raw `handles char literal with unicode escape: \u{1F600}`, () => {
|
|
73
|
+
const src = String.raw `let c = '\u{1F600}';`;
|
|
74
|
+
const out = stripStrings(src);
|
|
75
|
+
expect(out).toBe(src);
|
|
76
|
+
});
|
|
77
|
+
it('treats trailing apostrophe at EOF as a lifetime-style token', () => {
|
|
78
|
+
// After-byte is undefined — the lexer's safety branch.
|
|
79
|
+
const src = "let x = 1;'";
|
|
80
|
+
const out = stripStrings(src);
|
|
81
|
+
expect(out.length).toBe(src.length);
|
|
82
|
+
});
|
|
83
|
+
it('distinguishes a char literal from a lifetime when both are nearby', () => {
|
|
84
|
+
const src = "fn f<'a>() { let c = 'x'; let _: &'a str; }";
|
|
85
|
+
const out = stripStrings(src);
|
|
86
|
+
// Lifetimes 'a remain; char 'x' is preserved as code (not stripped).
|
|
87
|
+
expect(out).toContain("'a");
|
|
88
|
+
expect(out).toContain("'x'");
|
|
89
|
+
});
|
|
90
|
+
it('handles a lifetime followed by an escape-like sequence in scan window', () => {
|
|
91
|
+
// 'static is a long lifetime — no closing quote within ~6 chars.
|
|
92
|
+
const src = 'fn foo() -> &\'static str { "hi" }';
|
|
93
|
+
const out = stripStrings(src);
|
|
94
|
+
// 'static must survive
|
|
95
|
+
expect(out).toContain("'static");
|
|
96
|
+
// The "hi" content should be stripped
|
|
97
|
+
expect(out).not.toContain('hi');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('rust stripStrings — regular-string escape sequences', () => {
|
|
101
|
+
it(String.raw `handles \x## hex escapes inside regular strings`, () => {
|
|
102
|
+
const src = String.raw `let s = "before\x41after";`;
|
|
103
|
+
const out = stripStrings(src);
|
|
104
|
+
expect(out.length).toBe(src.length);
|
|
105
|
+
expect(out).not.toContain('before');
|
|
106
|
+
expect(out).not.toContain('after');
|
|
107
|
+
// The opening/closing quotes must remain
|
|
108
|
+
expect(out).toContain('let s = "');
|
|
109
|
+
});
|
|
110
|
+
it(String.raw `handles \u{...} unicode escapes inside regular strings`, () => {
|
|
111
|
+
const src = String.raw `let s = "emoji\u{1F600}tail";`;
|
|
112
|
+
const out = stripStrings(src);
|
|
113
|
+
expect(out.length).toBe(src.length);
|
|
114
|
+
expect(out).not.toContain('emoji');
|
|
115
|
+
expect(out).not.toContain('tail');
|
|
116
|
+
});
|
|
117
|
+
it(String.raw `handles \u without braces (treat as 2-char escape)`, () => {
|
|
118
|
+
// The lexer's else-branch for \u not followed by `{`: it advances 2
|
|
119
|
+
// more chars after the initial \u consumption.
|
|
120
|
+
const src = String.raw `let s = "xꮫ y";`;
|
|
121
|
+
const out = stripStrings(src);
|
|
122
|
+
expect(out.length).toBe(src.length);
|
|
123
|
+
expect(out).not.toContain('y');
|
|
124
|
+
});
|
|
125
|
+
it(String.raw `handles unterminated \u{...} escape that runs to EOF`, () => {
|
|
126
|
+
// \u{ with no closing brace — exercises the inner while-loop bound.
|
|
127
|
+
const src = String.raw `let s = "x\u{12345`;
|
|
128
|
+
const out = stripStrings(src);
|
|
129
|
+
expect(out.length).toBe(src.length);
|
|
130
|
+
});
|
|
131
|
+
it(String.raw `handles \\ (escaped backslash) inside a string`, () => {
|
|
132
|
+
const src = String.raw `let s = "a\\b";`;
|
|
133
|
+
const out = stripStrings(src);
|
|
134
|
+
expect(out.length).toBe(src.length);
|
|
135
|
+
expect(out).not.toContain(String.raw `a\b`);
|
|
136
|
+
});
|
|
137
|
+
it('strips byte string content with escapes', () => {
|
|
138
|
+
const src = String.raw `let b = b"\x00\x01end";`;
|
|
139
|
+
const out = stripStrings(src);
|
|
140
|
+
expect(out.length).toBe(src.length);
|
|
141
|
+
expect(out).not.toContain('end');
|
|
142
|
+
});
|
|
143
|
+
it('handles byte-raw strings br"..."', () => {
|
|
144
|
+
const src = String.raw `let b = br"raw\bytes";`;
|
|
145
|
+
const out = stripStrings(src);
|
|
146
|
+
expect(out.length).toBe(src.length);
|
|
147
|
+
expect(out).not.toContain('raw');
|
|
148
|
+
expect(out).not.toContain('bytes');
|
|
149
|
+
});
|
|
150
|
+
it('handles byte-raw strings with hashes br#"..."#', () => {
|
|
151
|
+
const src = 'let b = br#"has "quotes" within"#;';
|
|
152
|
+
const out = stripStrings(src);
|
|
153
|
+
expect(out.length).toBe(src.length);
|
|
154
|
+
expect(out).not.toContain('quotes');
|
|
155
|
+
expect(out).not.toContain('within');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('rust stripComments — additional cases', () => {
|
|
159
|
+
it('handles unterminated block comment (runs to EOF)', () => {
|
|
160
|
+
const src = 'let x = 1; /* unterminated\nmore content';
|
|
161
|
+
const out = stripComments(src);
|
|
162
|
+
expect(out.length).toBe(src.length);
|
|
163
|
+
expect(out).not.toContain('unterminated');
|
|
164
|
+
expect(out).not.toContain('more content');
|
|
165
|
+
expect(out).toContain('let x = 1;');
|
|
166
|
+
});
|
|
167
|
+
it('preserves newline structure inside block comments', () => {
|
|
168
|
+
const src = '/* a\n b\n c */let x = 1;';
|
|
169
|
+
const out = stripComments(src);
|
|
170
|
+
expect(out.length).toBe(src.length);
|
|
171
|
+
expect(out.split('\n').length).toBe(src.split('\n').length);
|
|
172
|
+
expect(out).toContain('let x = 1;');
|
|
173
|
+
});
|
|
174
|
+
it('handles a comment immediately followed by a string', () => {
|
|
175
|
+
const src = '/*c*/"s"';
|
|
176
|
+
const out = stripComments(src);
|
|
177
|
+
expect(out.length).toBe(src.length);
|
|
178
|
+
expect(out).not.toContain('c');
|
|
179
|
+
expect(out).not.toContain('s');
|
|
180
|
+
expect(out).toContain('"');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=strip.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.test.js","sourceRoot":"","sources":["../../src/__tests__/strip.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACzD,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,GAAG,GAAG,8BAA8B,CAAC;QAC3C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpC,kDAAkD;QAClD,MAAM,C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