Skip to content

Commit 3b2238f

Browse files
JS: Added properties (#3099)
1 parent 3f24dc7 commit 3b2238f

21 files changed

+527
-317
lines changed

components/prism-actionscript.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Prism.languages.actionscript = Prism.languages.extend('javascript', {
44
});
55
Prism.languages.actionscript['class-name'].alias = 'function';
66

7+
// doesn't work with AS because AS is too complex
8+
delete Prism.languages.actionscript['parameter'];
9+
delete Prism.languages.actionscript['literal-property'];
10+
711
if (Prism.languages.markup) {
812
Prism.languages.insertBefore('actionscript', 'string', {
913
'xml': {

components/prism-actionscript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-javascript.js

+14
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,23 @@ Prism.languages.insertBefore('javascript', 'string', {
9898
},
9999
'string': /[\s\S]+/
100100
}
101+
},
102+
'string-property': {
103+
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
104+
lookbehind: true,
105+
greedy: true,
106+
alias: 'property'
101107
}
102108
});
103109

110+
Prism.languages.insertBefore('javascript', 'operator', {
111+
'literal-property': {
112+
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
113+
lookbehind: true,
114+
alias: 'property'
115+
},
116+
});
117+
104118
if (Prism.languages.markup) {
105119
Prism.languages.markup.tag.addInlined('script', 'javascript');
106120

components/prism-javascript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-tsx.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// doesn't work with TS because TS is too complex
66
delete Prism.languages.tsx['parameter'];
7+
delete Prism.languages.tsx['literal-property'];
78

89
// This will prevent collisions between TSX tags and TS generic types.
910
// Idea by https://github.com/karlhorky

components/prism-tsx.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-typescript.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
// doesn't work with TS because TS is too complex
2323
delete Prism.languages.typescript['parameter'];
24+
delete Prism.languages.typescript['literal-property'];
2425

2526
// a version of typescript specifically for highlighting types
2627
var typeInside = Prism.languages.extend('typescript', {});

components/prism-typescript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

+14
Original file line numberDiff line numberDiff line change
@@ -1647,9 +1647,23 @@ Prism.languages.insertBefore('javascript', 'string', {
16471647
},
16481648
'string': /[\s\S]+/
16491649
}
1650+
},
1651+
'string-property': {
1652+
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
1653+
lookbehind: true,
1654+
greedy: true,
1655+
alias: 'property'
16501656
}
16511657
});
16521658

1659+
Prism.languages.insertBefore('javascript', 'operator', {
1660+
'literal-property': {
1661+
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
1662+
lookbehind: true,
1663+
alias: 'property'
1664+
},
1665+
});
1666+
16531667
if (Prism.languages.markup) {
16541668
Prism.languages.markup.tag.addInlined('script', 'javascript');
16551669

tests/languages/javascript+http/issue2733.test

+13-13
Original file line numberDiff line numberDiff line change
@@ -47,66 +47,66 @@ transfer-encoding: chunked
4747
["application-json", [
4848
["punctuation", "{"],
4949

50-
["string", "\"id\""],
50+
["string-property", "\"id\""],
5151
["operator", ":"],
5252
["number", "1"],
5353
["punctuation", ","],
5454

55-
["string", "\"name\""],
55+
["string-property", "\"name\""],
5656
["operator", ":"],
5757
["string", "\"John Doe\""],
5858
["punctuation", ","],
5959

60-
["string", "\"userName\""],
60+
["string-property", "\"userName\""],
6161
["operator", ":"],
6262
["string", "\"jdoe\""],
6363
["punctuation", ","],
6464

65-
["string", "\"email\""],
65+
["string-property", "\"email\""],
6666
["operator", ":"],
6767
["string", "\"whatever@something.zzz\""],
6868
["punctuation", ","],
6969

70-
["string", "\"phone\""],
70+
["string-property", "\"phone\""],
7171
["operator", ":"],
7272
["string", "\"1234567890\""],
7373
["punctuation", ","],
7474

75-
["string", "\"birthDate\""],
75+
["string-property", "\"birthDate\""],
7676
["operator", ":"],
7777
["string", "\"1878-05-06\""],
7878
["punctuation", ","],
7979

80-
["string", "\"address\""],
80+
["string-property", "\"address\""],
8181
["operator", ":"],
8282
["punctuation", "{"],
8383

84-
["string", "\"street\""],
84+
["string-property", "\"street\""],
8585
["operator", ":"],
8686
["string", "\"Fake St\""],
8787
["punctuation", ","],
8888

89-
["string", "\"street2\""],
89+
["string-property", "\"street2\""],
9090
["operator", ":"],
9191
["string", "\"Apt. 556\""],
9292
["punctuation", ","],
9393

94-
["string", "\"city\""],
94+
["string-property", "\"city\""],
9595
["operator", ":"],
9696
["string", "\"Gwenborough\""],
9797
["punctuation", ","],
9898

99-
["string", "\"state\""],
99+
["string-property", "\"state\""],
100100
["operator", ":"],
101101
["string", "\"ZZ\""],
102102
["punctuation", ","],
103103

104-
["string", "\"zip\""],
104+
["string-property", "\"zip\""],
105105
["operator", ":"],
106106
["string", "\"12345\""],
107107

108108
["punctuation", "}"],
109109

110110
["punctuation", "}"]
111111
]]
112-
]
112+
]

