Skip to content

Commit

Permalink
Add support for stage 1 null coalesce operator.
Browse files Browse the repository at this point in the history
Issue #495
  • Loading branch information
sthub1 committed Apr 29, 2018
1 parent 2f57ce9 commit f835e71
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
6 changes: 6 additions & 0 deletions grammars/Babel Language.json
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,12 @@
"1": { "name": "keyword.operator.$1.js" }
}
},
{
"match": "\\s*+(\\?\\?)",
"captures": {
"1": { "name": "keyword.operator.nullcoalesce.js" }
}
},
{
"match": "\\s*+(!(?!=)|&&|\\|\\|)",
"captures": {
Expand Down
88 changes: 88 additions & 0 deletions spec/fixtures/grammar/issues.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,93 @@
// SYNTAX TEST "source.js.jsx"

// Issue #495
const undefinedValue = response.settings?.undefinedValue ?? 'some other default'; // result: 'some other default'
// <- storage.type.js
// <- storage.type.js
//^^^ storage.type.js
// ^^^^^^^^^^^^^^ variable.other.readwrite.js
// ^ keyword.operator.assignment.js
// ^^^^^^^^ variable.other.object.js
// ^ keyword.operator.accessor.js
// ^^^^^^^^ ^^^^^^^^^^^^^^ meta.property.object.js
// ^^^^^^^^ ^^^^^^^^^^^^^^ variable.other.property.js
// ^^ keyword.operator.existential.js
// ^^ keyword.operator.nullcoalesce.js
// ^^^^^ ^^^^^ ^^^^^^^^ string.quoted.single.js
// ^ punctuation.definition.string.begin.js
// ^ punctuation.definition.string.end.js
// ^ punctuation.terminator.statement.js
// ^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^ comment.line.double-slash.js
// ^^ punctuation.definition.comment.js
const nullValue = response.settings?.nullValue ?? 'some other default'; // result: 'some other default'
// <- storage.type.js
// <- storage.type.js
//^^^ storage.type.js
// ^^^^^^^^^ variable.other.readwrite.js
// ^ keyword.operator.assignment.js
// ^^^^^^^^ variable.other.object.js
// ^ keyword.operator.accessor.js
// ^^^^^^^^ ^^^^^^^^^ meta.property.object.js
// ^^^^^^^^ ^^^^^^^^^ variable.other.property.js
// ^^ keyword.operator.existential.js
// ^^ keyword.operator.nullcoalesce.js
// ^^^^^ ^^^^^ ^^^^^^^^ string.quoted.single.js
// ^ punctuation.definition.string.begin.js
// ^ punctuation.definition.string.end.js
// ^ punctuation.terminator.statement.js
// ^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^ comment.line.double-slash.js
// ^^ punctuation.definition.comment.js
const headerText = response.settings?.headerText ?? 'Hello, world!'; // result: ''
// <- storage.type.js
// <- storage.type.js
//^^^ storage.type.js
// ^^^^^^^^^^ variable.other.readwrite.js
// ^ keyword.operator.assignment.js
// ^^^^^^^^ variable.other.object.js
// ^ keyword.operator.accessor.js
// ^^^^^^^^ ^^^^^^^^^^ meta.property.object.js
// ^^^^^^^^ ^^^^^^^^^^ variable.other.property.js
// ^^ keyword.operator.existential.js
// ^^ keyword.operator.nullcoalesce.js
// ^^^^^^^ ^^^^^^^ string.quoted.single.js
// ^ punctuation.definition.string.begin.js
// ^ punctuation.definition.string.end.js
// ^ punctuation.terminator.statement.js
// ^^ ^^^^^^^ ^^ comment.line.double-slash.js
// ^^ punctuation.definition.comment.js
const animationDuration = response.settings?.animationDuration ?? 300; // result: 0
// <- storage.type.js
// <- storage.type.js
//^^^ storage.type.js
// ^^^^^^^^^^^^^^^^^ variable.other.readwrite.js
// ^ keyword.operator.assignment.js
// ^^^^^^^^ variable.other.object.js
// ^ keyword.operator.accessor.js
// ^^^^^^^^ ^^^^^^^^^^^^^^^^^ meta.property.object.js
// ^^^^^^^^ ^^^^^^^^^^^^^^^^^ variable.other.property.js
// ^^ keyword.operator.existential.js
// ^^ keyword.operator.nullcoalesce.js
// ^^^ constant.numeric.js
// ^ punctuation.terminator.statement.js
// ^^ ^^^^^^^ ^ comment.line.double-slash.js
// ^^ punctuation.definition.comment.js
const showSplashScreen = response.settings?.showSplashScreen ?? true; // result: false
// <- storage.type.js
// <- storage.type.js
//^^^ storage.type.js
// ^^^^^^^^^^^^^^^^ variable.other.readwrite.js
// ^ keyword.operator.assignment.js
// ^^^^^^^^ variable.other.object.js
// ^ keyword.operator.accessor.js
// ^^^^^^^^ ^^^^^^^^^^^^^^^^ meta.property.object.js
// ^^^^^^^^ ^^^^^^^^^^^^^^^^ variable.other.property.js
// ^^ keyword.operator.existential.js
// ^^ keyword.operator.nullcoalesce.js
// ^^^^ constant.language.boolean.true.js
// ^ punctuation.terminator.statement.js
// ^^ ^^^^^^^ ^^^^^ comment.line.double-slash.js
// ^^ punctuation.definition.comment.js

// Issue #480
const thing :THING =<S>() => {}
// <- storage.type.js
Expand Down

0 comments on commit f835e71

Please sign in to comment.