Added literal kind properties for each node.#11342
Conversation
| else { | ||
| forEachChild(node, bind); | ||
| if (node.operator === SyntaxKind.PlusEqualsToken || node.operator === SyntaxKind.MinusMinusToken) { | ||
| if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) { |
There was a problem hiding this comment.
This was discovered due to the use of the more specific kind property.
| const enumType = <EnumType>getDeclaredTypeOfEnum(getParentOfSymbol(symbol)); | ||
| links.declaredType = enumType.flags & TypeFlags.Union ? | ||
| enumType.memberTypes[getEnumMemberValue(<EnumDeclaration>symbol.valueDeclaration)] : | ||
| enumType.memberTypes[getEnumMemberValue(<EnumMember>symbol.valueDeclaration)] : |
There was a problem hiding this comment.
This was discovered due to the use of the more specific kind property.
| } | ||
|
|
||
| if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { | ||
| if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) { |
There was a problem hiding this comment.
This was discovered due to the use of the more specific kind property. This was an unnecessary condition since MethodSignature would not be a legal element.
| } | ||
| else { | ||
| Debug.fail("Unexpected syntax kind:" + prop.kind); | ||
| Debug.fail("Unexpected syntax kind:" + (<Node>prop).kind); |
There was a problem hiding this comment.
This branch is possibly unnecessary since prop is typed as never here.
|
// CC: @mhegazy, @ahejlsberg, @DanielRosenwasser |
| getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; | ||
| getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; | ||
| getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>; | ||
| getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier; |
There was a problem hiding this comment.
Kind of funny that the Identifier constructor needs to take a SyntaxKind
There was a problem hiding this comment.
Who knows, we could eventually have different kind's of Identifier nodes.
| checkCollisionWithCapturedThisVariable(node, node.name); | ||
| checkCollisionWithRequireExportsInGeneratedCode(node, node.name); | ||
| checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); | ||
| if (isIdentifier(node.name)) { |
There was a problem hiding this comment.
Was this a bug, or are we just trying to assert here that this is an Identifier?
There was a problem hiding this comment.
We were calling each checkCollisionWith function with the node's name which may have been a StringLiteral. It may have been a bug that we never saw since StringLiterals cannot collide with any identifiers.
This PR adds literal
kindproperties on eachNodesubtype in the compiler. While this is not a full migration to ADTs, it has caught a few errors in the compiler not presently caught by existing unit tests.This also relaxes the
typeOperatorSpacingRulefor tslint so that it allows union and intersection types to span multiple lines.