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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-javascript.js

Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-tsx.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-typescript.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

Lines changed: 14 additions & 0 deletions
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

Lines changed: 13 additions & 13 deletions
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", "\"[email protected]\""],
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+
]

0 commit comments

Comments
 (0)