Skip to content

Commit

Permalink
Improve JavaScript function definition highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 24, 2024
1 parent ca52161 commit c809216
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/FileExt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ TypeScript
tsx TypeScript with JSX
cts cjs
mts mjs
ets HarmonyOS ArkTS, https://developer.harmonyos.com/cn/develop/arkts/
ets HarmonyOS ArkTS, https://developer.huawei.com/consumer/cn/arkts/


VBScript
Expand Down
13 changes: 10 additions & 3 deletions scintilla/lexers/LexJavaScript.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum class KeywordType {
Enum = SCE_JS_ENUM,
Function = SCE_JS_FUNCTION_DEFINITION,
Label = SCE_JS_LABEL,
Return = 0x40,
};

enum class DocTagState {
Expand Down Expand Up @@ -227,8 +228,10 @@ void ColouriseJsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
kwType = KeywordType::Enum;
} else if (StrEqualsAny(s, "break", "continue")) {
kwType = KeywordType::Label;
} else if (StrEqualsAny(s, "return", "yield")) {
kwType = KeywordType::Return;
}
if (kwType != KeywordType::None) {
if (kwType > KeywordType::None && kwType < KeywordType::Return) {
const int chNext = sc.GetLineNextChar();
if (!(IsJsIdentifierStart(chNext) || chNext == '\\')) {
kwType = KeywordType::None;
Expand All @@ -251,12 +254,16 @@ void ColouriseJsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
sc.ChangeState(SCE_JS_LABEL);
}
} else if (sc.ch != '.') {
if (kwType != KeywordType::None) {
if (kwType > KeywordType::None && kwType < KeywordType::Return) {
sc.ChangeState(static_cast<int>(kwType));
} else {
const int chNext = sc.GetDocNextChar(sc.ch == '?');
if (chNext == '(') {
sc.ChangeState(SCE_JS_FUNCTION);
if (kwType != KeywordType::Return && (IsIdentifierCharEx(chBeforeIdentifier) || chBeforeIdentifier == ']')) {
sc.ChangeState(SCE_JS_FUNCTION_DEFINITION);
} else {
sc.ChangeState(SCE_JS_FUNCTION);
}
} else if (sc.Match('[', ']')
|| (chBeforeIdentifier == '<' && (chNext == '>' || chNext == '<'))) {
// type[]
Expand Down

0 comments on commit c809216

Please sign in to comment.