Skip to content

Commit 411dae1

Browse files
committed
Perform error reporting in checker
1 parent 36bc00d commit 411dae1

File tree

3,077 files changed

+23473
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,077 files changed

+23473
-191
lines changed

src/compiler/checker.ts

Lines changed: 98 additions & 88 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ module ts {
157157
Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
158158
An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
159159
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
160+
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
160161
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
161162
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
162163
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@
619619
"category": "Error",
620620
"code": 1199
621621
},
622+
"Line terminator not permitted before arrow.": {
623+
"category": "Error",
624+
"code": 1200
625+
},
622626
"Duplicate identifier '{0}'.": {
623627
"category": "Error",
624628
"code": 2300

src/compiler/parser.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ module ts {
29162916
// To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized
29172917
// parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
29182918
// identifier and the current token is an arrow.
2919-
if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken && !scanner.hasPrecedingLineBreak()) {
2919+
if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) {
29202920
return parseSimpleArrowFunctionExpression(<Identifier>expr);
29212921
}
29222922

@@ -2998,7 +2998,7 @@ module ts {
29982998
function parseSimpleArrowFunctionExpression(identifier: Identifier): Expression {
29992999
Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
30003000

3001-
var node = <FunctionExpression>createNode(SyntaxKind.ArrowFunction, identifier.pos);
3001+
var node = <ArrowFunctionExpression>createNode(SyntaxKind.ArrowFunction, identifier.pos);
30023002

30033003
var parameter = <ParameterDeclaration>createNode(SyntaxKind.Parameter, identifier.pos);
30043004
parameter.name = identifier;
@@ -3008,6 +3008,7 @@ module ts {
30083008
node.parameters.pos = parameter.pos;
30093009
node.parameters.end = parameter.end;
30103010

3011+
node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak();
30113012
parseExpected(SyntaxKind.EqualsGreaterThanToken);
30123013
node.body = parseArrowFunctionExpressionBody();
30133014

@@ -3132,7 +3133,7 @@ module ts {
31323133
}
31333134

31343135
function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression {
3135-
var node = <FunctionExpression>createNode(SyntaxKind.ArrowFunction);
3136+
var node = <ArrowFunctionExpression>createNode(SyntaxKind.ArrowFunction);
31363137
// Arrow functions are never generators.
31373138
//
31383139
// If we're speculatively parsing a signature for a parenthesized arrow function, then
@@ -3160,10 +3161,7 @@ module ts {
31603161
return undefined;
31613162
}
31623163

3163-
// Must be no line terminator before token `=>`.
3164-
if (scanner.hasPrecedingLineBreak()) {
3165-
return undefined;
3166-
}
3164+
node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak();
31673165

31683166
return node;
31693167
}

src/compiler/types.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ module ts {
328328

329329
// If the parser encountered an error when parsing the code that created this node. Note
330330
// the parser only sets this directly on the node it creates right after encountering the
331-
// error.
331+
// error.
332332
ThisNodeHasError = 1 << 4,
333333

334334
// Context flags set directly by the parser.
335335
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | ThisNodeHasError,
336336

337337
// Context flags computed by aggregating child flags upwards.
338338

339-
// Used during incremental parsing to determine if this node or any of its children had an
339+
// Used during incremental parsing to determine if this node or any of its children had an
340340
// error. Computed only once and then cached.
341341
ThisNodeOrAnySubNodesHasError = 1 << 5,
342342

@@ -353,7 +353,7 @@ module ts {
353353
export interface Node extends TextRange {
354354
kind: SyntaxKind;
355355
flags: NodeFlags;
356-
// Specific context the parser was in when this node was created. Normally undefined.
356+
// Specific context the parser was in when this node was created. Normally undefined.
357357
// Only set when the parser was in some interesting context (like async/yield).
358358
parserContextFlags?: ParserContextFlags;
359359
modifiers?: ModifiersArray; // Array of modifiers
@@ -523,7 +523,7 @@ module ts {
523523
body?: Block;
524524
}
525525

526-
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
526+
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
527527
// ClassElement and an ObjectLiteralElement.
528528
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
529529
_accessorDeclarationBrand: any;
@@ -574,12 +574,12 @@ module ts {
574574

575575
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
576576

577-
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
577+
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
578578
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
579579
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
580580
// takes an Expression without any error. By using the 'brands' we ensure that the type
581-
// checker actually thinks you have something of the right type. Note: the brands are
582-
// never actually given values. At runtime they have zero cost.
581+
// checker actually thinks you have something of the right type. Note: the brands are
582+
// never actually given values. At runtime they have zero cost.
583583

584584
export interface Expression extends Node {
585585
_expressionBrand: any;
@@ -652,6 +652,10 @@ module ts {
652652
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
653653
}
654654

655+
export interface ArrowFunctionExpression extends FunctionExpression {
656+
lineTerminatorBeforeArrow: boolean;
657+
}
658+
655659
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
656660
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
657661
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
@@ -734,7 +738,7 @@ module ts {
734738
}
735739

736740
export interface VariableStatement extends Statement {
737-
declarationList: VariableDeclarationList;
741+
declarationList: VariableDeclarationList;
738742
}
739743

740744
export interface ExpressionStatement extends Statement {
@@ -898,7 +902,7 @@ module ts {
898902
moduleSpecifier: Expression;
899903
}
900904

901-
// In case of:
905+
// In case of:
902906
// import d from "mod" => name = d, namedBinding = undefined
903907
// import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns }
904908
// import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns }
@@ -964,18 +968,18 @@ module ts {
964968
externalModuleIndicator: Node;
965969
languageVersion: ScriptTarget;
966970
identifiers: Map<string>;
967-
971+
968972
/* @internal */ nodeCount: number;
969973
/* @internal */ identifierCount: number;
970974
/* @internal */ symbolCount: number;
971975

972976
// File level diagnostics reported by the parser (includes diagnostics about /// references
973977
// as well as code diagnostics).
974978
/* @internal */ parseDiagnostics: Diagnostic[];
975-
979+
976980
// File level diagnostics reported by the binder.
977981
/* @internal */ bindDiagnostics: Diagnostic[];
978-
982+
979983
// Stores a line map for the file.
980984
// This field should never be used directly to obtain line map, use getLineMap function instead.
981985
/* @internal */ lineMap: number[];
@@ -995,10 +999,10 @@ module ts {
995999
getSourceFiles(): SourceFile[];
9961000

9971001
/**
998-
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
1002+
* Emits the javascript and declaration files. If targetSourceFile is not specified, then
9991003
* the javascript and declaration files will be produced for all the files in this program.
10001004
* If targetSourceFile is specified, then only the javascript and declaration for that
1001-
* specific file will be generated.
1005+
* specific file will be generated.
10021006
*
10031007
* If writeFile is not specified then the writeFile callback from the compiler host will be
10041008
* used for writing the javascript and declaration files. Otherwise, the writeFile parameter
@@ -1016,7 +1020,7 @@ module ts {
10161020

10171021
getCommonSourceDirectory(): string;
10181022

1019-
// For testing purposes only. Should not be used by any other consumers (including the
1023+
// For testing purposes only. Should not be used by any other consumers (including the
10201024
// language service).
10211025
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker;
10221026

@@ -1053,7 +1057,7 @@ module ts {
10531057
// when -version or -help was provided, or this was a normal compilation, no diagnostics
10541058
// were produced, and all outputs were generated successfully.
10551059
Success = 0,
1056-
1060+
10571061
// Diagnostics were produced and because of them no code was generated.
10581062
DiagnosticsPresent_OutputsSkipped = 1,
10591063

@@ -1163,12 +1167,12 @@ module ts {
11631167

11641168
// Write symbols's type argument if it is instantiated symbol
11651169
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
1166-
// var a: C<number>;
1170+
// var a: C<number>;
11671171
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
1168-
WriteTypeParametersOrArguments = 0x00000001,
1172+
WriteTypeParametersOrArguments = 0x00000001,
11691173

11701174
// Use only external alias information to get the symbol name in the given context
1171-
// eg. module m { export class c { } } import x = m.c;
1175+
// eg. module m { export class c { } } import x = m.c;
11721176
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
11731177
UseOnlyExternalAliasing = 0x00000002,
11741178
}
@@ -1772,7 +1776,7 @@ module ts {
17721776
// Gets a count of how many times this collection has been modified. This value changes
17731777
// each time 'add' is called (regardless of whether or not an equivalent diagnostic was
17741778
// already in the collection). As such, it can be used as a simple way to tell if any
1775-
// operation caused diagnostics to be returned by storing and comparing the return value
1779+
// operation caused diagnostics to be returned by storing and comparing the return value
17761780
// of this method before/after the operation is performed.
17771781
getModificationCount(): number;
17781782
}

tests/baselines/reference/APISample_compile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ declare module "typescript" {
552552
name?: Identifier;
553553
body: Block | Expression;
554554
}
555+
interface ArrowFunctionExpression extends FunctionExpression {
556+
lineTerminatorBeforeArrow: boolean;
557+
}
555558
interface LiteralExpression extends PrimaryExpression {
556559
text: string;
557560
isUnterminated?: boolean;

tests/baselines/reference/APISample_compile.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,13 @@ declare module "typescript" {
16651665
>body : Expression | Block
16661666
>Block : Block
16671667
>Expression : Expression
1668+
}
1669+
interface ArrowFunctionExpression extends FunctionExpression {
1670+
>ArrowFunctionExpression : ArrowFunctionExpression
1671+
>FunctionExpression : FunctionExpression
1672+
1673+
lineTerminatorBeforeArrow: boolean;
1674+
>lineTerminatorBeforeArrow : boolean
16681675
}
16691676
interface LiteralExpression extends PrimaryExpression {
16701677
>LiteralExpression : LiteralExpression

tests/baselines/reference/APISample_linter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ declare module "typescript" {
583583
name?: Identifier;
584584
body: Block | Expression;
585585
}
586+
interface ArrowFunctionExpression extends FunctionExpression {
587+
lineTerminatorBeforeArrow: boolean;
588+
}
586589
interface LiteralExpression extends PrimaryExpression {
587590
text: string;
588591
isUnterminated?: boolean;

tests/baselines/reference/APISample_linter.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,13 @@ declare module "typescript" {
18111811
>body : Expression | Block
18121812
>Block : Block
18131813
>Expression : Expression
1814+
}
1815+
interface ArrowFunctionExpression extends FunctionExpression {
1816+
>ArrowFunctionExpression : ArrowFunctionExpression
1817+
>FunctionExpression : FunctionExpression
1818+
1819+
lineTerminatorBeforeArrow: boolean;
1820+
>lineTerminatorBeforeArrow : boolean
18141821
}
18151822
interface LiteralExpression extends PrimaryExpression {
18161823
>LiteralExpression : LiteralExpression

tests/baselines/reference/APISample_transform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,9 @@ declare module "typescript" {
584584
name?: Identifier;
585585
body: Block | Expression;
586586
}
587+
interface ArrowFunctionExpression extends FunctionExpression {
588+
lineTerminatorBeforeArrow: boolean;
589+
}
587590
interface LiteralExpression extends PrimaryExpression {
588591
text: string;
589592
isUnterminated?: boolean;

tests/baselines/reference/APISample_transform.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,13 @@ declare module "typescript" {
17611761
>body : Expression | Block
17621762
>Block : Block
17631763
>Expression : Expression
1764+
}
1765+
interface ArrowFunctionExpression extends FunctionExpression {
1766+
>ArrowFunctionExpression : ArrowFunctionExpression
1767+
>FunctionExpression : FunctionExpression
1768+
1769+
lineTerminatorBeforeArrow: boolean;
1770+
>lineTerminatorBeforeArrow : boolean
17641771
}
17651772
interface LiteralExpression extends PrimaryExpression {
17661773
>LiteralExpression : LiteralExpression

tests/baselines/reference/APISample_watcher.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ declare module "typescript" {
621621
name?: Identifier;
622622
body: Block | Expression;
623623
}
624+
interface ArrowFunctionExpression extends FunctionExpression {
625+
lineTerminatorBeforeArrow: boolean;
626+
}
624627
interface LiteralExpression extends PrimaryExpression {
625628
text: string;
626629
isUnterminated?: boolean;

tests/baselines/reference/APISample_watcher.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,13 @@ declare module "typescript" {
19341934
>body : Expression | Block
19351935
>Block : Block
19361936
>Expression : Expression
1937+
}
1938+
interface ArrowFunctionExpression extends FunctionExpression {
1939+
>ArrowFunctionExpression : ArrowFunctionExpression
1940+
>FunctionExpression : FunctionExpression
1941+
1942+
lineTerminatorBeforeArrow: boolean;
1943+
>lineTerminatorBeforeArrow : boolean
19371944
}
19381945
interface LiteralExpression extends PrimaryExpression {
19391946
>LiteralExpression : LiteralExpression

0 commit comments

Comments
 (0)