Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-3980
Browse files Browse the repository at this point in the history
  • Loading branch information
akhtarmdsaad committed Feb 26, 2024
2 parents 89853e2 + 607a929 commit 81079eb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ New Grammars:
- added 3rd party Ballerina grammar to SUPPORTED_LANGUAGES [Yasith Deelaka][]

Core Grammars:
- fix(cpp) fixed highlighter break state [Md Saad Akhtar][]
- fix(rust) added negative-lookahead for callable keywords `if` `while` `for` [Omar Hussein][]
- enh(armasm) added `x0-x30` and `w0-w30` ARMv8 registers [Nicholas Thompson][]
- enh(haxe) added `final`, `is`, `macro` keywords and `$` identifiers [Robert Borghese][]
Expand Down
22 changes: 17 additions & 5 deletions src/languages/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ export default function(hljs) {
"unknown"
];
const NAMESPACE = {
beginKeywords: 'namespace',
end: /\{/,
excludeEnd: true,
contains: [ tsLanguage.exports.CLASS_REFERENCE ]
begin: [
/namespace/,
/\s+/,
hljs.IDENT_RE
],
beginScope: {
1: "keyword",
3: "title.class"
}
};
const INTERFACE = {
beginKeywords: 'interface',
Expand All @@ -50,7 +55,7 @@ export default function(hljs) {
};
const TS_SPECIFIC_KEYWORDS = [
"type",
"namespace",
// "namespace",
"interface",
"public",
"private",
Expand All @@ -62,6 +67,13 @@ export default function(hljs) {
"enum",
"override"
];

/*
namespace is a TS keyword but it's fine to use it as a variable name too.
const message = 'foo';
const namespace = 'bar';
*/

const KEYWORDS = {
$pattern: ECMAScript.IDENT_RE,
keyword: ECMAScript.KEYWORDS.concat(TS_SPECIFIC_KEYWORDS),
Expand Down
4 changes: 4 additions & 0 deletions test/markup/typescript/namespace_as_identifier.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<span class="hljs-keyword">const</span> message = <span class="hljs-string">&#x27;foo&#x27;</span>;
<span class="hljs-keyword">const</span> namespace = <span class="hljs-string">&#x27;bar&#x27;</span>;
<span class="hljs-keyword">function</span> <span class="hljs-title function_">baz</span>(<span class="hljs-params"></span>) {}
3 changes: 3 additions & 0 deletions test/markup/typescript/namespace_as_identifier.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const message = 'foo';
const namespace = 'bar';
function baz() {}

0 comments on commit 81079eb

Please sign in to comment.