From e6b06d0072dad4c7d8d07c901f2b109feffb1cd2 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 9 Jun 2020 14:25:48 -0700 Subject: [PATCH 1/6] Dart: allow built-in types to be identified with trailing ? --- src/languages/dart.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/languages/dart.js b/src/languages/dart.js index 25a05b63f1..0132c80753 100644 --- a/src/languages/dart.js +++ b/src/languages/dart.js @@ -72,17 +72,28 @@ export default function(hljs) { hljs.C_NUMBER_MODE, STRING ]; + var BUILT_IN_TYPES = + // dart:core + 'Comparable DateTime Duration Function Iterable Iterator List Map Match Object Pattern RegExp Set Stopwatch ' + + 'String StringBuffer StringSink Symbol Type Uri bool double int num ' + + // dart:html + 'Element ElementList'; + var KEYWORDS = { keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + 'dynamic else enum export extends extension external factory false final finally for Function get hide if ' + 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + 'show static super switch sync this throw true try typedef var void while with yield', built_in: + // non-nullable built-in types + BUILT_IN_TYPES + ' ' + + // nullable built-in types + BUILT_IN_TYPES.split(' ').map((e) => { e + '?' }).join(' ') + ' ' + // dart:core - 'Comparable DateTime Duration Function Iterable Iterator List Map Match Never Null Object Pattern RegExp ' + - 'Set Stopwatch String StringBuffer StringSink Symbol Type Uri bool double dynamic int num print ' + + 'Never Null dynamic print ' + // dart:html - 'Element ElementList document querySelector querySelectorAll window' + 'document querySelector querySelectorAll window', + $pattern: /[A-Za-z][A-Za-z0-9_]+\??/ }; return { From 4c4990237621a6caf1cd787161bb35f8578ea2be Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 9 Jun 2020 16:48:11 -0700 Subject: [PATCH 2/6] Feedback --- src/languages/dart.js | 57 +++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/languages/dart.js b/src/languages/dart.js index 0132c80753..dfd21eae65 100644 --- a/src/languages/dart.js +++ b/src/languages/dart.js @@ -72,12 +72,36 @@ export default function(hljs) { hljs.C_NUMBER_MODE, STRING ]; - var BUILT_IN_TYPES = + var BUILT_IN_TYPES = [ // dart:core - 'Comparable DateTime Duration Function Iterable Iterator List Map Match Object Pattern RegExp Set Stopwatch ' + - 'String StringBuffer StringSink Symbol Type Uri bool double int num ' + + 'Comparable', + 'DateTime', + 'Duration', + 'Function', + 'Iterable', + 'Iterator', + 'List', + 'Map', + 'Match', + 'Object', + 'Pattern', + 'RegExp', + 'Set', + 'Stopwatch', + 'String', + 'StringBuffer', + 'StringSink', + 'Symbol', + 'Type', + 'Uri', + 'bool', + 'double', + 'int', + 'num', // dart:html - 'Element ElementList'; + 'Element', + 'ElementList', + ]; var KEYWORDS = { keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + @@ -85,15 +109,22 @@ export default function(hljs) { 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + 'show static super switch sync this throw true try typedef var void while with yield', built_in: - // non-nullable built-in types - BUILT_IN_TYPES + ' ' + - // nullable built-in types - BUILT_IN_TYPES.split(' ').map((e) => { e + '?' }).join(' ') + ' ' + - // dart:core - 'Never Null dynamic print ' + - // dart:html - 'document querySelector querySelectorAll window', - $pattern: /[A-Za-z][A-Za-z0-9_]+\??/ + // non-nullable built-in types + BUILT_IN_TYPES.concat( + // nullable built-in types + BUILT_IN_TYPES.map((e) => `${e}?`)).concat([ + // dart:core + 'Never', + 'Null', + 'dynamic', + 'print', + // dart:html + 'document', + 'querySelector', + 'querySelectorAll', + 'window', + ]).join(' '), + $pattern: /[A-Za-z][A-Za-z0-9_]*\??/ }; return { From 937d1c7bb334fd3e0d4b0dc10144de4283d308af Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 11 Jun 2020 11:33:56 -0400 Subject: [PATCH 3/6] style --- src/languages/dart.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/languages/dart.js b/src/languages/dart.js index dfd21eae65..b4867ef501 100644 --- a/src/languages/dart.js +++ b/src/languages/dart.js @@ -102,6 +102,7 @@ export default function(hljs) { 'Element', 'ElementList', ]; + var NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`); var KEYWORDS = { keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + @@ -109,21 +110,20 @@ export default function(hljs) { 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + 'show static super switch sync this throw true try typedef var void while with yield', built_in: - // non-nullable built-in types - BUILT_IN_TYPES.concat( - // nullable built-in types - BUILT_IN_TYPES.map((e) => `${e}?`)).concat([ - // dart:core - 'Never', - 'Null', - 'dynamic', - 'print', - // dart:html - 'document', - 'querySelector', - 'querySelectorAll', - 'window', - ]).join(' '), + BUILT_IN_TYPES + .concat(NULLABLE_BUILT_IN_TYPES) + .concat([ + // dart:core + 'Never', + 'Null', + 'dynamic', + 'print', + // dart:html + 'document', + 'querySelector', + 'querySelectorAll', + 'window', + ]).join(' '), $pattern: /[A-Za-z][A-Za-z0-9_]*\??/ }; @@ -172,5 +172,5 @@ export default function(hljs) { begin: '=>' // No markup, just a relevance booster } ] - } + }; } From 63931f0253c42129b6613a7aa05f49cfd72201e7 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 11 Jun 2020 11:39:45 -0400 Subject: [PATCH 4/6] const vs var --- src/languages/dart.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/languages/dart.js b/src/languages/dart.js index b4867ef501..41e6a47511 100644 --- a/src/languages/dart.js +++ b/src/languages/dart.js @@ -8,23 +8,23 @@ Category: scripting */ export default function(hljs) { - var SUBST = { + const SUBST = { className: 'subst', variants: [{ begin: '\\$[A-Za-z0-9_]+' }], }; - var BRACED_SUBST = { + const BRACED_SUBST = { className: 'subst', variants: [{ begin: '\\${', end: '}' - }, ], + }], keywords: 'true false null this is new super', }; - var STRING = { + const STRING = { className: 'string', variants: [{ begin: 'r\'\'\'', @@ -72,7 +72,7 @@ export default function(hljs) { hljs.C_NUMBER_MODE, STRING ]; - var BUILT_IN_TYPES = [ + const BUILT_IN_TYPES = [ // dart:core 'Comparable', 'DateTime', @@ -102,13 +102,13 @@ export default function(hljs) { 'Element', 'ElementList', ]; - var NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`); + const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`); - var KEYWORDS = { + const KEYWORDS = { keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + 'dynamic else enum export extends extension external factory false final finally for Function get hide if ' + 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + - 'show static super switch sync this throw true try typedef var void while with yield', + 'show static super switch sync this throw true try typedef const void while with yield', built_in: BUILT_IN_TYPES .concat(NULLABLE_BUILT_IN_TYPES) From bfd12b241ba508dbaa72318fb8834d6e17a00a94 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 11 Jun 2020 09:32:06 -0700 Subject: [PATCH 5/6] CHANGES --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 75e435d373..54c2439e17 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,7 +44,7 @@ Language Improvements: - fix(typescript) `=>` function with nested `()` in params now works (#2502) [Josh Goebel][] - fix(yaml) Fix tags to include non-word characters (#2486) [Peter Plantinga][] - fix(swift) `@objcMembers` was being partially highlighted (#2543) [Nick Randall][] -- enh(dart) Add `late` and `required` keywords, and `Never` built-in type (#2550) [Sam Rawlins][] +- enh(dart) Add `late` and `required` keywords, the `Never` built-in type, and nullable built-in types (#2550) [Sam Rawlins][] - enh(erlang) Add underscore separators to numeric literals (#2554) [Sergey Prokhorov][] - enh(handlebars) Support for sub-expressions, path-expressions, hashes, block-parameters and literals (#2344) [Nils Knappmeier][] - enh(protobuf) Support multiline comments (#2597) [Pavel Evstigneev][] From 145bb82321e6251ac2ae400c393b33d756d5ee7e Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 11 Jun 2020 18:40:16 -0400 Subject: [PATCH 6/6] Update src/languages/dart.js --- src/languages/dart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/dart.js b/src/languages/dart.js index 41e6a47511..08808da60f 100644 --- a/src/languages/dart.js +++ b/src/languages/dart.js @@ -108,7 +108,7 @@ export default function(hljs) { keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + 'dynamic else enum export extends extension external factory false final finally for Function get hide if ' + 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + - 'show static super switch sync this throw true try typedef const void while with yield', + 'show static super switch sync this throw true try typedef var void while with yield', built_in: BUILT_IN_TYPES .concat(NULLABLE_BUILT_IN_TYPES)