make flow transformer use internal state to track whether we're in a type or not - fixes #2083
This commit is contained in:
11
test/fixtures/flow/regression/issue-2083/actual.js
vendored
Normal file
11
test/fixtures/flow/regression/issue-2083/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
foo() {
|
||||
switch (1) {
|
||||
case (MatrixType.IsScaling | MatrixType.IsTranslation):
|
||||
}
|
||||
}
|
||||
|
||||
bar() {
|
||||
switch ((typeA << 4) | typeB) {}
|
||||
}
|
||||
}
|
||||
487
test/fixtures/flow/regression/issue-2083/expected.json
vendored
Normal file
487
test/fixtures/flow/regression/issue-2083/expected.json
vendored
Normal file
@@ -0,0 +1,487 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 6,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 10,
|
||||
"end": 164,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "MethodDefinition",
|
||||
"start": 14,
|
||||
"end": 110,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 14,
|
||||
"end": 17,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"static": false,
|
||||
"kind": "method",
|
||||
"value": {
|
||||
"type": "FunctionExpression",
|
||||
"start": 17,
|
||||
"end": 110,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 20,
|
||||
"end": 110,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "SwitchStatement",
|
||||
"start": 26,
|
||||
"end": 106,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"discriminant": {
|
||||
"type": "Literal",
|
||||
"start": 34,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"value": 1,
|
||||
"rawValue": 1,
|
||||
"raw": "1"
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"type": "SwitchCase",
|
||||
"start": 45,
|
||||
"end": 100,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 61
|
||||
}
|
||||
},
|
||||
"consequent": [],
|
||||
"test": {
|
||||
"type": "BinaryExpression",
|
||||
"start": 51,
|
||||
"end": 98,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 59
|
||||
}
|
||||
},
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start": 51,
|
||||
"end": 71,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start": 51,
|
||||
"end": 61,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 22
|
||||
}
|
||||
},
|
||||
"name": "MatrixType"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start": 62,
|
||||
"end": 71,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"name": "IsScaling"
|
||||
},
|
||||
"computed": false
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start": 74,
|
||||
"end": 98,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 35
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 59
|
||||
}
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start": 74,
|
||||
"end": 84,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 35
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 45
|
||||
}
|
||||
},
|
||||
"name": "MatrixType"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start": 85,
|
||||
"end": 98,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 46
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 59
|
||||
}
|
||||
},
|
||||
"name": "IsTranslation"
|
||||
},
|
||||
"computed": false
|
||||
},
|
||||
"parenthesizedExpression": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "MethodDefinition",
|
||||
"start": 114,
|
||||
"end": 162,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 114,
|
||||
"end": 117,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"name": "bar"
|
||||
},
|
||||
"static": false,
|
||||
"kind": "method",
|
||||
"value": {
|
||||
"type": "FunctionExpression",
|
||||
"start": 117,
|
||||
"end": 162,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 120,
|
||||
"end": 162,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "SwitchStatement",
|
||||
"start": 126,
|
||||
"end": 158,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 36
|
||||
}
|
||||
},
|
||||
"discriminant": {
|
||||
"type": "BinaryExpression",
|
||||
"start": 134,
|
||||
"end": 154,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"start": 135,
|
||||
"end": 145,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start": 135,
|
||||
"end": 140,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 18
|
||||
}
|
||||
},
|
||||
"name": "typeA"
|
||||
},
|
||||
"operator": "<<",
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"start": 144,
|
||||
"end": 145,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"value": 4,
|
||||
"rawValue": 4,
|
||||
"raw": "4"
|
||||
},
|
||||
"parenthesizedExpression": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start": 149,
|
||||
"end": 154,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 27
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"name": "typeB"
|
||||
}
|
||||
},
|
||||
"cases": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
1
test/fixtures/jsx/regression/issue-2083/actual.js
vendored
Normal file
1
test/fixtures/jsx/regression/issue-2083/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
true ? (<div />) : <div />;
|
||||
182
test/fixtures/jsx/regression/issue-2083/expected.json
vendored
Normal file
182
test/fixtures/jsx/regression/issue-2083/expected.json
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "ConditionalExpression",
|
||||
"start": 0,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"type": "Literal",
|
||||
"start": 0,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"value": true,
|
||||
"rawValue": true,
|
||||
"raw": "true"
|
||||
},
|
||||
"consequent": {
|
||||
"type": "JSXElement",
|
||||
"start": 8,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"openingElement": {
|
||||
"type": "JSXOpeningElement",
|
||||
"start": 8,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"attributes": [],
|
||||
"name": {
|
||||
"type": "JSXIdentifier",
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"name": "div"
|
||||
},
|
||||
"selfClosing": true
|
||||
},
|
||||
"closingElement": null,
|
||||
"children": [],
|
||||
"parenthesizedExpression": true
|
||||
},
|
||||
"alternate": {
|
||||
"type": "JSXElement",
|
||||
"start": 19,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"openingElement": {
|
||||
"type": "JSXOpeningElement",
|
||||
"start": 19,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"attributes": [],
|
||||
"name": {
|
||||
"type": "JSXIdentifier",
|
||||
"start": 20,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 20
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"name": "div"
|
||||
},
|
||||
"selfClosing": true
|
||||
},
|
||||
"closingElement": null,
|
||||
"children": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user