Skip to content

Commit 0d7c84e

Browse files
committed
Added literal kind properties for each node.
1 parent 4800464 commit 0d7c84e

21 files changed

+507
-378
lines changed

scripts/tslint/typeOperatorSpacingRule.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ class TypeOperatorSpacingWalker extends Lint.RuleWalker {
1818
for (let i = 1; i < types.length; i++) {
1919
const currentType = types[i];
2020
if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) {
21-
const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING);
22-
this.addFailure(failure);
21+
const sourceFile = currentType.getSourceFile();
22+
const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end);
23+
const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos);
24+
if (previousTypeEndPos.line === currentTypeStartPos.line) {
25+
const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING);
26+
this.addFailure(failure);
27+
}
2328
}
2429
expectedStart = currentType.end + 2;
2530
}

src/compiler/binder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ namespace ts {
11111111
}
11121112
else {
11131113
forEachChild(node, bind);
1114-
if (node.operator === SyntaxKind.PlusEqualsToken || node.operator === SyntaxKind.MinusMinusToken) {
1114+
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
11151115
bindAssignmentTargetFlow(node.operand);
11161116
}
11171117
}
@@ -1360,7 +1360,7 @@ namespace ts {
13601360
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
13611361
const body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
13621362
if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) {
1363-
for (const stat of (<Block>body).statements) {
1363+
for (const stat of (<BlockLike>body).statements) {
13641364
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
13651365
return true;
13661366
}

src/compiler/checker.ts

+21-19
Original file line numberDiff line numberDiff line change
@@ -3886,7 +3886,7 @@ namespace ts {
38863886
if (!links.declaredType) {
38873887
const enumType = <EnumType>getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
38883888
links.declaredType = enumType.flags & TypeFlags.Union ?
3889-
enumType.memberTypes[getEnumMemberValue(<EnumDeclaration>symbol.valueDeclaration)] :
3889+
enumType.memberTypes[getEnumMemberValue(<EnumMember>symbol.valueDeclaration)] :
38903890
enumType;
38913891
}
38923892
return links.declaredType;
@@ -6049,7 +6049,7 @@ namespace ts {
60496049
return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow;
60506050
}
60516051

6052-
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | MethodDeclaration {
6052+
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
60536053
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func);
60546054
}
60556055

@@ -10022,7 +10022,7 @@ namespace ts {
1002210022
}
1002310023
}
1002410024

10025-
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression {
10025+
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction {
1002610026
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
1002710027
}
1002810028

@@ -10033,7 +10033,7 @@ namespace ts {
1003310033
: undefined;
1003410034
}
1003510035

10036-
function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | MethodDeclaration) {
10036+
function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | ArrowFunction | MethodDeclaration) {
1003710037
return isObjectLiteralMethod(node) ?
1003810038
getContextualTypeForObjectLiteralMethod(node) :
1003910039
getApparentTypeOfContextualType(node);
@@ -10044,7 +10044,7 @@ namespace ts {
1004410044
// If the contextual type is a union type, get the signature from each type possible and if they are
1004510045
// all identical ignoring their return type, the result is same signature but with return type as
1004610046
// union type of return types from these signatures
10047-
function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature {
10047+
function getContextualSignature(node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature {
1004810048
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
1004910049
const type = getContextualTypeForFunctionLikeDeclaration(node);
1005010050
if (!type) {
@@ -11392,7 +11392,7 @@ namespace ts {
1139211392
argCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature);
1139311393
}
1139411394
else {
11395-
const callExpression = <CallExpression>node;
11395+
const callExpression = <CallExpression | NewExpression>node;
1139611396
if (!callExpression.arguments) {
1139711397
// This only happens when we have something of the form: 'new C'
1139811398
Debug.assert(callExpression.kind === SyntaxKind.NewExpression);
@@ -11403,7 +11403,7 @@ namespace ts {
1140311403
argCount = signatureHelpTrailingComma ? args.length + 1 : args.length;
1140411404

1140511405
// If we are missing the close paren, the call is incomplete.
11406-
callIsIncomplete = (<CallExpression>callExpression).arguments.end === callExpression.end;
11406+
callIsIncomplete = callExpression.arguments.end === callExpression.end;
1140711407

1140811408
typeArguments = callExpression.typeArguments;
1140911409
spreadArgIndex = getSpreadArgumentIndex(args);
@@ -12490,7 +12490,7 @@ namespace ts {
1249012490
* @param node The call/new expression to be checked.
1249112491
* @returns On success, the expression's signature's return type. On failure, anyType.
1249212492
*/
12493-
function checkCallExpression(node: CallExpression): Type {
12493+
function checkCallExpression(node: CallExpression | NewExpression): Type {
1249412494
// Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true
1249512495
checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
1249612496

@@ -12945,7 +12945,7 @@ namespace ts {
1294512945
}
1294612946
}
1294712947

12948-
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
12948+
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) {
1294912949
checkCollisionWithCapturedSuperVariable(node, (<FunctionExpression>node).name);
1295012950
checkCollisionWithCapturedThisVariable(node, (<FunctionExpression>node).name);
1295112951
}
@@ -17419,9 +17419,12 @@ namespace ts {
1741917419
}
1742017420
}
1742117421

17422-
checkCollisionWithCapturedThisVariable(node, node.name);
17423-
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
17424-
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
17422+
if (isIdentifier(node.name)) {
17423+
checkCollisionWithCapturedThisVariable(node, node.name);
17424+
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
17425+
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
17426+
}
17427+
1742517428
checkExportsOnMergedDeclarations(node);
1742617429
const symbol = getSymbolOfNode(node);
1742717430

@@ -19040,15 +19043,15 @@ namespace ts {
1904019043
return undefined;
1904119044
}
1904219045

19043-
function isLiteralConstDeclaration(node: VariableDeclaration): boolean {
19046+
function isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean {
1904419047
if (isConst(node)) {
1904519048
const type = getTypeOfSymbol(getSymbolOfNode(node));
1904619049
return !!(type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral);
1904719050
}
1904819051
return false;
1904919052
}
1905019053

19051-
function writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter) {
19054+
function writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter) {
1905219055
const type = getTypeOfSymbol(getSymbolOfNode(node));
1905319056
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
1905419057
}
@@ -19785,7 +19788,7 @@ namespace ts {
1978519788
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
1978619789
}
1978719790

19788-
function checkGrammarForOmittedArgument(node: CallExpression, args: NodeArray<Expression>): boolean {
19791+
function checkGrammarForOmittedArgument(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
1978919792
if (args) {
1979019793
const sourceFile = getSourceFileOfNode(node);
1979119794
for (const arg of args) {
@@ -19796,7 +19799,7 @@ namespace ts {
1979619799
}
1979719800
}
1979819801

19799-
function checkGrammarArguments(node: CallExpression, args: NodeArray<Expression>): boolean {
19802+
function checkGrammarArguments(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
1980019803
return checkGrammarForOmittedArgument(node, args);
1980119804
}
1980219805

@@ -19918,8 +19921,7 @@ namespace ts {
1991819921

1991919922
for (const prop of node.properties) {
1992019923
const name = prop.name;
19921-
if (prop.kind === SyntaxKind.OmittedExpression ||
19922-
name.kind === SyntaxKind.ComputedPropertyName) {
19924+
if (name.kind === SyntaxKind.ComputedPropertyName) {
1992319925
// If the name is not a ComputedPropertyName, the grammar checking will skip it
1992419926
checkGrammarComputedPropertyName(<ComputedPropertyName>name);
1992519927
}
@@ -19966,7 +19968,7 @@ namespace ts {
1996619968
currentKind = SetAccessor;
1996719969
}
1996819970
else {
19969-
Debug.fail("Unexpected syntax kind:" + prop.kind);
19971+
Debug.fail("Unexpected syntax kind:" + (<Node>prop).kind);
1997019972
}
1997119973

1997219974
const effectiveName = getPropertyNameForPropertyNameNode(name);

src/compiler/core.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1813,9 +1813,9 @@ namespace ts {
18131813

18141814
export interface ObjectAllocator {
18151815
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
1816-
getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
1817-
getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
1818-
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
1816+
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
1817+
getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier;
1818+
getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos?: number, end?: number) => SourceFile;
18191819
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
18201820
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
18211821
getSignatureConstructor(): new (checker: TypeChecker) => Signature;

src/compiler/declarationEmitter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ namespace ts {
11211121
writeLine();
11221122
}
11231123

1124-
function emitVariableDeclaration(node: VariableDeclaration) {
1124+
function emitVariableDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
11251125
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
11261126
// so there is no check needed to see if declaration is visible
11271127
if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
@@ -1136,7 +1136,7 @@ namespace ts {
11361136
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
11371137
// we don't want to emit property declaration with "?"
11381138
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
1139-
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) {
1139+
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(<ParameterDeclaration>node))) && hasQuestionToken(node)) {
11401140
write("?");
11411141
}
11421142
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {
@@ -1626,8 +1626,7 @@ namespace ts {
16261626
}
16271627
}
16281628

1629-
function emitBindingElement(bindingElement: BindingElement) {
1630-
1629+
function emitBindingElement(bindingElement: BindingElement | OmittedExpression) {
16311630
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
16321631
// If bindingElement is an omittedExpression (i.e. containing elision),
16331632
// we will emit blank space (although this may differ from users' original code,

src/compiler/emitter.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ const _super = (function (geti, seti) {
655655
case SyntaxKind.ModuleDeclaration:
656656
return emitModuleDeclaration(<ModuleDeclaration>node);
657657
case SyntaxKind.ModuleBlock:
658-
return emitModuleBlock(<Block>node);
658+
return emitModuleBlock(<ModuleBlock>node);
659659
case SyntaxKind.CaseBlock:
660660
return emitCaseBlock(<CaseBlock>node);
661661
case SyntaxKind.ImportEqualsDeclaration:
@@ -1394,7 +1394,7 @@ const _super = (function (geti, seti) {
13941394
}
13951395
}
13961396

1397-
function emitBlockStatements(node: Block) {
1397+
function emitBlockStatements(node: BlockLike) {
13981398
if (getEmitFlags(node) & EmitFlags.SingleLine) {
13991399
emitList(node, node.statements, ListFormat.SingleLineBlockStatements);
14001400
}
@@ -1795,7 +1795,7 @@ const _super = (function (geti, seti) {
17951795
}
17961796

17971797
function emitModuleBlock(node: ModuleBlock) {
1798-
if (isSingleLineEmptyBlock(node)) {
1798+
if (isEmptyBlock(node)) {
17991799
write("{ }");
18001800
}
18011801
else {
@@ -2615,7 +2615,11 @@ const _super = (function (geti, seti) {
26152615

26162616
function isSingleLineEmptyBlock(block: Block) {
26172617
return !block.multiLine
2618-
&& block.statements.length === 0
2618+
&& isEmptyBlock(block);
2619+
}
2620+
2621+
function isEmptyBlock(block: BlockLike) {
2622+
return block.statements.length === 0
26192623
&& rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile);
26202624
}
26212625

0 commit comments

Comments
 (0)