Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JS: Added properties (#3099)
  • Loading branch information
RunDevelopment committed Oct 10, 2021
1 parent 3f24dc7 commit 3b2238f
Show file tree
Hide file tree
Showing 21 changed files with 527 additions and 317 deletions.
4 changes: 4 additions & 0 deletions components/prism-actionscript.js
Expand Up @@ -4,6 +4,10 @@ Prism.languages.actionscript = Prism.languages.extend('javascript', {
});
Prism.languages.actionscript['class-name'].alias = 'function';

// doesn't work with AS because AS is too complex
delete Prism.languages.actionscript['parameter'];
delete Prism.languages.actionscript['literal-property'];

if (Prism.languages.markup) {
Prism.languages.insertBefore('actionscript', 'string', {
'xml': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-actionscript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions components/prism-javascript.js
Expand Up @@ -98,9 +98,23 @@ Prism.languages.insertBefore('javascript', 'string', {
},
'string': /[\s\S]+/
}
},
'string-property': {
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
lookbehind: true,
greedy: true,
alias: 'property'
}
});

Prism.languages.insertBefore('javascript', 'operator', {
'literal-property': {
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
lookbehind: true,
alias: 'property'
},
});

if (Prism.languages.markup) {
Prism.languages.markup.tag.addInlined('script', 'javascript');

Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/prism-tsx.js
Expand Up @@ -4,6 +4,7 @@

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

// This will prevent collisions between TSX tags and TS generic types.
// Idea by https://github.com/karlhorky
Expand Down
2 changes: 1 addition & 1 deletion components/prism-tsx.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/prism-typescript.js
Expand Up @@ -21,6 +21,7 @@

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

// a version of typescript specifically for highlighting types
var typeInside = Prism.languages.extend('typescript', {});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-typescript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions prism.js
Expand Up @@ -1647,9 +1647,23 @@ Prism.languages.insertBefore('javascript', 'string', {
},
'string': /[\s\S]+/
}
},
'string-property': {
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
lookbehind: true,
greedy: true,
alias: 'property'
}
});

Prism.languages.insertBefore('javascript', 'operator', {
'literal-property': {
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
lookbehind: true,
alias: 'property'
},
});

if (Prism.languages.markup) {
Prism.languages.markup.tag.addInlined('script', 'javascript');

Expand Down
26 changes: 13 additions & 13 deletions tests/languages/javascript+http/issue2733.test
Expand Up @@ -47,66 +47,66 @@ transfer-encoding: chunked
["application-json", [
["punctuation", "{"],

["string", "\"id\""],
["string-property", "\"id\""],
["operator", ":"],
["number", "1"],
["punctuation", ","],

["string", "\"name\""],
["string-property", "\"name\""],
["operator", ":"],
["string", "\"John Doe\""],
["punctuation", ","],

["string", "\"userName\""],
["string-property", "\"userName\""],
["operator", ":"],
["string", "\"jdoe\""],
["punctuation", ","],

["string", "\"email\""],
["string-property", "\"email\""],
["operator", ":"],
["string", "\"whatever@something.zzz\""],
["punctuation", ","],

["string", "\"phone\""],
["string-property", "\"phone\""],
["operator", ":"],
["string", "\"1234567890\""],
["punctuation", ","],

["string", "\"birthDate\""],
["string-property", "\"birthDate\""],
["operator", ":"],
["string", "\"1878-05-06\""],
["punctuation", ","],

["string", "\"address\""],
["string-property", "\"address\""],
["operator", ":"],
["punctuation", "{"],

["string", "\"street\""],
["string-property", "\"street\""],
["operator", ":"],
["string", "\"Fake St\""],
["punctuation", ","],

["string", "\"street2\""],
["string-property", "\"street2\""],
["operator", ":"],
["string", "\"Apt. 556\""],
["punctuation", ","],

["string", "\"city\""],
["string-property", "\"city\""],
["operator", ":"],
["string", "\"Gwenborough\""],
["punctuation", ","],

["string", "\"state\""],
["string-property", "\"state\""],
["operator", ":"],
["string", "\"ZZ\""],
["punctuation", ","],

["string", "\"zip\""],
["string-property", "\"zip\""],
["operator", ":"],
["string", "\"12345\""],

["punctuation", "}"],

["punctuation", "}"]
]]
]
]
4 changes: 2 additions & 2 deletions tests/languages/javascript/class-method_feature.test
Expand Up @@ -57,10 +57,10 @@ class Test {
["punctuation", "("],
["parameter", [
["punctuation", "{"],
" props",
["literal-property", "props"],
["operator", ":"],
["punctuation", "{"],
" a",
["literal-property", "a"],
["operator", ":"],
" _A",
["punctuation", ","],
Expand Down
29 changes: 13 additions & 16 deletions tests/languages/javascript/function-variable_feature.test
Expand Up @@ -43,18 +43,16 @@ a = function () {}, b = () => {}
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation","}"],
["punctuation","}"],
["punctuation", "}"],
["punctuation", "}"],

["function-variable", "bar"],
["operator", "="],
["keyword", "async"],
["keyword", "function"],
["function", "baz"],
["punctuation", "("],
["parameter", [
"x"
]],
["parameter", ["x"]],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],
Expand All @@ -63,18 +61,16 @@ a = function () {}, b = () => {}
["operator", "="],
["keyword", "async"],
["punctuation", "("],
["parameter", [
"x"
]],
["parameter", ["x"]],
["punctuation", ")"],
["operator", "=>"], " x\r\n",
["operator", "=>"],
" x\r\n",

["function-variable", "fooBar"],
["operator", "="],
["parameter", [
"x"
]],
["operator", "=>"], " x\r\n",
["parameter", ["x"]],
["operator", "=>"],
" x\r\n",

["function-variable", "fooBar"],
["operator", "="],
Expand All @@ -85,7 +81,8 @@ a = function () {}, b = () => {}
" y"
]],
["punctuation", ")"],
["operator", "=>"], " x\r\n",
["operator", "=>"],
" x\r\n",

["function-variable", "ಠ_ಠ"],
["operator", "="],
Expand Down Expand Up @@ -118,10 +115,10 @@ a = function () {}, b = () => {}
["punctuation", "("],
["parameter", [
["punctuation", "{"],
" props",
["literal-property", "props"],
["operator", ":"],
["punctuation", "{"],
" a",
["literal-property", "a"],
["operator", ":"],
" _A",
["punctuation", ","],
Expand Down

0 comments on commit 3b2238f

Please sign in to comment.