Skip to content

Commit

Permalink
enh(dart) highlight built-in nullable types (#2598)
Browse files Browse the repository at this point in the history
* Dart: allow built-in nullable types with trailing ? to be highlighted
  • Loading branch information
srawlins authored Jun 11, 2020
1 parent a010c15 commit b4046ce
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]
Expand Down
64 changes: 53 additions & 11 deletions src/languages/dart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\'\'\'',
Expand Down Expand Up @@ -72,17 +72,59 @@ export default function(hljs) {
hljs.C_NUMBER_MODE, STRING
];

var KEYWORDS = {
const 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',
];
const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`);

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',
built_in:
// 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 ' +
// dart:html
'Element ElementList document querySelector querySelectorAll window'
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_]*\??/
};

return {
Expand Down Expand Up @@ -130,5 +172,5 @@ export default function(hljs) {
begin: '=>' // No markup, just a relevance booster
}
]
}
};
}

0 comments on commit b4046ce

Please sign in to comment.