mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 07:21:18 -05:00
fix parsing of leading union/intersection operator (#31265)
* fix parsing of leading union/intersection operator Fixes: #30995 * test declaration emit
This commit is contained in:
committed by
Ron Buckton
parent
a2c1fea20b
commit
0c9db717ad
@@ -3124,15 +3124,16 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseUnionOrIntersectionType(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, parseConstituentType: () => TypeNode, operator: SyntaxKind.BarToken | SyntaxKind.AmpersandToken): TypeNode {
|
||||
parseOptional(operator);
|
||||
const start = scanner.getStartPos();
|
||||
const hasLeadingOperator = parseOptional(operator);
|
||||
let type = parseConstituentType();
|
||||
if (token() === operator) {
|
||||
if (token() === operator || hasLeadingOperator) {
|
||||
const types = [type];
|
||||
while (parseOptional(operator)) {
|
||||
types.push(parseConstituentType());
|
||||
}
|
||||
const node = <UnionOrIntersectionTypeNode>createNode(kind, type.pos);
|
||||
node.types = createNodeArray(types, type.pos);
|
||||
const node = <UnionOrIntersectionTypeNode>createNode(kind, start);
|
||||
node.types = createNodeArray(types, start);
|
||||
type = finishNode(node);
|
||||
}
|
||||
return type;
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace ts {
|
||||
parsesCorrectly("callSignatureInRecordType", "{{(): number}}");
|
||||
parsesCorrectly("methodInRecordType", "{{foo(): number}}");
|
||||
parsesCorrectly("unionType", "{(number|string)}");
|
||||
parsesCorrectly("unionTypeWithLeadingOperator", "{( | number | string )}");
|
||||
parsesCorrectly("unionTypeWithOneElementAndLeadingOperator", "{( | number )}");
|
||||
parsesCorrectly("topLevelNoParenUnionType", "{number|string}");
|
||||
parsesCorrectly("functionType1", "{function()}");
|
||||
parsesCorrectly("functionType2", "{function(string, boolean)}");
|
||||
|
||||
Reference in New Issue
Block a user