From 3b2238fa8ffd81f25e638468d0260045a72b9bfd Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sun, 10 Oct 2021 19:36:58 +0200 Subject: [PATCH] JS: Added properties (#3099) --- components/prism-actionscript.js | 4 + components/prism-actionscript.min.js | 2 +- components/prism-javascript.js | 14 + components/prism-javascript.min.js | 2 +- components/prism-tsx.js | 1 + components/prism-tsx.min.js | 2 +- components/prism-typescript.js | 1 + components/prism-typescript.min.js | 2 +- prism.js | 14 + .../languages/javascript+http/issue2733.test | 26 +- .../javascript/class-method_feature.test | 4 +- .../javascript/function-variable_feature.test | 29 +- .../javascript/function_feature.test | 77 +++- .../languages/javascript/keyword_feature.test | 2 +- .../javascript/property_feature.test | 159 +++++++ .../javascript/template-string_feature.test | 12 +- tests/languages/jsx/issue1235.test | 2 +- tests/languages/jsx/issue1335.test | 38 +- tests/languages/jsx/issue1408.test | 6 +- tests/languages/mongodb/document_feature.test | 402 ++++++++---------- tests/languages/pug/tag_feature.test | 45 +- 21 files changed, 527 insertions(+), 317 deletions(-) create mode 100644 tests/languages/javascript/property_feature.test diff --git a/components/prism-actionscript.js b/components/prism-actionscript.js index 6d91121632..72a4d232be 100644 --- a/components/prism-actionscript.js +++ b/components/prism-actionscript.js @@ -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': { diff --git a/components/prism-actionscript.min.js b/components/prism-actionscript.min.js index 187430b78d..30844f1fa8 100644 --- a/components/prism-actionscript.min.js +++ b/components/prism-actionscript.min.js @@ -1 +1 @@ -Prism.languages.actionscript=Prism.languages.extend("javascript",{keyword:/\b(?:as|break|case|catch|class|const|default|delete|do|dynamic|each|else|extends|final|finally|for|function|get|if|implements|import|in|include|instanceof|interface|internal|is|namespace|native|new|null|override|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|use|var|void|while|with)\b/,operator:/\+\+|--|(?:[+\-*\/%^]|&&?|\|\|?|<>?>?|[!=]=?)=?|[~?@]/}),Prism.languages.actionscript["class-name"].alias="function",Prism.languages.markup&&Prism.languages.insertBefore("actionscript","string",{xml:{pattern:/(^|[^.])<\/?\w+(?:\s+[^\s>\/=]+=("|')(?:\\[\s\S]|(?!\2)[^\\])*\2)*\s*\/?>/,lookbehind:!0,inside:Prism.languages.markup}}); \ No newline at end of file +Prism.languages.actionscript=Prism.languages.extend("javascript",{keyword:/\b(?:as|break|case|catch|class|const|default|delete|do|dynamic|each|else|extends|final|finally|for|function|get|if|implements|import|in|include|instanceof|interface|internal|is|namespace|native|new|null|override|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|use|var|void|while|with)\b/,operator:/\+\+|--|(?:[+\-*\/%^]|&&?|\|\|?|<>?>?|[!=]=?)=?|[~?@]/}),Prism.languages.actionscript["class-name"].alias="function",delete Prism.languages.actionscript.parameter,delete Prism.languages.actionscript["literal-property"],Prism.languages.markup&&Prism.languages.insertBefore("actionscript","string",{xml:{pattern:/(^|[^.])<\/?\w+(?:\s+[^\s>\/=]+=("|')(?:\\[\s\S]|(?!\2)[^\\])*\2)*\s*\/?>/,lookbehind:!0,inside:Prism.languages.markup}}); \ No newline at end of file diff --git a/components/prism-javascript.js b/components/prism-javascript.js index 9b5f9b8591..9471cbfc93 100644 --- a/components/prism-javascript.js +++ b/components/prism-javascript.js @@ -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'); diff --git a/components/prism-javascript.min.js b/components/prism-javascript.min.js index 0e14ff07bd..75b4d33434 100644 --- a/components/prism-javascript.min.js +++ b/components/prism-javascript.min.js @@ -1 +1 @@ -Prism.languages.javascript=Prism.languages.extend("clike",{"class-name":[Prism.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:/\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:Prism.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined("script","javascript"),Prism.languages.markup.tag.addAttribute("on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)","javascript")),Prism.languages.js=Prism.languages.javascript; \ No newline at end of file +Prism.languages.javascript=Prism.languages.extend("clike",{"class-name":[Prism.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:/\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:Prism.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),Prism.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined("script","javascript"),Prism.languages.markup.tag.addAttribute("on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)","javascript")),Prism.languages.js=Prism.languages.javascript; \ No newline at end of file diff --git a/components/prism-tsx.js b/components/prism-tsx.js index 2bb2fdc9d6..33b0ec6e1c 100644 --- a/components/prism-tsx.js +++ b/components/prism-tsx.js @@ -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 diff --git a/components/prism-tsx.min.js b/components/prism-tsx.min.js index 79b70fd034..5819dcdd2b 100644 --- a/components/prism-tsx.min.js +++ b/components/prism-tsx.min.js @@ -1 +1 @@ -!function(e){var a=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend("jsx",a),delete e.languages.tsx.parameter;var t=e.languages.tsx.tag;t.pattern=RegExp("(^|[^\\w$]|(?=]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter;var s=e.languages.extend("typescript",{});delete s["class-name"],e.languages.typescript["class-name"].inside=s,e.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:s}}}}),e.languages.ts=e.languages.typescript}(Prism); \ No newline at end of file +!function(e){e.languages.typescript=e.languages.extend("javascript",{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript["literal-property"];var s=e.languages.extend("typescript",{});delete s["class-name"],e.languages.typescript["class-name"].inside=s,e.languages.insertBefore("typescript","function",{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:"operator"},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:s}}}}),e.languages.ts=e.languages.typescript}(Prism); \ No newline at end of file diff --git a/prism.js b/prism.js index 00d8cedf40..41d8ef3af0 100644 --- a/prism.js +++ b/prism.js @@ -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'); diff --git a/tests/languages/javascript+http/issue2733.test b/tests/languages/javascript+http/issue2733.test index cdd0e2e827..aa07a46d5a 100644 --- a/tests/languages/javascript+http/issue2733.test +++ b/tests/languages/javascript+http/issue2733.test @@ -47,61 +47,61 @@ 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\""], @@ -109,4 +109,4 @@ transfer-encoding: chunked ["punctuation", "}"] ]] -] \ No newline at end of file +] diff --git a/tests/languages/javascript/class-method_feature.test b/tests/languages/javascript/class-method_feature.test index f2f1e2dedf..31d08e3415 100644 --- a/tests/languages/javascript/class-method_feature.test +++ b/tests/languages/javascript/class-method_feature.test @@ -57,10 +57,10 @@ class Test { ["punctuation", "("], ["parameter", [ ["punctuation", "{"], - " props", + ["literal-property", "props"], ["operator", ":"], ["punctuation", "{"], - " a", + ["literal-property", "a"], ["operator", ":"], " _A", ["punctuation", ","], diff --git a/tests/languages/javascript/function-variable_feature.test b/tests/languages/javascript/function-variable_feature.test index 37d08f9c18..2ebc2a97e5 100644 --- a/tests/languages/javascript/function-variable_feature.test +++ b/tests/languages/javascript/function-variable_feature.test @@ -43,8 +43,8 @@ a = function () {}, b = () => {} ["punctuation", "("], ["punctuation", ")"], ["punctuation", "{"], - ["punctuation","}"], - ["punctuation","}"], + ["punctuation", "}"], + ["punctuation", "}"], ["function-variable", "bar"], ["operator", "="], @@ -52,9 +52,7 @@ a = function () {}, b = () => {} ["keyword", "function"], ["function", "baz"], ["punctuation", "("], - ["parameter", [ - "x" - ]], + ["parameter", ["x"]], ["punctuation", ")"], ["punctuation", "{"], ["punctuation", "}"], @@ -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", "="], @@ -85,7 +81,8 @@ a = function () {}, b = () => {} " y" ]], ["punctuation", ")"], - ["operator", "=>"], " x\r\n", + ["operator", "=>"], + " x\r\n", ["function-variable", "ಠ_ಠ"], ["operator", "="], @@ -118,10 +115,10 @@ a = function () {}, b = () => {} ["punctuation", "("], ["parameter", [ ["punctuation", "{"], - " props", + ["literal-property", "props"], ["operator", ":"], ["punctuation", "{"], - " a", + ["literal-property", "a"], ["operator", ":"], " _A", ["punctuation", ","], diff --git a/tests/languages/javascript/function_feature.test b/tests/languages/javascript/function_feature.test index 3665f673c1..fcd88c97f3 100644 --- a/tests/languages/javascript/function_feature.test +++ b/tests/languages/javascript/function_feature.test @@ -15,19 +15,70 @@ foo({ y: fun() }) ---------------------------------------------------- [ - ["function", "foo"], ["punctuation", "("], ["punctuation", ")"], - ["function", "foo"], ["punctuation", "("], ["punctuation", ")"], - ["function", "foo"], ["punctuation", "."], ["function", "call"], ["punctuation", "("], ["punctuation", ")"], - ["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"], - ["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"], - ["function", "f42"], ["punctuation", "("], ["punctuation", ")"], - ["function", "_"], ["punctuation", "("], ["punctuation", ")"], - ["function", "$"], ["punctuation", "("], ["punctuation", ")"], - ["function", "ಠ_ಠ"], ["punctuation", "("], ["punctuation", ")"], - ["function", "Ƞȡ_҇"], ["punctuation", "("], ["punctuation", ")"], - ["keyword", "if"], ["punctuation", "("], "notAFunction", ["punctuation", ")"], - ["function", "foo"], ["punctuation", "("], ["punctuation", "{"], " x ", ["punctuation", "}"], ["punctuation", ")"], - ["function", "foo"], ["punctuation", "("], ["punctuation", "{"], " y", ["operator", ":"], ["function", "fun"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", "}"], ["punctuation", ")"] + ["function", "foo"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "foo"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "foo"], + ["punctuation", "."], + ["function", "call"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "foo_bar"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "foo_bar"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "f42"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "_"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "$"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "ಠ_ಠ"], + ["punctuation", "("], + ["punctuation", ")"], + + ["function", "Ƞȡ_҇"], + ["punctuation", "("], + ["punctuation", ")"], + + ["keyword", "if"], + ["punctuation", "("], + "notAFunction", + ["punctuation", ")"], + + ["function", "foo"], + ["punctuation", "("], + ["punctuation", "{"], + " x ", + ["punctuation", "}"], + ["punctuation", ")"], + + ["function", "foo"], + ["punctuation", "("], + ["punctuation", "{"], + ["literal-property", "y"], + ["operator", ":"], + ["function", "fun"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "}"], + ["punctuation", ")"] ] ---------------------------------------------------- diff --git a/tests/languages/javascript/keyword_feature.test b/tests/languages/javascript/keyword_feature.test index ee4eab02c9..b303733569 100644 --- a/tests/languages/javascript/keyword_feature.test +++ b/tests/languages/javascript/keyword_feature.test @@ -207,7 +207,7 @@ assert.equal(foo, bar); ["string", "\"./foo.json\""], ["keyword", "assert"], ["punctuation", "{"], - " type", + ["literal-property", "type"], ["operator", ":"], ["string", "\"json\""], ["punctuation", "}"], diff --git a/tests/languages/javascript/property_feature.test b/tests/languages/javascript/property_feature.test new file mode 100644 index 0000000000..594cfb4cc2 --- /dev/null +++ b/tests/languages/javascript/property_feature.test @@ -0,0 +1,159 @@ +{ foo: 0, bar: 0 }; +{ 'foo': 0, "bar": 0 }; +{ + // comment + foo: 0, + // comment + "bar": 0 +} + +const test = new TYPE.Application({ + key1: viewDim.x, + key2: viewDim.y, + key3: 0x89ddff, + key4: window.devicePixelRatio || 1, + key5: resize() +}); + +// doesn't conflict with function properties +{ + foo: () => 0, + bar: async function () {} +} + +// no problem with keywords +switch(foo) { + default: return true; +} + +---------------------------------------------------- + +[ + ["punctuation", "{"], + ["literal-property", "foo"], + ["operator", ":"], + ["number", "0"], + ["punctuation", ","], + ["literal-property", "bar"], + ["operator", ":"], + ["number", "0"], + ["punctuation", "}"], + ["punctuation", ";"], + + ["punctuation", "{"], + ["string-property", "'foo'"], + ["operator", ":"], + ["number", "0"], + ["punctuation", ","], + ["string-property", "\"bar\""], + ["operator", ":"], + ["number", "0"], + ["punctuation", "}"], + ["punctuation", ";"], + + ["punctuation", "{"], + + ["comment", "// comment"], + + ["literal-property", "foo"], + ["operator", ":"], + ["number", "0"], + ["punctuation", ","], + + ["comment", "// comment"], + + ["string-property", "\"bar\""], + ["operator", ":"], + ["number", "0"], + + ["punctuation", "}"], + + ["keyword", "const"], + " test ", + ["operator", "="], + ["keyword", "new"], + ["class-name", [ + "TYPE", + ["punctuation", "."], + "Application" + ]], + ["punctuation", "("], + ["punctuation", "{"], + + ["literal-property", "key1"], + ["operator", ":"], + " viewDim", + ["punctuation", "."], + "x", + ["punctuation", ","], + + ["literal-property", "key2"], + ["operator", ":"], + " viewDim", + ["punctuation", "."], + "y", + ["punctuation", ","], + + ["literal-property", "key3"], + ["operator", ":"], + ["number", "0x89ddff"], + ["punctuation", ","], + + ["literal-property", "key4"], + ["operator", ":"], + " window", + ["punctuation", "."], + "devicePixelRatio ", + ["operator", "||"], + ["number", "1"], + ["punctuation", ","], + + ["literal-property", "key5"], + ["operator", ":"], + ["function", "resize"], + ["punctuation", "("], + ["punctuation", ")"], + + ["punctuation", "}"], + ["punctuation", ")"], + ["punctuation", ";"], + + ["comment", "// doesn't conflict with function properties"], + + ["punctuation", "{"], + + ["function-variable", "foo"], + ["operator", ":"], + ["punctuation", "("], + ["punctuation", ")"], + ["operator", "=>"], + ["number", "0"], + ["punctuation", ","], + + ["function-variable", "bar"], + ["operator", ":"], + ["keyword", "async"], + ["keyword", "function"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + + ["punctuation", "}"], + + ["comment", "// no problem with keywords"], + + ["keyword", "switch"], + ["punctuation", "("], + "foo", + ["punctuation", ")"], + ["punctuation", "{"], + + ["keyword", "default"], + ["operator", ":"], + ["keyword", "return"], + ["boolean", "true"], + ["punctuation", ";"], + + ["punctuation", "}"] +] diff --git a/tests/languages/javascript/template-string_feature.test b/tests/languages/javascript/template-string_feature.test index 97e7d0e396..10a2924581 100644 --- a/tests/languages/javascript/template-string_feature.test +++ b/tests/languages/javascript/template-string_feature.test @@ -18,11 +18,13 @@ console.log(`This is ${it.with({ type: false })}!`) ["string", "foo bar"], ["template-punctuation", "`"] ]], + ["template-string", [ ["template-punctuation", "`"], ["string", "foo\r\nbar"], ["template-punctuation", "`"] ]], + ["template-string", [ ["template-punctuation", "`"], ["string", "40+2="], @@ -35,6 +37,7 @@ console.log(`This is ${it.with({ type: false })}!`) ]], ["template-punctuation", "`"] ]], + ["template-string", [ ["template-punctuation", "`"], ["interpolation", [ @@ -46,6 +49,7 @@ console.log(`This is ${it.with({ type: false })}!`) ]], ["template-punctuation", "`"] ]], + ["template-string", [ ["template-punctuation", "`"], ["string", "\\${foo}"], @@ -56,13 +60,16 @@ console.log(`This is ${it.with({ type: false })}!`) ]], ["template-punctuation", "`"] ]], + ["string", "\"foo `a` `b` `c` `d` bar\""], + ["string", "\"test // test\""], ["template-string", [ ["template-punctuation", "`"], ["string", "template"], ["template-punctuation", "`"] ]], + "\r\n\r\nconsole", ["punctuation", "."], ["function", "log"], @@ -77,7 +84,7 @@ console.log(`This is ${it.with({ type: false })}!`) ["function", "with"], ["punctuation", "("], ["punctuation", "{"], - " type", + ["literal-property", "type"], ["operator", ":"], ["boolean", "false"], ["punctuation", "}"], @@ -88,12 +95,13 @@ console.log(`This is ${it.with({ type: false })}!`) ["template-punctuation", "`"] ]], ["punctuation", ")"], + ["template-string", [ ["template-punctuation", "`"], ["interpolation", [ ["interpolation-punctuation", "${"], ["punctuation", "{"], - "foo", + ["literal-property", "foo"], ["operator", ":"], ["string", "'bar'"], ["punctuation", "}"], diff --git a/tests/languages/jsx/issue1235.test b/tests/languages/jsx/issue1235.test index 97c5178683..7021b8de37 100644 --- a/tests/languages/jsx/issue1235.test +++ b/tests/languages/jsx/issue1235.test @@ -13,7 +13,7 @@ ["script-punctuation", "="], ["punctuation", "{"], ["punctuation", "{"], - " track", + ["literal-property", "track"], ["operator", ":"], ["boolean", "true"], ["punctuation", "}"], diff --git a/tests/languages/jsx/issue1335.test b/tests/languages/jsx/issue1335.test index c7863f27b8..be0d3e0b4b 100644 --- a/tests/languages/jsx/issue1335.test +++ b/tests/languages/jsx/issue1335.test @@ -16,16 +16,12 @@ ["punctuation", "<"], ["class-name", "Button"] ]], - ["attr-name", [ - "onClick" - ]], + ["attr-name", ["onClick"]], ["script", [ ["script-punctuation", "="], ["punctuation", "{"], ["punctuation", "("], - ["parameter", [ - "e" - ]], + ["parameter", ["e"]], ["punctuation", ")"], ["operator", "=>"], ["keyword", "this"], @@ -33,7 +29,7 @@ ["function", "setState"], ["punctuation", "("], ["punctuation", "{"], - "clicked", + ["literal-property", "clicked"], ["operator", ":"], ["boolean", "true"], ["punctuation", "}"], @@ -42,51 +38,54 @@ ]], ["punctuation", "/>"] ]], + ["tag", [ ["tag", [ ["punctuation", "<"], ["class-name", "Component"] ]], - ["attr-name", [ - "data" - ]], + + ["attr-name", ["data"]], ["script", [ ["script-punctuation", "="], ["punctuation", "{"], ["punctuation", "["], + ["punctuation", "{"], - "id", + ["literal-property", "id"], ["operator", ":"], ["number", "0"], ["punctuation", ","], - " name", + ["literal-property", "name"], ["operator", ":"], ["string", "'Joe'"], ["punctuation", "}"], ["punctuation", ","], + ["punctuation", "{"], - "id", + ["literal-property", "id"], ["operator", ":"], ["number", "1"], ["punctuation", ","], - " name", + ["literal-property", "name"], ["operator", ":"], ["string", "'Sue'"], ["punctuation", "}"], ["punctuation", ","], + ["punctuation", "]"], ["punctuation", "}"] ]], + ["punctuation", "/>"] ]], + ["tag", [ ["tag", [ ["punctuation", "<"], ["class-name", "Component"] ]], - ["attr-name", [ - "title" - ]], + ["attr-name", ["title"]], ["script", [ ["script-punctuation", "="], ["punctuation", "{"], @@ -103,14 +102,13 @@ ]], ["punctuation", "/>"] ]], + ["tag", [ ["tag", [ ["punctuation", "<"], ["class-name", "Component"] ]], - ["attr-name", [ - "title" - ]], + ["attr-name", ["title"]], ["script", [ ["script-punctuation", "="], ["punctuation", "{"], diff --git a/tests/languages/jsx/issue1408.test b/tests/languages/jsx/issue1408.test index 395f1dd317..2e458670b8 100644 --- a/tests/languages/jsx/issue1408.test +++ b/tests/languages/jsx/issue1408.test @@ -8,14 +8,12 @@ ["punctuation", "<"], "div" ]], - ["attr-name", [ - "style" - ]], + ["attr-name", ["style"]], ["script", [ ["script-punctuation", "="], ["punctuation", "{"], ["punctuation", "{"], - " marginLeft", + ["literal-property", "marginLeft"], ["operator", ":"], ["template-string", [ ["template-punctuation", "`"], diff --git a/tests/languages/mongodb/document_feature.test b/tests/languages/mongodb/document_feature.test index 51f167d99e..6d5c5fff1f 100644 --- a/tests/languages/mongodb/document_feature.test +++ b/tests/languages/mongodb/document_feature.test @@ -25,234 +25,180 @@ ---------------------------------------------------- [ - ["punctuation", "{"], - ["property", [ - "'_id'" - ]], - ["operator", ":"], - ["builtin", "ObjectId"], - ["punctuation", "("], - ["string", [ - "'5ec72ffe00316be87cab3927'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'code'" - ]], - ["operator", ":"], - ["builtin", "Code"], - ["punctuation", "("], - ["string", [ - "'function () { return 22; }'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'binary'" - ]], - ["operator", ":"], - ["builtin", "BinData"], - ["punctuation", "("], - ["number", "1"], - ["punctuation", ","], - ["string", [ - "'232sa3d323sd232a32sda3s2d3a2s1d23s21d3sa'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'dbref'" - ]], - ["operator", ":"], - ["builtin", "DBRef"], - ["punctuation", "("], - ["string", [ - "'namespace'" - ]], - ["punctuation", ","], - ["builtin", "ObjectId"], - ["punctuation", "("], - ["string", [ - "'5ec72f4200316be87cab3926'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["string", [ - "'db'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'timestamp'" - ]], - ["operator", ":"], - ["builtin", "Timestamp"], - ["punctuation", "("], - ["number", "0"], - ["punctuation", ","], - ["number", "0"], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'long'" - ]], - ["operator", ":"], - ["builtin", "NumberLong"], - ["punctuation", "("], - ["number", "9223372036854775807"], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'decimal'" - ]], - ["operator", ":"], - ["builtin", "NumberDecimal"], - ["punctuation", "("], - ["string", [ - "'1000.55'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'integer'" - ]], - ["operator", ":"], - ["number", "100"], - ["punctuation", ","], - ["property", [ - "'maxkey'" - ]], - ["operator", ":"], - ["builtin", "MaxKey"], - ["punctuation", "("], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'minkey'" - ]], - ["operator", ":"], - ["builtin", "MinKey"], - ["punctuation", "("], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'isodate'" - ]], - ["operator", ":"], - ["builtin", "ISODate"], - ["punctuation", "("], - ["string", [ - "'2012-01-01T00:00:00.000Z'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'regexp'" - ]], - ["operator", ":"], - ["builtin", "RegExp"], - ["punctuation", "("], - ["string", [ - "'prism(js)?'" - ]], - ["punctuation", ","], - ["string", [ - "'i'" - ]], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'string'" - ]], - ["operator", ":"], - ["string", [ - "'Hello World'" - ]], - ["punctuation", ","], - ["property", [ - "'numberArray'" - ]], - ["operator", ":"], - ["punctuation", "["], - ["number", "1"], - ["punctuation", ","], - ["number", "2"], - ["punctuation", ","], - ["number", "3"], - ["punctuation", "]"], - ["punctuation", ","], - ["property", [ - "'stringArray'" - ]], - ["operator", ":"], - ["punctuation", "["], - ["string", [ - "'1'" - ]], - ["punctuation", ","], - ["string", [ - "'2'" - ]], - ["punctuation", ","], - ["string", [ - "'3'" - ]], - ["punctuation", "]"], - ["punctuation", ","], - ["property", [ - "'randomKey'" - ]], - ["operator", ":"], - ["keyword", "null"], - ["punctuation", ","], - ["property", [ - "'object'" - ]], - ["operator", ":"], - ["punctuation", "{"], - ["property", [ - "'a'" - ]], - ["operator", ":"], - ["number", "1"], - ["punctuation", ","], - ["property", [ - "'b'" - ]], - ["operator", ":"], - ["number", "2"], - ["punctuation", "}"], - ["punctuation", ","], - ["property", [ - "'max_key2'" - ]], - ["operator", ":"], - ["builtin", "MaxKey"], - ["punctuation", "("], - ["punctuation", ")"], - ["punctuation", ","], - ["property", [ - "'number'" - ]], - ["operator", ":"], - ["number", "1234"], - ["punctuation", ","], - ["property", [ - "'invalid-key'" - ]], - ["operator", ":"], - ["number", "123"], - ["punctuation", ","], - ["property", [ - "noQuotesKey" - ]], - ["operator", ":"], - ["string", [ - "'value'" - ]], - ["punctuation", ","], - ["punctuation", "}"] + ["punctuation", "{"], + + ["string-property", "'_id'"], + ["operator", ":"], + ["builtin", "ObjectId"], + ["punctuation", "("], + ["string", ["'5ec72ffe00316be87cab3927'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'code'"], + ["operator", ":"], + ["builtin", "Code"], + ["punctuation", "("], + ["string", ["'function () { return 22; }'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'binary'"], + ["operator", ":"], + ["builtin", "BinData"], + ["punctuation", "("], + ["number", "1"], + ["punctuation", ","], + ["string", ["'232sa3d323sd232a32sda3s2d3a2s1d23s21d3sa'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'dbref'"], + ["operator", ":"], + ["builtin", "DBRef"], + ["punctuation", "("], + ["string", ["'namespace'"]], + ["punctuation", ","], + ["builtin", "ObjectId"], + ["punctuation", "("], + ["string", ["'5ec72f4200316be87cab3926'"]], + ["punctuation", ")"], + ["punctuation", ","], + ["string", ["'db'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'timestamp'"], + ["operator", ":"], + ["builtin", "Timestamp"], + ["punctuation", "("], + ["number", "0"], + ["punctuation", ","], + ["number", "0"], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'long'"], + ["operator", ":"], + ["builtin", "NumberLong"], + ["punctuation", "("], + ["number", "9223372036854775807"], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'decimal'"], + ["operator", ":"], + ["builtin", "NumberDecimal"], + ["punctuation", "("], + ["string", ["'1000.55'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'integer'"], + ["operator", ":"], + ["number", "100"], + ["punctuation", ","], + + ["string-property", "'maxkey'"], + ["operator", ":"], + ["builtin", "MaxKey"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'minkey'"], + ["operator", ":"], + ["builtin", "MinKey"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'isodate'"], + ["operator", ":"], + ["builtin", "ISODate"], + ["punctuation", "("], + ["string", ["'2012-01-01T00:00:00.000Z'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'regexp'"], + ["operator", ":"], + ["builtin", "RegExp"], + ["punctuation", "("], + ["string", ["'prism(js)?'"]], + ["punctuation", ","], + ["string", ["'i'"]], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'string'"], + ["operator", ":"], + ["string", ["'Hello World'"]], + ["punctuation", ","], + + ["string-property", "'numberArray'"], + ["operator", ":"], + ["punctuation", "["], + ["number", "1"], + ["punctuation", ","], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", ","], + + ["string-property", "'stringArray'"], + ["operator", ":"], + ["punctuation", "["], + ["string", ["'1'"]], + ["punctuation", ","], + ["string", ["'2'"]], + ["punctuation", ","], + ["string", ["'3'"]], + ["punctuation", "]"], + ["punctuation", ","], + + ["string-property", "'randomKey'"], + ["operator", ":"], + ["keyword", "null"], + ["punctuation", ","], + + ["string-property", "'object'"], + ["operator", ":"], + ["punctuation", "{"], + ["string-property", "'a'"], + ["operator", ":"], + ["number", "1"], + ["punctuation", ","], + ["string-property", "'b'"], + ["operator", ":"], + ["number", "2"], + ["punctuation", "}"], + ["punctuation", ","], + + ["string-property", "'max_key2'"], + ["operator", ":"], + ["builtin", "MaxKey"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + + ["string-property", "'number'"], + ["operator", ":"], + ["number", "1234"], + ["punctuation", ","], + + ["string-property", "'invalid-key'"], + ["operator", ":"], + ["number", "123"], + ["punctuation", ","], + + ["property", ["noQuotesKey"]], + ["operator", ":"], + ["string", ["'value'"]], + ["punctuation", ","], + + ["punctuation", "}"] ] ---------------------------------------------------- diff --git a/tests/languages/pug/tag_feature.test b/tests/languages/pug/tag_feature.test index 9f07b5fa9b..97e3618e71 100644 --- a/tests/languages/pug/tag_feature.test +++ b/tests/languages/pug/tag_feature.test @@ -29,7 +29,7 @@ a: span ["function", "attributes"], ["punctuation", "("], ["punctuation", "{"], - ["string", "'data-foo'"], + ["string-property", "'data-foo'"], ["operator", ":"], ["string", "'bar'"], ["punctuation", "}"], @@ -43,11 +43,15 @@ a: span ["punctuation", "("], ["attr-name", "data-bar"], ["punctuation", "="], - ["attr-value", [["string", "\"foo\""]]], + ["attr-value", [ + ["string", "\"foo\""] + ]], ["punctuation", ","], ["attr-name", "type"], ["punctuation", "="], - ["attr-value", [["string", "'checkbox'"]]], + ["attr-value", [ + ["string", "'checkbox'"] + ]], ["punctuation", ","], ["attr-name", "checked"], ["punctuation", ")"] @@ -62,11 +66,11 @@ a: span ["punctuation", "="], ["attr-value", [ ["punctuation", "{"], - "color", + ["literal-property", "color"], ["operator", ":"], ["string", "'red'"], ["punctuation", ","], - " background", + ["literal-property", "background"], ["operator", ":"], ["string", "'green'"], ["punctuation", "}"] @@ -81,30 +85,45 @@ a: span ["punctuation", "("], ["attr-name", "unescaped"], ["punctuation", "!="], - ["attr-value", [["string", "\"\""]]], + ["attr-value", [ + ["string", "\"\""] + ]], ["punctuation", ")"] ]] ]], ["tag", [ "a", - ["attr-class", ".button"]]], - ["tag", [["attr-class", ".content"]]], + ["attr-class", ".button"] + ]], + ["tag", [ + ["attr-class", ".content"] + ]], + ["tag", [ "a", - ["attr-id", "#main-link"]]], - ["tag", [["attr-id", "#content"]]], + ["attr-id", "#main-link"] + ]], + ["tag", [ + ["attr-id", "#content"] + ]], + ["tag", [ "div", ["attr-id", "#test-id"], ["attr-class", ".test-class1"], - ["attr-class", ".test-class2"]]], + ["attr-class", ".test-class2"] + ]], ["tag", [ ["attr-class", ".test-class1"], ["attr-id", "#test-id"], - ["attr-class", ".test-class2"]]], + ["attr-class", ".test-class2"] + ]], - ["tag", ["a", ["punctuation", ":"]]], + ["tag", [ + "a", + ["punctuation", ":"] + ]], ["tag", ["span"]] ]