@opensip-cli/lang-go 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 +231 -0
- package/dist/__tests__/adapter.test.js.map +1 -0
- package/dist/__tests__/strip.test.d.ts +2 -0
- package/dist/__tests__/strip.test.d.ts.map +1 -0
- package/dist/__tests__/strip.test.js +53 -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 +72 -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 +12 -0
- package/dist/enclosing.d.ts.map +1 -0
- package/dist/enclosing.js +19 -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 +23 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +23 -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 +80 -0
- package/dist/strip.js.map +1 -0
- package/package.json +51 -0
- package/wasm/tree-sitter-go.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-go
|
|
6
|
+
|
|
7
|
+
> Go 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-go` 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-go
|
|
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,231 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { goAdapter } from '../adapter.js';
|
|
3
|
+
import { stripComments, stripStrings } from '../strip.js';
|
|
4
|
+
describe('goAdapter', () => {
|
|
5
|
+
it('declares the expected identity and extension', () => {
|
|
6
|
+
expect(goAdapter.id).toBe('go');
|
|
7
|
+
expect(goAdapter.fileExtensions).toContain('.go');
|
|
8
|
+
});
|
|
9
|
+
it('parse() returns a real tree-sitter tree + source', () => {
|
|
10
|
+
const src = 'package main\n\nfunc main() {}\n';
|
|
11
|
+
const tree = goAdapter.parse(src, 'foo.go');
|
|
12
|
+
expect(tree).not.toBeNull();
|
|
13
|
+
expect(tree?.source).toBe(src);
|
|
14
|
+
expect(tree?.tree.rootNode.type).toBe('source_file');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('go stripStrings', () => {
|
|
18
|
+
it('replaces regular string content but preserves length', () => {
|
|
19
|
+
const src = 's := "hello world"';
|
|
20
|
+
const out = stripStrings(src);
|
|
21
|
+
expect(out.length).toBe(src.length);
|
|
22
|
+
expect(out).not.toContain('hello');
|
|
23
|
+
expect(out).toContain('s :=');
|
|
24
|
+
expect(out).toContain('"');
|
|
25
|
+
});
|
|
26
|
+
it('strips raw multi-line string body and preserves newlines', () => {
|
|
27
|
+
const src = 's := `\nline1\nline2\n`';
|
|
28
|
+
const out = stripStrings(src);
|
|
29
|
+
expect(out.length).toBe(src.length);
|
|
30
|
+
expect(out).not.toContain('line1');
|
|
31
|
+
expect(out).not.toContain('line2');
|
|
32
|
+
// Newlines must survive so line numbers stay stable
|
|
33
|
+
expect(out.split('\n').length).toBe(src.split('\n').length);
|
|
34
|
+
expect(out).toContain('s :=');
|
|
35
|
+
expect(out).toContain('`');
|
|
36
|
+
});
|
|
37
|
+
it('preserves rune literals (single chars are code, not strings)', () => {
|
|
38
|
+
const src = "c := 'x'";
|
|
39
|
+
const out = stripStrings(src);
|
|
40
|
+
expect(out).toBe(src);
|
|
41
|
+
});
|
|
42
|
+
it('strips entire content of regular string with escape', () => {
|
|
43
|
+
const src = String.raw `s := "tab\there"`;
|
|
44
|
+
const out = stripStrings(src);
|
|
45
|
+
expect(out.length).toBe(src.length);
|
|
46
|
+
expect(out).not.toContain('tab');
|
|
47
|
+
expect(out).not.toContain('here');
|
|
48
|
+
expect(out).toContain('s :=');
|
|
49
|
+
expect(out).toContain('"');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('go stripComments', () => {
|
|
53
|
+
it('replaces line comments', () => {
|
|
54
|
+
const src = 'x := 1 // comment';
|
|
55
|
+
const out = stripComments(src);
|
|
56
|
+
expect(out.length).toBe(src.length);
|
|
57
|
+
expect(out).not.toContain('comment');
|
|
58
|
+
expect(out).toContain('x := 1');
|
|
59
|
+
});
|
|
60
|
+
it('replaces block comments', () => {
|
|
61
|
+
const src = 'x := /* hi */ 2';
|
|
62
|
+
const out = stripComments(src);
|
|
63
|
+
expect(out.length).toBe(src.length);
|
|
64
|
+
expect(out).not.toContain('hi');
|
|
65
|
+
expect(out).toContain('x :=');
|
|
66
|
+
expect(out).toContain('2');
|
|
67
|
+
});
|
|
68
|
+
it('strips string body when // appears inside a string', () => {
|
|
69
|
+
const src = 's := "// not a comment"';
|
|
70
|
+
const out = stripComments(src);
|
|
71
|
+
expect(out.length).toBe(src.length);
|
|
72
|
+
expect(out).not.toContain('not a comment');
|
|
73
|
+
// Outside the string, structure remains intact
|
|
74
|
+
expect(out).toContain('s :=');
|
|
75
|
+
expect(out).toContain('"');
|
|
76
|
+
});
|
|
77
|
+
it('also strips strings', () => {
|
|
78
|
+
const src = '// hi\ns := "secret"';
|
|
79
|
+
const out = stripComments(src);
|
|
80
|
+
expect(out).not.toContain('secret');
|
|
81
|
+
expect(out).not.toContain('hi');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
// Edge-case regression tests (Wave 1 P0 — audit findings F4/F5).
|
|
85
|
+
// These pin behavior that the current scanner already handles correctly so
|
|
86
|
+
// future refactors of strip.ts cannot silently regress them.
|
|
87
|
+
describe('go strip edge cases', () => {
|
|
88
|
+
describe('// inside raw string', () => {
|
|
89
|
+
it('does not treat // inside backticks as a comment, but strips trailing line comment', () => {
|
|
90
|
+
const src = 'x := `// not a comment`\ny := 1 // real comment';
|
|
91
|
+
const out = stripComments(src);
|
|
92
|
+
expect(out.length).toBe(src.length);
|
|
93
|
+
// Raw-string body is replaced by whitespace, including the // sequence
|
|
94
|
+
expect(out).not.toContain('// not a comment');
|
|
95
|
+
expect(out).not.toContain('not a comment');
|
|
96
|
+
// The trailing real comment text is also stripped
|
|
97
|
+
expect(out).not.toContain('real comment');
|
|
98
|
+
// Code structure outside the string/comment is preserved
|
|
99
|
+
expect(out).toContain('x :=');
|
|
100
|
+
expect(out).toContain('y := 1');
|
|
101
|
+
expect(out).toContain('`');
|
|
102
|
+
});
|
|
103
|
+
it('stripStrings alone does not interpret // inside raw string as a comment', () => {
|
|
104
|
+
const src = 'x := `// not a comment`';
|
|
105
|
+
const out = stripStrings(src);
|
|
106
|
+
expect(out.length).toBe(src.length);
|
|
107
|
+
expect(out).not.toContain('not a comment');
|
|
108
|
+
expect(out).toContain('x :=');
|
|
109
|
+
expect(out).toContain('`');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('unterminated literals (graceful handling)', () => {
|
|
113
|
+
it('does not crash on an unterminated raw string and preserves length', () => {
|
|
114
|
+
const src = 'x := `unfinished';
|
|
115
|
+
const out = stripStrings(src);
|
|
116
|
+
expect(out.length).toBe(src.length);
|
|
117
|
+
expect(out).not.toContain('unfinished');
|
|
118
|
+
expect(out).toContain('x :=');
|
|
119
|
+
expect(out).toContain('`');
|
|
120
|
+
});
|
|
121
|
+
it('does not crash on an unterminated block comment and preserves length', () => {
|
|
122
|
+
const src = 'x := 1 /* never closed';
|
|
123
|
+
const out = stripComments(src);
|
|
124
|
+
expect(out.length).toBe(src.length);
|
|
125
|
+
expect(out).not.toContain('never closed');
|
|
126
|
+
expect(out).toContain('x := 1');
|
|
127
|
+
});
|
|
128
|
+
it('does not crash on an unterminated interpreted string and preserves length', () => {
|
|
129
|
+
const src = 's := "unfinished';
|
|
130
|
+
const out = stripStrings(src);
|
|
131
|
+
expect(out.length).toBe(src.length);
|
|
132
|
+
expect(out).toContain('s :=');
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('dispatch-order regressions (MISSED-1)', () => {
|
|
136
|
+
it('block comment with embedded `*/` does not nest — first `*/` terminates', () => {
|
|
137
|
+
// Go block comments are non-nesting (unlike Rust). Source:
|
|
138
|
+
// /* a */ b */
|
|
139
|
+
// The first `*/` closes the comment; ` b */` is plain code.
|
|
140
|
+
const src = '/* a */ b */';
|
|
141
|
+
const out = stripComments(src);
|
|
142
|
+
expect(out.length).toBe(src.length);
|
|
143
|
+
// The text inside the comment is gone.
|
|
144
|
+
expect(out).not.toContain('a');
|
|
145
|
+
// The trailing `b */` survives as code.
|
|
146
|
+
expect(out).toContain('b');
|
|
147
|
+
expect(out).toContain('*/');
|
|
148
|
+
});
|
|
149
|
+
it('rune literal inside a raw string is treated as raw content, not as a rune', () => {
|
|
150
|
+
// Source: x := `'a'`
|
|
151
|
+
// The raw-string branch must win over the rune branch — the `'a'`
|
|
152
|
+
// must NOT be interpreted as a rune literal interrupting the
|
|
153
|
+
// raw-string scan.
|
|
154
|
+
const src = "x := `'a'`";
|
|
155
|
+
const out = stripStrings(src);
|
|
156
|
+
expect(out.length).toBe(src.length);
|
|
157
|
+
// The body is stripped (raw-string region).
|
|
158
|
+
expect(out).not.toContain("'a'");
|
|
159
|
+
// The opening/closing backticks survive.
|
|
160
|
+
expect(out).toContain('`');
|
|
161
|
+
expect(out).toContain('x :=');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe('rune literals — pin current permissive behavior (audit F4)', () => {
|
|
165
|
+
// The audit notes the rune scanner is permissive: it accepts variable
|
|
166
|
+
// escape lengths rather than enforcing Go's exact rules (\uXXXX = 4 hex,
|
|
167
|
+
// \UXXXXXXXX = 8 hex). Today this is a non-issue because rune literals
|
|
168
|
+
// are preserved as code (not stripped) and surrounding code keeps the
|
|
169
|
+
// scanner aligned. These tests pin the current behavior so any future
|
|
170
|
+
// tightening of the scanner becomes a visible change.
|
|
171
|
+
it('preserves a single-char rune literal', () => {
|
|
172
|
+
const src = "r := 'a'";
|
|
173
|
+
const out = stripStrings(src);
|
|
174
|
+
expect(out).toBe(src);
|
|
175
|
+
});
|
|
176
|
+
it(String.raw `preserves a rune literal with a simple escape ('\n')`, () => {
|
|
177
|
+
const src = String.raw `r := '\n'`;
|
|
178
|
+
const out = stripStrings(src);
|
|
179
|
+
expect(out).toBe(src);
|
|
180
|
+
});
|
|
181
|
+
it(String.raw `preserves a rune literal with a 4-hex Unicode escape ('\u0041')`, () => {
|
|
182
|
+
const src = String.raw `r := 'A'`;
|
|
183
|
+
const out = stripStrings(src);
|
|
184
|
+
expect(out).toBe(src);
|
|
185
|
+
});
|
|
186
|
+
it(String.raw `preserves a rune literal with an 8-hex long Unicode escape ('\U0001F600')`, () => {
|
|
187
|
+
// F4 case: scanner is permissive about escape length; pin that the
|
|
188
|
+
// long-Unicode form still passes through unchanged today.
|
|
189
|
+
const src = String.raw `r := '\U0001F600'`;
|
|
190
|
+
const out = stripStrings(src);
|
|
191
|
+
expect(out).toBe(src);
|
|
192
|
+
});
|
|
193
|
+
it('preserves multiple rune literals in sequence alongside strings', () => {
|
|
194
|
+
const src = String.raw `a := 'a'; b := '\n'; c := 'A'; s := "hello"`;
|
|
195
|
+
const out = stripStrings(src);
|
|
196
|
+
expect(out.length).toBe(src.length);
|
|
197
|
+
// Rune literals survive verbatim
|
|
198
|
+
expect(out).toContain("'a'");
|
|
199
|
+
expect(out).toContain(String.raw `'\n'`);
|
|
200
|
+
expect(out).toContain(String.raw `'A'`);
|
|
201
|
+
// The interpreted string body is stripped
|
|
202
|
+
expect(out).not.toContain('hello');
|
|
203
|
+
expect(out).toContain('"');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
describe('length preservation — explicit assert across edge cases', () => {
|
|
207
|
+
const cases = [
|
|
208
|
+
{ name: '// inside raw string', src: 'x := `// not a comment`\ny := 1 // real' },
|
|
209
|
+
{ name: 'unterminated raw string', src: 'x := `unfinished' },
|
|
210
|
+
{ name: 'unterminated block comment', src: 'x := 1 /* never closed' },
|
|
211
|
+
{ name: 'unterminated interpreted string', src: 's := "unfinished' },
|
|
212
|
+
{ name: 'rune single char', src: "r := 'a'" },
|
|
213
|
+
{ name: 'rune simple escape', src: String.raw `r := '\n'` },
|
|
214
|
+
{ name: String.raw `rune \u escape`, src: String.raw `r := 'A'` },
|
|
215
|
+
{ name: String.raw `rune \U escape`, src: String.raw `r := '\U0001F600'` },
|
|
216
|
+
{
|
|
217
|
+
name: 'mixed runes and string',
|
|
218
|
+
src: String.raw `a := 'a'; b := '\n'; c := 'A'; s := "hello"`,
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
for (const { name, src } of cases) {
|
|
222
|
+
it(`stripStrings preserves length: ${name}`, () => {
|
|
223
|
+
expect(stripStrings(src).length).toBe(src.length);
|
|
224
|
+
});
|
|
225
|
+
it(`stripComments preserves length: ${name}`, () => {
|
|
226
|
+
expect(stripComments(src).length).toBe(src.length);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
//# 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,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,GAAG,GAAG,kCAAkC,CAAC;QAC/C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;A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AE,kBAAkB,EAAE,GAAG,EAAE,UAAU,EAAE;YAC7C,EAAE,IAAI,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,WAAW,EAAE;YAC1D,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAA,gBAAgB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,UAAU,EAAE;YAC/D,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAA,gBAAgB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,mBAAmB,EAAE;YACxE;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,6CAA6C;aAC7D;SACF,CAAC;QAEF,KAAK,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,KAAK,EAAE,CAAC;YAClC,EAAE,CAAC,kCAAkC,IAAI,EAAE,EAAE,GAAG,EAAE;gBAChD,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,mCAAmC,IAAI,EAAE,EAAE,GAAG,EAAE;gBACjD,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/strip.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { stripStrings, stripComments } from '../strip.js';
|
|
3
|
+
describe('stripStrings (Go)', () => {
|
|
4
|
+
it('strips double-quoted strings', () => {
|
|
5
|
+
const out = stripStrings('s := "hello"');
|
|
6
|
+
expect(out).not.toContain('hello');
|
|
7
|
+
});
|
|
8
|
+
it('strips raw (backtick) strings', () => {
|
|
9
|
+
const out = stripStrings('s := `multi\nline`');
|
|
10
|
+
expect(out).not.toContain('multi');
|
|
11
|
+
expect(out).not.toContain('line');
|
|
12
|
+
});
|
|
13
|
+
it('handles escape sequences in double-quoted strings', () => {
|
|
14
|
+
const out = stripStrings(String.raw `s := "a\"b"`);
|
|
15
|
+
expect(out).not.toContain('a');
|
|
16
|
+
});
|
|
17
|
+
it('preserves rune literals (no stripping)', () => {
|
|
18
|
+
expect(stripStrings("c := 'a'")).toContain("'a'");
|
|
19
|
+
});
|
|
20
|
+
it('preserves rune literals with escape', () => {
|
|
21
|
+
expect(stripStrings(String.raw `c := '\n'`)).toContain(String.raw `'\n'`);
|
|
22
|
+
});
|
|
23
|
+
it('handles unterminated rune literal at newline', () => {
|
|
24
|
+
const out = stripStrings("c := 'oops\nx := 1");
|
|
25
|
+
expect(out).toContain('x := 1');
|
|
26
|
+
});
|
|
27
|
+
it('handles unterminated double-quoted string', () => {
|
|
28
|
+
const out = stripStrings('s := "unterminated');
|
|
29
|
+
expect(out).toContain('s := ');
|
|
30
|
+
});
|
|
31
|
+
it('passes through code with no string-like tokens unchanged', () => {
|
|
32
|
+
const code = 'func foo() int { return 1 }';
|
|
33
|
+
expect(stripStrings(code)).toBe(code);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('stripComments (Go)', () => {
|
|
37
|
+
it('strips line comments', () => {
|
|
38
|
+
const out = stripComments('x := 1 // comment');
|
|
39
|
+
expect(out).not.toContain('comment');
|
|
40
|
+
expect(out).toContain('x := 1');
|
|
41
|
+
});
|
|
42
|
+
it('strips block comments', () => {
|
|
43
|
+
const out = stripComments('x := 1 /* hidden */ y := 2');
|
|
44
|
+
expect(out).not.toContain('hidden');
|
|
45
|
+
expect(out).toContain('x := 1');
|
|
46
|
+
expect(out).toContain('y := 2');
|
|
47
|
+
});
|
|
48
|
+
it('handles unterminated block comment', () => {
|
|
49
|
+
const out = stripComments('x := 1 /* oops');
|
|
50
|
+
expect(out).toContain('x := 1');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# 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,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,GAAG,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;QAC/C,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAA,aAAa,CAAC,CAAC;QAClD,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GA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AC,CAAC;IAEH,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAC/B,MAAM,GAAG,GAAG,aAAa,CAAC,4BAA4B,CAAC,CAAC;QACxD,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,GAAG,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAC5C,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substrate.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/substrate.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { RunScope, runWithScopeSync } from '@opensip-cli/core';
|
|
2
|
+
import { initParseCache, clearParseCache } from '@opensip-cli/core/languages/parse-cache.js';
|
|
3
|
+
import { walkNodes } from '@opensip-cli/tree-sitter';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { findEnclosingFunction, getEnclosingFunctionName } from '../enclosing.js';
|
|
6
|
+
import { parseGo } from '../parse.js';
|
|
7
|
+
import { isComment, isConditional, isFunction, isLoop, isMethod, isString, isStruct, } from '../predicates.js';
|
|
8
|
+
import { getSharedTree } from '../shared-tree.js';
|
|
9
|
+
const SRC = [
|
|
10
|
+
'// c',
|
|
11
|
+
'package app',
|
|
12
|
+
'type S struct { Name string }',
|
|
13
|
+
'func (s *S) M() int {',
|
|
14
|
+
'\tx := "h"',
|
|
15
|
+
'\tif true {',
|
|
16
|
+
'\t\treturn 1',
|
|
17
|
+
'\t}',
|
|
18
|
+
'\tfor i := 0; i < 3; i++ {',
|
|
19
|
+
'\t}',
|
|
20
|
+
'\treturn len(x)',
|
|
21
|
+
'}',
|
|
22
|
+
'func free() int { return 0 }',
|
|
23
|
+
'',
|
|
24
|
+
].join('\n');
|
|
25
|
+
function root() {
|
|
26
|
+
const tree = parseGo(SRC, 's.go');
|
|
27
|
+
if (!tree)
|
|
28
|
+
throw new Error('no tree');
|
|
29
|
+
return tree.tree.rootNode;
|
|
30
|
+
}
|
|
31
|
+
function count(pred) {
|
|
32
|
+
let n = 0;
|
|
33
|
+
walkNodes(root(), (node) => {
|
|
34
|
+
if (pred(node))
|
|
35
|
+
n++;
|
|
36
|
+
});
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
describe('go substrate', () => {
|
|
40
|
+
it('predicates match the tree-sitter-go node types', () => {
|
|
41
|
+
expect(count(isFunction)).toBe(2);
|
|
42
|
+
expect(count(isMethod)).toBe(1);
|
|
43
|
+
expect(count(isStruct)).toBe(1);
|
|
44
|
+
expect(count(isComment)).toBe(1);
|
|
45
|
+
expect(count(isString)).toBe(1);
|
|
46
|
+
expect(count(isConditional)).toBe(1);
|
|
47
|
+
expect(count(isLoop)).toBe(1);
|
|
48
|
+
});
|
|
49
|
+
it('getSharedTree caches within an active parse cache', () => {
|
|
50
|
+
runWithScopeSync(new RunScope(), () => {
|
|
51
|
+
initParseCache();
|
|
52
|
+
try {
|
|
53
|
+
const a = getSharedTree('x.go', 'package p\nfunc x() {}\n');
|
|
54
|
+
const b = getSharedTree('x.go', 'package p\nfunc x() {}\n');
|
|
55
|
+
expect(a).toBe(b);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
clearParseCache();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('findEnclosingFunction resolves the nearest func/method', () => {
|
|
63
|
+
const strings = [];
|
|
64
|
+
walkNodes(root(), (n) => {
|
|
65
|
+
if (n.type === 'interpreted_string_literal')
|
|
66
|
+
strings.push(n);
|
|
67
|
+
});
|
|
68
|
+
expect(getEnclosingFunctionName(strings[0])).toBe('M');
|
|
69
|
+
expect(findEnclosingFunction(strings[0])?.type).toBe('method_declaration');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=substrate.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substrate.test.js","sourceRoot":"","sources":["../../src/__tests__/substrate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EACL,SAAS,EACT,aAAa,EACb,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,MAAM,GAAG,GAAG;IACV,MAAM;IACN,aAAa;IACb,+BAA+B;IAC/B,uBAAuB;IACvB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,KAAK;IACL,4BAA4B;IAC5B,KAAK;IACL,iBAAiB;IACjB,GAAG;IACH,8BAA8B;IAC9B,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,SAAS,IAAI;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAClC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AM,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;gBAC5D,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;gBAC5D,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,CAAC;oBAAS,CAAC;gBACT,eAAe,EAAE,CAAC;YACpB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,OAAO,GAAW,EAAE,CAAC;QAC3B,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE;YACtB,IAAI,CAAC,CAAC,IAAI,KAAK,4BAA4B;gBAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type GoTree } from './parse.js';
|
|
2
|
+
import type { LanguageAdapter } from '@opensip-cli/core';
|
|
3
|
+
export declare const goAdapter: LanguageAdapter<GoTree>;
|
|
4
|
+
/** Plugin contract — exported as the lang plugin's `adapters` array. */
|
|
5
|
+
export declare const adapters: readonly [LanguageAdapter<import("@opensip-cli/tree-sitter").ParsedFile, unknown>];
|
|
6
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,eAAO,MAAM,SAAS,EAAE,eAAe,CAAC,MAAM,CAO7C,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,QAAQ,oFAAuB,CAAC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parseGo } from './parse.js';
|
|
2
|
+
import { stripComments, stripStrings } from './strip.js';
|
|
3
|
+
export const goAdapter = {
|
|
4
|
+
id: 'go',
|
|
5
|
+
fileExtensions: ['.go'],
|
|
6
|
+
aliases: ['golang'],
|
|
7
|
+
parse: parseGo,
|
|
8
|
+
stripStrings,
|
|
9
|
+
stripComments,
|
|
10
|
+
};
|
|
11
|
+
/** Plugin contract — exported as the lang plugin's `adapters` array. */
|
|
12
|
+
export const adapters = [goAdapter];
|
|
13
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAIzD,MAAM,CAAC,MAAM,SAAS,GAA4B;IAChD,EAAE,EAAE,IAAI;IACR,cAAc,EAAE,CAAC,KAAK,CAAC;IACvB,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,KAAK,EAAE,OAAO;IACd,YAAY;IACZ,aAAa;CACd,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,SAAS,CAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composed enclosing-scope helpers for Go (ADR-0010) — the per-language layer
|
|
3
|
+
* over the generic `findEnclosing`/`nameOf` from `@opensip-cli/tree-sitter`.
|
|
4
|
+
* `isMethod` is grammar-direct (Go's `method_declaration`), so it lives in
|
|
5
|
+
* predicates.ts; this module composes the enclosing-function lookups.
|
|
6
|
+
*/
|
|
7
|
+
import { type Node } from '@opensip-cli/tree-sitter';
|
|
8
|
+
/** The nearest enclosing func/method of `node`, or `null` at file scope. */
|
|
9
|
+
export declare function findEnclosingFunction(node: Node): Node | null;
|
|
10
|
+
/** The name of the nearest enclosing func/method, or `null`. */
|
|
11
|
+
export declare function getEnclosingFunctionName(node: Node): string | null;
|
|
12
|
+
//# sourceMappingURL=enclosing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enclosing.d.ts","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAI5E,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED,gEAAgE;AAChE,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAGlE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @fitness-ignore-file duplicate-utility-functions -- ADR-0010: the per-language tree-sitter vocabulary intentionally shares helper names across lang-* with grammar-specific implementations; consolidating would defeat the substrate design.
|
|
2
|
+
/**
|
|
3
|
+
* Composed enclosing-scope helpers for Go (ADR-0010) — the per-language layer
|
|
4
|
+
* over the generic `findEnclosing`/`nameOf` from `@opensip-cli/tree-sitter`.
|
|
5
|
+
* `isMethod` is grammar-direct (Go's `method_declaration`), so it lives in
|
|
6
|
+
* predicates.ts; this module composes the enclosing-function lookups.
|
|
7
|
+
*/
|
|
8
|
+
import { findEnclosing, nameOf } from '@opensip-cli/tree-sitter';
|
|
9
|
+
import { isFunction } from './predicates.js';
|
|
10
|
+
/** The nearest enclosing func/method of `node`, or `null` at file scope. */
|
|
11
|
+
export function findEnclosingFunction(node) {
|
|
12
|
+
return findEnclosing(node, isFunction);
|
|
13
|
+
}
|
|
14
|
+
/** The name of the nearest enclosing func/method, or `null`. */
|
|
15
|
+
export function getEnclosingFunctionName(node) {
|
|
16
|
+
const fn = findEnclosingFunction(node);
|
|
17
|
+
return fn ? nameOf(fn) : null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=enclosing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enclosing.js","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAa,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB,CAAC,IAAU;IAC9C,OAAO,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,wBAAwB,CAAC,IAAU;IACjD,MAAM,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { goAdapter, adapters } from './adapter.js';
|
|
2
|
+
export { parseGo, type GoTree } from './parse.js';
|
|
3
|
+
export { getSharedTree } from './shared-tree.js';
|
|
4
|
+
export { stripStrings, stripComments } from './strip.js';
|
|
5
|
+
export { isFunction, isMethod, isStruct, isComment, isString, isConditional, isLoop, } from './predicates.js';
|
|
6
|
+
export { findEnclosingFunction, getEnclosingFunctionName } from './enclosing.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { goAdapter, adapters } from './adapter.js';
|
|
2
|
+
export { parseGo } from './parse.js';
|
|
3
|
+
export { getSharedTree } from './shared-tree.js';
|
|
4
|
+
export { stripStrings, stripComments } from './strip.js';
|
|
5
|
+
export { isFunction, isMethod, isStruct, isComment, isString, isConditional, isLoop, } from './predicates.js';
|
|
6
|
+
export { findEnclosingFunction, getEnclosingFunctionName } from './enclosing.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,OAAO,EAAe,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Go parse — web-tree-sitter + vendored tree-sitter-go.wasm.
|
|
3
|
+
*
|
|
4
|
+
* ADR-0010: `lang-go` is the canonical Go parse substrate — fitness checks
|
|
5
|
+
* parse via the adapter (`getSharedTree`) and the graph Go adapter consumes
|
|
6
|
+
* this too. The grammar loads once at module top level (the WASM runtime is
|
|
7
|
+
* initialized by `@opensip-cli/tree-sitter`'s top-level `Parser.init()`); a
|
|
8
|
+
* single reused parser keeps `parse()` synchronous. Tree-sitter recovers from
|
|
9
|
+
* syntax errors with MISSING nodes, so a malformed file yields a partial tree
|
|
10
|
+
* (non-null) rather than throwing.
|
|
11
|
+
*/
|
|
12
|
+
import { type ParsedFile } from '@opensip-cli/tree-sitter';
|
|
13
|
+
/** Parsed Go source: tree-sitter parse tree plus the original source text. */
|
|
14
|
+
export type GoTree = ParsedFile;
|
|
15
|
+
/** Parses Go source into a {@link GoTree}, or null when no tree is produced. */
|
|
16
|
+
export declare function parseGo(content: string, _filePath: string): GoTree | null;
|
|
17
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAA0C,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAOnG,8EAA8E;AAC9E,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAEhC,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGzE"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Go parse — web-tree-sitter + vendored tree-sitter-go.wasm.
|
|
3
|
+
*
|
|
4
|
+
* ADR-0010: `lang-go` is the canonical Go parse substrate — fitness checks
|
|
5
|
+
* parse via the adapter (`getSharedTree`) and the graph Go adapter consumes
|
|
6
|
+
* this too. The grammar loads once at module top level (the WASM runtime is
|
|
7
|
+
* initialized by `@opensip-cli/tree-sitter`'s top-level `Parser.init()`); a
|
|
8
|
+
* single reused parser keeps `parse()` synchronous. Tree-sitter recovers from
|
|
9
|
+
* syntax errors with MISSING nodes, so a malformed file yields a partial tree
|
|
10
|
+
* (non-null) rather than throwing.
|
|
11
|
+
*/
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { loadGrammar, createParser, parseToTree } from '@opensip-cli/tree-sitter';
|
|
14
|
+
const grammar = await loadGrammar(fileURLToPath(new URL('../wasm/tree-sitter-go.wasm', import.meta.url)));
|
|
15
|
+
const parser = createParser(grammar);
|
|
16
|
+
/** Parses Go source into a {@link GoTree}, or null when no tree is produced. */
|
|
17
|
+
export function parseGo(content, _filePath) {
|
|
18
|
+
const tree = parseToTree(parser, content);
|
|
19
|
+
return tree ? { tree, source: content } : null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAmB,MAAM,0BAA0B,CAAC;AAEnG,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,aAAa,CAAC,IAAI,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CACvE,CAAC;AACF,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAKrC,gFAAgF;AAChF,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,SAAiB;IACxD,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1 per-language node-kind predicates for Go (ADR-0010). The generic
|
|
3
|
+
* traversal/position helpers live in `@opensip-cli/tree-sitter`; only the
|
|
4
|
+
* grammar-specific node `type` strings differ. Node types are from the
|
|
5
|
+
* tree-sitter-go grammar. Go has no class or try/catch — methods are a distinct
|
|
6
|
+
* `method_declaration` (receiver syntax) and error handling is value-based.
|
|
7
|
+
*/
|
|
8
|
+
import type { Node } from '@opensip-cli/tree-sitter';
|
|
9
|
+
/** A function or method declaration (both are callable defs). */
|
|
10
|
+
export declare const isFunction: (node: Node) => boolean;
|
|
11
|
+
/** A method declaration (a func with a receiver). */
|
|
12
|
+
export declare const isMethod: (node: Node) => boolean;
|
|
13
|
+
/** A `struct` type. */
|
|
14
|
+
export declare const isStruct: (node: Node) => boolean;
|
|
15
|
+
/** A comment. */
|
|
16
|
+
export declare const isComment: (node: Node) => boolean;
|
|
17
|
+
/** A string literal (interpreted `"..."` or raw backtick string). */
|
|
18
|
+
export declare const isString: (node: Node) => boolean;
|
|
19
|
+
/** An `if` statement. */
|
|
20
|
+
export declare const isConditional: (node: Node) => boolean;
|
|
21
|
+
/** A `for` statement (Go's only loop). */
|
|
22
|
+
export declare const isLoop: (node: Node) => boolean;
|
|
23
|
+
//# sourceMappingURL=predicates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,iEAAiE;AACjE,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,OACoC,CAAC;AAE7E,qDAAqD;AACrD,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,KAAG,OAA6C,CAAC;AAEpF,uBAAuB;AACvB,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,KAAG,OAAsC,CAAC;AAE7E,iBAAiB;AACjB,eAAO,MAAM,SAAS,GAAI,MAAM,IAAI,KAAG,OAAkC,CAAC;AAE1E,qEAAqE;AACrE,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,KAAG,OAC4C,CAAC;AAEnF,yBAAyB;AACzB,eAAO,MAAM,aAAa,GAAI,MAAM,IAAI,KAAG,OAAuC,CAAC;AAEnF,0CAA0C;AAC1C,eAAO,MAAM,MAAM,GAAI,MAAM,IAAI,KAAG,OAAwC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @fitness-ignore-file duplicate-utility-functions -- ADR-0010: the per-language tree-sitter vocabulary intentionally shares helper names across lang-* with grammar-specific implementations; consolidating would defeat the substrate design.
|
|
2
|
+
/**
|
|
3
|
+
* v1 per-language node-kind predicates for Go (ADR-0010). The generic
|
|
4
|
+
* traversal/position helpers live in `@opensip-cli/tree-sitter`; only the
|
|
5
|
+
* grammar-specific node `type` strings differ. Node types are from the
|
|
6
|
+
* tree-sitter-go grammar. Go has no class or try/catch — methods are a distinct
|
|
7
|
+
* `method_declaration` (receiver syntax) and error handling is value-based.
|
|
8
|
+
*/
|
|
9
|
+
/** A function or method declaration (both are callable defs). */
|
|
10
|
+
export const isFunction = (node) => node.type === 'function_declaration' || node.type === 'method_declaration';
|
|
11
|
+
/** A method declaration (a func with a receiver). */
|
|
12
|
+
export const isMethod = (node) => node.type === 'method_declaration';
|
|
13
|
+
/** A `struct` type. */
|
|
14
|
+
export const isStruct = (node) => node.type === 'struct_type';
|
|
15
|
+
/** A comment. */
|
|
16
|
+
export const isComment = (node) => node.type === 'comment';
|
|
17
|
+
/** A string literal (interpreted `"..."` or raw backtick string). */
|
|
18
|
+
export const isString = (node) => node.type === 'interpreted_string_literal' || node.type === 'raw_string_literal';
|
|
19
|
+
/** An `if` statement. */
|
|
20
|
+
export const isConditional = (node) => node.type === 'if_statement';
|
|
21
|
+
/** A `for` statement (Go's only loop). */
|
|
22
|
+
export const isLoop = (node) => node.type === 'for_statement';
|
|
23
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;;GAMG;AAIH,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAW,EAAE,CAChD,IAAI,CAAC,IAAI,KAAK,sBAAsB,IAAI,IAAI,CAAC,IAAI,KAAK,oBAAoB,CAAC;AAE7E,qDAAqD;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,oBAAoB,CAAC;AAEpF,uBAAuB;AACvB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC;AAE7E,iBAAiB;AACjB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;AAE1E,qEAAqE;AACrE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAW,EAAE,CAC9C,IAAI,CAAC,IAAI,KAAK,4BAA4B,IAAI,IAAI,CAAC,IAAI,KAAK,oBAAoB,CAAC;AAEnF,yBAAyB;AACzB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC;AAEnF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cached Go parse entry point — the analog of `lang-typescript`'s
|
|
3
|
+
* `getSharedSourceFile`. Routes through `core`'s active `LanguageParseCache`
|
|
4
|
+
* so a file parsed by a fitness check and by the graph adapter in the same run
|
|
5
|
+
* is parsed once; falls back to a direct parse when no cache is active.
|
|
6
|
+
*/
|
|
7
|
+
import type { GoTree } from './parse.js';
|
|
8
|
+
/** Returns the shared (cached) Go parse tree for `filePath`, or null when unparseable. */
|
|
9
|
+
export declare function getSharedTree(filePath: string, content: string): GoTree | null;
|
|
10
|
+
//# sourceMappingURL=shared-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-tree.d.ts","sourceRoot":"","sources":["../src/shared-tree.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE9E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @fitness-ignore-file duplicate-utility-functions -- ADR-0010: the per-language tree-sitter vocabulary intentionally shares helper names across lang-* with grammar-specific implementations; consolidating would defeat the substrate design.
|
|
2
|
+
/**
|
|
3
|
+
* Cached Go parse entry point — the analog of `lang-typescript`'s
|
|
4
|
+
* `getSharedSourceFile`. Routes through `core`'s active `LanguageParseCache`
|
|
5
|
+
* so a file parsed by a fitness check and by the graph adapter in the same run
|
|
6
|
+
* is parsed once; falls back to a direct parse when no cache is active.
|
|
7
|
+
*/
|
|
8
|
+
import { getParseTree } from '@opensip-cli/core/languages/parse-cache.js';
|
|
9
|
+
import { goAdapter } from './adapter.js';
|
|
10
|
+
/** Returns the shared (cached) Go parse tree for `filePath`, or null when unparseable. */
|
|
11
|
+
export function getSharedTree(filePath, content) {
|
|
12
|
+
return getParseTree(goAdapter, filePath, content);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=shared-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-tree.js","sourceRoot":"","sources":["../src/shared-tree.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,OAAe;IAC7D,OAAO,YAAY,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/strip.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Replace string literal content with whitespace; preserves length. */
|
|
2
|
+
export declare const stripStrings: (content: string) => string;
|
|
3
|
+
/** Replace string literals AND comments with whitespace; preserves length. */
|
|
4
|
+
export declare const stripComments: (content: string) => string;
|
|
5
|
+
//# sourceMappingURL=strip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AA6FA,wEAAwE;AACxE,eAAO,MAAM,YAAY,6BAAwB,CAAC;AAClD,8EAA8E;AAC9E,eAAO,MAAM,aAAa,6BAAyB,CAAC"}
|
package/dist/strip.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Go string and comment stripping.
|
|
2
|
+
//
|
|
3
|
+
// Hand-written lexer that recognizes:
|
|
4
|
+
// - Line comments (//) and block comments (slash-star ... star-slash) — Go block comments do NOT nest
|
|
5
|
+
// - Interpreted strings ("...") with escape handling
|
|
6
|
+
// - Raw strings (backtick ... backtick) — no escape processing, can span lines
|
|
7
|
+
// - Rune literals ('a', '\n') — preserved as code (not stripped)
|
|
8
|
+
//
|
|
9
|
+
// Both strip functions preserve byte length: replacement is whitespace
|
|
10
|
+
// (newlines preserved) so line/column positions remain stable.
|
|
11
|
+
import { makeStripper, scanBlockCommentNonNesting, scanCharLiteral, scanLineComment, scanRegularString, } from '@opensip-cli/core';
|
|
12
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity -- token-state-machine: cyclomatic complexity is inherent to lexer-style scanners; splitting hurts readability
|
|
13
|
+
function scan(src) {
|
|
14
|
+
const stringRegions = [];
|
|
15
|
+
const commentRegions = [];
|
|
16
|
+
const len = src.length;
|
|
17
|
+
let i = 0;
|
|
18
|
+
while (i < len) {
|
|
19
|
+
const c = src[i];
|
|
20
|
+
const next = src[i + 1];
|
|
21
|
+
// Line comment: // ... \n
|
|
22
|
+
if (c === '/' && next === '/') {
|
|
23
|
+
const start = i;
|
|
24
|
+
const lc = scanLineComment(src, i);
|
|
25
|
+
i = lc.end;
|
|
26
|
+
commentRegions.push({ start, end: i });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// Block comment: /* ... */ — Go block comments do NOT nest
|
|
30
|
+
if (c === '/' && next === '*') {
|
|
31
|
+
const start = i;
|
|
32
|
+
const bc = scanBlockCommentNonNesting(src, i);
|
|
33
|
+
i = bc.end;
|
|
34
|
+
commentRegions.push({ start, end: i });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Raw string: `...` — no escapes, can span lines.
|
|
38
|
+
//
|
|
39
|
+
// @todo Per the Go spec, carriage returns (\r) inside raw strings are
|
|
40
|
+
// discarded from the string value (see go/spec#raw_string_lit). We do
|
|
41
|
+
// not represent that here because the strip pass is region-bound, not
|
|
42
|
+
// value-extraction; a future `findStringLiterals` query API will need
|
|
43
|
+
// to apply the \r-discard rule when materializing literal values.
|
|
44
|
+
if (c === '`') {
|
|
45
|
+
const contentStart = i + 1;
|
|
46
|
+
let j = i + 1;
|
|
47
|
+
while (j < len && src[j] !== '`')
|
|
48
|
+
j++;
|
|
49
|
+
stringRegions.push({ start: contentStart, end: j });
|
|
50
|
+
i = j < len ? j + 1 : len;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
// Interpreted string: "..." with \ escapes
|
|
54
|
+
if (c === '"') {
|
|
55
|
+
const result = scanRegularString(src, i);
|
|
56
|
+
stringRegions.push({ start: i + 1, end: result.contentEnd });
|
|
57
|
+
i = result.next;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Rune literal: '...' — preserve as code (don't strip).
|
|
61
|
+
// Go runes have no fixed cap analogous to lang-java/lang-cpp; use a
|
|
62
|
+
// generous cap (12) to accommodate the longest valid form
|
|
63
|
+
// ('\U0001F600' = 12 chars including quotes). The shared helper's
|
|
64
|
+
// load-bearing branch order (escape before close-quote) is the same
|
|
65
|
+
// shape Go's previous inline scanner used.
|
|
66
|
+
if (c === "'") {
|
|
67
|
+
const result = scanCharLiteral(src, i, { maxScan: 12 });
|
|
68
|
+
i = result.end;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
return { stringRegions, commentRegions };
|
|
74
|
+
}
|
|
75
|
+
const stripper = makeStripper(scan);
|
|
76
|
+
/** Replace string literal content with whitespace; preserves length. */
|
|
77
|
+
export const stripStrings = stripper.stripStrings;
|
|
78
|
+
/** Replace string literals AND comments with whitespace; preserves length. */
|
|
79
|
+
export const stripComments = stripper.stripComments;
|
|
80
|
+
//# sourceMappingURL=strip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,sCAAsC;AACtC,sG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;AAC3C,CAAC;AAED,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,wEAAwE;AACxE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;AAClD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opensip-cli/lang-go",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Go language adapter for opensip-cli",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"opensip-cli",
|
|
8
|
+
"static-analysis",
|
|
9
|
+
"code-quality",
|
|
10
|
+
"parser",
|
|
11
|
+
"ast",
|
|
12
|
+
"tree-sitter",
|
|
13
|
+
"go",
|
|
14
|
+
"golang"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/opensip-ai/opensip-cli.git",
|
|
19
|
+
"directory": "packages/languages/lang-go"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/opensip-ai/opensip-cli",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/opensip-ai/opensip-cli/issues"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"wasm",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@opensip-cli/core": "0.1.0",
|
|
39
|
+
"@opensip-cli/tree-sitter": "0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.13.2",
|
|
43
|
+
"vitest": "^4.1.8"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"clean": "rm -rf dist"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
Binary file
|