diff --git a/CHANGES.md b/CHANGES.md
index f56b910725..89b141b1d1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,6 +5,7 @@ Core Grammars:
- fix(cpp) not all kinds of number literals are highlighted correctly [LĂȘ Duy Quang][]
- fix(css) fix overly greedy pseudo class matching [Bradley Mackey][]
- enh(arcade) updated to ArcGIS Arcade version 1.24 [Kristian Ekenes][]
+- fix(typescript): params types [Mohamed Ali][]
- fix(rust) fix escaped double quotes in string [Mohamed Ali][]
- fix(yaml) fix for yaml with keys having brackets highlighted incorrectly [Aneesh Kulkarni][]
- fix(bash) fix # within token being detected as the start of a comment [Felix Uhl][]
diff --git a/src/languages/javascript.js b/src/languages/javascript.js
index 4dd1090150..a0adc24dbc 100644
--- a/src/languages/javascript.js
+++ b/src/languages/javascript.js
@@ -256,7 +256,7 @@ export default function(hljs) {
const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
// eat recursive parens in sub expressions
{
- begin: /\(/,
+ begin: /(\s*)\(/,
end: /\)/,
keywords: KEYWORDS,
contains: ["self"].concat(SUBST_AND_COMMENTS)
@@ -264,7 +264,8 @@ export default function(hljs) {
]);
const PARAMS = {
className: 'params',
- begin: /\(/,
+ // convert this to negative lookbehind in v12
+ begin: /(\s*)\(/, // to match the parms with
end: /\)/,
excludeBegin: true,
excludeEnd: true,
@@ -509,7 +510,7 @@ export default function(hljs) {
skip: true
},
{
- begin: /\(/,
+ begin: /(\s*)\(/,
end: /\)/,
excludeBegin: true,
excludeEnd: true,
diff --git a/src/languages/typescript.js b/src/languages/typescript.js
index 98b9e89517..5e95bcbdd2 100644
--- a/src/languages/typescript.js
+++ b/src/languages/typescript.js
@@ -87,6 +87,13 @@ export default function(hljs) {
Object.assign(tsLanguage.keywords, KEYWORDS);
tsLanguage.exports.PARAMS_CONTAINS.push(DECORATOR);
+
+ // highlight the function params
+ const ATTRIBUTE_HIGHLIGHT = tsLanguage.contains.find(c => c.className === "attr");
+ tsLanguage.exports.PARAMS_CONTAINS.push([
+ tsLanguage.exports.CLASS_REFERENCE, // class reference for highlighting the params types
+ ATTRIBUTE_HIGHLIGHT, // highlight the params key
+ ]);
tsLanguage.contains = tsLanguage.contains.concat([
DECORATOR,
NAMESPACE,
diff --git a/test/markup/javascript/class.expect.txt b/test/markup/javascript/class.expect.txt
index 7e1dd67c80..2053069221 100644
--- a/test/markup/javascript/class.expect.txt
+++ b/test/markup/javascript/class.expect.txt
@@ -38,3 +38,29 @@
InT
CSSParserT
IResponseTsS
+
+
+class Car extends Vehicle {
+ constructor (speed, cost) {
+ super(speed);
+
+ var c = Symbol('cost');
+ this[c] = cost;
+
+ this.intro = `This is a car runs at
+ ${speed}.`;
+ }
+
+ join () {
+ }
+
+ other (a = ( ( 3 + 2 ) ) ) {
+ console.log(a)
+ }
+
+ something (a = ( ( 3 + 2 ) ), b = 1 ) {
+ console.log(a)
+ }
+
+ onemore (a=(3+2, b=(5*9))) {}
+}
diff --git a/test/markup/javascript/class.txt b/test/markup/javascript/class.txt
index 4badef7377..57b9f0bea7 100644
--- a/test/markup/javascript/class.txt
+++ b/test/markup/javascript/class.txt
@@ -38,3 +38,29 @@ OutT
InT
CSSParserT
IResponseTsS
+
+// this class to show that the params may be seperated with space after the function name and highlighted as params also.
+class Car extends Vehicle {
+ constructor (speed, cost) {
+ super(speed);
+
+ var c = Symbol('cost');
+ this[c] = cost;
+
+ this.intro = `This is a car runs at
+ ${speed}.`;
+ }
+
+ join () {
+ }
+
+ other (a = ( ( 3 + 2 ) ) ) {
+ console.log(a)
+ }
+
+ something (a = ( ( 3 + 2 ) ), b = 1 ) {
+ console.log(a)
+ }
+
+ onemore (a=(3+2, b=(5*9))) {}
+}
diff --git a/test/markup/javascript/seperated-parameters.expect.txt b/test/markup/javascript/seperated-parameters.expect.txt
new file mode 100644
index 0000000000..f63006c91d
--- /dev/null
+++ b/test/markup/javascript/seperated-parameters.expect.txt
@@ -0,0 +1,5 @@
+function visibleTodoFilter (state = 'watch', action) {}
+
+function visibleTodoFilter (state, action) {
+
+}
diff --git a/test/markup/javascript/seperated-parameters.txt b/test/markup/javascript/seperated-parameters.txt
new file mode 100644
index 0000000000..6dd0cd9eaf
--- /dev/null
+++ b/test/markup/javascript/seperated-parameters.txt
@@ -0,0 +1,5 @@
+function visibleTodoFilter (state = 'watch', action) {}
+
+function visibleTodoFilter (state, action) {
+ // ...
+}
diff --git a/test/markup/typescript/class.expect.txt b/test/markup/typescript/class.expect.txt
index 0245c33418..13dc789278 100644
--- a/test/markup/typescript/class.expect.txt
+++ b/test/markup/typescript/class.expect.txt
@@ -9,3 +9,20 @@
${speed}.`;
}
}
+
+interface TrainProps {
+ speed: number;
+ cost: number;
+}
+
+class Train extends Vehicle {
+ constructor (trainData: TrainProps) {
+ super(trainData.speed);
+
+ var c = Symbol('cost');
+ this[c] = trainData.cost;
+
+ this.intro = `This is a car runs at
+ ${trainData.speed}.`;
+ }
+}
diff --git a/test/markup/typescript/class.txt b/test/markup/typescript/class.txt
index 47fa67cc35..33f4921891 100644
--- a/test/markup/typescript/class.txt
+++ b/test/markup/typescript/class.txt
@@ -9,3 +9,20 @@ class Car extends Vehicle {
${speed}.`;
}
}
+
+interface TrainProps {
+ speed: number;
+ cost: number;
+}
+
+class Train extends Vehicle {
+ constructor (trainData: TrainProps) {
+ super(trainData.speed);
+
+ var c = Symbol('cost');
+ this[c] = trainData.cost;
+
+ this.intro = `This is a car runs at
+ ${trainData.speed}.`;
+ }
+}
diff --git a/test/markup/typescript/declares.expect.txt b/test/markup/typescript/declares.expect.txt
index 0521e1360c..689ee9a5f8 100644
--- a/test/markup/typescript/declares.expect.txt
+++ b/test/markup/typescript/declares.expect.txt
@@ -1,6 +1,6 @@
export declare class CommandHandler extends EventEmitter {
- constructor(config: CommandHandlerConfig);
+ constructor(config: CommandHandlerConfig);