Add more tests for the nullish coalescing operator
This commit is contained in:
parent
f1d2db6cf4
commit
fcdfb0e31e
1
test/fixtures/experimental/nullish-coalescing-operator/associativity/actual.js
vendored
Normal file
1
test/fixtures/experimental/nullish-coalescing-operator/associativity/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a ?? b ?? c;
|
||||||
132
test/fixtures/experimental/nullish-coalescing-operator/associativity/expected.json
vendored
Normal file
132
test/fixtures/experimental/nullish-coalescing-operator/associativity/expected.json
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "script",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 6,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 0,
|
||||||
|
"end": 1,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"identifierName": "a"
|
||||||
|
},
|
||||||
|
"name": "a"
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 5,
|
||||||
|
"end": 6,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 6
|
||||||
|
},
|
||||||
|
"identifierName": "b"
|
||||||
|
},
|
||||||
|
"name": "b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 10,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 10
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
},
|
||||||
|
"identifierName": "c"
|
||||||
|
},
|
||||||
|
"name": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
4
test/fixtures/experimental/nullish-coalescing-operator/associativity/options.json
vendored
Normal file
4
test/fixtures/experimental/nullish-coalescing-operator/associativity/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["nullishCoalescingOperator"]
|
||||||
|
}
|
||||||
|
|
||||||
3
test/fixtures/experimental/nullish-coalescing-operator/multiline/actual.js
vendored
Normal file
3
test/fixtures/experimental/nullish-coalescing-operator/multiline/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
a
|
||||||
|
?? b
|
||||||
|
?? c;
|
||||||
132
test/fixtures/experimental/nullish-coalescing-operator/multiline/expected.json
vendored
Normal file
132
test/fixtures/experimental/nullish-coalescing-operator/multiline/expected.json
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "script",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 16,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 9,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 0,
|
||||||
|
"end": 1,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"identifierName": "a"
|
||||||
|
},
|
||||||
|
"name": "a"
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 8,
|
||||||
|
"end": 9,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 6
|
||||||
|
},
|
||||||
|
"identifierName": "b"
|
||||||
|
},
|
||||||
|
"name": "b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 15,
|
||||||
|
"end": 16,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 6
|
||||||
|
},
|
||||||
|
"identifierName": "c"
|
||||||
|
},
|
||||||
|
"name": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
4
test/fixtures/experimental/nullish-coalescing-operator/multiline/options.json
vendored
Normal file
4
test/fixtures/experimental/nullish-coalescing-operator/multiline/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["nullishCoalescingOperator"]
|
||||||
|
}
|
||||||
|
|
||||||
1
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/actual.js
vendored
Normal file
1
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a |> b ?? c;
|
||||||
132
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/expected.json
vendored
Normal file
132
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/expected.json
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "script",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 0,
|
||||||
|
"end": 1,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"identifierName": "a"
|
||||||
|
},
|
||||||
|
"name": "a"
|
||||||
|
},
|
||||||
|
"operator": "|>",
|
||||||
|
"right": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 5,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 5,
|
||||||
|
"end": 6,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 6
|
||||||
|
},
|
||||||
|
"identifierName": "b"
|
||||||
|
},
|
||||||
|
"name": "b"
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 10,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 10
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
},
|
||||||
|
"identifierName": "c"
|
||||||
|
},
|
||||||
|
"name": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
4
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/options.json
vendored
Normal file
4
test/fixtures/experimental/nullish-coalescing-operator/precedence-high/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["nullishCoalescingOperator", "pipelineOperator"]
|
||||||
|
}
|
||||||
|
|
||||||
1
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/actual.js
vendored
Normal file
1
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a && b ?? c;
|
||||||
132
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/expected.json
vendored
Normal file
132
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/expected.json
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "script",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "LogicalExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 6,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 0,
|
||||||
|
"end": 1,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"identifierName": "a"
|
||||||
|
},
|
||||||
|
"name": "a"
|
||||||
|
},
|
||||||
|
"operator": "&&",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 5,
|
||||||
|
"end": 6,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 5
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 6
|
||||||
|
},
|
||||||
|
"identifierName": "b"
|
||||||
|
},
|
||||||
|
"name": "b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"operator": "??",
|
||||||
|
"right": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 10,
|
||||||
|
"end": 11,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 10
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 11
|
||||||
|
},
|
||||||
|
"identifierName": "c"
|
||||||
|
},
|
||||||
|
"name": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
4
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/options.json
vendored
Normal file
4
test/fixtures/experimental/nullish-coalescing-operator/precedence-low/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["nullishCoalescingOperator"]
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user