tests/languages/javascript/class-method_feature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class Test {
5757
["punctuation", "("],
5858
["parameter", [
5959
["punctuation", "{"],
60-
" props",
60+
["literal-property", "props"],
6161
["operator", ":"],
6262
["punctuation", "{"],
63-
" a",
63+
["literal-property", "a"],
6464
["operator", ":"],
6565
" _A",
6666
["punctuation", ","],

tests/languages/javascript/function-variable_feature.test

+13-16
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ a = function () {}, b = () => {}
4343
["punctuation", "("],
4444
["punctuation", ")"],
4545
["punctuation", "{"],
46-
["punctuation","}"],
47-
["punctuation","}"],
46+
["punctuation", "}"],
47+
["punctuation", "}"],
4848

4949
["function-variable", "bar"],
5050
["operator", "="],
5151
["keyword", "async"],
5252
["keyword", "function"],
5353
["function", "baz"],
5454
["punctuation", "("],
55-
["parameter", [
56-
"x"
57-
]],
55+
["parameter", ["x"]],
5856
["punctuation", ")"],
5957
["punctuation", "{"],
6058
["punctuation", "}"],
@@ -63,18 +61,16 @@ a = function () {}, b = () => {}
6361
["operator", "="],
6462
["keyword", "async"],
6563
["punctuation", "("],
66-
["parameter", [
67-
"x"
68-
]],
64+
["parameter", ["x"]],
6965
["punctuation", ")"],
70-
["operator", "=>"], " x\r\n",
66+
["operator", "=>"],
67+
" x\r\n",
7168

7269
["function-variable", "fooBar"],
7370
["operator", "="],
74-
["parameter", [
75-
"x"
76-
]],
77-
["operator", "=>"], " x\r\n",
71+
["parameter", ["x"]],
72+
["operator", "=>"],
73+
" x\r\n",
7874

7975
["function-variable", "fooBar"],
8076
["operator", "="],
@@ -85,7 +81,8 @@ a = function () {}, b = () => {}
8581
" y"
8682
]],
8783
["punctuation", ")"],
88-
["operator", "=>"], " x\r\n",
84+
["operator", "=>"],
85+
" x\r\n",
8986

9087
["function-variable", "ಠ_ಠ"],
9188
["operator", "="],
@@ -118,10 +115,10 @@ a = function () {}, b = () => {}
118115
["punctuation", "("],
119116
["parameter", [
120117
["punctuation", "{"],
121-
" props",
118+
["literal-property", "props"],
122119
["operator", ":"],
123120
["punctuation", "{"],
124-
" a",
121+
["literal-property", "a"],
125122
["operator", ":"],
126123
" _A",
127124
["punctuation", ","],

0 commit comments

Comments
 (0)