Add class & method recognization ability for JavaScript function list

Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/13013#issuecomment-1899399803

Fix #13013, close #16342
This commit is contained in:
Don Ho 2025-03-29 21:19:40 +01:00
parent 2a24867e98
commit 3ae0875a8c
4 changed files with 43 additions and 3 deletions

View File

@ -366,4 +366,26 @@ var LoginToken = new Schema({
}
exports.defineModels = defineModels;
class Car {
constructor(name, year) {
this.name = name;
this.year = year;
}
age(x) {
return x - this.year;
}
}
const date = new Date();
let year = date.getFullYear();
const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML=
"My car is " + myCar.age(year) + " years old.";

View File

@ -1 +1 @@
{"leaves":["extractKeywords","convertBasicMarkup","function","function","function","function","defineModels","slugGenerator","slugGenerator","validatePresenceOf","function","function","function","function","function","function"],"root":"unitTest"}
{"leaves":["extractKeywords","convertBasicMarkup","function","function","function","function","defineModels","slugGenerator","slugGenerator","validatePresenceOf","function","function","function","function","function","function"],"nodes":[{"leaves":["constructor","age"],"name":"Car"}],"root":"unitTest"}

View File

@ -15,9 +15,24 @@
id ="javascript_function"
commentExpr="(?s:/\*.*?\*/)|(?m-s://.*?$)"
>
<classRange mainExpr="\bclass\s+[A-Za-z_$][\w$]*[^{]*{" openSymbole="\{" closeSymbole="\}">
<className>
<!-- Make consecutive patterns to extract the identifier. -->
<nameExpr expr="class\s+[A-Za-z_$][\w$]*" />
<nameExpr expr="\s+[A-Za-z_$][\w$]*" />
<nameExpr expr="[A-Za-z_$][\w$]*" />
</className>
<function mainExpr="\b(?:(?:static|async)\s+)?\b(?!if|while|for|switch)\b[A-Za-z_$][\w$]*\s*\([^\)]*\)\s*{">
<functionName>
<funcNameExpr expr="[A-Za-z_$][\w$]*\s*\(" />-->
<funcNameExpr expr="[A-Za-z_$][\w$]*" />-->
</functionName>
</function>
</classRange>
<function
mainExpr="((^|\s+|[;\}\.])([A-Za-z_$][\w$]*\.)*[A-Za-z_$][\w$]*\s*[=:]|^|[\s;\}]+)\s*function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{"
>
>
<functionName>
<nameExpr expr="[A-Za-z_$][\w$]*\s*[=:]|[A-Za-z_$][\w$]*\s*\(" />
<nameExpr expr="[A-Za-z_$][\w$]*" />

View File

@ -100,6 +100,9 @@
<association id= "gdscript.xml" langID= "88"/>
<association id= "hollywood.xml" langID= "89"/>
<association id= "go.xml" langID= "90"/>
<association id= "raku.xml" langID= "91"/>
<association id= "toml.xml" langID= "92"/>
<association id= "sas.xml" langID= "93"/>
If you create your own parse rule of supported languages (above) for your specific need,
you can copy it without modifying the original one, and make it point to your rule.