From 80c5acc04ef75911547376276d13d5bf15663cc4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 8 Dec 2014 11:22:52 -0800 Subject: [PATCH 01/16] Add new method on interface Boolean to ensure it is not assignable from other types --- src/lib/core.d.ts | 2 + .../assignFromBooleanInterface2.errors.txt | 11 +++++- .../reference/booleanAssignment.errors.txt | 38 +++++++++++++++++++ .../baselines/reference/booleanAssignment.js | 24 ++++++++++++ ...tringsArrayTypeDefinedInES5Mode.errors.txt | 2 +- ...ingsArrayTypeRedefinedInES6Mode.errors.txt | 2 +- tests/cases/compiler/booleanAssignment.ts | 12 ++++++ 7 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/booleanAssignment.errors.txt create mode 100644 tests/baselines/reference/booleanAssignment.js create mode 100644 tests/cases/compiler/booleanAssignment.ts diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 1c87984bc27..cb5324fbd3d 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -426,6 +426,8 @@ interface StringConstructor { declare var String: StringConstructor; interface Boolean { + /** Returns the primitive value of the specified object. */ + valueOf(): boolean; } interface BooleanConstructor { diff --git a/tests/baselines/reference/assignFromBooleanInterface2.errors.txt b/tests/baselines/reference/assignFromBooleanInterface2.errors.txt index 66d55e00d86..c03eab60c74 100644 --- a/tests/baselines/reference/assignFromBooleanInterface2.errors.txt +++ b/tests/baselines/reference/assignFromBooleanInterface2.errors.txt @@ -1,8 +1,12 @@ +tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + Type 'Object' is not assignable to type 'boolean'. tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'. tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(20,1): error TS2322: Type 'NotBoolean' is not assignable to type 'boolean'. -==== tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts (2 errors) ==== +==== tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts (3 errors) ==== interface Boolean { doStuff(): string; } @@ -17,6 +21,11 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts( a = x; a = b; + ~ +!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. +!!! error TS2322: Type 'Object' is not assignable to type 'boolean'. b = a; b = x; diff --git a/tests/baselines/reference/booleanAssignment.errors.txt b/tests/baselines/reference/booleanAssignment.errors.txt new file mode 100644 index 00000000000..2d6c6b045ea --- /dev/null +++ b/tests/baselines/reference/booleanAssignment.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type 'number' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + Type 'Object' is not assignable to type 'boolean'. +tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type 'string' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. +tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + + +==== tests/cases/compiler/booleanAssignment.ts (3 errors) ==== + var b = new Boolean(); + b = 1; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. +!!! error TS2322: Type 'Object' is not assignable to type 'boolean'. + b = "a"; // Error + ~ +!!! error TS2322: Type 'string' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. + b = {}; // Error + ~ +!!! error TS2322: Type '{}' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. + + var o = {}; + o = b; // OK + + b = true; // OK + + var b2:boolean; + b = b2; // OK \ No newline at end of file diff --git a/tests/baselines/reference/booleanAssignment.js b/tests/baselines/reference/booleanAssignment.js new file mode 100644 index 00000000000..573367a4293 --- /dev/null +++ b/tests/baselines/reference/booleanAssignment.js @@ -0,0 +1,24 @@ +//// [booleanAssignment.ts] +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error + +var o = {}; +o = b; // OK + +b = true; // OK + +var b2:boolean; +b = b2; // OK + +//// [booleanAssignment.js] +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error +var o = {}; +o = b; // OK +b = true; // OK +var b2; +b = b2; // OK diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index b15a867a79e..dc494c7c3f4 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -lib.d.ts(513,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. +lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index 248ea95e348..db383b216a5 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,4 +1,4 @@ -lib.d.ts(513,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. +lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. diff --git a/tests/cases/compiler/booleanAssignment.ts b/tests/cases/compiler/booleanAssignment.ts new file mode 100644 index 00000000000..619b16bc419 --- /dev/null +++ b/tests/cases/compiler/booleanAssignment.ts @@ -0,0 +1,12 @@ +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error + +var o = {}; +o = b; // OK + +b = true; // OK + +var b2:boolean; +b = b2; // OK \ No newline at end of file From e9a5be46a4a40aa3e0439b57f28595b13b0d4566 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 13:25:40 -0800 Subject: [PATCH 02/16] Improve test 262 baselines. --- src/harness/test262Runner.ts | 48 +++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 756ff82ef97..0473a1c5aec 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -27,9 +27,12 @@ class Test262BaselineRunner extends RunnerBase { } function getFlagName(flags: any, f: number): any { - if (f === 0) return 0; + if (f === 0) { + return 0; + } + var result = ""; - ts.forEach(Object.getOwnPropertyNames(flags),(v: any) => { + ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => { if (isFinite(v)) { v = +v; if (f === +v) { @@ -51,45 +54,56 @@ class Test262BaselineRunner extends RunnerBase { function getParserContextFlagName(f: number) { return getFlagName((ts).ParserContextFlags, f); } function serializeNode(n: ts.Node): any { - var o = { kind: getKindName(n.kind) }; - ts.forEach(Object.getOwnPropertyNames(n), i => { - switch (i) { + var o: any = { kind: getKindName(n.kind) }; + + ts.forEach(Object.getOwnPropertyNames(n), propertyName => { + switch (propertyName) { case "parent": case "symbol": case "locals": case "localSymbol": case "kind": case "semanticDiagnostics": - case "parseDiagnostics": - case "grammarDiagnostics": - return undefined; + case "id": + case "nodeCount": + case "symbolCount": + case "identifierCount": + // Blacklist of items we never put in the baseline file. + break; case "flags": - (o)[i] = getNodeFlagName(n.flags); - return undefined; + // Print out flags with their enum names. + o[propertyName] = getNodeFlagName(n.flags); + break; case "parserContextFlags": - (o)[i] = getParserContextFlagName(n.parserContextFlags); - return undefined; + o[propertyName] = getParserContextFlagName(n.parserContextFlags); + break; case "nextContainer": if (n.nextContainer) { - (o)[i] = { kind: n.nextContainer.kind, pos: n.nextContainer.pos, end: n.nextContainer.end }; - return undefined; + o[propertyName] = { kind: n.nextContainer.kind, pos: n.nextContainer.pos, end: n.nextContainer.end }; } + break; case "text": - if (n.kind === ts.SyntaxKind.SourceFile) return undefined; + // Include 'text' field for identifiers/literals, but not for source files. + if (n.kind !== ts.SyntaxKind.SourceFile) { + o[propertyName] = (n)[propertyName]; + } + break; default: - (o)[i] = ((n)[i]); + o[propertyName] = (n)[propertyName]; } + return undefined; }); + return o; } - return JSON.stringify(file,(k, v) => { + return JSON.stringify(file, (k, v) => { return (v && typeof v.pos === "number") ? serializeNode(v) : v; }, " "); } From 4f4e249a042d4fb0365c588b6550ad3ae0ccf268 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 14:03:31 -0800 Subject: [PATCH 03/16] Add tree invariant checking to the test262 runner. --- src/harness/test262Runner.ts | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 756ff82ef97..fa4dc14e213 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -21,6 +21,38 @@ class Test262BaselineRunner extends RunnerBase { return Test262BaselineRunner.basePath + "/" + filename; } + private static checkInvariants(node: ts.Node, parent: ts.Node): void { + if (node) { + if (node.pos < 0) { + throw new Error("node.pos < 0"); + } + if (node.end < 0) { + throw new Error("node.end < 0"); + } + if (node.end < node.pos) { + throw new Error("node.end < node.pos"); + } + if (node.parent !== parent) { + throw new Error("node.parent !== parent"); + } + ts.forEachChild(node, child => { + Test262BaselineRunner.checkInvariants(child, node); + }); + + var childNodesAndArrays: any[] = []; + ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) }); + + for (var childName in node) { + var child = (node)[childName]; + if (Test262BaselineRunner.isNodeOrArray(child)) { + if (childNodesAndArrays.indexOf(child) < 0) { + throw new Error("Child when forEach'ing over node. " + (ts).SyntaxKind[node.kind] + "-" + childName); + } + } + } + } + } + private static serializeSourceFile(file: ts.SourceFile): string { function getKindName(k: number): string { return (ts).SyntaxKind[k] @@ -89,11 +121,15 @@ class Test262BaselineRunner extends RunnerBase { return o; } - return JSON.stringify(file,(k, v) => { - return (v && typeof v.pos === "number") ? serializeNode(v) : v; + return JSON.stringify(file, (k, v) => { + return Test262BaselineRunner.isNodeOrArray(v) ? serializeNode(v) : v; }, " "); } + private static isNodeOrArray(a: any): boolean { + return a !== undefined && typeof a.pos === "number"; + } + private runTest(filePath: string) { describe('test262 test for ' + filePath, () => { // Mocha holds onto the closure environment of the describe callback even after the test is done. @@ -150,6 +186,11 @@ class Test262BaselineRunner extends RunnerBase { }, false, Test262BaselineRunner.baselineOptions); }); + it('satisfies invariants', () => { + var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); + Test262BaselineRunner.checkInvariants(sourceFile, /*parent:*/ undefined); + }); + it('has the expected AST',() => { Harness.Baseline.runBaseline('has the expected AST', testState.filename + '.AST.txt',() => { var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); From 929d359bdfb880339845cb88df0bb959a89a9220 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 8 Dec 2014 14:28:19 -0800 Subject: [PATCH 04/16] fix formatting to add space after comma between arguments when arguments starts with open paren --- src/services/formatting/rules.ts | 6 +++++- .../formattingSpaceAfterCommaBeforeOpenParen.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 5dc44650346..d04097aab32 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -283,7 +283,7 @@ module ts.formatting { this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext), RuleAction.Delete)); + this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete)); this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Delete)); this.SpaceAfterVoidOperator = new Rule(RuleDescriptor.create3(SyntaxKind.VoidKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), RuleAction.Space)); @@ -625,6 +625,10 @@ module ts.formatting { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); } + static IsPreviousTokenNotComma(context: FormattingContext): boolean { + return context.currentTokenSpan.kind !== SyntaxKind.CommaToken; + } + static IsSameLineTokenContext(context: FormattingContext): boolean { return context.TokensAreOnSameLine(); } diff --git a/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts b/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts new file mode 100644 index 00000000000..4df76f9e9dd --- /dev/null +++ b/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts @@ -0,0 +1,12 @@ +/// + +////foo(a,(b))/*1*/ +////foo(a,(c).d)/*2*/ + +goTo.marker("1"); +edit.insert(";"); +verify.currentLineContentIs("foo(a, (b));"); + +goTo.marker("2"); +edit.insert(";"); +verify.currentLineContentIs("foo(a, (c).d);"); \ No newline at end of file From e9beba783efb27060a578d14985badc9c8cd24c1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 8 Dec 2014 15:02:45 -0800 Subject: [PATCH 05/16] Fix speculative parsing by terminating the list when encounting illegal token --- src/compiler/parser.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c331a89e0d..8d0ae33dc32 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2440,6 +2440,14 @@ module ts { // a generator, or in strict mode (or both)) and it started a yield expression. return true; default: + // Error tolerance. If we see the start of some binary operator, we consider + // that the start of an expression. That way we'll parse out a missing identifier, + // give a good message about an identifier being missing, and then consume the + // rest of the binary expression. + if (isBinaryOperator()) { + return true; + } + return isIdentifier(); } } @@ -2826,7 +2834,7 @@ module ts { // reScanGreaterToken so that we merge token sequences like > and = into >= reScanGreaterToken(); - var newPrecedence = getOperatorPrecedence(); + var newPrecedence = getBinaryOperatorPrecedence(); // Check the precedence to see if we should "take" this operator if (newPrecedence <= precedence) { @@ -2845,7 +2853,15 @@ module ts { return leftOperand; } - function getOperatorPrecedence(): number { + function isBinaryOperator() { + if (inDisallowInContext() && token === SyntaxKind.InKeyword) { + return false; + } + + return getBinaryOperatorPrecedence() > 0; + } + + function getBinaryOperatorPrecedence(): number { switch (token) { case SyntaxKind.BarBarToken: return 1; From 5db51fead829628bf7237b565097127b2798bbec Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 15:35:09 -0800 Subject: [PATCH 06/16] Better error recovery when encountering an errant comma in a semicolon delimited list. --- src/compiler/parser.ts | 37 +++++++++++++------ .../parserCommaInTypeMemberList2.errors.txt | 24 ++---------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c331a89e0d..dc873755cdf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1338,15 +1338,17 @@ module ts { return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); } - function parseSemicolon(diagnosticMessage?: DiagnosticMessage): void { + function parseSemicolon(diagnosticMessage?: DiagnosticMessage): boolean { if (canParseSemicolon()) { if (token === SyntaxKind.SemicolonToken) { // consume the semicolon if it was explicitly provided. nextToken(); } + + return true; } else { - parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage); + return parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage); } } @@ -2052,13 +2054,27 @@ module ts { return requireCompleteParameterList ? undefined : createMissingList(); } + function parseTypeMemberSemicolon() { + // Try to parse out an explicit or implicit (ASI) semicolon for a type member. If we + // don't have one, then an appropriate error will be reported. + if (parseSemicolon()) { + return; + } + + // If we don't have a semicolon, then the user may have written a comma instead + // accidently (pretty easy to do since commas are so prevalent as list separators). So + // just consume the comma and keep going. Note: we'll have already reported the error + // about the missing semicolon above. + parseOptional(SyntaxKind.CommaToken); + } + function parseSignatureMember(kind: SyntaxKind): SignatureDeclaration { var node = createNode(kind); if (kind === SyntaxKind.ConstructSignature) { parseExpected(SyntaxKind.NewKeyword); } fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(node); } @@ -2130,11 +2146,11 @@ module ts { setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(node) } - function parsePropertyOrMethod(): Declaration { + function parsePropertyOrMethodSignature(): Declaration { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); @@ -2147,8 +2163,7 @@ module ts { // Method signatues don't exist in expression contexts. So they have neither // [Yield] nor [GeneratorParameter] fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, method); - - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(method); } else { @@ -2156,7 +2171,7 @@ module ts { property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(property); } } @@ -2188,7 +2203,7 @@ module ts { return parseSignatureMember(SyntaxKind.CallSignature); case SyntaxKind.OpenBracketToken: // Indexer or computed property - return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethod(); + return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); @@ -2196,10 +2211,10 @@ module ts { // fall through. case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); default: if (isIdentifierOrKeyword()) { - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); } } } diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt index 025febbc9a5..fb563542961 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt @@ -1,29 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,38): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,60): error TS1005: ';' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,53): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,9): error TS2304: Cannot find name '$'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,31): error TS2304: Cannot find name 'any'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,50): error TS2304: Cannot find name 'any'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,55): error TS2304: Cannot find name 'width'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,62): error TS2304: Cannot find name 'string'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (8 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (2 errors) ==== var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workItem: this._workItem }, {}); - ~ -!!! error TS1134: Variable declaration expected. - ~ + ~ !!! error TS1005: ';' expected. - ~ -!!! error TS1128: Declaration or statement expected. ~ !!! error TS2304: Cannot find name '$'. - ~~~ -!!! error TS2304: Cannot find name 'any'. - ~~~ -!!! error TS2304: Cannot find name 'any'. - ~~~~~ -!!! error TS2304: Cannot find name 'width'. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. \ No newline at end of file From 6e94d4d658e8abaa425d6ac8b24e6b4a79adb501 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 8 Dec 2014 15:38:35 -0800 Subject: [PATCH 07/16] Update and add test cases --- .../MemberFunctionDeclaration8_es6.errors.txt | 27 +++----- ...torWithIncompleteTypeAnnotation.errors.txt | 63 ++++++++----------- .../parserAmbiguityWithBinaryOperator1.js | 12 ++++ .../parserAmbiguityWithBinaryOperator1.types | 20 ++++++ .../parserAmbiguityWithBinaryOperator2.js | 12 ++++ .../parserAmbiguityWithBinaryOperator2.types | 20 ++++++ .../parserAmbiguityWithBinaryOperator3.js | 13 ++++ .../parserAmbiguityWithBinaryOperator3.types | 21 +++++++ ...serAmbiguityWithBinaryOperator4.errors.txt | 10 +++ .../parserAmbiguityWithBinaryOperator4.js | 12 ++++ .../parserCommaInTypeMemberList2.errors.txt | 4 +- .../parserErrorRecovery_Block2.errors.txt | 8 +-- ...rserErrorRecovery_ClassElement3.errors.txt | 23 ++++--- ...serErrorRecovery_ParameterList4.errors.txt | 8 +-- .../Blocks/parserErrorRecovery_Block2.ts | 2 +- .../parserErrorRecovery_ClassElement3.ts | 6 +- .../parserErrorRecovery_ParameterList4.ts | 2 +- .../parserAmbiguityWithBinaryOperator1.ts | 4 ++ .../parserAmbiguityWithBinaryOperator2.ts | 4 ++ .../parserAmbiguityWithBinaryOperator3.ts | 4 ++ .../parserAmbiguityWithBinaryOperator4.ts | 4 ++ 21 files changed, 200 insertions(+), 79 deletions(-) create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts diff --git a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt index 1b216b72c89..a946c17ff71 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt @@ -1,14 +1,11 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,12): error TS1127: Invalid character. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1129: Statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,19): error TS1005: '(' expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(6,3): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(7,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1109: Expression expected. tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,9): error TS2304: Cannot find name 'a'. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2304: Cannot find name 'bar'. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,12): error TS2304: Cannot find name 'bar'. -==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (8 errors) ==== +==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (5 errors) ==== class C { foo() { // Make sure we don't think of *bar as the start of a generator method. @@ -16,19 +13,13 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration !!! error TS1127: Invalid character. ~ -!!! error TS1129: Statement expected. - ~ -!!! error TS1005: '(' expected. +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name 'a'. ~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS2304: Cannot find name 'bar'. return bar; - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~ +!!! error TS2304: Cannot find name 'bar'. } - ~ -!!! error TS1128: Declaration or statement expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 8d544ff1bcb..ed7843ad45e 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -3,15 +3,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,28): error TS1005: ':' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,29): error TS1005: ',' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,18): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,33): error TS1138: Parameter declaration expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,34): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,36): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: '=' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,26): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(38,17): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,41): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,45): error TS1002: Unterminated string literal. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(46,13): error TS1005: 'try' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(49,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. @@ -43,21 +41,19 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,35): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,1): error TS2304: Cannot find name 'module'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,26): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,17): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2304: Cannot find name 'retValue'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression. @@ -82,12 +78,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,52): error TS2304: Cannot find name 'string'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS2304: Cannot find name 'DefaultValue'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (87 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (84 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -136,30 +133,24 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { ~~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1138: Parameter declaration expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS1005: '=' expected. return 1; ^ ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. retValue = bfs.TYPES(); + ~ +!!! error TS1005: ';' expected. ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1 && } @@ -171,25 +162,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS1005: ';' expected. !!! error TS1002: Unterminated string literal. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1; } } catch (e) { - ~~~~~ -!!! error TS1005: 'try' expected. console.log(e); ~~~~~~~ !!! error TS2304: Cannot find name 'console'. } finally { + ~~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. } @@ -501,7 +490,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~ !!! error TS1005: ';' expected. ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. ~~~~~~~~~ !!! error TS2304: Cannot find name 'Overloads'. ~~~~~~ @@ -510,12 +499,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'string'. public DefaultValue(value?: string = "Hello") { } - ~~~~~~ -!!! error TS1129: Statement expected. + ~~~~~~~~~~~~ +!!! error TS1005: ';' expected. ~ !!! error TS1109: Expression expected. ~ !!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. ~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'DefaultValue'. ~~~~~ diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js new file mode 100644 index 00000000000..18a1dee3e9f --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator1.ts] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator1.js] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types new file mode 100644 index 00000000000..1a087485e26 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts === +function f1() { +>f1 : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b || b > (c + 1)) { } +>a < b || b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js new file mode 100644 index 00000000000..9589d57e3af --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator2.ts] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator2.js] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types new file mode 100644 index 00000000000..05ac7172cff --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b > (c + 1)) { } +>a < b && b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js new file mode 100644 index 00000000000..95745263c71 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js @@ -0,0 +1,13 @@ +//// [parserAmbiguityWithBinaryOperator3.ts] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} + + +//// [parserAmbiguityWithBinaryOperator3.js] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types new file mode 100644 index 00000000000..03283115bf9 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b < (c + 1)) { } +>a < b && b < (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b < (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} + diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt new file mode 100644 index 00000000000..2c7bef61598 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. + + +==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (1 errors) ==== + function g() { + var a, b, c; + if (a(c + 1)) { } + ~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js new file mode 100644 index 00000000000..cdcec030ae7 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator4.ts] +function g() { + var a, b, c; + if (a(c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator4.js] +function g() { + var a, b, c; + if (a(c + 1)) { + } +} diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt index 025febbc9a5..bc6f3dc0644 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,38): error TS1134: Variable declaration expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,60): error TS1005: ';' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1109: Expression expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,9): error TS2304: Cannot find name '$'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,31): error TS2304: Cannot find name 'any'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,50): error TS2304: Cannot find name 'any'. @@ -15,7 +15,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMember ~ !!! error TS1005: ';' expected. ~ -!!! error TS1128: Declaration or statement expected. +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name '$'. ~~~ diff --git a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt index bce96874f4c..53279be443f 100644 --- a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1129: Statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ==== function f() { - | - ~ -!!! error TS1129: Statement expected. + # + +!!! error TS1127: Invalid character. return; } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt index e2856855824..63c62bcd13d 100644 --- a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt @@ -1,19 +1,22 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,4): error TS1127: Invalid character. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,5): error TS1005: '}' expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (4 errors) ==== module M { - | - ~ -!!! error TS1128: Declaration or statement expected. + # + +!!! error TS1127: Invalid character. class C { } - | - ~ -!!! error TS1128: Declaration or statement expected. + @ + +!!! error TS1127: Invalid character. enum E { - } + # + +!!! error TS1127: Invalid character. !!! error TS1005: '}' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt index d44f6eadcf2..fa97550dd19 100644 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1138: Parameter declaration expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts (1 errors) ==== - function f(a,|) { - ~ -!!! error TS1138: Parameter declaration expected. + function f(a,#) { + +!!! error TS1127: Invalid character. } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts index a28fa48ec87..2473a9d1ffb 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts @@ -1,4 +1,4 @@ function f() { - | + # return; } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts index c6e2649f1b2..d4ea9d60787 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts @@ -1,7 +1,7 @@ module M { - | + # class C { } - | + @ enum E { - } \ No newline at end of file + # \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts index 62b39e7f3cc..f46e4695145 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts @@ -1,2 +1,2 @@ -function f(a,|) { +function f(a,#) { } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts new file mode 100644 index 00000000000..d008e7f7abc --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts @@ -0,0 +1,4 @@ +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts new file mode 100644 index 00000000000..ed2fb80fef0 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts new file mode 100644 index 00000000000..25bc7e0c95d --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts new file mode 100644 index 00000000000..22fc2f8e182 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts @@ -0,0 +1,4 @@ +function g() { + var a, b, c; + if (a(c + 1)) { } +} \ No newline at end of file From c1d509a940b72eab9866505c72890eb8657f5cc6 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 8 Dec 2014 15:38:35 -0800 Subject: [PATCH 08/16] Update and add test cases --- .../MemberFunctionDeclaration8_es6.errors.txt | 27 +++----- ...torWithIncompleteTypeAnnotation.errors.txt | 63 ++++++++----------- ...arseIncompleteBinaryExpression1.errors.txt | 10 +++ .../parserAmbiguityWithBinaryOperator1.js | 12 ++++ .../parserAmbiguityWithBinaryOperator1.types | 20 ++++++ .../parserAmbiguityWithBinaryOperator2.js | 12 ++++ .../parserAmbiguityWithBinaryOperator2.types | 20 ++++++ .../parserAmbiguityWithBinaryOperator3.js | 13 ++++ .../parserAmbiguityWithBinaryOperator3.types | 21 +++++++ ...serAmbiguityWithBinaryOperator4.errors.txt | 10 +++ .../parserAmbiguityWithBinaryOperator4.js | 12 ++++ .../parserCommaInTypeMemberList2.errors.txt | 4 +- .../parserErrorRecovery_Block2.errors.txt | 8 +-- ...rserErrorRecovery_ClassElement3.errors.txt | 23 ++++--- ...serErrorRecovery_ParameterList4.errors.txt | 8 +-- .../Blocks/parserErrorRecovery_Block2.ts | 2 +- .../parserErrorRecovery_ClassElement3.ts | 6 +- .../parserErrorRecovery_ParameterList4.ts | 2 +- .../parseIncompleteBinaryExpression1.ts | 1 + .../parserAmbiguityWithBinaryOperator1.ts | 4 ++ .../parserAmbiguityWithBinaryOperator2.ts | 4 ++ .../parserAmbiguityWithBinaryOperator3.ts | 4 ++ .../parserAmbiguityWithBinaryOperator4.ts | 4 ++ 23 files changed, 211 insertions(+), 79 deletions(-) create mode 100644 tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt create mode 100644 tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js create mode 100644 tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts create mode 100644 tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts diff --git a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt index 1b216b72c89..a946c17ff71 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt @@ -1,14 +1,11 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,12): error TS1127: Invalid character. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1129: Statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,19): error TS1005: '(' expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(6,3): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(7,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1109: Expression expected. tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,9): error TS2304: Cannot find name 'a'. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2304: Cannot find name 'bar'. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,12): error TS2304: Cannot find name 'bar'. -==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (8 errors) ==== +==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (5 errors) ==== class C { foo() { // Make sure we don't think of *bar as the start of a generator method. @@ -16,19 +13,13 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration !!! error TS1127: Invalid character. ~ -!!! error TS1129: Statement expected. - ~ -!!! error TS1005: '(' expected. +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name 'a'. ~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS2304: Cannot find name 'bar'. return bar; - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~ +!!! error TS2304: Cannot find name 'bar'. } - ~ -!!! error TS1128: Declaration or statement expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 8d544ff1bcb..ed7843ad45e 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -3,15 +3,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,28): error TS1005: ':' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,29): error TS1005: ',' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,18): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,33): error TS1138: Parameter declaration expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,34): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,36): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: '=' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,26): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(38,17): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,41): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,45): error TS1002: Unterminated string literal. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(46,13): error TS1005: 'try' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(49,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. @@ -43,21 +41,19 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,35): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,1): error TS2304: Cannot find name 'module'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,26): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,17): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2304: Cannot find name 'retValue'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression. @@ -82,12 +78,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,52): error TS2304: Cannot find name 'string'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS2304: Cannot find name 'DefaultValue'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (87 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (84 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -136,30 +133,24 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { ~~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1138: Parameter declaration expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS1005: '=' expected. return 1; ^ ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. retValue = bfs.TYPES(); + ~ +!!! error TS1005: ';' expected. ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1 && } @@ -171,25 +162,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS1005: ';' expected. !!! error TS1002: Unterminated string literal. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1; } } catch (e) { - ~~~~~ -!!! error TS1005: 'try' expected. console.log(e); ~~~~~~~ !!! error TS2304: Cannot find name 'console'. } finally { + ~~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. } @@ -501,7 +490,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~ !!! error TS1005: ';' expected. ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. ~~~~~~~~~ !!! error TS2304: Cannot find name 'Overloads'. ~~~~~~ @@ -510,12 +499,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'string'. public DefaultValue(value?: string = "Hello") { } - ~~~~~~ -!!! error TS1129: Statement expected. + ~~~~~~~~~~~~ +!!! error TS1005: ';' expected. ~ !!! error TS1109: Expression expected. ~ !!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. ~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'DefaultValue'. ~~~~~ diff --git a/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt b/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt new file mode 100644 index 00000000000..e0155acc3f1 --- /dev/null +++ b/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts(1,9): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts(1,12): error TS2304: Cannot find name 'b'. + + +==== tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts (2 errors) ==== + var v = || b; + ~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS2304: Cannot find name 'b'. \ No newline at end of file diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js new file mode 100644 index 00000000000..18a1dee3e9f --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator1.ts] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator1.js] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types new file mode 100644 index 00000000000..1a087485e26 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts === +function f1() { +>f1 : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b || b > (c + 1)) { } +>a < b || b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js new file mode 100644 index 00000000000..9589d57e3af --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator2.ts] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator2.js] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types new file mode 100644 index 00000000000..05ac7172cff --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b > (c + 1)) { } +>a < b && b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js new file mode 100644 index 00000000000..95745263c71 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js @@ -0,0 +1,13 @@ +//// [parserAmbiguityWithBinaryOperator3.ts] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} + + +//// [parserAmbiguityWithBinaryOperator3.js] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types new file mode 100644 index 00000000000..03283115bf9 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b < (c + 1)) { } +>a < b && b < (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b < (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} + diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt new file mode 100644 index 00000000000..2c7bef61598 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. + + +==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (1 errors) ==== + function g() { + var a, b, c; + if (a(c + 1)) { } + ~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js new file mode 100644 index 00000000000..cdcec030ae7 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator4.ts] +function g() { + var a, b, c; + if (a(c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator4.js] +function g() { + var a, b, c; + if (a(c + 1)) { + } +} diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt index 025febbc9a5..bc6f3dc0644 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,38): error TS1134: Variable declaration expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,60): error TS1005: ';' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1109: Expression expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,9): error TS2304: Cannot find name '$'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,31): error TS2304: Cannot find name 'any'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,50): error TS2304: Cannot find name 'any'. @@ -15,7 +15,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMember ~ !!! error TS1005: ';' expected. ~ -!!! error TS1128: Declaration or statement expected. +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name '$'. ~~~ diff --git a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt index bce96874f4c..53279be443f 100644 --- a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1129: Statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ==== function f() { - | - ~ -!!! error TS1129: Statement expected. + # + +!!! error TS1127: Invalid character. return; } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt index e2856855824..63c62bcd13d 100644 --- a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt @@ -1,19 +1,22 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,4): error TS1127: Invalid character. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,5): error TS1005: '}' expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (4 errors) ==== module M { - | - ~ -!!! error TS1128: Declaration or statement expected. + # + +!!! error TS1127: Invalid character. class C { } - | - ~ -!!! error TS1128: Declaration or statement expected. + @ + +!!! error TS1127: Invalid character. enum E { - } + # + +!!! error TS1127: Invalid character. !!! error TS1005: '}' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt index d44f6eadcf2..fa97550dd19 100644 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1138: Parameter declaration expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts (1 errors) ==== - function f(a,|) { - ~ -!!! error TS1138: Parameter declaration expected. + function f(a,#) { + +!!! error TS1127: Invalid character. } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts index a28fa48ec87..2473a9d1ffb 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts @@ -1,4 +1,4 @@ function f() { - | + # return; } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts index c6e2649f1b2..d4ea9d60787 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts @@ -1,7 +1,7 @@ module M { - | + # class C { } - | + @ enum E { - } \ No newline at end of file + # \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts index 62b39e7f3cc..f46e4695145 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts @@ -1,2 +1,2 @@ -function f(a,|) { +function f(a,#) { } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts b/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts new file mode 100644 index 00000000000..f5a3bb0e701 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts @@ -0,0 +1 @@ +var v = || b; \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts new file mode 100644 index 00000000000..d008e7f7abc --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts @@ -0,0 +1,4 @@ +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts new file mode 100644 index 00000000000..ed2fb80fef0 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts new file mode 100644 index 00000000000..25bc7e0c95d --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts new file mode 100644 index 00000000000..22fc2f8e182 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts @@ -0,0 +1,4 @@ +function g() { + var a, b, c; + if (a(c + 1)) { } +} \ No newline at end of file From c1b19d761d94578a1591982f3ed2df8c60fb8bad Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 16:16:11 -0800 Subject: [PATCH 09/16] Remove the 'Method' syntaxkind and introduce MethodSignature and MethodDeclaration instead. Sharing a single kind here would be bad for incremental scenarios as these two node types are not interchangeable. For now, i have updated nearly all code to look for both kinds. However, it may not make sense in all locations, and we could likely tighten up many code locations to only have to deal with one or the other. --- src/compiler/binder.ts | 6 ++-- src/compiler/checker.ts | 59 +++++++++++++++++++------------- src/compiler/emitter.ts | 41 ++++++++++++++-------- src/compiler/parser.ts | 41 +++++++++++++--------- src/compiler/types.ts | 3 +- src/services/breakpoints.ts | 6 ++-- src/services/formatting.ts | 3 +- src/services/formatting/rules.ts | 6 ++-- src/services/navigationBar.ts | 3 +- src/services/services.ts | 30 ++++++++++------ src/services/smartIndenter.ts | 9 +++-- 11 files changed, 132 insertions(+), 75 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7acb99d624d..d98f7dc844b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -265,7 +265,8 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -410,7 +411,8 @@ module ts { case SyntaxKind.ConstructSignature: bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d913f7360c..2ef8d7efe79 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -391,7 +391,8 @@ module ts { break loop; } break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -1624,7 +1625,8 @@ module ts { case SyntaxKind.Property: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.flags & (NodeFlags.Private | NodeFlags.Protected)) { // Private/protected properties/methods are not visible return false; @@ -2581,7 +2583,8 @@ module ts { case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: @@ -3247,7 +3250,7 @@ module ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -3264,7 +3267,8 @@ module ts { (isContextSensitive((node).left) || isContextSensitive((node).right)); case SyntaxKind.PropertyAssignment: return isContextSensitive((node).initializer); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return isContextSensitiveFunctionLikeDeclaration(node); } @@ -4478,7 +4482,8 @@ module ts { case SyntaxKind.SourceFile: case SyntaxKind.ModuleDeclaration: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: @@ -4690,7 +4695,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4748,13 +4754,15 @@ module ts { if (container && container.parent && container.parent.kind === SyntaxKind.ClassDeclaration) { if (container.flags & NodeFlags.Static) { canUseSuperExpression = - container.kind === SyntaxKind.Method || + container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor; } else { canUseSuperExpression = - container.kind === SyntaxKind.Method || + container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor || container.kind === SyntaxKind.Property || @@ -5051,7 +5059,7 @@ module ts { // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); var type = isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -5156,7 +5164,7 @@ module ts { if (memberDecl.kind === SyntaxKind.PropertyAssignment) { type = checkExpression((memberDecl).initializer, contextualMapper); } - else if (memberDecl.kind === SyntaxKind.Method) { + else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { @@ -5299,7 +5307,7 @@ module ts { // - In a static member function or static member accessor // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { + if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } else { @@ -5320,7 +5328,7 @@ module ts { if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { - if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { + if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { return false; } else { @@ -6208,7 +6216,7 @@ module ts { } function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | MethodDeclaration, contextualMapper?: TypeMapper): Type { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); // The identityMapper object is used to indicate that function expressions are wildcards if (contextualMapper === identityMapper) { @@ -6241,7 +6249,7 @@ module ts { } } - if (fullTypeCheck && node.kind !== SyntaxKind.Method) { + if (fullTypeCheck && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { checkCollisionWithCapturedSuperVariable(node, (node).name); checkCollisionWithCapturedThisVariable(node,(node).name); } @@ -6250,7 +6258,7 @@ module ts { } function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } @@ -7199,7 +7207,7 @@ module ts { // TODO(jfreeman): These are methods, so handle computed name case if (node.name && (subsequentNode).name && (node.name).text === ((subsequentNode).name).text) { // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members - Debug.assert(node.kind === SyntaxKind.Method); + Debug.assert(node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature); Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static)); var diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static; error(errorNode, diagnostic); @@ -7240,7 +7248,7 @@ module ts { previousDeclaration = undefined; } - if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor) { + if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.Constructor) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -7542,7 +7550,8 @@ module ts { // all kinds that might have rest parameters case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: if (hasRestParameters(current)) { @@ -7561,7 +7570,8 @@ module ts { } if (node.kind === SyntaxKind.Property || - node.kind === SyntaxKind.Method || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { // it is ok to have member named '_super' or '_this' - member access is always qualified @@ -8571,7 +8581,8 @@ module ts { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: return checkSignatureDeclaration(node); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return checkMethodDeclaration(node); case SyntaxKind.Constructor: return checkConstructorDeclaration(node); @@ -8661,7 +8672,8 @@ module ts { forEach((node).parameters, checkFunctionExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: forEach((node).parameters, checkFunctionExpressionBodies); if (isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -8942,7 +8954,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return node === (parent).type; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6dc9b31322c..ce4ac8ae46f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -761,6 +761,10 @@ module ts { writeLine(); } + function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { + return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); + } + function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { function emitTypeParameter(node: TypeParameterDeclaration) { increaseIndent(); @@ -768,12 +772,13 @@ module ts { decreaseIndent(); writeTextOfNode(currentSourceFile, node.name); // If there is constraint present and this is not a type parameter of the private method emit the constraint - if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) { + if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); if (node.parent.kind === SyntaxKind.FunctionType || node.parent.kind === SyntaxKind.ConstructorType || (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { - Debug.assert(node.parent.kind === SyntaxKind.Method || + Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || + node.parent.kind === SyntaxKind.MethodSignature || node.parent.kind === SyntaxKind.FunctionType || node.parent.kind === SyntaxKind.ConstructorType || node.parent.kind === SyntaxKind.CallSignature || @@ -805,7 +810,8 @@ module ts { diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } @@ -1113,7 +1119,7 @@ module ts { if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === SyntaxKind.Method) { + else if (node.kind === SyntaxKind.MethodDeclaration) { emitClassMemberDeclarationFlags(node); } if (node.kind === SyntaxKind.FunctionDeclaration) { @@ -1208,7 +1214,8 @@ module ts { Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? @@ -1296,7 +1303,8 @@ module ts { Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? @@ -1343,7 +1351,8 @@ module ts { switch (node.kind) { case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return emitFunctionDeclaration(node); case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: @@ -1728,7 +1737,8 @@ module ts { } else if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression || - node.kind === SyntaxKind.Method || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor || node.kind === SyntaxKind.ModuleDeclaration || @@ -2126,7 +2136,8 @@ module ts { case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -2827,7 +2838,7 @@ module ts { return emitPinnedOrTripleSlashComments(node); } - if (node.kind !== SyntaxKind.Method) { + if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { // Methods will emit the comments as part of emitting method declaration emitLeadingComments(node); } @@ -2836,7 +2847,7 @@ module ts { emit(node.name); } emitSignatureAndBody(node); - if (node.kind !== SyntaxKind.Method) { + if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); } } @@ -2998,7 +3009,7 @@ module ts { function emitMemberFunctions(node: ClassDeclaration) { forEach(node.members, member => { - if (member.kind === SyntaxKind.Method) { + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { return emitPinnedOrTripleSlashComments(member); } @@ -3653,7 +3664,8 @@ module ts { switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: return emitDownlevelShorthandPropertyAssignment(node); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return emitDownlevelMethod(node); } } @@ -3663,7 +3675,8 @@ module ts { switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: return emitShorthandPropertyAssignment(node); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return emitMethod(node); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c331a89e0d..e40c074a56a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -289,7 +289,8 @@ module ts { children((node).typeParameters) || children((node).parameters) || child((node).type); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -509,7 +510,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: @@ -525,7 +527,7 @@ module ts { } export function isObjectLiteralMethod(node: Node) { - return node !== undefined && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; + return node !== undefined && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression; } export function getContainingFunction(node: Node): FunctionLikeDeclaration { @@ -553,7 +555,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -572,7 +575,8 @@ module ts { } switch (node.kind) { case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -694,7 +698,8 @@ module ts { switch (node.kind) { case SyntaxKind.Parameter: return (node).questionToken !== undefined; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.PropertyAssignment: @@ -739,7 +744,8 @@ module ts { case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -2134,13 +2140,13 @@ module ts { return finishNode(node) } - function parsePropertyOrMethod(): Declaration { + function parsePropertyOrMethodSignature(): Declaration { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - var method = createNode(SyntaxKind.Method, fullStart); + var method = createNode(SyntaxKind.MethodSignature, fullStart); method.name = name; method.questionToken = questionToken; @@ -2188,7 +2194,7 @@ module ts { return parseSignatureMember(SyntaxKind.CallSignature); case SyntaxKind.OpenBracketToken: // Indexer or computed property - return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethod(); + return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); @@ -2196,10 +2202,10 @@ module ts { // fall through. case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); default: if (isIdentifierOrKeyword()) { - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); } } } @@ -3830,7 +3836,7 @@ module ts { } function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, requireBlock: boolean): MethodDeclaration { - var method = createNode(SyntaxKind.Method, fullStart); + var method = createNode(SyntaxKind.MethodDeclaration, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -4551,7 +4557,9 @@ module ts { case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); - case SyntaxKind.Method: return checkMethod(node); + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); case SyntaxKind.NumericLiteral: return checkNumericLiteral(node); @@ -5166,7 +5174,7 @@ module ts { var currentKind: number; if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || - prop.kind === SyntaxKind.Method) { + prop.kind === SyntaxKind.MethodDeclaration) { currentKind = Property; } else if (prop.kind === SyntaxKind.GetAccessor) { @@ -5221,7 +5229,8 @@ module ts { case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c2d57876e6a..328ed3c6c06 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -148,7 +148,8 @@ module ts { Parameter, // TypeMember Property, - Method, + MethodSignature, + MethodDeclaration, Constructor, GetAccessor, SetAccessor, diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 260fa5892aa..68974cc3b69 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -93,7 +93,8 @@ module ts.BreakpointResolver { return spanInParameterDeclaration(node); case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: @@ -463,7 +464,8 @@ module ts.BreakpointResolver { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: diff --git a/src/services/formatting.ts b/src/services/formatting.ts index 9660d9af6df..b6c2df9e9c8 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -911,7 +911,8 @@ module ts.formatting { case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: if ((node).typeParameters === list) { return SyntaxKind.LessThanToken; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 5dc44650346..d9cf61ae4a1 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -536,7 +536,8 @@ module ts.formatting { static IsFunctionDeclContext(context: FormattingContext): boolean { switch (context.contextNode.kind) { case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: //case SyntaxKind.MemberFunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -652,7 +653,8 @@ module ts.formatting { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.CallExpression: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index bf7892ce6cb..56fca4ffdfe 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -205,7 +205,8 @@ module ts.NavigationBar { } return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberFunctionElement); case SyntaxKind.GetAccessor: diff --git a/src/services/services.ts b/src/services/services.ts index 980b7ecda3d..5eae06e759e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -766,7 +766,8 @@ module ts { forEachChild(sourceFile, function visit(node: Node): void { switch (node.kind) { case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { @@ -1990,7 +1991,8 @@ module ts { case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.ModuleDeclaration: @@ -2571,7 +2573,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -2732,7 +2735,8 @@ module ts { } switch (node.kind) { case SyntaxKind.SourceFile: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.GetAccessor: @@ -2847,7 +2851,9 @@ module ts { case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; - case SyntaxKind.Method: return ScriptElementKind.memberFunctionElement; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return ScriptElementKind.memberFunctionElement; case SyntaxKind.Property: return ScriptElementKind.memberVariableElement; case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement; case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement; @@ -3258,7 +3264,7 @@ module ts { forEach(signatureDeclarations, d => { if ((selectConstructors && d.kind === SyntaxKind.Constructor) || - (!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.Method))) { + (!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.MethodDeclaration || d.kind === SyntaxKind.MethodSignature))) { declarations.push(d); if ((d).body) definition = d; } @@ -4272,7 +4278,8 @@ module ts { switch (searchSpaceNode.kind) { case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4316,7 +4323,8 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (isObjectLiteralMethod(searchSpaceNode)) { break; } @@ -4374,7 +4382,8 @@ module ts { result.push(getReferenceEntryFromNode(node)); } break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } @@ -4735,7 +4744,8 @@ module ts { case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index e93cb5616a9..cafd92a7551 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -234,7 +234,8 @@ module ts.formatting { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: var start = node.getStart(sourceFile); @@ -358,7 +359,8 @@ module ts.formatting { case SyntaxKind.IfStatement: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: @@ -414,7 +416,8 @@ module ts.formatting { return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: return !(n).body || isCompletedNode((n).body, sourceFile); case SyntaxKind.ModuleDeclaration: From cc83925f323551ab841d5b70aff66746a4e9c596 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 16:37:35 -0800 Subject: [PATCH 10/16] Also split out .PropertyDeclaration and .PropertySignature from .Property. --- src/compiler/binder.ts | 3 ++- src/compiler/checker.ts | 39 ++++++++++++++++++++------------ src/compiler/emitter.ts | 14 +++++++----- src/compiler/parser.ts | 29 ++++++++++++++++-------- src/compiler/types.ts | 3 ++- src/services/breakpoints.ts | 3 ++- src/services/formatting/rules.ts | 3 ++- src/services/navigationBar.ts | 3 ++- src/services/services.ts | 23 ++++++++++++------- 9 files changed, 77 insertions(+), 43 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d98f7dc844b..281985b0ba0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -397,7 +397,8 @@ module ts { bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2ef8d7efe79..4690d0ad75d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -361,7 +361,8 @@ module ts { break loop; } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or @@ -1622,7 +1623,8 @@ module ts { // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: @@ -1740,7 +1742,8 @@ module ts { return; } switch (declaration.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: var diagnostic = Diagnostics.Member_0_implicitly_has_an_1_type; break; case SyntaxKind.Parameter: @@ -4631,7 +4634,7 @@ module ts { function captureLexicalThis(node: Node, container: Node): void { var classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; - if (container.kind === SyntaxKind.Property || container.kind === SyntaxKind.Constructor) { + if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { getNodeLinks(classNode).flags |= NodeCheckFlags.CaptureThis; } else { @@ -4666,7 +4669,8 @@ module ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: if (container.flags & NodeFlags.Static) { error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -4694,7 +4698,8 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -4765,7 +4770,8 @@ module ts { container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor || - container.kind === SyntaxKind.Property || + container.kind === SyntaxKind.PropertyDeclaration || + container.kind === SyntaxKind.PropertySignature || container.kind === SyntaxKind.Constructor; } } @@ -5010,7 +5016,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return getContextualTypeForInitializerExpression(node); case SyntaxKind.ArrowFunction: case SyntaxKind.ReturnStatement: @@ -5229,7 +5236,7 @@ module ts { // If a symbol is a synthesized symbol with no value declaration, we assume it is a property. Example of this are the synthesized // '.prototype' property as well as synthesized tuple index properties. function getDeclarationKindFromSymbol(s: Symbol) { - return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.Property; + return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.PropertyDeclaration; } function getDeclarationFlagsFromSymbol(s: Symbol) { @@ -6952,7 +6959,7 @@ module ts { } function isInstancePropertyWithInitializer(n: Node): boolean { - return n.kind === SyntaxKind.Property && + return n.kind === SyntaxKind.PropertyDeclaration && !(n.flags & NodeFlags.Static) && !!(n).initializer; } @@ -7569,7 +7576,8 @@ module ts { return false; } - if (node.kind === SyntaxKind.Property || + if (node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || @@ -8573,7 +8581,8 @@ module ts { return checkTypeParameter(node); case SyntaxKind.Parameter: return checkParameter(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return checkPropertyDeclaration(node); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -8689,7 +8698,8 @@ module ts { checkFunctionExpressionBodies((node).expression); break; case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.PropertyAssignment: @@ -8946,7 +8956,8 @@ module ts { switch (parent.kind) { case SyntaxKind.TypeParameter: return node === (parent).constraint; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: return node === (parent).type; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ce4ac8ae46f..f84f19b256c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -950,10 +950,10 @@ module ts { if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? - if (node.kind === SyntaxKind.Property && hasQuestionToken(node)) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { write("?"); } - if (node.kind === SyntaxKind.Property && node.parent.kind === SyntaxKind.TypeLiteral) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & NodeFlags.Private)) { @@ -971,7 +971,7 @@ module ts { Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit - else if (node.kind === SyntaxKind.Property) { + else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? @@ -1363,7 +1363,8 @@ module ts { return emitAccessorDeclaration(node); case SyntaxKind.VariableStatement: return emitVariableStatement(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return emitPropertyDeclaration(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); @@ -2132,7 +2133,8 @@ module ts { switch (parent.kind) { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: @@ -2985,7 +2987,7 @@ module ts { function emitMemberAssignments(node: ClassDeclaration, staticFlag: NodeFlags) { forEach(node.members, member => { - if (member.kind === SyntaxKind.Property && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { + if (member.kind === SyntaxKind.PropertyDeclaration && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { writeLine(); emitLeadingComments(member); emitStart(member); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e40c074a56a..e9941421768 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -272,7 +272,8 @@ module ts { child((node).questionToken) || child((node).type) || child((node).initializer); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return children(node.modifiers) || @@ -554,7 +555,8 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -574,7 +576,8 @@ module ts { return undefined; } switch (node.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -641,7 +644,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: return (parent).initializer === node; @@ -703,7 +707,8 @@ module ts { return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.PropertyAssignment: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return (node).questionToken !== undefined; } } @@ -740,7 +745,8 @@ module ts { case SyntaxKind.TypeParameter: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: @@ -2158,7 +2164,7 @@ module ts { return finishNode(method); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertySignature, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -3857,7 +3863,7 @@ module ts { return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -4566,7 +4572,9 @@ module ts { case SyntaxKind.Parameter: return checkParameter(node); case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); - case SyntaxKind.Property: return checkProperty(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return checkProperty(node); case SyntaxKind.ReturnStatement: return checkReturnStatement(node); case SyntaxKind.SetAccessor: return checkSetAccessor(node); case SyntaxKind.SourceFile: return checkSourceFile(node); @@ -5228,7 +5236,8 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 328ed3c6c06..44108c347ae 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -147,7 +147,8 @@ module ts { TypeParameter, Parameter, // TypeMember - Property, + PropertySignature, + PropertyDeclaration, MethodSignature, MethodDeclaration, Constructor, diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 68974cc3b69..3a2cc2ad7e7 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -86,7 +86,8 @@ module ts.BreakpointResolver { return spanInVariableDeclaration((node).declarations[0]); case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return spanInVariableDeclaration(node); case SyntaxKind.Parameter: diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index d9cf61ae4a1..9b6f0cecb9d 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -458,7 +458,8 @@ module ts.formatting { // equal in p = 0; case SyntaxKind.Parameter: case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; // "in" keyword in for (var x in []) { } case SyntaxKind.ForInStatement: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 56fca4ffdfe..0840ccbf7de 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -227,7 +227,8 @@ module ts.NavigationBar { case SyntaxKind.ConstructSignature: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); case SyntaxKind.FunctionDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 5eae06e759e..54c17f01019 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -824,7 +824,8 @@ module ts { // fall through case SyntaxKind.VariableDeclaration: case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: namedDeclarations.push(node); break; } @@ -1988,7 +1989,8 @@ module ts { function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { switch (node.parent.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.MethodDeclaration: @@ -2605,7 +2607,7 @@ module ts { containingNodeKind === SyntaxKind.InterfaceDeclaration; // interface a { | case SyntaxKind.SemicolonToken: - return containingNodeKind === SyntaxKind.Property && + return containingNodeKind === SyntaxKind.PropertySignature && previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration; // interface a { f; | case SyntaxKind.PublicKeyword: @@ -2854,7 +2856,9 @@ module ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return ScriptElementKind.memberFunctionElement; - case SyntaxKind.Property: return ScriptElementKind.memberVariableElement; + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return ScriptElementKind.memberVariableElement; case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement; case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement; case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement; @@ -4277,7 +4281,8 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -4328,8 +4333,9 @@ module ts { if (isObjectLiteralMethod(searchSpaceNode)) { break; } - // fall through - case SyntaxKind.Property: + // fall through + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4740,7 +4746,8 @@ module ts { switch (node.kind) { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: From 40e5c73504fc6bc40afb9e3f6e25c37d55039923 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 8 Dec 2014 16:51:23 -0800 Subject: [PATCH 11/16] Update version to 1.4 --- package.json | 2 +- src/compiler/tsc.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 00752302254..f6391394c6a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.3.0", + "version": "1.4.0", "licenses": [ { "type": "Apache License 2.0", diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 333f80a663e..fbe596ee0f7 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -9,7 +9,7 @@ /// module ts { - var version = "1.3.0.0"; + var version = "1.4.0.0"; /** * Checks to see if the locale is in the appropriate format, From 174d48a29e8c7cb839e79f2ea0375fce67693f76 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 17:02:34 -0800 Subject: [PATCH 12/16] Fix some parts of for-each invariant checking. --- src/harness/test262Runner.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 1602379902a..7fdc347bd96 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -42,7 +42,19 @@ class Test262BaselineRunner extends RunnerBase { var childNodesAndArrays: any[] = []; ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) }); + /* + parent?: Node; // Parent node (initialized by binding) + symbol?: Symbol; // Symbol declared by node (initialized by binding) + locals?: SymbolTable; // Locals associated with node (initialized by binding) + nextContainer?: Node; // Next container in declaration order (initialized by binding) + localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + modifiers?: ModifiersArray; // Array of modifiers + */ + for (var childName in node) { + if (childName === "parent" || childName === "nextContainer" || childName === "modifiers") { + continue; + } var child = (node)[childName]; if (Test262BaselineRunner.isNodeOrArray(child)) { if (childNodesAndArrays.indexOf(child) < 0) { From 21301b94cb73e3b0be7c847f9c2b250e036efc52 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 17:42:54 -0800 Subject: [PATCH 13/16] Prevent json recursion overflow in 262 tests. --- src/harness/test262Runner.ts | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 7fdc347bd96..547cc48a617 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -42,15 +42,6 @@ class Test262BaselineRunner extends RunnerBase { var childNodesAndArrays: any[] = []; ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) }); - /* - parent?: Node; // Parent node (initialized by binding) - symbol?: Symbol; // Symbol declared by node (initialized by binding) - locals?: SymbolTable; // Locals associated with node (initialized by binding) - nextContainer?: Node; // Next container in declaration order (initialized by binding) - localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) - modifiers?: ModifiersArray; // Array of modifiers - */ - for (var childName in node) { if (childName === "parent" || childName === "nextContainer" || childName === "modifiers") { continue; @@ -96,6 +87,19 @@ class Test262BaselineRunner extends RunnerBase { function getNodeFlagName(f: number) { return getFlagName((ts).NodeFlags, f); } function getParserContextFlagName(f: number) { return getFlagName((ts).ParserContextFlags, f); } + function convertDiagnostics(diagnostics: ts.Diagnostic[]) { + return diagnostics.map(convertDiagnostic); + } + + function convertDiagnostic(diagnostic: ts.Diagnostic): any { + return { + start: diagnostic.start, + length: diagnostic.length, + messageText: diagnostic.messageText, + category: (ts).DiagnosticCategory[diagnostic.category], + code: diagnostic.code + }; + } function serializeNode(n: ts.Node): any { var o: any = { kind: getKindName(n.kind) }; @@ -124,6 +128,12 @@ class Test262BaselineRunner extends RunnerBase { o[propertyName] = getParserContextFlagName(n.parserContextFlags); break; + case "referenceDiagnostics": + case "parseDiagnostics": + case "grammarDiagnostics": + o[propertyName] = convertDiagnostics((n)[propertyName]); + break; + case "nextContainer": if (n.nextContainer) { o[propertyName] = { kind: n.nextContainer.kind, pos: n.nextContainer.pos, end: n.nextContainer.end }; From afc57777f33ed66de2e8406427720d52a6e2a256 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 18:36:25 -0800 Subject: [PATCH 14/16] Put the actual parsing logic at the top of createSourceFile instead of the bottom. This makes it vastly simpler to fix up that logic since you no longer have to go find the end of the function first. --- src/compiler/parser.ts | 92 ++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 52 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dfee57c68b3..dc99bdbeb89 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1007,7 +1007,6 @@ module ts { } export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { - var token: SyntaxKind; var parsingContext: ParsingContext; var identifiers: Map = {}; var identifierCount = 0; @@ -1016,8 +1015,7 @@ module ts { // Flags that dictate what parsing context we're in. For example: // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is - // that some tokens that would be considered identifiers may be considered keywords. When - // rewinding, we need to store and restore this as the mode may have changed. + // that some tokens that would be considered identifiers may be considered keywords. // // When adding more parser context flags, consider which is the more common case that the // flag will be in. This should be hte 'false' state for that flag. The reason for this is @@ -1091,6 +1089,41 @@ module ts { // Note: any errors at the end of the file that do not precede a regular node, should get // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; + var sourceFile = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, + fileExtensionIs(filename, ".d.ts") ? NodeFlags.DeclarationFile : 0); + + sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; + sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; + sourceFile.getLineStarts = getLineStarts; + sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; + + sourceFile.filename = normalizePath(filename); + sourceFile.text = sourceText; + + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.grammarDiagnostics = []; + sourceFile.semanticDiagnostics = []; + + processReferenceComments(); + + // Create and prime the scanner before parsing the source elements. + var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); + var token = nextToken(); + + sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); + Debug.assert(token === SyntaxKind.EndOfFileToken); + sourceFile.endOfFileToken = parseTokenNode(); + + sourceFile.externalModuleIndicator = getExternalModuleIndicator(); + + sourceFile.nodeCount = nodeCount; + sourceFile.identifierCount = identifierCount; + sourceFile.version = version; + sourceFile.isOpen = isOpen; + sourceFile.languageVersion = languageVersion; + sourceFile.identifiers = identifiers; + return sourceFile; function setContextFlag(val: Boolean, flag: ParserContextFlags) { if (val) { @@ -4338,7 +4371,7 @@ module ts { : parseStatement(); } - function processReferenceComments(): ReferenceComments { + function processReferenceComments(): void { var triviaScanner = createScanner(languageVersion, /*skipTrivia*/false, sourceText); var referencedFiles: FileReference[] = []; var amdDependencies: string[] = []; @@ -4389,11 +4422,9 @@ module ts { } } - return { - referencedFiles, - amdDependencies, - amdModuleName - }; + sourceFile.referencedFiles = referencedFiles; + sourceFile.amdDependencies = amdDependencies; + sourceFile.amdModuleName = amdModuleName; } function getExternalModuleIndicator() { @@ -4423,49 +4454,6 @@ module ts { Debug.assert(syntacticDiagnostics !== undefined); return syntacticDiagnostics; } - - var rootNodeFlags: NodeFlags = 0; - if (fileExtensionIs(filename, ".d.ts")) { - rootNodeFlags = NodeFlags.DeclarationFile; - } - - var sourceFile = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); - - sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; - sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; - sourceFile.getLineStarts = getLineStarts; - sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; - - sourceFile.filename = normalizePath(filename); - sourceFile.text = sourceText; - - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.grammarDiagnostics = []; - sourceFile.semanticDiagnostics = []; - - var referenceComments = processReferenceComments(); - sourceFile.referencedFiles = referenceComments.referencedFiles; - sourceFile.amdDependencies = referenceComments.amdDependencies; - sourceFile.amdModuleName = referenceComments.amdModuleName; - - // Create and prime the scanner before parsing the source elements. - var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); - nextToken(); - - sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); - Debug.assert(token === SyntaxKind.EndOfFileToken); - sourceFile.endOfFileToken = parseTokenNode(); - - sourceFile.externalModuleIndicator = getExternalModuleIndicator(); - - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.version = version; - sourceFile.isOpen = isOpen; - sourceFile.languageVersion = languageVersion; - sourceFile.identifiers = identifiers; - return sourceFile; } function isLeftHandSideExpression(expr: Expression): boolean { From 89cd1e28f2cf261a9b64b994a503d29920762c56 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 18:58:13 -0800 Subject: [PATCH 15/16] Remove unused type. --- src/compiler/parser.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dc99bdbeb89..588b1f53974 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -48,12 +48,6 @@ module ts { return node; } - interface ReferenceComments { - referencedFiles: FileReference[]; - amdDependencies: string[]; - amdModuleName: string; - } - export function getSourceFileOfNode(node: Node): SourceFile { while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; return node; From edc60ed80881d43767eeedbe3e58becca08db116 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 8 Dec 2014 23:46:30 -0800 Subject: [PATCH 16/16] Fix invariant issues. --- src/compiler/parser.ts | 4 ++++ src/harness/test262Runner.ts | 42 +++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 588b1f53974..bc91227f381 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -293,6 +293,7 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: return children(node.modifiers) || + child((node).asteriskToken) || child((node).name) || child((node).questionToken) || children((node).typeParameters) || @@ -345,6 +346,9 @@ module ts { return child((node).expression); case SyntaxKind.PrefixUnaryExpression: return child((node).operand); + case SyntaxKind.YieldExpression: + return child((node).asteriskToken) || + child((node).expression); case SyntaxKind.PostfixUnaryExpression: return child((node).operand); case SyntaxKind.BinaryExpression: diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 547cc48a617..a29c6ac8619 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -35,15 +35,55 @@ class Test262BaselineRunner extends RunnerBase { if (node.parent !== parent) { throw new Error("node.parent !== parent"); } + if (parent) { + // Make sure each child is contained within the parent. + if (node.pos < parent.pos) { + throw new Error("node.pos < parent.pos"); + } + if (node.end > parent.end) { + throw new Error("node.end > parent.end"); + } + } + ts.forEachChild(node, child => { Test262BaselineRunner.checkInvariants(child, node); }); + // Make sure each of the children is in order. + var currentPos = 0; + ts.forEachChild(node, + child => { + if (child.pos < currentPos) { + throw new Error("child.pos < currentPos"); + } + currentPos = child.end; + }, + (array: ts.NodeArray) => { + if (array.pos < node.pos) { + throw new Error("array.pos < node.pos"); + } + if (array.end > node.end) { + throw new Error("array.end > node.end"); + } + + if (array.pos < currentPos) { + throw new Error("array.pos < currentPos"); + } + for (var i = 0, n = array.length; i < n; i++) { + if (array[i].pos < currentPos) { + throw new Error("array[i].pos < currentPos"); + } + currentPos = array[i].end + } + + currentPos = array.end; + }); + var childNodesAndArrays: any[] = []; ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) }); for (var childName in node) { - if (childName === "parent" || childName === "nextContainer" || childName === "modifiers") { + if (childName === "parent" || childName === "nextContainer" || childName === "modifiers" || childName === "externalModuleIndicator") { continue; } var child = (node)[childName];