Skip to content

Commit 5e501c7

Browse files
authored
Merge pull request #33 from aboutcode-org/29-fix-js-string-collection
Add typescript symbol and string parser
2 parents 2887e60 + 70efede commit 5e501c7

15 files changed

+672
-12
lines changed

Diff for: src/source_inspector/symbols_tree_sitter.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ def traverse(node, symbols, strings, language_info):
178178
"JavaScript": {
179179
"wheel": "tree_sitter_javascript",
180180
"identifiers": ["identifier"],
181-
"string_literals": ["string_literal"],
181+
"string_literals": ["string_fragment"],
182+
},
183+
"TypeScript": {
184+
"wheel": "tree_sitter_javascript",
185+
"identifiers": ["identifier"],
186+
"string_literals": ["string_fragment"],
182187
},
183188
"Objective-C": {
184189
"wheel": "tree_sitter_objc",
File renamed without changes.

Diff for: tests/data/symbols_tree_sitter/javascript/main.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Set the possible characters for the password
2+
const charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+=";
3+
4+
// Function to generate a random password
5+
function generatePassword(length) {
6+
let password = "";
7+
for (let i = 0; i < length; i++) {
8+
// Choose a random character from the character set
9+
const randomIndex = Math.floor(Math.random() * charSet.length);
10+
const randomChar = charSet[randomIndex];
11+
// Add the random character to the password string
12+
password += randomChar;
13+
}
14+
return password;
15+
}
16+
17+
// Get the password length from the user
18+
const passwordLength = parseInt(prompt("Enter the desired length of your password:"));
19+
20+
// Generate the password and display it to the user
21+
const password = generatePassword(passwordLength);
22+
alert(`Your random password is: ${password}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"files": [
3+
{
4+
"path": "main.js",
5+
"type": "file",
6+
"source_symbols": [
7+
"charSet",
8+
"generatePassword",
9+
"length",
10+
"password",
11+
"i",
12+
"i",
13+
"length",
14+
"i",
15+
"randomIndex",
16+
"Math",
17+
"Math",
18+
"charSet",
19+
"randomChar",
20+
"charSet",
21+
"randomIndex",
22+
"password",
23+
"randomChar",
24+
"password",
25+
"passwordLength",
26+
"parseInt",
27+
"prompt",
28+
"password",
29+
"generatePassword",
30+
"passwordLength",
31+
"alert",
32+
"password"
33+
],
34+
"source_strings": [
35+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+=",
36+
"Enter the desired length of your password:",
37+
"Your random password is: "
38+
],
39+
"scan_errors": []
40+
}
41+
]
42+
}

0 commit comments

Comments
 (0)