From 4a346045ce89137c76cda3436abba5603abdb686 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 15:38:26 -0700 Subject: [PATCH 01/51] Add specialized semantic diagnostics for JavaScript files. --- .../diagnosticInformationMap.generated.ts | 15 ++ src/compiler/diagnosticMessages.json | 61 +++++++ src/services/services.ts | 154 +++++++++++++++++- 3 files changed, 229 insertions(+), 1 deletion(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 622b28d5f18..739c2ea460f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -486,6 +486,21 @@ module ts { Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, + import_can_only_be_used_in_TypeScript: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in TypeScript." }, + export_can_only_be_used_in_TypeScript: { code: 8003, category: DiagnosticCategory.Error, key: "'export=' can only be used in TypeScript." }, + type_parameter_declarations_can_only_be_used_in_TypeScript: { code: 8004, category: DiagnosticCategory.Error, key: "'type parameter declarations' can only be used in TypeScript." }, + implements_clauses_can_only_be_used_in_TypeScript: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in TypeScript." }, + interface_declarations_can_only_be_used_in_TypeScript: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in TypeScript." }, + module_declarations_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in TypeScript." }, + type_aliases_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, + _0_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, + types_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, + type_arguments_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, + parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, + can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, + property_declarations_can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, + enum_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, + type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 410cce54d17..552f1b04606 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1938,6 +1938,67 @@ "category": "Error", "code": 8001 }, + "'import ... =' can only be used in TypeScript.": { + "category": "Error", + "code": 8002 + }, + "'export=' can only be used in TypeScript.": { + "category": "Error", + "code": 8003 + }, + "'type parameter declarations' can only be used in TypeScript.": { + "category": "Error", + "code": 8004 + }, + "'implements clauses' can only be used in TypeScript.": { + "category": "Error", + "code": 8005 + }, + "'interface declarations' can only be used in TypeScript.": { + "category": "Error", + "code": 8006 + }, + "'module declarations' can only be used in TypeScript.": { + "category": "Error", + "code": 8007 + }, + "'type aliases' can only be used in TypeScript.": { + "category": "Error", + "code": 8007 + }, + "'{0}' can only be used in TypeScript.": { + "category": "Error", + "code": 8008 + }, + "'types' can only be used in TypeScript.": { + "category": "Error", + "code": 8009 + }, + "'type arguments' can only be used in TypeScript.": { + "category": "Error", + "code": 8010 + }, + "'parameter modifiers' can only be used in TypeScript.": { + "category": "Error", + "code": 8011 + }, + "'?' can only be used in TypeScript.": { + "category": "Error", + "code": 8012 + }, + "'property declarations' can only be used in TypeScript.": { + "category": "Error", + "code": 8013 + }, + "'enum declarations' can only be used in TypeScript.": { + "category": "Error", + "code": 8014 + }, + "'type assertion expressions' can only be used in TypeScript.": { + "category": "Error", + "code": 8014 + }, + "'yield' expressions are not currently supported.": { "category": "Error", "code": 9000 diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d4..88a56a850cb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2370,15 +2370,25 @@ module ts { return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } + function isJavaScript(fileName: string) { + return fileExtensionIs(fileName, ".tsjs"); + } + /** * getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors * If '-d' enabled, report both semantic and emitter errors */ - function getSemanticDiagnostics(fileName: string) { + function getSemanticDiagnostics(fileName: string): Diagnostic[] { synchronizeHostData(); let targetSourceFile = getValidSourceFile(fileName); + // For JavaScript files, we don't want to report the normal typescript semantic errors. + // Instead, we just report errors for using TypeScript + if (isJavaScript(fileName)) { + return getJavaScriptSemanticDiagnostics(targetSourceFile); + } + // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. // Therefore only get diagnostics for given file. @@ -2392,6 +2402,148 @@ module ts { return semanticDiagnostics.concat(declarationDiagnostics); } + function getJavaScriptSemanticDiagnostics(sourceFile: SourceFile): Diagnostic[] { + let diagnostics: Diagnostic[] = []; + walk(sourceFile); + + return diagnostics; + + function walk(node: Node) { + if (!node) { + return; + } + + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.ExportAssignment: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.TypeParameter: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_parameter_declarations_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.ClassDeclaration: + let classDeclaration = node; + if (checkModifiers(classDeclaration.modifiers)) { + return; + } + break; + case SyntaxKind.HeritageClause: + let heritageClause = node; + if (heritageClause.token === SyntaxKind.ImplementsKeyword) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_TypeScript)); + return; + } + break; + case SyntaxKind.InterfaceDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.ModuleDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.TypeAliasDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionDeclaration: + let functionDeclaration = node; + if (checkModifiers(functionDeclaration.modifiers) || + checkTypeAnnotation(functionDeclaration.type)) { + return; + } + break; + case SyntaxKind.VariableStatement: + let variableStatement = node; + if (checkModifiers(variableStatement.modifiers)) { + return; + } + break; + case SyntaxKind.VariableDeclaration: + let variableDeclaration = node; + if (checkTypeAnnotation(variableDeclaration.type)) { + return; + } + break; + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + let expression = node; + if (expression.typeArguments && expression.typeArguments.length > 0) { + diagnostics.push(createFileDiagnostic(sourceFile, expression.typeArguments.pos, expression.typeArguments.end, + Diagnostics.type_arguments_can_only_be_used_in_TypeScript)); + return; + } + break; + case SyntaxKind.Parameter: + let parameter = node; + if (parameter.modifiers) { + diagnostics.push(createFileDiagnostic(sourceFile, parameter.modifiers.pos, parameter.modifiers.end, + Diagnostics.parameter_modifiers_can_only_be_used_in_TypeScript)); + return; + } + if (parameter.questionToken) { + diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics.can_only_be_used_in_TypeScript)); + return; + } + if (parameter.type) { + diagnostics.push(createDiagnosticForNode(parameter.type, Diagnostics.types_can_only_be_used_in_TypeScript)); + return; + } + break; + case SyntaxKind.PropertyDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.property_declarations_can_only_be_used_in_TypeScript)); + return + case SyntaxKind.EnumDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_TypeScript)); + return; + case SyntaxKind.TypeAssertionExpression: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); + return; + } + + forEachChild(node, walk); + } + + function checkTypeAnnotation(type: TypeNode): boolean { + if (type) { + diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_TypeScript)); + return true; + } + + return false; + } + + function checkModifiers(modifiers: ModifiersArray): boolean { + if (modifiers) { + for (let modifier of modifiers) { + switch (modifier.kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.DeclareKeyword: + diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_TypeScript, tokenToString(modifier.kind))); + return true; + + // These are all legal modifiers. + case SyntaxKind.StaticKeyword: + case SyntaxKind.ExportKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.DefaultKeyword: + } + } + } + + return false; + } + } + function getCompilerOptionsDiagnostics() { synchronizeHostData(); return program.getGlobalDiagnostics(); From e650e8a6d408b0d9ad3e6ec98dbd78831c8ba4b6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 16:27:56 -0700 Subject: [PATCH 02/51] Add tests for javascript semantic dianostics. --- src/harness/fourslash.ts | 17 ++++++++++- src/services/services.ts | 22 ++++++++++---- src/services/shims.ts | 29 +++++++++++-------- tests/cases/fourslash/fourslash.ts | 4 +++ .../getJavaScriptSemanticDiagnostics1.ts | 15 ++++++++++ .../getJavaScriptSemanticDiagnostics2.ts | 15 ++++++++++ .../getJavaScriptSemanticDiagnostics3.ts | 15 ++++++++++ 7 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 95a320ac052..44927a7a49a 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -14,6 +14,7 @@ // /// +/// /// /// /// @@ -126,12 +127,13 @@ module FourSlash { outDir: 'outDir', sourceMap: 'sourceMap', sourceRoot: 'sourceRoot', + allowNonTsExtensions: 'allowNonTsExtensions', resolveReference: 'ResolveReference', // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file }; // List of allowed metadata names var fileMetadataNames = [testOptMetadataNames.fileName, testOptMetadataNames.emitThisFile, testOptMetadataNames.resolveReference]; - var globalMetadataNames = [testOptMetadataNames.baselineFile, testOptMetadataNames.declaration, + var globalMetadataNames = [testOptMetadataNames.allowNonTsExtensions, testOptMetadataNames.baselineFile, testOptMetadataNames.declaration, testOptMetadataNames.mapRoot, testOptMetadataNames.module, testOptMetadataNames.out, testOptMetadataNames.outDir, testOptMetadataNames.sourceMap, testOptMetadataNames.sourceRoot] @@ -141,6 +143,9 @@ module FourSlash { for (var prop in globalOptions) { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { + case testOptMetadataNames.allowNonTsExtensions: + settings.allowNonTsExtensions = true; + break; case testOptMetadataNames.declaration: settings.declaration = true; break; @@ -788,6 +793,16 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } + public getSemanticDiagnostics(expected: string) { + var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); + var realized = ts.realizeDiagnostics(diagnostics, "\r\n"); + var actual = JSON.stringify(realized, null, " "); + if (actual !== expected) { + ts.sys.writeFile("c:\\temp\\out.txt", actual); + } + assert.equal(actual, expected); + } + public verifyQuickInfoString(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { diff --git a/src/services/services.ts b/src/services/services.ts index 88a56a850cb..8715a171c8b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2420,12 +2420,10 @@ module ts { case SyntaxKind.ExportAssignment: diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_TypeScript)); return; - case SyntaxKind.TypeParameter: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_parameter_declarations_can_only_be_used_in_TypeScript)); - return; case SyntaxKind.ClassDeclaration: let classDeclaration = node; - if (checkModifiers(classDeclaration.modifiers)) { + if (checkModifiers(classDeclaration.modifiers) || + checkTypeParameters(classDeclaration.typeParameters)) { return; } break; @@ -2456,6 +2454,7 @@ module ts { case SyntaxKind.FunctionDeclaration: let functionDeclaration = node; if (checkModifiers(functionDeclaration.modifiers) || + checkTypeParameters(functionDeclaration.typeParameters) || checkTypeAnnotation(functionDeclaration.type)) { return; } @@ -2476,7 +2475,8 @@ module ts { case SyntaxKind.NewExpression: let expression = node; if (expression.typeArguments && expression.typeArguments.length > 0) { - diagnostics.push(createFileDiagnostic(sourceFile, expression.typeArguments.pos, expression.typeArguments.end, + let start = expression.typeArguments.pos; + diagnostics.push(createFileDiagnostic(sourceFile, start, expression.typeArguments.end - start, Diagnostics.type_arguments_can_only_be_used_in_TypeScript)); return; } @@ -2484,7 +2484,8 @@ module ts { case SyntaxKind.Parameter: let parameter = node; if (parameter.modifiers) { - diagnostics.push(createFileDiagnostic(sourceFile, parameter.modifiers.pos, parameter.modifiers.end, + let start = parameter.modifiers.pos; + diagnostics.push(createFileDiagnostic(sourceFile, start, parameter.modifiers.end - start, Diagnostics.parameter_modifiers_can_only_be_used_in_TypeScript)); return; } @@ -2511,6 +2512,15 @@ module ts { forEachChild(node, walk); } + function checkTypeParameters(typeParameters: NodeArray): boolean { + if (typeParameters) { + let start = typeParameters.pos; + diagnostics.push(createFileDiagnostic(sourceFile, start, typeParameters.end - start, Diagnostics.type_parameter_declarations_can_only_be_used_in_TypeScript)); + return true; + } + return false; + } + function checkTypeAnnotation(type: TypeNode): boolean { if (type) { diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_TypeScript)); diff --git a/src/services/shims.ts b/src/services/shims.ts index fc47ff95280..f2082ee39cb 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -325,6 +325,22 @@ module ts { } } + /* @internal */ + export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; } []{ + return diagnostics.map(d => realizeDiagnostic(d, newLine)); + } + + function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } { + return { + message: flattenDiagnosticMessageText(diagnostic.messageText, newLine), + start: diagnostic.start, + length: diagnostic.length, + /// TODO: no need for the tolowerCase call + category: DiagnosticCategory[diagnostic.category].toLowerCase(), + code: diagnostic.code + }; + } + class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim { private logger: Logger; @@ -385,18 +401,7 @@ module ts { private realizeDiagnostics(diagnostics: Diagnostic[]): { message: string; start: number; length: number; category: string; }[]{ var newLine = this.getNewLine(); - return diagnostics.map(d => this.realizeDiagnostic(d, newLine)); - } - - private realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } { - return { - message: flattenDiagnosticMessageText(diagnostic.messageText, newLine), - start: diagnostic.start, - length: diagnostic.length, - /// TODO: no need for the tolowerCase call - category: DiagnosticCategory[diagnostic.category].toLowerCase(), - code: diagnostic.code - }; + return ts.realizeDiagnostics(diagnostics, newLine); } public getSyntacticClassifications(fileName: string, start: number, length: number): string { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 087c43786f0..8ade18fc200 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -439,6 +439,10 @@ module FourSlashInterface { displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); } + + public getSemanticDiagnostics(expected: string) { + FourSlash.currentTestState.getSemanticDiagnostics(expected); + } } export class edit { diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts new file mode 100644 index 00000000000..e73b487347a --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// import a = b; + +verify.getSemanticDiagnostics(`[ + { + "message": "'import ... =' can only be used in TypeScript.", + "start": 0, + "length": 13, + "category": "error", + "code": 8002 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts new file mode 100644 index 00000000000..e239577e5e4 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// export = b; + +verify.getSemanticDiagnostics(`[ + { + "message": "'export=' can only be used in TypeScript.", + "start": 0, + "length": 11, + "category": "error", + "code": 8003 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts new file mode 100644 index 00000000000..d74e97b36cc --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// class C; + +verify.getSemanticDiagnostics(`[ + { + "message": "'type parameter declarations' can only be used in TypeScript.", + "start": 8, + "length": 1, + "category": "error", + "code": 8004 + } +]`); \ No newline at end of file From 1eca182cebf7d54635ee1318358352970928cd21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 16:32:19 -0700 Subject: [PATCH 03/51] Add additional tests. --- .../getJavaScriptSemanticDiagnostics3.ts | 2 +- .../getJavaScriptSemanticDiagnostics4.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics5.ts | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts index d74e97b36cc..c27308cd27c 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts @@ -2,7 +2,7 @@ // @allowNonTsExtensions: true // @Filename: a.tsjs -//// class C; +//// class C { } verify.getSemanticDiagnostics(`[ { diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts new file mode 100644 index 00000000000..27635cb34b7 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// public class C { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'public' can only be used in TypeScript.", + "start": 0, + "length": 6, + "category": "error", + "code": 8008 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts new file mode 100644 index 00000000000..9fd183b9e69 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// class C implements D { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'implements clauses' can only be used in TypeScript.", + "start": 8, + "length": 12, + "category": "error", + "code": 8005 + } +]`); \ No newline at end of file From c69846555c1cc9f5fda5cfc1bbc8af10da51f888 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 16:56:19 -0700 Subject: [PATCH 04/51] Add additional tests. --- .../diagnosticInformationMap.generated.ts | 18 +++++++++--------- src/compiler/diagnosticMessages.json | 18 +++++++++--------- src/harness/fourslash.ts | 3 --- src/services/services.ts | 6 ++++-- .../getJavaScriptSemanticDiagnostics10.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics11.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics12.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics13.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics14.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics15.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics16.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics17.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics18.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics19.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics20.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics4.ts | 2 +- .../getJavaScriptSemanticDiagnostics6.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics7.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics8.ts | 15 +++++++++++++++ .../getJavaScriptSemanticDiagnostics9.ts | 15 +++++++++++++++ 20 files changed, 248 insertions(+), 24 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 739c2ea460f..9fc4248c519 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -492,15 +492,15 @@ module ts { implements_clauses_can_only_be_used_in_TypeScript: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in TypeScript." }, interface_declarations_can_only_be_used_in_TypeScript: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in TypeScript." }, module_declarations_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in TypeScript." }, - type_aliases_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, - _0_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, - types_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, - type_arguments_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, - parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, - can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, - property_declarations_can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, - enum_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, - type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, + type_aliases_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, + _0_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, + types_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, + type_arguments_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, + parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, + can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, + property_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, + enum_declarations_can_only_be_used_in_TypeScript: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, + type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 552f1b04606..379a95bc405 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1964,39 +1964,39 @@ }, "'type aliases' can only be used in TypeScript.": { "category": "Error", - "code": 8007 + "code": 8008 }, "'{0}' can only be used in TypeScript.": { "category": "Error", - "code": 8008 + "code": 8009 }, "'types' can only be used in TypeScript.": { "category": "Error", - "code": 8009 + "code": 8010 }, "'type arguments' can only be used in TypeScript.": { "category": "Error", - "code": 8010 + "code": 8011 }, "'parameter modifiers' can only be used in TypeScript.": { "category": "Error", - "code": 8011 + "code": 8012 }, "'?' can only be used in TypeScript.": { "category": "Error", - "code": 8012 + "code": 8013 }, "'property declarations' can only be used in TypeScript.": { "category": "Error", - "code": 8013 + "code": 8014 }, "'enum declarations' can only be used in TypeScript.": { "category": "Error", - "code": 8014 + "code": 8015 }, "'type assertion expressions' can only be used in TypeScript.": { "category": "Error", - "code": 8014 + "code": 8016 }, "'yield' expressions are not currently supported.": { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 44927a7a49a..9d55fcc58b9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -797,9 +797,6 @@ module FourSlash { var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); var realized = ts.realizeDiagnostics(diagnostics, "\r\n"); var actual = JSON.stringify(realized, null, " "); - if (actual !== expected) { - ts.sys.writeFile("c:\\temp\\out.txt", actual); - } assert.equal(actual, expected); } diff --git a/src/services/services.ts b/src/services/services.ts index 8715a171c8b..a64358dd9fc 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2384,7 +2384,8 @@ module ts { let targetSourceFile = getValidSourceFile(fileName); // For JavaScript files, we don't want to report the normal typescript semantic errors. - // Instead, we just report errors for using TypeScript + // Instead, we just report errors for using TypeScript-only constructs from within a + // JavaScript file. if (isJavaScript(fileName)) { return getJavaScriptSemanticDiagnostics(targetSourceFile); } @@ -2505,7 +2506,8 @@ module ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_TypeScript)); return; case SyntaxKind.TypeAssertionExpression: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); + let typeAssertionExpression = node; + diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); return; } diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts new file mode 100644 index 00000000000..d5bf9e142d7 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F() { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'type parameter declarations' can only be used in TypeScript.", + "start": 11, + "length": 1, + "category": "error", + "code": 8004 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts new file mode 100644 index 00000000000..060dfa4c01a --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(): number { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 14, + "length": 6, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts new file mode 100644 index 00000000000..4a73b44725d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// declare var v; + +verify.getSemanticDiagnostics(`[ + { + "message": "'declare' can only be used in TypeScript.", + "start": 0, + "length": 7, + "category": "error", + "code": 8009 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts new file mode 100644 index 00000000000..2717e23aba9 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// var v: () => number; + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 7, + "length": 12, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts new file mode 100644 index 00000000000..c67659379fc --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// Foo(); + +verify.getSemanticDiagnostics(`[ + { + "message": "'type arguments' can only be used in TypeScript.", + "start": 4, + "length": 6, + "category": "error", + "code": 8011 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts new file mode 100644 index 00000000000..756e17d9a34 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(public p) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'parameter modifiers' can only be used in TypeScript.", + "start": 11, + "length": 6, + "category": "error", + "code": 8012 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts new file mode 100644 index 00000000000..1ce8f3a767d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(p?) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'?' can only be used in TypeScript.", + "start": 12, + "length": 1, + "category": "error", + "code": 8013 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts new file mode 100644 index 00000000000..fad657f9b50 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// function F(a: number) { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'types' can only be used in TypeScript.", + "start": 14, + "length": 6, + "category": "error", + "code": 8010 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts new file mode 100644 index 00000000000..6c2578d6e85 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// class C { v } + +verify.getSemanticDiagnostics(`[ + { + "message": "'property declarations' can only be used in TypeScript.", + "start": 10, + "length": 1, + "category": "error", + "code": 8014 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts new file mode 100644 index 00000000000..6dc83c38327 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// enum E { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'enum declarations' can only be used in TypeScript.", + "start": 5, + "length": 1, + "category": "error", + "code": 8015 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts new file mode 100644 index 00000000000..cf5f16b827a --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// var v = undefined; + +verify.getSemanticDiagnostics(`[ + { + "message": "'type assertion expressions' can only be used in TypeScript.", + "start": 9, + "length": 6, + "category": "error", + "code": 8016 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts index 27635cb34b7..8505798e230 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts @@ -10,6 +10,6 @@ verify.getSemanticDiagnostics(`[ "start": 0, "length": 6, "category": "error", - "code": 8008 + "code": 8009 } ]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts new file mode 100644 index 00000000000..09cd23ffbf6 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// interface I { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'interface declarations' can only be used in TypeScript.", + "start": 10, + "length": 1, + "category": "error", + "code": 8006 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts new file mode 100644 index 00000000000..77c0b1f4e0d --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// module M { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'module declarations' can only be used in TypeScript.", + "start": 7, + "length": 1, + "category": "error", + "code": 8007 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts new file mode 100644 index 00000000000..c0a27621539 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// type a = b; + +verify.getSemanticDiagnostics(`[ + { + "message": "'type aliases' can only be used in TypeScript.", + "start": 0, + "length": 11, + "category": "error", + "code": 8008 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts new file mode 100644 index 00000000000..6b7eed188fe --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.tsjs +//// public function F() { } + +verify.getSemanticDiagnostics(`[ + { + "message": "'public' can only be used in TypeScript.", + "start": 0, + "length": 6, + "category": "error", + "code": 8009 + } +]`); \ No newline at end of file From e14b745df8ba58764067e3d9822c6452e6d63588 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Mar 2015 17:56:04 -0700 Subject: [PATCH 05/51] Clean up getCompletions code. --- src/services/services.ts | 44 ++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index a64358dd9fc..3fea33a40dd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2614,7 +2614,7 @@ module ts { }; } - function getCompletionsAtPosition(fileName: string, position: number) { + function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { synchronizeHostData(); let syntacticStart = new Date().getTime(); @@ -2688,6 +2688,29 @@ module ts { let isNewIdentifierLocation: boolean; if (isRightOfDot) { + if (!tryGetMemberCompletionEntries()) { + return undefined; + } + } + else { + if (!tryGetGlobalCompletionEntries()) { + return undefined; + } + } + + // Add keywords if this is not a member completion list + if (!isMemberCompletion) { + addRange(activeCompletionSession.entries, keywordCompletions); + } + log("getCompletionsAtPosition: Semantic work: " + (new Date().getTime() - semanticStart)); + + return { + isMemberCompletion, + isNewIdentifierLocation, + entries: activeCompletionSession.entries + }; + + function tryGetMemberCompletionEntries(): boolean { // Right of dot member completion list let symbols: Symbol[] = []; isMemberCompletion = true; @@ -2722,8 +2745,10 @@ module ts { } getCompletionEntriesFromSymbols(symbols, activeCompletionSession); + return true; } - else { + + function tryGetGlobalCompletionEntries(): boolean { let containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(previousToken); if (containingObjectLiteral) { // Object literal expression, look up possible property names from contextual type @@ -2732,7 +2757,7 @@ module ts { let contextualType = typeInfoResolver.getContextualType(containingObjectLiteral); if (!contextualType) { - return undefined; + return false; } let contextualTypeMembers = typeInfoResolver.getPropertiesOfType(contextualType); @@ -2766,20 +2791,9 @@ module ts { getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } - } - // Add keywords if this is not a member completion list - if (!isMemberCompletion) { - Array.prototype.push.apply(activeCompletionSession.entries, keywordCompletions); + return true; } - log("getCompletionsAtPosition: Semantic work: " + (new Date().getTime() - semanticStart)); - - return { - isMemberCompletion, - isNewIdentifierLocation, - isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation - entries: activeCompletionSession.entries - }; function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { let start = new Date().getTime(); From c030b83c5dd6cfd0273817ed32349970d9fa4bbe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Mar 2015 17:59:24 -0700 Subject: [PATCH 06/51] Further simplification --- src/services/services.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 3fea33a40dd..4c5fb5ce679 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2654,10 +2654,11 @@ module ts { return undefined; } - // Find the node where completion is requested on, in the case of a completion after a dot, it is the member access expression - // other wise, it is a request for all visible symbols in the scope, and the node is the current location - let node: Node; - let isRightOfDot: boolean; + // Find the node where completion is requested on, in the case of a completion after + // a dot, it is the member access expression other wise, it is a request for all + // visible symbols in the scope, and the node is the current location. + let node = currentToken; + let isRightOfDot = false; if (previousToken && previousToken.kind === SyntaxKind.DotToken && previousToken.parent.kind === SyntaxKind.PropertyAccessExpression) { node = (previousToken.parent).expression; isRightOfDot = true; @@ -2666,10 +2667,6 @@ module ts { node = (previousToken.parent).left; isRightOfDot = true; } - else { - node = currentToken; - isRightOfDot = false; - } // Clear the current activeCompletionSession for this session activeCompletionSession = { From 1b06677decb599fc254a037c45714a7a13cf58bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 23 Mar 2015 14:14:19 -0700 Subject: [PATCH 07/51] Treat .js files as javascript in the LS. --- src/compiler/types.ts | 10 +-- src/services/services.ts | 87 ++++++++++++++++--- .../baselines/reference/APISample_compile.js | 10 +-- .../reference/APISample_compile.types | 10 +-- tests/baselines/reference/APISample_linter.js | 10 +-- .../reference/APISample_linter.types | 10 +-- .../reference/APISample_transform.js | 10 +-- .../reference/APISample_transform.types | 10 +-- .../baselines/reference/APISample_watcher.js | 10 +-- .../reference/APISample_watcher.types | 10 +-- .../getJavaScriptSemanticDiagnostics1.ts | 2 +- .../getJavaScriptSemanticDiagnostics10.ts | 2 +- .../getJavaScriptSemanticDiagnostics11.ts | 2 +- .../getJavaScriptSemanticDiagnostics12.ts | 2 +- .../getJavaScriptSemanticDiagnostics13.ts | 2 +- .../getJavaScriptSemanticDiagnostics14.ts | 2 +- .../getJavaScriptSemanticDiagnostics15.ts | 2 +- .../getJavaScriptSemanticDiagnostics16.ts | 2 +- .../getJavaScriptSemanticDiagnostics17.ts | 2 +- .../getJavaScriptSemanticDiagnostics18.ts | 2 +- .../getJavaScriptSemanticDiagnostics19.ts | 2 +- .../getJavaScriptSemanticDiagnostics2.ts | 2 +- .../getJavaScriptSemanticDiagnostics20.ts | 2 +- .../getJavaScriptSemanticDiagnostics3.ts | 2 +- .../getJavaScriptSemanticDiagnostics4.ts | 2 +- .../getJavaScriptSemanticDiagnostics5.ts | 2 +- .../getJavaScriptSemanticDiagnostics6.ts | 2 +- .../getJavaScriptSemanticDiagnostics7.ts | 2 +- .../getJavaScriptSemanticDiagnostics8.ts | 2 +- .../getJavaScriptSemanticDiagnostics9.ts | 2 +- 30 files changed, 138 insertions(+), 79 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 87d219c2e84..a60c0666419 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1005,14 +1005,14 @@ module ts { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; diff --git a/src/services/services.ts b/src/services/services.ts index 4c5fb5ce679..188a1bfcb03 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2371,7 +2371,7 @@ module ts { } function isJavaScript(fileName: string) { - return fileExtensionIs(fileName, ".tsjs"); + return fileExtensionIs(fileName, ".js"); } /** @@ -2562,7 +2562,7 @@ module ts { } /// Completion - function getValidCompletionEntryDisplayName(symbol: Symbol, target: ScriptTarget): string { + function getValidCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget): string { let displayName = symbol.getName(); if (displayName && displayName.length > 0) { let firstCharCode = displayName.charCodeAt(0); @@ -2573,7 +2573,8 @@ module ts { return undefined; } - if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && + if (displayName && displayName.length >= 2 && + firstCharCode === displayName.charCodeAt(displayName.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. @@ -2585,7 +2586,6 @@ module ts { isValid = isIdentifierPart(displayName.charCodeAt(i), target); } - if (isValid) { return unescapeIdentifier(displayName); } @@ -2594,11 +2594,29 @@ module ts { return undefined; } + function getValidCompletionEntryDisplayName(displayName: string, target: ScriptTarget): string { + let firstCharCode = displayName.charCodeAt(0); + if (displayName && displayName.length >= 2 && + firstCharCode === displayName.charCodeAt(displayName.length - 1) && + (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an + // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. + displayName = displayName.substring(1, displayName.length - 1); + } + + let isValid = isIdentifierStart(displayName.charCodeAt(0), target); + for (let i = 1, n = displayName.length; isValid && i < n; i++) { + isValid = isIdentifierPart(displayName.charCodeAt(i), target); + } + + return isValid ? unescapeIdentifier(displayName) : undefined; + } + function createCompletionEntry(symbol: Symbol, typeChecker: TypeChecker, location: Node): CompletionEntry { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) - let displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target); + let displayName = getValidCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target); if (!displayName) { return undefined; } @@ -2685,11 +2703,22 @@ module ts { let isNewIdentifierLocation: boolean; if (isRightOfDot) { - if (!tryGetMemberCompletionEntries()) { - return undefined; + if (isJavaScript(fileName)) { + // If this is JavaScript, then just present a simple identifier list. + if (!tryGetJavaScriptMemberCompletionEntries()) { + return undefined; + } + } + else { + if (!tryGetTypeScriptMemberCompletionEntries()) { + return undefined; + } } } else { + // For JavaScript or TypeScript, if we're not after a dot, then just try to get the + // global symbols in scope. These results should be valid for either language as + // the set of symbols that can be referenced from this location. if (!tryGetGlobalCompletionEntries()) { return undefined; } @@ -2707,7 +2736,31 @@ module ts { entries: activeCompletionSession.entries }; - function tryGetMemberCompletionEntries(): boolean { + function tryGetJavaScriptMemberCompletionEntries(): boolean { + let allIdentifiers: Map = {}; + for (let sourceFile of program.getSourceFiles()) { + let nameTable = getNameTable(sourceFile); + for (let name in nameTable) { + allIdentifiers[name] = name; + } + } + + var target = program.getCompilerOptions().target; + for (let name in allIdentifiers) { + let displayName = getValidCompletionEntryDisplayName(name, target); + if (displayName) { + activeCompletionSession.entries.push({ + name: displayName, + kind: ScriptElementKind.unknown, + kindModifiers: "" + }); + } + } + + return true; + } + + function tryGetTypeScriptMemberCompletionEntries(): boolean { // Right of dot member completion list let symbols: Symbol[] = []; isMemberCompletion = true; @@ -2741,7 +2794,7 @@ module ts { }); } - getCompletionEntriesFromSymbols(symbols, activeCompletionSession); + getCompletionEntriesFromSymbols(symbols); return true; } @@ -2761,7 +2814,7 @@ module ts { if (contextualTypeMembers && contextualTypeMembers.length > 0) { // Add filtered items to the completion list let filteredMembers = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); - getCompletionEntriesFromSymbols(filteredMembers, activeCompletionSession); + getCompletionEntriesFromSymbols(filteredMembers); } } else if (getAncestor(previousToken, SyntaxKind.ImportClause)) { @@ -2774,7 +2827,7 @@ module ts { Debug.assert(importDeclaration !== undefined); let exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); let filteredExports = filterModuleExports(exports, importDeclaration); - getCompletionEntriesFromSymbols(filteredExports, activeCompletionSession); + getCompletionEntriesFromSymbols(filteredExports); } } else { @@ -2786,13 +2839,14 @@ module ts { let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; let symbols = typeInfoResolver.getSymbolsInScope(node, symbolMeanings); - getCompletionEntriesFromSymbols(symbols, activeCompletionSession); + getCompletionEntriesFromSymbols(symbols); } return true; } - function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { + function getCompletionEntriesFromSymbols(symbols: Symbol[]): void { + let session = activeCompletionSession; let start = new Date().getTime(); forEach(symbols, symbol => { let entry = createCompletionEntry(symbol, session.typeChecker, location); @@ -5073,8 +5127,13 @@ module ts { function getEmitOutput(fileName: string): EmitOutput { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + // If the option is set to not emit on errors, and there are any errors, then we don't + // want to proceed. + if (program.getCompilerOptions().noEmitOnError && getPreEmitDiagnostics(program).length > 0) { + return { outputFiles: [], emitSkipped: true }; + } + let sourceFile = getValidSourceFile(fileName); let outputFiles: OutputFile[] = []; function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 575c2bdaf36..4ea2a7a7bed 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -801,14 +801,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 336d70aa1a1..d0ba1e8457b 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2440,14 +2440,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index e7145e24070..6e6665e3d40 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -832,14 +832,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index a40848b9e4c..839e41a62f4 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2586,14 +2586,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index da8fe979d17..ed852980b0c 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -833,14 +833,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index b694678d4cb..589af2369f7 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2536,14 +2536,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index f380994eba8..c0f6f52e774 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -870,14 +870,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 06329de5c96..78261fffa91 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2709,14 +2709,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts index e73b487347a..5fbe669de30 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// import a = b; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts index d5bf9e142d7..ecefb25d218 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// function F() { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts index 060dfa4c01a..da468d59f3b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// function F(): number { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts index 4a73b44725d..89e459d2a5b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// declare var v; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts index 2717e23aba9..c3c0fc9ef7b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// var v: () => number; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts index c67659379fc..5e7c2010480 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// Foo(); verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts index 756e17d9a34..2c7d87a74e2 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// function F(public p) { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts index 1ce8f3a767d..3bc3030e2b1 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// function F(p?) { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts index fad657f9b50..39b67b13ea8 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// function F(a: number) { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts index 6c2578d6e85..96dc2bce892 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// class C { v } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts index 6dc83c38327..efbe1694419 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// enum E { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts index e239577e5e4..abf9f693b0c 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// export = b; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts index cf5f16b827a..d0f6cef468e 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// var v = undefined; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts index c27308cd27c..4e424281dfd 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// class C { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts index 8505798e230..80e8873b01a 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// public class C { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts index 9fd183b9e69..411bef8a82f 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// class C implements D { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts index 09cd23ffbf6..f86d26ba723 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// interface I { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts index 77c0b1f4e0d..ccd9450f49b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// module M { } verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts index c0a27621539..11105a44197 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// type a = b; verify.getSemanticDiagnostics(`[ diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts index 6b7eed188fe..81016fd8ba7 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts @@ -1,7 +1,7 @@ /// // @allowNonTsExtensions: true -// @Filename: a.tsjs +// @Filename: a.js //// public function F() { } verify.getSemanticDiagnostics(`[ From d3e9ed1de8e56cbf8757d4b16fd3880201246075 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 24 Mar 2015 14:11:03 -0700 Subject: [PATCH 08/51] back to tsjs --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index cc1e5391444..0844e4b40d8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2368,7 +2368,7 @@ module ts { } function isJavaScript(fileName: string) { - return fileExtensionIs(fileName, ".js"); + return fileExtensionIs(fileName, ".tsjs"); } /** From 273c3a92d008afbc467aa207400ee79129b4a769 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 24 Mar 2015 14:54:27 -0700 Subject: [PATCH 09/51] Back to .js --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5eb3c21e67f..6372fa3440b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2374,7 +2374,7 @@ module ts { } function isJavaScript(fileName: string) { - return fileExtensionIs(fileName, ".tsjs"); + return fileExtensionIs(fileName, ".js"); } /** From 2de0a974bb2cc25becc4b98ce29fad6272d24be7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 24 Mar 2015 18:24:42 -0700 Subject: [PATCH 10/51] Added tests. --- ...ionListForTransitivelyExportedMembers01.ts | 39 ++++++++++++++++++ ...ionListForTransitivelyExportedMembers02.ts | 39 ++++++++++++++++++ ...ionListForTransitivelyExportedMembers03.ts | 40 +++++++++++++++++++ ...ionListForTransitivelyExportedMembers04.ts | 37 +++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 tests/cases/fourslash/completionListForTransitivelyExportedMembers01.ts create mode 100644 tests/cases/fourslash/completionListForTransitivelyExportedMembers02.ts create mode 100644 tests/cases/fourslash/completionListForTransitivelyExportedMembers03.ts create mode 100644 tests/cases/fourslash/completionListForTransitivelyExportedMembers04.ts diff --git a/tests/cases/fourslash/completionListForTransitivelyExportedMembers01.ts b/tests/cases/fourslash/completionListForTransitivelyExportedMembers01.ts new file mode 100644 index 00000000000..017b04592c1 --- /dev/null +++ b/tests/cases/fourslash/completionListForTransitivelyExportedMembers01.ts @@ -0,0 +1,39 @@ +/// + +// @Filename: A.ts +////export interface I1 { one: number } +////export interface I2 { two: string } +////export type I1_OR_I2 = I1 | I2; +//// +////export class C1 { +//// one: string; +////} +//// +////export module Inner { +//// export interface I3 { +//// three: boolean +//// } +//// +//// export var varVar = 100; +//// export let letVar = 200; +//// export const constVar = 300; +////} + +// @Filename: B.ts +////export var bVar = "bee!"; + +// @Filename: C.ts +////export var cVar = "see!"; +////export * from "A"; +////export * from "B" + +// @Filename: D.ts +////import * as c from "C"; +////var x = c./**/ + +goTo.marker(); +verify.completionListContains("C1"); +verify.completionListContains("Inner"); +verify.completionListContains("bVar"); +verify.completionListContains("cVar"); +verify.not.completionListContains("__export"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListForTransitivelyExportedMembers02.ts b/tests/cases/fourslash/completionListForTransitivelyExportedMembers02.ts new file mode 100644 index 00000000000..868859746b4 --- /dev/null +++ b/tests/cases/fourslash/completionListForTransitivelyExportedMembers02.ts @@ -0,0 +1,39 @@ +/// + + +// @Filename: A.ts +////export interface I1 { one: number } +////export interface I2 { two: string } +////export type I1_OR_I2 = I1 | I2; +//// +////export class C1 { +//// one: string; +////} +//// +////export module Inner { +//// export interface I3 { +//// three: boolean +//// } +//// +//// export var varVar = 100; +//// export let letVar = 200; +//// export const constVar = 300; +////} + +// @Filename: B.ts +////export var bVar = "bee!"; + +// @Filename: C.ts +////export var cVar = "see!"; +////export * from "A"; +////export * from "B" + +// @Filename: D.ts +////import * as c from "C"; +////var x = c.Inner./**/ + +goTo.marker(); +verify.completionListContains("varVar"); +verify.completionListContains("letVar"); +verify.completionListContains("constVar"); +verify.not.completionListContains("__export"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListForTransitivelyExportedMembers03.ts b/tests/cases/fourslash/completionListForTransitivelyExportedMembers03.ts new file mode 100644 index 00000000000..78ef3ec7c72 --- /dev/null +++ b/tests/cases/fourslash/completionListForTransitivelyExportedMembers03.ts @@ -0,0 +1,40 @@ +/// + + +// @Filename: A.ts +////export interface I1 { one: number } +////export interface I2 { two: string } +////export type I1_OR_I2 = I1 | I2; +//// +////export class C1 { +//// one: string; +////} +//// +////export module Inner { +//// export interface I3 { +//// three: boolean +//// } +//// +//// export var varVar = 100; +//// export let letVar = 200; +//// export const constVar = 300; +////} + +// @Filename: B.ts +////export var bVar = "bee!"; + +// @Filename: C.ts +////export var cVar = "see!"; +////export * from "A"; +////export * from "B" + +// @Filename: D.ts +////import * as c from "C"; +////var x: c./**/ + +goTo.marker(); +verify.completionListContains("I1"); +verify.completionListContains("I2"); +verify.completionListContains("I1_OR_I2"); +verify.completionListContains("C1"); +verify.not.completionListContains("__export"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListForTransitivelyExportedMembers04.ts b/tests/cases/fourslash/completionListForTransitivelyExportedMembers04.ts new file mode 100644 index 00000000000..114e370d31d --- /dev/null +++ b/tests/cases/fourslash/completionListForTransitivelyExportedMembers04.ts @@ -0,0 +1,37 @@ +/// + + +// @Filename: A.ts +////export interface I1 { one: number } +////export interface I2 { two: string } +////export type I1_OR_I2 = I1 | I2; +//// +////export class C1 { +//// one: string; +////} +//// +////export module Inner { +//// export interface I3 { +//// three: boolean +//// } +//// +//// export var varVar = 100; +//// export let letVar = 200; +//// export const constVar = 300; +////} + +// @Filename: B.ts +////export var bVar = "bee!"; + +// @Filename: C.ts +////export var cVar = "see!"; +////export * from "A"; +////export * from "B" + +// @Filename: D.ts +////import * as c from "C"; +////var x: c.Inner./**/ + +goTo.marker(); +verify.completionListContains("I3"); +verify.not.completionListContains("__export"); \ No newline at end of file From fd3b4ca9cd8a24a1efcfc1f9bc0c4c168942433a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 24 Mar 2015 18:45:22 -0700 Subject: [PATCH 11/51] Fixed transitive export completion list issue. --- src/compiler/checker.ts | 8 ++++++-- src/compiler/types.ts | 5 +++-- src/services/services.ts | 9 ++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc614a34692..73bf603c682 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -74,7 +74,10 @@ module ts { isImplementationOfOverload, getAliasedSymbol: resolveAlias, getEmitResolver, - getExportsOfExternalModule, + getExportsOfImportDeclaration, + getExportsOfModule(moduleSymbol: Symbol): Symbol[] { + return mapToArray(getExportsOfModule(moduleSymbol)); + } }; let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); @@ -794,6 +797,7 @@ module ts { } function getExportsOfSymbol(symbol: Symbol): SymbolTable { + // TODO (drosen): Why do we not use getExportsOfModule for exteral modules as weel? return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports; } @@ -2921,7 +2925,7 @@ module ts { return result; } - function getExportsOfExternalModule(node: ImportDeclaration): Symbol[]{ + function getExportsOfImportDeclaration(node: ImportDeclaration): Symbol[] { if (!node.moduleSpecifier) { return emptyArray; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e615a9d0bbd..d6edc5300d4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -902,7 +902,7 @@ module ts { // import "mod" => importClause = undefined, moduleSpecifier = "mod" // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. - export interface ImportDeclaration extends Statement, ModuleElement { + export interface ImportDeclaration extends ModuleElement { importClause?: ImportClause; moduleSpecifier: Expression; } @@ -1115,7 +1115,8 @@ module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; + getExportsOfImportDeclaration(node: ImportDeclaration): Symbol[]; + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/src/services/services.ts b/src/services/services.ts index 58fba22a71f..980c79c231f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2533,8 +2533,10 @@ module ts { if (symbol && symbol.flags & SymbolFlags.HasExports) { // Extract module or enum members - forEachValue(symbol.exports, symbol => { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + let exportedMembers = typeInfoResolver.getExportsOfModule(symbol); + forEach(exportedMembers, symbol => { + if (!(symbol.flags & SymbolFlags.ExportStar) + && typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); @@ -2577,7 +2579,8 @@ module ts { if (showCompletionsInImportsClause(previousToken)) { let importDeclaration = getAncestor(previousToken, SyntaxKind.ImportDeclaration); Debug.assert(importDeclaration !== undefined); - let exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); + + let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); symbols = filterModuleExports(exports, importDeclaration); } } From d1fa506db6e7454619af4266bbb401e41d7e99a1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 25 Mar 2015 17:36:51 -0700 Subject: [PATCH 12/51] Use 'symbolsToArray' to avoid filtering. --- src/compiler/checker.ts | 4 +--- src/services/services.ts | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e2d668b8055..c1ce6869380 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -75,9 +75,7 @@ module ts { getAliasedSymbol: resolveAlias, getEmitResolver, getExportsOfImportDeclaration, - getExportsOfModule(moduleSymbol: Symbol): Symbol[] { - return mapToArray(getExportsOfModule(moduleSymbol)); - } + getExportsOfModule: moduleSymbol => symbolsToArray(getExportsOfModule(moduleSymbol)), }; let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); diff --git a/src/services/services.ts b/src/services/services.ts index cd62d7fce88..6a0925460a1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2535,10 +2535,9 @@ module ts { if (symbol && symbol.flags & SymbolFlags.HasExports) { // Extract module or enum members - let exportedMembers = typeInfoResolver.getExportsOfModule(symbol); - forEach(exportedMembers, symbol => { - if (!(symbol.flags & SymbolFlags.ExportStar) - && typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + let exportedSymbols = typeInfoResolver.getExportsOfModule(symbol); + forEach(exportedSymbols, symbol => { + if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); From 82222472b5ae75ae59574d28300970c1c32a032f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 25 Mar 2015 18:01:57 -0700 Subject: [PATCH 13/51] Subsume 'getExportsOfImportDeclaration' with 'getExportsOfModule'. --- src/compiler/checker.ts | 1 - src/compiler/types.ts | 1 - src/services/services.ts | 12 ++++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1ce6869380..7435fd095b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -74,7 +74,6 @@ module ts { isImplementationOfOverload, getAliasedSymbol: resolveAlias, getEmitResolver, - getExportsOfImportDeclaration, getExportsOfModule: moduleSymbol => symbolsToArray(getExportsOfModule(moduleSymbol)), }; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 609baef833e..6a2677fe720 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1127,7 +1127,6 @@ module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfImportDeclaration(node: ImportDeclaration): Symbol[]; getExportsOfModule(moduleSymbol: Symbol): Symbol[]; // Should not be called directly. Should only be accessed through the Program instance. diff --git a/src/services/services.ts b/src/services/services.ts index 6a0925460a1..44c0d2d8206 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2581,8 +2581,16 @@ module ts { let importDeclaration = getAncestor(contextToken, SyntaxKind.ImportDeclaration); Debug.assert(importDeclaration !== undefined); - let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); - symbols = filterModuleExports(exports, importDeclaration); + let exports: Symbol[]; + if (importDeclaration.moduleSpecifier) { + let moduleSpecifierSymbol = typeInfoResolver.getSymbolAtLocation(importDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeInfoResolver.getExportsOfModule(moduleSpecifierSymbol); + } + } + + //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); + symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; } } else { From 77492382ea43bf7c5d53ddc85936509cbbee4d34 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 25 Mar 2015 18:08:46 -0700 Subject: [PATCH 14/51] Updated API baselines. --- tests/baselines/reference/APISample_compile.js | 4 ++-- tests/baselines/reference/APISample_compile.types | 11 +++++------ tests/baselines/reference/APISample_linter.js | 4 ++-- tests/baselines/reference/APISample_linter.types | 11 +++++------ tests/baselines/reference/APISample_transform.js | 4 ++-- tests/baselines/reference/APISample_transform.types | 11 +++++------ tests/baselines/reference/APISample_watcher.js | 4 ++-- tests/baselines/reference/APISample_watcher.types | 11 +++++------ 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 07d5e4337a6..49159b322e8 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -746,7 +746,7 @@ declare module "typescript" { interface ExternalModuleReference extends Node { expression?: Expression; } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { importClause?: ImportClause; moduleSpecifier: Expression; } @@ -888,7 +888,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index eff47a4cb7b..86003fc494e 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2269,9 +2269,8 @@ declare module "typescript" { >expression : Expression >Expression : Expression } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { >ImportDeclaration : ImportDeclaration ->Statement : Statement >ModuleElement : ModuleElement importClause?: ImportClause; @@ -2780,10 +2779,10 @@ declare module "typescript" { >Symbol : Symbol >Symbol : Symbol - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; ->getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[] ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; +>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[] +>moduleSymbol : Symbol +>Symbol : Symbol >Symbol : Symbol } interface SymbolDisplayBuilder { diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b57acaf0e9c..f7902f85998 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -777,7 +777,7 @@ declare module "typescript" { interface ExternalModuleReference extends Node { expression?: Expression; } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { importClause?: ImportClause; moduleSpecifier: Expression; } @@ -919,7 +919,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 600bf5c6adc..41cf18cc3f1 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2415,9 +2415,8 @@ declare module "typescript" { >expression : Expression >Expression : Expression } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { >ImportDeclaration : ImportDeclaration ->Statement : Statement >ModuleElement : ModuleElement importClause?: ImportClause; @@ -2926,10 +2925,10 @@ declare module "typescript" { >Symbol : Symbol >Symbol : Symbol - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; ->getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[] ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; +>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[] +>moduleSymbol : Symbol +>Symbol : Symbol >Symbol : Symbol } interface SymbolDisplayBuilder { diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 4004007508a..68c51a8f652 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -778,7 +778,7 @@ declare module "typescript" { interface ExternalModuleReference extends Node { expression?: Expression; } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { importClause?: ImportClause; moduleSpecifier: Expression; } @@ -920,7 +920,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4ea9c49d758..de371435b42 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2365,9 +2365,8 @@ declare module "typescript" { >expression : Expression >Expression : Expression } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { >ImportDeclaration : ImportDeclaration ->Statement : Statement >ModuleElement : ModuleElement importClause?: ImportClause; @@ -2876,10 +2875,10 @@ declare module "typescript" { >Symbol : Symbol >Symbol : Symbol - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; ->getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[] ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; +>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[] +>moduleSymbol : Symbol +>Symbol : Symbol >Symbol : Symbol } interface SymbolDisplayBuilder { diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 34503a0d81a..02c8bdb6889 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -815,7 +815,7 @@ declare module "typescript" { interface ExternalModuleReference extends Node { expression?: Expression; } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { importClause?: ImportClause; moduleSpecifier: Expression; } @@ -957,7 +957,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 3903e169b4e..1114e9680f9 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2538,9 +2538,8 @@ declare module "typescript" { >expression : Expression >Expression : Expression } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { >ImportDeclaration : ImportDeclaration ->Statement : Statement >ModuleElement : ModuleElement importClause?: ImportClause; @@ -3049,10 +3048,10 @@ declare module "typescript" { >Symbol : Symbol >Symbol : Symbol - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; ->getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[] ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; +>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[] +>moduleSymbol : Symbol +>Symbol : Symbol >Symbol : Symbol } interface SymbolDisplayBuilder { From 19211b12928fc489b62176ff1db3081cb6f1552b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 25 Mar 2015 18:40:06 -0700 Subject: [PATCH 15/51] Got rid of 'getExportsOfImportDeclaration'. --- src/compiler/checker.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7435fd095b6..6bd75c5d283 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3001,17 +3001,6 @@ module ts { return result; } - function getExportsOfImportDeclaration(node: ImportDeclaration): Symbol[] { - if (!node.moduleSpecifier) { - return emptyArray; - } - let module = resolveExternalModuleName(node, node.moduleSpecifier); - if (!module) { - return emptyArray; - } - return symbolsToArray(getExportsOfModule(module)); - } - function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { let links = getNodeLinks(declaration); if (!links.resolvedSignature) { From eb5e1bcbad55656c773b75038a3af41729fd89ab Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 26 Mar 2015 23:55:10 -0700 Subject: [PATCH 16/51] Use a function declaration vs a function expression to help deal with a reported Atom+IO.js issue. --- src/services/services.ts | 239 ++++++++++++++++++++------------------- 1 file changed, 122 insertions(+), 117 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 41ffc04e5ae..80e28827b24 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -730,7 +730,7 @@ module ts { public statements: NodeArray; public endOfFileToken: Node; - public amdDependencies: {name: string; path: string}[]; + public amdDependencies: { name: string; path: string }[]; public amdModuleName: string; public referencedFiles: FileReference[]; @@ -769,126 +769,131 @@ module ts { public getNamedDeclarations() { if (!this.namedDeclarations) { - let sourceFile = this; - let namedDeclarations: Declaration[] = []; - - forEachChild(sourceFile, function visit(node: Node): void { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - let functionDeclaration = node; - - if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - let lastDeclaration = namedDeclarations.length > 0 ? - namedDeclarations[namedDeclarations.length - 1] : - undefined; - - // Check whether this declaration belongs to an "overload group". - if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { - // Overwrite the last declaration if it was an overload - // and this one is an implementation. - if (functionDeclaration.body && !(lastDeclaration).body) { - namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; - } - } - else { - namedDeclarations.push(functionDeclaration); - } - - forEachChild(node, visit); - } - break; - - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportSpecifier: - case SyntaxKind.ImportSpecifier: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ImportClause: - case SyntaxKind.NamespaceImport: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.TypeLiteral: - if ((node).name) { - namedDeclarations.push(node); - } - // fall through - case SyntaxKind.Constructor: - case SyntaxKind.VariableStatement: - case SyntaxKind.VariableDeclarationList: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.ModuleBlock: - forEachChild(node, visit); - break; - - case SyntaxKind.Block: - if (isFunctionBlock(node)) { - forEachChild(node, visit); - } - break; - - case SyntaxKind.Parameter: - // Only consider properties defined as constructor parameters - if (!(node.flags & NodeFlags.AccessibilityModifier)) { - break; - } - // fall through - case SyntaxKind.VariableDeclaration: - case SyntaxKind.BindingElement: - if (isBindingPattern((node).name)) { - forEachChild((node).name, visit); - break; - } - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - namedDeclarations.push(node); - break; - - case SyntaxKind.ExportDeclaration: - // Handle named exports case e.g.: - // export {a, b as B} from "mod"; - if ((node).exportClause) { - forEach((node).exportClause.elements, visit); - } - break; - - case SyntaxKind.ImportDeclaration: - let importClause = (node).importClause; - if (importClause) { - // Handle default import case e.g.: - // import d from "mod"; - if (importClause.name) { - namedDeclarations.push(importClause); - } - - // Handle named bindings in imports e.g.: - // import * as NS from "mod"; - // import {a, b as B} from "mod"; - if (importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - namedDeclarations.push(importClause.namedBindings); - } - else { - forEach((importClause.namedBindings).elements, visit); - } - } - } - break; - } - }); - - this.namedDeclarations = namedDeclarations; + this.namedDeclarations = this.computeNamedDeclarations(); } return this.namedDeclarations; } + + private computeNamedDeclarations() { + let namedDeclarations: Declaration[] = []; + + forEachChild(this, visit); + + return namedDeclarations; + + function visit(node: Node): void { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + let functionDeclaration = node; + + if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { + let lastDeclaration = namedDeclarations.length > 0 ? + namedDeclarations[namedDeclarations.length - 1] : + undefined; + + // Check whether this declaration belongs to an "overload group". + if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + // Overwrite the last declaration if it was an overload + // and this one is an implementation. + if (functionDeclaration.body && !(lastDeclaration).body) { + namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + } + } + else { + namedDeclarations.push(functionDeclaration); + } + + forEachChild(node, visit); + } + break; + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.TypeLiteral: + if ((node).name) { + namedDeclarations.push(node); + } + // fall through + case SyntaxKind.Constructor: + case SyntaxKind.VariableStatement: + case SyntaxKind.VariableDeclarationList: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ModuleBlock: + forEachChild(node, visit); + break; + + case SyntaxKind.Block: + if (isFunctionBlock(node)) { + forEachChild(node, visit); + } + break; + + case SyntaxKind.Parameter: + // Only consider properties defined as constructor parameters + if (!(node.flags & NodeFlags.AccessibilityModifier)) { + break; + } + // fall through + case SyntaxKind.VariableDeclaration: + case SyntaxKind.BindingElement: + if (isBindingPattern((node).name)) { + forEachChild((node).name, visit); + break; + } + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + namedDeclarations.push(node); + break; + + case SyntaxKind.ExportDeclaration: + // Handle named exports case e.g.: + // export {a, b as B} from "mod"; + if ((node).exportClause) { + forEach((node).exportClause.elements, visit); + } + break; + + case SyntaxKind.ImportDeclaration: + let importClause = (node).importClause; + if (importClause) { + // Handle default import case e.g.: + // import d from "mod"; + if (importClause.name) { + namedDeclarations.push(importClause); + } + + // Handle named bindings in imports e.g.: + // import * as NS from "mod"; + // import {a, b as B} from "mod"; + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + namedDeclarations.push(importClause.namedBindings); + } + else { + forEach((importClause.namedBindings).elements, visit); + } + } + } + break; + } + } + } } // From d45143815b825f3335fbf204c5020089ecfc353f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 12:20:30 -0700 Subject: [PATCH 17/51] initial checkin --- tests/cases/unittests/versionCache.ts | 1347 +++++++++++++++++++++++++ 1 file changed, 1347 insertions(+) create mode 100644 tests/cases/unittests/versionCache.ts diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts new file mode 100644 index 00000000000..a2b1d5e585a --- /dev/null +++ b/tests/cases/unittests/versionCache.ts @@ -0,0 +1,1347 @@ +/// +/// + +module ts{ + var gloError = false; + + function editFlat(s: number, dl: number, nt: string, source: string) { + return source.substring(0, s) + nt + source.substring(s + dl, source.length); + } + + var testDataDir = "../../tests/versionCacheTest/"; + + function bigTest() { + editStress("types.ts", false); + editStress("tst.ts", false); + editStress("client.ts", false); + } + + function recordError() { + gloError = true; + } + + function tstTest() { + var fname = testDataDir + 'tst.ts'; + var content = ts.sys.readFile(fname); + var lm = server.LineIndex.linesFromText(content); + var lines = lm.lines; + if (lines.length == 0) { + return; + } + var lineMap = lm.lineMap; + + var lineIndex = new server.LineIndex(); + lineIndex.load(lines); + + var editedText = lineIndex.getText(0, content.length); + + var snapshot: server.LineIndex; + var checkText: string; + var insertString: string; + + // change 9 1 0 1 {"y"} + var pos = lineColToPosition(lineIndex, 9, 1); + insertString = "y"; + checkText = editFlat(pos, 0, insertString, content); + snapshot = lineIndex.edit(pos, 0, insertString); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // change 9 2 0 1 {"."} + var pos = lineColToPosition(snapshot, 9, 2); + insertString = "."; + checkText = editFlat(pos, 0, insertString, checkText); + snapshot = snapshot.edit(pos, 0, insertString); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // change 9 3 0 1 {"\n"} + var pos = lineColToPosition(snapshot, 9, 3); + insertString = "\n"; + checkText = editFlat(pos, 0, insertString, checkText); + snapshot = snapshot.edit(pos, 0, insertString); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // change 10 1 0 10 {"\n\n\n\n\n\n\n\n\n\n"} + pos = lineColToPosition(snapshot, 10, 1); + insertString = "\n\n\n\n\n\n\n\n\n\n"; + checkText = editFlat(pos, 0, insertString, checkText); + snapshot = snapshot.edit(pos, 0, insertString); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // change 19 1 1 0 + pos = lineColToPosition(snapshot, 19, 1); + checkText = editFlat(pos, 1, "", checkText); + snapshot = snapshot.edit(pos, 1); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // change 18 1 1 0 + pos = lineColToPosition(snapshot, 18, 1); + checkText = editFlat(pos, 1, "", checkText); + snapshot = snapshot.edit(pos, 1); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + function lineColToPosition(lineIndex: server.LineIndex, line: number, col: number) { + var lineInfo = lineIndex.lineNumberToInfo(line); + return (lineInfo.offset + col - 1); + } + } + + function editTest() { + var fname = testDataDir + 'editme'; + var content = ts.sys.readFile(fname); + var lm = server.LineIndex.linesFromText(content); + var lines = lm.lines; + if (lines.length == 0) { + return; + } + var lineMap = lm.lineMap; + + var lineIndex = new server.LineIndex(); + lineIndex.load(lines); + + var editedText = lineIndex.getText(0, content.length); + + var snapshot: server.LineIndex; + var checkText: string; + var insertString: string; + + // Case VII: insert at end of file + insertString = "hmmmm...\r\n"; + checkText = editFlat(content.length, 0, insertString, content); + snapshot = lineIndex.edit(content.length, 0, insertString); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // Case IV: unusual line endings merge + snapshot = lineIndex.edit(lines[0].length - 1, lines[1].length, ""); + editedText = snapshot.getText(0, content.length - lines[1].length); + checkText = editFlat(lines[0].length - 1, lines[1].length, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + // Case VIIa: delete whole line and nothing but line (last line) + var llpos = lm.lineMap[lm.lineMap.length - 2]; + snapshot = lineIndex.edit(llpos, lines[lines.length - 1].length, ""); + checkText = editFlat(llpos, lines[lines.length - 1].length, "", content); + editedText = snapshot.getText(0, checkText.length); + if (editedText != checkText) { + recordError(); + return; + } + + // Case VIIb: delete whole line and nothing but line (first line) + snapshot = lineIndex.edit(0, lines[0].length, ""); + editedText = snapshot.getText(0, content.length - lines[0].length); + checkText = editFlat(0, lines[0].length, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + // and insert with no line breaks + insertString = "moo, moo, moo! "; + snapshot = lineIndex.edit(0, lines[0].length, insertString); + editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); + checkText = editFlat(0, lines[0].length, insertString, content); + if (editedText != checkText) { + recordError(); + return; + } + + // and insert with multiple line breaks + insertString = "moo, \r\nmoo, \r\nmoo! "; + snapshot = lineIndex.edit(0, lines[0].length, insertString); + editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); + checkText = editFlat(0, lines[0].length, insertString, content); + if (editedText != checkText) { + recordError(); + return; + } + + snapshot = lineIndex.edit(0, lines[0].length + lines[1].length, ""); + editedText = snapshot.getText(0, content.length - (lines[0].length + lines[1].length)); + checkText = editFlat(0, lines[0].length + lines[1].length, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + snapshot = lineIndex.edit(lines[0].length, lines[1].length + lines[2].length, ""); + + editedText = snapshot.getText(0, content.length - (lines[1].length + lines[2].length)); + checkText = editFlat(lines[0].length, lines[1].length + lines[2].length, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + // Case VI: insert multiple line breaks + + insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); + if (editedText != checkText) { + recordError(); + return; + } + + insertString = "cr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); + if (editedText != checkText) { + recordError(); + return; + } + + // leading '\n' + insertString = "\ncr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); + if (editedText != checkText) { + recordError(); + return; + } + + // Case I: single line no line breaks deleted or inserted + // delete 1 char + snapshot = lineIndex.edit(21, 1); + editedText = snapshot.getText(0, content.length - 1); + checkText = editFlat(21, 1, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + // insert 1 char + snapshot = lineIndex.edit(21, 0, "b"); + editedText = snapshot.getText(0, content.length + 1); + checkText = editFlat(21, 0, "b", content); + if (editedText != checkText) { + recordError(); + return; + } + + // delete 1, insert 2 + snapshot = lineIndex.edit(21, 1, "cr"); + editedText = snapshot.getText(0, content.length + 1); + checkText = editFlat(21, 1, "cr", content); + if (editedText != checkText) { + recordError(); + return; + } + + // Case II: delete across line break + snapshot = lineIndex.edit(21, 22); + editedText = snapshot.getText(0, content.length - 22); + checkText = editFlat(21, 22, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + snapshot = lineIndex.edit(21, 32); + editedText = snapshot.getText(0, content.length - 32); + checkText = editFlat(21, 32, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + // Case III: delete across multiple line breaks and insert no line breaks + snapshot = lineIndex.edit(21, 42); + editedText = snapshot.getText(0, content.length - 42); + checkText = editFlat(21, 42, "", content); + if (editedText != checkText) { + recordError(); + return; + } + + snapshot = lineIndex.edit(21, 42, "slithery "); + editedText = snapshot.getText(0, content.length - 33); + checkText = editFlat(21, 42, "slithery ", content); + if (editedText != checkText) { + recordError(); + return; + } + } + + function editStress(fname: string, timing: boolean) { + var content = ts.sys.readFile(testDataDir + fname); + var lm = server.LineIndex.linesFromText(content); + var lines = lm.lines; + if (lines.length == 0) { + return; + } + var lineMap = lm.lineMap; + + var lineIndex = new server.LineIndex(); + lineIndex.load(lines); + var totalChars = content.length; + var rsa: number[] = []; + var la: number[] = []; + var las: number[] = []; + var elas: number[] = []; + var ersa: number[] = []; + var ela: number[] = []; + var etotalChars = totalChars; + var j: number; + + var startTime: number; + for (j = 0; j < 100000; j++) { + rsa[j] = Math.floor(Math.random() * totalChars); + la[j] = Math.floor(Math.random() * (totalChars - rsa[j])); + if (la[j] > 4) { + las[j] = 4; + } + else { + las[j] = la[j]; + } + if (j < 4000) { + ersa[j] = Math.floor(Math.random() * etotalChars); + ela[j] = Math.floor(Math.random() * (etotalChars - ersa[j])); + if (ela[j] > 4) { + elas[j] = 4; + } + else { + elas[j] = ela[j]; + } + etotalChars += (las[j] - elas[j]); + } + } + if (timing) { + startTime = Date.now(); + } + for (j = 0; j < 2000; j++) { + var s2 = lineIndex.getText(rsa[j], la[j]); + if (!timing) { + var s1 = content.substring(rsa[j], rsa[j] + la[j]); + if (s1 != s2) { + recordError(); + return; + } + } + } + if (timing) { + console.log("range (average length 1/4 file size): " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); + } + // console.log("check1"); + if (timing) { + startTime = Date.now(); + } + for (j = 0; j < 10000; j++) { + var s2 = lineIndex.getText(rsa[j], las[j]); + if (!timing) { + var s1 = content.substring(rsa[j], rsa[j] + las[j]); + if (s1 != s2) { + recordError(); + return; + } + } + } + // console.log("check2"); + if (timing) { + console.log("range (average length 4 chars): " + ((Date.now() - startTime) / 10).toFixed(3) + " us"); + } + + if (timing) { + startTime = Date.now(); + } + var snapshot: server.LineIndex; + for (j = 0; j < 2000; j++) { + var insertString = content.substring(rsa[100000 - j], rsa[100000 - j] + las[100000 - j]); + snapshot = lineIndex.edit(rsa[j], las[j], insertString); + if (!timing) { + var checkText = editFlat(rsa[j], las[j], insertString, content); + var snapText = snapshot.getText(0, checkText.length); + if (checkText != snapText) { + if (s1 != s2) { + recordError(); + return; + } + } + } + } + // console.log("check3"); + if (timing) { + console.log("edit (average length 4): " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); + } + + var svc = server.ScriptVersionCache.fromString(content); + checkText = content; + if (timing) { + startTime = Date.now(); + } + for (j = 0; j < 2000; j++) { + insertString = content.substring(rsa[j], rsa[j] + las[j]); + svc.edit(ersa[j], elas[j], insertString); + if (!timing) { + checkText = editFlat(ersa[j], elas[j], insertString, checkText); + } + if (0 == (j % 4)) { + var snap = svc.getSnapshot(); + if (!timing) { + snapText = snap.getText(0, checkText.length); + if (checkText != snapText) { + if (s1 != s2) { + recordError(); + return; + } + } + } + } + } + if (timing) { + console.log("edit ScriptVersionCache: " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); + } + + // console.log("check4"); + if (timing) { + startTime = Date.now(); + } + for (j = 0; j < 5000; j++) { + insertString = content.substring(rsa[100000 - j], rsa[100000 - j] + la[100000 - j]); + snapshot = lineIndex.edit(rsa[j], la[j], insertString); + if (!timing) { + checkText = editFlat(rsa[j], la[j], insertString, content); + snapText = snapshot.getText(0, checkText.length); + if (checkText != snapText) { + if (s1 != s2) { + recordError(); + return; + } + } + } + } + if (timing) { + console.log("edit (average length 1/4th file size): " + ((Date.now() - startTime) / 5).toFixed(3) + " us"); + } + + var t: ts.LineAndCharacter; + var errorCount = 0; + if (timing) { + startTime = Date.now(); + } + // console.log("check5"); + for (j = 0; j < 100000; j++) { + var lp = lineIndex.charOffsetToLineNumberAndPos(rsa[j]); + if (!timing) { + var lac = ts.getLineAndCharacterOfPosition(lineMap, rsa[j]); + + if (lac.line != lp.line) { + recordError(); + console.log("arrgh " + lac.line + " " + lp.line + " " + j); + return; + } + if (lac.character != (lp.offset + 1)) { + recordError(); + console.log("arrgh ch... " + lac.character + " " + (lp.offset + 1) + " " + j); + return; + } + } + } + // console.log("check6"); + if (timing) { + console.log("line/offset from pos: " + ((Date.now() - startTime) / 100).toFixed(3) + " us"); + } + + if (timing) { + startTime = Date.now(); + } + + var outer = 1; + if (timing) { + outer = 100; + } + for (var ko = 0; ko < outer; ko++) { + for (var k = 0, llen = lines.length; k < llen; k++) { + var lineInfo = lineIndex.lineNumberToInfo(k + 1); + var lineIndexOffset = lineInfo.offset; + if (!timing) { + var lineMapOffset = lineMap[k]; + if (lineIndexOffset != lineMapOffset) { + recordError(); + return; + } + } + } + } + if (timing) { + console.log("start pos from line: " + (((Date.now() - startTime) / lines.length) * 10).toFixed(3) + " us"); + } + } + + function edTest() { + editTest(); + tstTest(); + if (!gloError) { + bigTest(); + } + if (gloError) { + console.log(" ! Fail: versionCache"); + } + else { + console.log("Pass"); + } + } + + edTest(); +} + + +//module ts { +// ts.disableIncrementalParsing = false; + +// function withChange(text: IScriptSnapshot, start: number, length: number, newText: string): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { +// var contents = text.getText(0, text.getLength()); +// var newContents = contents.substr(0, start) + newText + contents.substring(start + length); + +// return { text: ScriptSnapshot.fromString(newContents), textChangeRange: createTextChangeRange(createTextSpan(start, length), newText.length) } +// } + +// function withInsert(text: IScriptSnapshot, start: number, newText: string): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { +// return withChange(text, start, 0, newText); +// } + +// function withDelete(text: IScriptSnapshot, start: number, length: number): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { +// return withChange(text, start, length, ""); +// } + +// function createTree(text: IScriptSnapshot, version: string) { +// return createLanguageServiceSourceFile(/*fileName:*/ "", text, ScriptTarget.Latest, version, /*setNodeParents:*/ true) +// } + +// function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) { +// var diagnostics1 = file1.parseDiagnostics; +// var diagnostics2 = file2.parseDiagnostics; + +// assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length"); +// for (var i = 0, n = diagnostics1.length; i < n; i++) { +// var d1 = diagnostics1[i]; +// var d2 = diagnostics2[i]; + +// assert.equal(d1.file, file1, "d1.file !== file1"); +// assert.equal(d2.file, file2, "d2.file !== file2"); +// assert.equal(d1.start, d2.start, "d1.start !== d2.start"); +// assert.equal(d1.length, d2.length, "d1.length !== d2.length"); +// assert.equal(d1.messageText, d2.messageText, "d1.messageText !== d2.messageText"); +// assert.equal(d1.category, d2.category, "d1.category !== d2.category"); +// assert.equal(d1.code, d2.code, "d1.code !== d2.code"); +// } +// } + +// // NOTE: 'reusedElements' is the expected count of elements reused from the old tree to the new +// // tree. It may change as we tweak the parser. If the count increases then that should always +// // be a good thing. If it decreases, that's not great (less reusability), but that may be +// // unavoidable. If it does decrease an investigation should be done to make sure that things +// // are still ok and we're still appropriately reusing most of the tree. +// function compareTrees(oldText: IScriptSnapshot, newText: IScriptSnapshot, textChangeRange: TextChangeRange, expectedReusedElements: number, oldTree?: SourceFile): SourceFile { +// oldTree = oldTree || createTree(oldText, /*version:*/ "."); +// Utils.assertInvariants(oldTree, /*parent:*/ undefined); + +// // Create a tree for the new text, in a non-incremental fashion. +// var newTree = createTree(newText, oldTree.version + "."); +// Utils.assertInvariants(newTree, /*parent:*/ undefined); + +// // Create a tree for the new text, in an incremental fashion. +// var incrementalNewTree = updateLanguageServiceSourceFile(oldTree, newText, oldTree.version + ".", textChangeRange); +// Utils.assertInvariants(incrementalNewTree, /*parent:*/ undefined); + +// // We should get the same tree when doign a full or incremental parse. +// Utils.assertStructuralEquals(newTree, incrementalNewTree); + +// // We should also get the exact same set of diagnostics. +// assertSameDiagnostics(newTree, incrementalNewTree); + +// // There should be no reused nodes between two trees that are fully parsed. +// assert.isTrue(reusedElements(oldTree, newTree) === 0); + +// assert.equal(newTree.fileName, incrementalNewTree.fileName, "newTree.fileName !== incrementalNewTree.fileName"); +// assert.equal(newTree.text, incrementalNewTree.text, "newTree.text !== incrementalNewTree.text"); + +// if (expectedReusedElements !== -1) { +// var actualReusedCount = reusedElements(oldTree, incrementalNewTree); +// assert.equal(actualReusedCount, expectedReusedElements, actualReusedCount + " !== " + expectedReusedElements); +// } + +// return incrementalNewTree; +// } + +// function reusedElements(oldNode: SourceFile, newNode: SourceFile): number { +// var allOldElements = collectElements(oldNode); +// var allNewElements = collectElements(newNode); + +// return filter(allOldElements, v => contains(allNewElements, v)).length; +// } + +// function collectElements(node: Node) { +// var result: Node[] = []; +// visit(node); +// return result; + +// function visit(node: Node) { +// result.push(node); +// forEachChild(node, visit); +// } +// } + +// function deleteCode(source: string, index: number, toDelete: string) { +// var repeat = toDelete.length; +// var oldTree = createTree(ScriptSnapshot.fromString(source), /*version:*/ "."); +// for (var i = 0; i < repeat; i++) { +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, 1); +// var newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); + +// source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); +// oldTree = newTree; +// } +// } + +// function insertCode(source: string, index: number, toInsert: string) { +// var repeat = toInsert.length; +// var oldTree = createTree(ScriptSnapshot.fromString(source), /*version:*/ "."); +// for (var i = 0; i < repeat; i++) { +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + i, toInsert.charAt(i)); +// var newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); + +// source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); +// oldTree = newTree; +// } +// } + +// describe('Incremental',() => { +// it('Inserting into method',() => { +// var source = "class C {\r\n" + +// " public foo1() { }\r\n" + +// " public foo2() {\r\n" + +// " return 1;\r\n" + +// " }\r\n" + +// " public foo3() { }\r\n" + +// "}"; + +// var oldText = ScriptSnapshot.fromString(source); +// var semicolonIndex = source.indexOf(";"); +// var newTextAndChange = withInsert(oldText, semicolonIndex, " + 1"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); +// }); + +// it('Deleting from method',() => { +// var source = "class C {\r\n" + +// " public foo1() { }\r\n" + +// " public foo2() {\r\n" + +// " return 1 + 1;\r\n" + +// " }\r\n" + +// " public foo3() { }\r\n" + +// "}"; + +// var index = source.indexOf("+ 1"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, "+ 1".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); +// }); + +// it('Regular expression 1',() => { +// var source = "class C { public foo1() { /; } public foo2() { return 1;} public foo3() { } }"; + +// var semicolonIndex = source.indexOf(";}"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Regular expression 2',() => { +// var source = "class C { public foo1() { ; } public foo2() { return 1/;} public foo3() { } }"; + +// var semicolonIndex = source.indexOf(";"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); +// }); + +// it('Comment 1',() => { +// var source = "class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; + +// var semicolonIndex = source.indexOf(";"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Comment 2',() => { +// var source = "class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, 0, "//"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Comment 3',() => { +// var source = "//class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, 0, 2); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Comment 4',() => { +// var source = "class C { public foo1() { /; } public foo2() { */ return 1; } public foo3() { } }"; + +// var index = source.indexOf(";"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index, "*"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); +// }); + +// it('Parameter 1',() => { +// // Should be able to reuse all the parameters. +// var source = "class C {\r\n" + +// " public foo2(a, b, c, d) {\r\n" + +// " return 1;\r\n" + +// " }\r\n" + +// "}"; + +// var semicolonIndex = source.indexOf(";"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, semicolonIndex, " + 1"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); +// }); + +// it('Type member 1',() => { +// // Should be able to reuse most of the type members. +// var source = "interface I { a: number; b: string; (c): d; new (e): f; g(): h }"; + +// var index = source.indexOf(": string"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index, "?"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 14); +// }); + +// it('Enum element 1',() => { +// // Should be able to reuse most of the enum elements. +// var source = "enum E { a = 1, b = 1 << 1, c = 3, e = 4, f = 5, g = 7, h = 8, i = 9, j = 10 }"; + +// var index = source.indexOf("<<"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, 2, "+"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 24); +// }); + +// it('Strict mode 1',() => { +// // In non-strict mode 'package' means nothing and can be reused. In strict mode though +// // we'll have to reparse the nodes (and generate an error for 'package();' +// // +// // Note: in this test we don't actually add 'use strict'. This is so we can compare +// // reuse with/without a strict mode change. +// var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();"; + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, 0, "'strict';\r\n"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 2',() => { +// // In non-strict mode 'package' means nothing and can be reused. In strict mode though +// // we'll have to reparse the nodes (and generate an error for 'package();' +// var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();"; + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, 0, "'use strict';\r\n"); + +// // Note the decreased reuse of nodes compared to 'Strict mode 1' +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 3',() => { +// // In non-strict mode 'package' means nothing and can be reused. In strict mode though +// // we'll have to reparse the nodes (and generate an error for 'package();' +// // +// // Note: in this test we don't actually remove 'use strict'. This is so we can compare +// // reuse with/without a strict mode change. +// var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();"; + +// var index = source.indexOf('f'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, 0, index); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 4',() => { +// // In non-strict mode 'package' means nothing and can be reused. In strict mode though +// // we'll have to reparse the nodes (and generate an error for 'package();' +// var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();"; + +// var index = source.indexOf('f'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, 0, index); + +// // Note the decreased reuse of nodes compared to testStrictMode3 +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 5',() => { +// var source = "'use blahhh';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; + +// var index = source.indexOf('b'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, 6, "strict"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 6',() => { +// var source = "'use strict';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; + +// var index = source.indexOf('s'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, 6, "blahhh"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Strict mode 7',() => { +// var source = "'use blahhh';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; + +// var index = source.indexOf('f'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, 0, index); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Parenthesized expression to arrow function 1',() => { +// var source = "var v = (a, b, c, d, e)"; + +// var index = source.indexOf('a'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 1, ":"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Parenthesized expression to arrow function 2',() => { +// var source = "var v = (a, b) = c"; + +// var index = source.indexOf("= c") + 1; +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index, ">"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Arrow function to parenthesized expression 1',() => { +// var source = "var v = (a:, b, c, d, e)"; + +// var index = source.indexOf(':'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, 1); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Arrow function to parenthesized expression 2',() => { +// var source = "var v = (a, b) => c"; + +// var index = source.indexOf(">"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, 1); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Speculative generic lookahead 1',() => { +// var source = "var v = Fe"; + +// var index = source.indexOf('b'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 1, ",x"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); +// }); + +// it('Speculative generic lookahead 2',() => { +// var source = "var v = Fe"; + +// var index = source.indexOf('b'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 1, ",x"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); +// }); + +// it('Speculative generic lookahead 3',() => { +// var source = "var v = Fe"; + +// var index = source.indexOf('b'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 1, ",x"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); +// }); + +// it('Speculative generic lookahead 4',() => { +// var source = "var v = Fe"; + +// var index = source.indexOf('b'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 1, ",x"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); +// }); + +// it('Assertion to arrow function',() => { +// var source = "var v = (a);"; + +// var index = source.indexOf(';'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index, " => 1"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Arrow function to assertion',() => { +// var source = "var v = (a) => 1;"; + +// var index = source.indexOf(' =>'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, " => 1".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Contextual shift to shift-equals',() => { +// var source = "var v = 1 >> = 2"; + +// var index = source.indexOf('>> ='); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index + 2, 1); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Contextual shift-equals to shift',() => { +// var source = "var v = 1 >>= 2"; + +// var index = source.indexOf('>>='); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index + 2, " "); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Contextual shift to generic invocation',() => { +// var source = "var v = T>>(2)"; + +// var index = source.indexOf('T'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, index, "Foo { +// var source = "var v = Foo>(2)"; + +// var index = source.indexOf('Foo { +// var source = "var v = T>>=2;"; + +// var index = source.indexOf('='); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, "= ".length, ": Foo { +// var source = "var v : Foo>=2;"; + +// var index = source.indexOf(':'); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, ": Foo0"; + +// var index = source.indexOf("0"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, index, 1, "()"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Type argument list to arithmetic operator',() => { +// var source = "var v = new Dictionary()"; + +// var index = source.indexOf("()"); +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, index, 2); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Yield context 1',() => { +// // We're changing from a non-generator to a genarator. We can't reuse statement nodes. +// var source = "function foo() {\r\nyield(foo1);\r\n}"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("foo"); +// var newTextAndChange = withInsert(oldText, index, "*"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Yield context 2',() => { +// // We're changing from a generator to a non-genarator. We can't reuse statement nodes. +// var source = "function *foo() {\r\nyield(foo1);\r\n}"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("*"); +// var newTextAndChange = withDelete(oldText, index, "*".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Delete semicolon',() => { +// var source = "export class Foo {\r\n}\r\n\r\nexport var foo = new Foo();\r\n\r\n export function test(foo: Foo) {\r\n return true;\r\n }\r\n"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.lastIndexOf(";"); +// var newTextAndChange = withDelete(oldText, index, 1); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); +// }); + +// it('Edit after empty type parameter list',() => { +// var source = "class Dictionary<> { }\r\nvar y;\r\n"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.length; +// var newTextAndChange = withInsert(oldText, index, "var x;"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Delete parameter after comment',() => { +// var source = "function fn(/* comment! */ a: number, c) { }"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("a:"); +// var newTextAndChange = withDelete(oldText, index, "a: number,".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Modifier added to accessor',() => { +// var source = +// "class C {\ +// set Bar(bar:string) {}\ +//}\ +//var o2 = { set Foo(val:number) { } };"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("set"); +// var newTextAndChange = withInsert(oldText, index, "public "); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 6); +// }); + +// it('Insert parameter ahead of parameter',() => { +// var source = +// "alert(100);\ +//\ +//class OverloadedMonster {\ +//constructor();\ +//constructor(name) { }\ +//}"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("100"); +// var newTextAndChange = withInsert(oldText, index, "'1', "); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 5); +// }); + +// it('Insert declare modifier before module',() => { +// var source = +// "module mAmbient {\ +//module m3 { }\ +//}"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = 0; +// var newTextAndChange = withInsert(oldText, index, "declare "); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 3); +// }); + +// it('Insert function above arrow function with comment',() => { +// var source = +// "\ +//() =>\ +// // do something\ +//0;"; + +// var oldText = ScriptSnapshot.fromString(source); +// var index = 0; +// var newTextAndChange = withInsert(oldText, index, "function Foo() { }"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Finish incomplete regular expression',() => { +// var source = "while (true) /3; return;" + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.length - 1; +// var newTextAndChange = withInsert(oldText, index, "/"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Regular expression to divide operation',() => { +// var source = "return;\r\nwhile (true) /3/g;" + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("while"); +// var newTextAndChange = withDelete(oldText, index, "while ".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Divide operation to regular expression',() => { +// var source = "return;\r\n(true) /3/g;" + +// var oldText = ScriptSnapshot.fromString(source); +// var index = source.indexOf("("); +// var newTextAndChange = withInsert(oldText, index, "while "); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Unterminated comment after keyword converted to identifier',() => { +// // 'public' as a keyword should be incrementally unusable (because it has an +// // unterminated comment). When we convert it to an identifier, that shouldn't +// // change anything, and we should still get the same errors. +// var source = "return; a.public /*" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, 0, ""); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); +// }); + +// it('Class to interface',() => { +// var source = "class A { public M1() { } public M2() { } public M3() { } p1 = 0; p2 = 0; p3 = 0 }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Interface to class',() => { +// var source = "interface A { M1?(); M2?(); M3?(); p1?; p2?; p3? }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Surrounding function declarations with block',() => { +// var source = "declare function F1() { } export function F2() { } declare export function F3() { }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withInsert(oldText, 0, "{"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9); +// }); + +// it('Removing block around function declarations',() => { +// var source = "{ declare function F1() { } export function F2() { } declare export function F3() { }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withDelete(oldText, 0, "{".length); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Moving methods from class to object literal',() => { +// var source = "class C { public A() { } public B() { } public C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "class C".length, "var v ="); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Moving methods from object literal to class',() => { +// var source = "var v = { public A() { } public B() { } public C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. +// }); + +// it('Moving methods from object literal to class in strict mode', () => { +// var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); +// }); + +// it('Moving index signatures from class to interface',() => { +// var source = "class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. +// }); + +// it('Moving index signatures from class to interface in strict mode', () => { +// var source = "\"use strict\"; class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 14, "class".length, "interface"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); +// }); + +// it('Moving index signatures from interface to class',() => { +// var source = "interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. +// }); + + +// it('Moving index signatures from interface to class in strict mode', () => { +// var source = "\"use strict\"; interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 14, "interface".length, "class"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); +// }); + +// it('Moving accessors from class to object literal',() => { +// var source = "class C { public get A() { } public get B() { } public get C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "class C".length, "var v ="); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); +// }); + +// it('Moving accessors from object literal to class',() => { +// var source = "var v = { public get A() { } public get B() { } public get C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. +// }); + + +// it('Moving accessors from object literal to class in strict mode', () => { +// var source = "\"use strict\"; var v = { public get A() { } public get B() { } public get C() { } }" + +// var oldText = ScriptSnapshot.fromString(source); +// var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + +// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); +// }); + +// // Simulated typing tests. + +// it('Type extends clause 1',() => { +// var source = "interface IFoo { }\r\ninterface Array extends IFoo { }"; + +// var index = source.indexOf('extends'); +// deleteCode(source, index, "extends IFoo"); +// }); + +// it('Type after incomplete enum 1',() => { +// var source = "function foo() {\r\n" + +// " function getOccurrencesAtPosition() {\r\n" + +// " switch (node) {\r\n" + +// " enum \r\n" + +// " }\r\n" + +// " \r\n" + +// " return undefined;\r\n" + +// " \r\n" + +// " function keywordToReferenceEntry() {\r\n" + +// " }\r\n" + +// " }\r\n" + +// " \r\n" + +// " return {\r\n" + +// " getEmitOutput: (fileName): Bar => null,\r\n" + +// " };\r\n" + +// " }"; + +// var index = source.indexOf("enum ") + "enum ".length; +// insertCode(source, index, "Fo"); +// }); +// }); +//} \ No newline at end of file From bf565c70a404a3f40740cd756deba1f7b37a4358 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 12:21:11 -0700 Subject: [PATCH 18/51] Use assert --- tests/cases/unittests/versionCache.ts | 215 ++++++++------------------ 1 file changed, 63 insertions(+), 152 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index a2b1d5e585a..2dcf11a6278 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -1,23 +1,17 @@ -/// +/// /// module ts{ - var gloError = false; - function editFlat(s: number, dl: number, nt: string, source: string) { return source.substring(0, s) + nt + source.substring(s + dl, source.length); } - var testDataDir = "../../tests/versionCacheTest/"; + var testDataDir = "..\..\..\src\compiler"; function bigTest() { - editStress("types.ts", false); - editStress("tst.ts", false); - editStress("client.ts", false); - } - - function recordError() { - gloError = true; + editStress("scanner.ts", false); + editStress("sys.ts", false); + editStress("binder.ts", false); } function tstTest() { @@ -45,10 +39,8 @@ module ts{ checkText = editFlat(pos, 0, insertString, content); snapshot = lineIndex.edit(pos, 0, insertString); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // change 9 2 0 1 {"."} var pos = lineColToPosition(snapshot, 9, 2); @@ -56,10 +48,8 @@ module ts{ checkText = editFlat(pos, 0, insertString, checkText); snapshot = snapshot.edit(pos, 0, insertString); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // change 9 3 0 1 {"\n"} var pos = lineColToPosition(snapshot, 9, 3); @@ -67,10 +57,8 @@ module ts{ checkText = editFlat(pos, 0, insertString, checkText); snapshot = snapshot.edit(pos, 0, insertString); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // change 10 1 0 10 {"\n\n\n\n\n\n\n\n\n\n"} pos = lineColToPosition(snapshot, 10, 1); @@ -78,30 +66,24 @@ module ts{ checkText = editFlat(pos, 0, insertString, checkText); snapshot = snapshot.edit(pos, 0, insertString); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // change 19 1 1 0 pos = lineColToPosition(snapshot, 19, 1); checkText = editFlat(pos, 1, "", checkText); snapshot = snapshot.edit(pos, 1); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // change 18 1 1 0 pos = lineColToPosition(snapshot, 18, 1); checkText = editFlat(pos, 1, "", checkText); snapshot = snapshot.edit(pos, 1); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); function lineColToPosition(lineIndex: server.LineIndex, line: number, col: number) { var lineInfo = lineIndex.lineNumberToInfo(line); @@ -133,75 +115,59 @@ module ts{ checkText = editFlat(content.length, 0, insertString, content); snapshot = lineIndex.edit(content.length, 0, insertString); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case IV: unusual line endings merge snapshot = lineIndex.edit(lines[0].length - 1, lines[1].length, ""); editedText = snapshot.getText(0, content.length - lines[1].length); checkText = editFlat(lines[0].length - 1, lines[1].length, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case VIIa: delete whole line and nothing but line (last line) var llpos = lm.lineMap[lm.lineMap.length - 2]; snapshot = lineIndex.edit(llpos, lines[lines.length - 1].length, ""); checkText = editFlat(llpos, lines[lines.length - 1].length, "", content); editedText = snapshot.getText(0, checkText.length); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case VIIb: delete whole line and nothing but line (first line) snapshot = lineIndex.edit(0, lines[0].length, ""); editedText = snapshot.getText(0, content.length - lines[0].length); checkText = editFlat(0, lines[0].length, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // and insert with no line breaks insertString = "moo, moo, moo! "; snapshot = lineIndex.edit(0, lines[0].length, insertString); editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); checkText = editFlat(0, lines[0].length, insertString, content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // and insert with multiple line breaks insertString = "moo, \r\nmoo, \r\nmoo! "; snapshot = lineIndex.edit(0, lines[0].length, insertString); editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); checkText = editFlat(0, lines[0].length, insertString, content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); snapshot = lineIndex.edit(0, lines[0].length + lines[1].length, ""); editedText = snapshot.getText(0, content.length - (lines[0].length + lines[1].length)); checkText = editFlat(0, lines[0].length + lines[1].length, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); snapshot = lineIndex.edit(lines[0].length, lines[1].length + lines[2].length, ""); editedText = snapshot.getText(0, content.length - (lines[1].length + lines[2].length)); checkText = editFlat(lines[0].length, lines[1].length + lines[2].length, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case VI: insert multiple line breaks @@ -209,91 +175,71 @@ module ts{ snapshot = lineIndex.edit(21, 1, insertString); editedText = snapshot.getText(0, content.length + insertString.length - 1); checkText = editFlat(21, 1, insertString, content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); insertString = "cr...\r\ncr...\r\ncr"; snapshot = lineIndex.edit(21, 1, insertString); editedText = snapshot.getText(0, content.length + insertString.length - 1); checkText = editFlat(21, 1, insertString, content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // leading '\n' insertString = "\ncr...\r\ncr...\r\ncr"; snapshot = lineIndex.edit(21, 1, insertString); editedText = snapshot.getText(0, content.length + insertString.length - 1); checkText = editFlat(21, 1, insertString, content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case I: single line no line breaks deleted or inserted // delete 1 char snapshot = lineIndex.edit(21, 1); editedText = snapshot.getText(0, content.length - 1); checkText = editFlat(21, 1, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // insert 1 char snapshot = lineIndex.edit(21, 0, "b"); editedText = snapshot.getText(0, content.length + 1); checkText = editFlat(21, 0, "b", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // delete 1, insert 2 snapshot = lineIndex.edit(21, 1, "cr"); editedText = snapshot.getText(0, content.length + 1); checkText = editFlat(21, 1, "cr", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case II: delete across line break snapshot = lineIndex.edit(21, 22); editedText = snapshot.getText(0, content.length - 22); checkText = editFlat(21, 22, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); snapshot = lineIndex.edit(21, 32); editedText = snapshot.getText(0, content.length - 32); checkText = editFlat(21, 32, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); // Case III: delete across multiple line breaks and insert no line breaks snapshot = lineIndex.edit(21, 42); editedText = snapshot.getText(0, content.length - 42); checkText = editFlat(21, 42, "", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); snapshot = lineIndex.edit(21, 42, "slithery "); editedText = snapshot.getText(0, content.length - 33); checkText = editFlat(21, 42, "slithery ", content); - if (editedText != checkText) { - recordError(); - return; - } + + assert.equal(editedText, checkText); } function editStress(fname: string, timing: boolean) { @@ -346,10 +292,7 @@ module ts{ var s2 = lineIndex.getText(rsa[j], la[j]); if (!timing) { var s1 = content.substring(rsa[j], rsa[j] + la[j]); - if (s1 != s2) { - recordError(); - return; - } + assert.equal(s1, s2); } } if (timing) { @@ -363,10 +306,7 @@ module ts{ var s2 = lineIndex.getText(rsa[j], las[j]); if (!timing) { var s1 = content.substring(rsa[j], rsa[j] + las[j]); - if (s1 != s2) { - recordError(); - return; - } + assert.equal(s1, s2); } } // console.log("check2"); @@ -385,10 +325,7 @@ module ts{ var checkText = editFlat(rsa[j], las[j], insertString, content); var snapText = snapshot.getText(0, checkText.length); if (checkText != snapText) { - if (s1 != s2) { - recordError(); - return; - } + assert.equal(s1, s2); } } } @@ -413,10 +350,7 @@ module ts{ if (!timing) { snapText = snap.getText(0, checkText.length); if (checkText != snapText) { - if (s1 != s2) { - recordError(); - return; - } + assert.equal(s1, s2); } } } @@ -436,10 +370,7 @@ module ts{ checkText = editFlat(rsa[j], la[j], insertString, content); snapText = snapshot.getText(0, checkText.length); if (checkText != snapText) { - if (s1 != s2) { - recordError(); - return; - } + assert.equal(s1, s2); } } } @@ -456,18 +387,9 @@ module ts{ for (j = 0; j < 100000; j++) { var lp = lineIndex.charOffsetToLineNumberAndPos(rsa[j]); if (!timing) { - var lac = ts.getLineAndCharacterOfPosition(lineMap, rsa[j]); - - if (lac.line != lp.line) { - recordError(); - console.log("arrgh " + lac.line + " " + lp.line + " " + j); - return; - } - if (lac.character != (lp.offset + 1)) { - recordError(); - console.log("arrgh ch... " + lac.character + " " + (lp.offset + 1) + " " + j); - return; - } + var lac = ts.computeLineAndCharacterOfPosition(lineMap, rsa[j]); + assert.equal(lac.line, lp.line, "Line number mismatch " + lac.line + " " + lp.line + " " + j); + assert.equal(lac.character, (lp.offset + 1), "Charachter offset mismatch " + lac.character + " " + (lp.offset + 1) + " " + j); } } // console.log("check6"); @@ -489,10 +411,7 @@ module ts{ var lineIndexOffset = lineInfo.offset; if (!timing) { var lineMapOffset = lineMap[k]; - if (lineIndexOffset != lineMapOffset) { - recordError(); - return; - } + assert.equal(lineIndexOffset, lineMapOffset); } } } @@ -504,15 +423,7 @@ module ts{ function edTest() { editTest(); tstTest(); - if (!gloError) { - bigTest(); - } - if (gloError) { - console.log(" ! Fail: versionCache"); - } - else { - console.log("Pass"); - } + bigTest(); } edTest(); From b6d5781c117cfc738dd4eb79fb51f44050aeb18d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 12:25:44 -0700 Subject: [PATCH 19/51] Remove commented code --- tests/cases/unittests/versionCache.ts | 828 -------------------------- 1 file changed, 828 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 2dcf11a6278..8a4d1b1af0d 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -428,831 +428,3 @@ module ts{ edTest(); } - - -//module ts { -// ts.disableIncrementalParsing = false; - -// function withChange(text: IScriptSnapshot, start: number, length: number, newText: string): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { -// var contents = text.getText(0, text.getLength()); -// var newContents = contents.substr(0, start) + newText + contents.substring(start + length); - -// return { text: ScriptSnapshot.fromString(newContents), textChangeRange: createTextChangeRange(createTextSpan(start, length), newText.length) } -// } - -// function withInsert(text: IScriptSnapshot, start: number, newText: string): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { -// return withChange(text, start, 0, newText); -// } - -// function withDelete(text: IScriptSnapshot, start: number, length: number): { text: IScriptSnapshot; textChangeRange: TextChangeRange; } { -// return withChange(text, start, length, ""); -// } - -// function createTree(text: IScriptSnapshot, version: string) { -// return createLanguageServiceSourceFile(/*fileName:*/ "", text, ScriptTarget.Latest, version, /*setNodeParents:*/ true) -// } - -// function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) { -// var diagnostics1 = file1.parseDiagnostics; -// var diagnostics2 = file2.parseDiagnostics; - -// assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length"); -// for (var i = 0, n = diagnostics1.length; i < n; i++) { -// var d1 = diagnostics1[i]; -// var d2 = diagnostics2[i]; - -// assert.equal(d1.file, file1, "d1.file !== file1"); -// assert.equal(d2.file, file2, "d2.file !== file2"); -// assert.equal(d1.start, d2.start, "d1.start !== d2.start"); -// assert.equal(d1.length, d2.length, "d1.length !== d2.length"); -// assert.equal(d1.messageText, d2.messageText, "d1.messageText !== d2.messageText"); -// assert.equal(d1.category, d2.category, "d1.category !== d2.category"); -// assert.equal(d1.code, d2.code, "d1.code !== d2.code"); -// } -// } - -// // NOTE: 'reusedElements' is the expected count of elements reused from the old tree to the new -// // tree. It may change as we tweak the parser. If the count increases then that should always -// // be a good thing. If it decreases, that's not great (less reusability), but that may be -// // unavoidable. If it does decrease an investigation should be done to make sure that things -// // are still ok and we're still appropriately reusing most of the tree. -// function compareTrees(oldText: IScriptSnapshot, newText: IScriptSnapshot, textChangeRange: TextChangeRange, expectedReusedElements: number, oldTree?: SourceFile): SourceFile { -// oldTree = oldTree || createTree(oldText, /*version:*/ "."); -// Utils.assertInvariants(oldTree, /*parent:*/ undefined); - -// // Create a tree for the new text, in a non-incremental fashion. -// var newTree = createTree(newText, oldTree.version + "."); -// Utils.assertInvariants(newTree, /*parent:*/ undefined); - -// // Create a tree for the new text, in an incremental fashion. -// var incrementalNewTree = updateLanguageServiceSourceFile(oldTree, newText, oldTree.version + ".", textChangeRange); -// Utils.assertInvariants(incrementalNewTree, /*parent:*/ undefined); - -// // We should get the same tree when doign a full or incremental parse. -// Utils.assertStructuralEquals(newTree, incrementalNewTree); - -// // We should also get the exact same set of diagnostics. -// assertSameDiagnostics(newTree, incrementalNewTree); - -// // There should be no reused nodes between two trees that are fully parsed. -// assert.isTrue(reusedElements(oldTree, newTree) === 0); - -// assert.equal(newTree.fileName, incrementalNewTree.fileName, "newTree.fileName !== incrementalNewTree.fileName"); -// assert.equal(newTree.text, incrementalNewTree.text, "newTree.text !== incrementalNewTree.text"); - -// if (expectedReusedElements !== -1) { -// var actualReusedCount = reusedElements(oldTree, incrementalNewTree); -// assert.equal(actualReusedCount, expectedReusedElements, actualReusedCount + " !== " + expectedReusedElements); -// } - -// return incrementalNewTree; -// } - -// function reusedElements(oldNode: SourceFile, newNode: SourceFile): number { -// var allOldElements = collectElements(oldNode); -// var allNewElements = collectElements(newNode); - -// return filter(allOldElements, v => contains(allNewElements, v)).length; -// } - -// function collectElements(node: Node) { -// var result: Node[] = []; -// visit(node); -// return result; - -// function visit(node: Node) { -// result.push(node); -// forEachChild(node, visit); -// } -// } - -// function deleteCode(source: string, index: number, toDelete: string) { -// var repeat = toDelete.length; -// var oldTree = createTree(ScriptSnapshot.fromString(source), /*version:*/ "."); -// for (var i = 0; i < repeat; i++) { -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, 1); -// var newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); - -// source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); -// oldTree = newTree; -// } -// } - -// function insertCode(source: string, index: number, toInsert: string) { -// var repeat = toInsert.length; -// var oldTree = createTree(ScriptSnapshot.fromString(source), /*version:*/ "."); -// for (var i = 0; i < repeat; i++) { -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + i, toInsert.charAt(i)); -// var newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); - -// source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); -// oldTree = newTree; -// } -// } - -// describe('Incremental',() => { -// it('Inserting into method',() => { -// var source = "class C {\r\n" + -// " public foo1() { }\r\n" + -// " public foo2() {\r\n" + -// " return 1;\r\n" + -// " }\r\n" + -// " public foo3() { }\r\n" + -// "}"; - -// var oldText = ScriptSnapshot.fromString(source); -// var semicolonIndex = source.indexOf(";"); -// var newTextAndChange = withInsert(oldText, semicolonIndex, " + 1"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); -// }); - -// it('Deleting from method',() => { -// var source = "class C {\r\n" + -// " public foo1() { }\r\n" + -// " public foo2() {\r\n" + -// " return 1 + 1;\r\n" + -// " }\r\n" + -// " public foo3() { }\r\n" + -// "}"; - -// var index = source.indexOf("+ 1"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, "+ 1".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); -// }); - -// it('Regular expression 1',() => { -// var source = "class C { public foo1() { /; } public foo2() { return 1;} public foo3() { } }"; - -// var semicolonIndex = source.indexOf(";}"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Regular expression 2',() => { -// var source = "class C { public foo1() { ; } public foo2() { return 1/;} public foo3() { } }"; - -// var semicolonIndex = source.indexOf(";"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); -// }); - -// it('Comment 1',() => { -// var source = "class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; - -// var semicolonIndex = source.indexOf(";"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, semicolonIndex, "/"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Comment 2',() => { -// var source = "class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, 0, "//"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Comment 3',() => { -// var source = "//class C { public foo1() { /; } public foo2() { return 1; } public foo3() { } }"; - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, 0, 2); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Comment 4',() => { -// var source = "class C { public foo1() { /; } public foo2() { */ return 1; } public foo3() { } }"; - -// var index = source.indexOf(";"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index, "*"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); -// }); - -// it('Parameter 1',() => { -// // Should be able to reuse all the parameters. -// var source = "class C {\r\n" + -// " public foo2(a, b, c, d) {\r\n" + -// " return 1;\r\n" + -// " }\r\n" + -// "}"; - -// var semicolonIndex = source.indexOf(";"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, semicolonIndex, " + 1"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); -// }); - -// it('Type member 1',() => { -// // Should be able to reuse most of the type members. -// var source = "interface I { a: number; b: string; (c): d; new (e): f; g(): h }"; - -// var index = source.indexOf(": string"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index, "?"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 14); -// }); - -// it('Enum element 1',() => { -// // Should be able to reuse most of the enum elements. -// var source = "enum E { a = 1, b = 1 << 1, c = 3, e = 4, f = 5, g = 7, h = 8, i = 9, j = 10 }"; - -// var index = source.indexOf("<<"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, 2, "+"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 24); -// }); - -// it('Strict mode 1',() => { -// // In non-strict mode 'package' means nothing and can be reused. In strict mode though -// // we'll have to reparse the nodes (and generate an error for 'package();' -// // -// // Note: in this test we don't actually add 'use strict'. This is so we can compare -// // reuse with/without a strict mode change. -// var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();"; - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, 0, "'strict';\r\n"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 2',() => { -// // In non-strict mode 'package' means nothing and can be reused. In strict mode though -// // we'll have to reparse the nodes (and generate an error for 'package();' -// var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();"; - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, 0, "'use strict';\r\n"); - -// // Note the decreased reuse of nodes compared to 'Strict mode 1' -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 3',() => { -// // In non-strict mode 'package' means nothing and can be reused. In strict mode though -// // we'll have to reparse the nodes (and generate an error for 'package();' -// // -// // Note: in this test we don't actually remove 'use strict'. This is so we can compare -// // reuse with/without a strict mode change. -// var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();"; - -// var index = source.indexOf('f'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, 0, index); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 4',() => { -// // In non-strict mode 'package' means nothing and can be reused. In strict mode though -// // we'll have to reparse the nodes (and generate an error for 'package();' -// var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();"; - -// var index = source.indexOf('f'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, 0, index); - -// // Note the decreased reuse of nodes compared to testStrictMode3 -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 5',() => { -// var source = "'use blahhh';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; - -// var index = source.indexOf('b'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, 6, "strict"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 6',() => { -// var source = "'use strict';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; - -// var index = source.indexOf('s'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, 6, "blahhh"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Strict mode 7',() => { -// var source = "'use blahhh';\r\nfoo1();\r\nfoo2();\r\nfoo3();\r\nfoo4();\r\nfoo4();\r\nfoo6();\r\nfoo7();\r\nfoo8();\r\nfoo9();\r\n"; - -// var index = source.indexOf('f'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, 0, index); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Parenthesized expression to arrow function 1',() => { -// var source = "var v = (a, b, c, d, e)"; - -// var index = source.indexOf('a'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 1, ":"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Parenthesized expression to arrow function 2',() => { -// var source = "var v = (a, b) = c"; - -// var index = source.indexOf("= c") + 1; -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index, ">"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Arrow function to parenthesized expression 1',() => { -// var source = "var v = (a:, b, c, d, e)"; - -// var index = source.indexOf(':'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, 1); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Arrow function to parenthesized expression 2',() => { -// var source = "var v = (a, b) => c"; - -// var index = source.indexOf(">"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, 1); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Speculative generic lookahead 1',() => { -// var source = "var v = Fe"; - -// var index = source.indexOf('b'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 1, ",x"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); -// }); - -// it('Speculative generic lookahead 2',() => { -// var source = "var v = Fe"; - -// var index = source.indexOf('b'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 1, ",x"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); -// }); - -// it('Speculative generic lookahead 3',() => { -// var source = "var v = Fe"; - -// var index = source.indexOf('b'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 1, ",x"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); -// }); - -// it('Speculative generic lookahead 4',() => { -// var source = "var v = Fe"; - -// var index = source.indexOf('b'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 1, ",x"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); -// }); - -// it('Assertion to arrow function',() => { -// var source = "var v = (a);"; - -// var index = source.indexOf(';'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index, " => 1"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Arrow function to assertion',() => { -// var source = "var v = (a) => 1;"; - -// var index = source.indexOf(' =>'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, " => 1".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Contextual shift to shift-equals',() => { -// var source = "var v = 1 >> = 2"; - -// var index = source.indexOf('>> ='); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index + 2, 1); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Contextual shift-equals to shift',() => { -// var source = "var v = 1 >>= 2"; - -// var index = source.indexOf('>>='); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index + 2, " "); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Contextual shift to generic invocation',() => { -// var source = "var v = T>>(2)"; - -// var index = source.indexOf('T'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, index, "Foo { -// var source = "var v = Foo>(2)"; - -// var index = source.indexOf('Foo { -// var source = "var v = T>>=2;"; - -// var index = source.indexOf('='); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, "= ".length, ": Foo { -// var source = "var v : Foo>=2;"; - -// var index = source.indexOf(':'); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, ": Foo0"; - -// var index = source.indexOf("0"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, index, 1, "()"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Type argument list to arithmetic operator',() => { -// var source = "var v = new Dictionary()"; - -// var index = source.indexOf("()"); -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, index, 2); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Yield context 1',() => { -// // We're changing from a non-generator to a genarator. We can't reuse statement nodes. -// var source = "function foo() {\r\nyield(foo1);\r\n}"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("foo"); -// var newTextAndChange = withInsert(oldText, index, "*"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Yield context 2',() => { -// // We're changing from a generator to a non-genarator. We can't reuse statement nodes. -// var source = "function *foo() {\r\nyield(foo1);\r\n}"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("*"); -// var newTextAndChange = withDelete(oldText, index, "*".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Delete semicolon',() => { -// var source = "export class Foo {\r\n}\r\n\r\nexport var foo = new Foo();\r\n\r\n export function test(foo: Foo) {\r\n return true;\r\n }\r\n"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.lastIndexOf(";"); -// var newTextAndChange = withDelete(oldText, index, 1); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); -// }); - -// it('Edit after empty type parameter list',() => { -// var source = "class Dictionary<> { }\r\nvar y;\r\n"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.length; -// var newTextAndChange = withInsert(oldText, index, "var x;"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Delete parameter after comment',() => { -// var source = "function fn(/* comment! */ a: number, c) { }"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("a:"); -// var newTextAndChange = withDelete(oldText, index, "a: number,".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Modifier added to accessor',() => { -// var source = -// "class C {\ -// set Bar(bar:string) {}\ -//}\ -//var o2 = { set Foo(val:number) { } };"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("set"); -// var newTextAndChange = withInsert(oldText, index, "public "); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 6); -// }); - -// it('Insert parameter ahead of parameter',() => { -// var source = -// "alert(100);\ -//\ -//class OverloadedMonster {\ -//constructor();\ -//constructor(name) { }\ -//}"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("100"); -// var newTextAndChange = withInsert(oldText, index, "'1', "); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 5); -// }); - -// it('Insert declare modifier before module',() => { -// var source = -// "module mAmbient {\ -//module m3 { }\ -//}"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = 0; -// var newTextAndChange = withInsert(oldText, index, "declare "); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 3); -// }); - -// it('Insert function above arrow function with comment',() => { -// var source = -// "\ -//() =>\ -// // do something\ -//0;"; - -// var oldText = ScriptSnapshot.fromString(source); -// var index = 0; -// var newTextAndChange = withInsert(oldText, index, "function Foo() { }"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Finish incomplete regular expression',() => { -// var source = "while (true) /3; return;" - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.length - 1; -// var newTextAndChange = withInsert(oldText, index, "/"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Regular expression to divide operation',() => { -// var source = "return;\r\nwhile (true) /3/g;" - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("while"); -// var newTextAndChange = withDelete(oldText, index, "while ".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Divide operation to regular expression',() => { -// var source = "return;\r\n(true) /3/g;" - -// var oldText = ScriptSnapshot.fromString(source); -// var index = source.indexOf("("); -// var newTextAndChange = withInsert(oldText, index, "while "); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Unterminated comment after keyword converted to identifier',() => { -// // 'public' as a keyword should be incrementally unusable (because it has an -// // unterminated comment). When we convert it to an identifier, that shouldn't -// // change anything, and we should still get the same errors. -// var source = "return; a.public /*" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, 0, ""); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8); -// }); - -// it('Class to interface',() => { -// var source = "class A { public M1() { } public M2() { } public M3() { } p1 = 0; p2 = 0; p3 = 0 }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Interface to class',() => { -// var source = "interface A { M1?(); M2?(); M3?(); p1?; p2?; p3? }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Surrounding function declarations with block',() => { -// var source = "declare function F1() { } export function F2() { } declare export function F3() { }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withInsert(oldText, 0, "{"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9); -// }); - -// it('Removing block around function declarations',() => { -// var source = "{ declare function F1() { } export function F2() { } declare export function F3() { }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withDelete(oldText, 0, "{".length); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Moving methods from class to object literal',() => { -// var source = "class C { public A() { } public B() { } public C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "class C".length, "var v ="); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Moving methods from object literal to class',() => { -// var source = "var v = { public A() { } public B() { } public C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. -// }); - -// it('Moving methods from object literal to class in strict mode', () => { -// var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); -// }); - -// it('Moving index signatures from class to interface',() => { -// var source = "class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. -// }); - -// it('Moving index signatures from class to interface in strict mode', () => { -// var source = "\"use strict\"; class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 14, "class".length, "interface"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); -// }); - -// it('Moving index signatures from interface to class',() => { -// var source = "interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. -// }); - - -// it('Moving index signatures from interface to class in strict mode', () => { -// var source = "\"use strict\"; interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 14, "interface".length, "class"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); -// }); - -// it('Moving accessors from class to object literal',() => { -// var source = "class C { public get A() { } public get B() { } public get C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "class C".length, "var v ="); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); -// }); - -// it('Moving accessors from object literal to class',() => { -// var source = "var v = { public get A() { } public get B() { } public get C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. -// }); - - -// it('Moving accessors from object literal to class in strict mode', () => { -// var source = "\"use strict\"; var v = { public get A() { } public get B() { } public get C() { } }" - -// var oldText = ScriptSnapshot.fromString(source); -// var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); - -// compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); -// }); - -// // Simulated typing tests. - -// it('Type extends clause 1',() => { -// var source = "interface IFoo { }\r\ninterface Array extends IFoo { }"; - -// var index = source.indexOf('extends'); -// deleteCode(source, index, "extends IFoo"); -// }); - -// it('Type after incomplete enum 1',() => { -// var source = "function foo() {\r\n" + -// " function getOccurrencesAtPosition() {\r\n" + -// " switch (node) {\r\n" + -// " enum \r\n" + -// " }\r\n" + -// " \r\n" + -// " return undefined;\r\n" + -// " \r\n" + -// " function keywordToReferenceEntry() {\r\n" + -// " }\r\n" + -// " }\r\n" + -// " \r\n" + -// " return {\r\n" + -// " getEmitOutput: (fileName): Bar => null,\r\n" + -// " };\r\n" + -// " }"; - -// var index = source.indexOf("enum ") + "enum ".length; -// insertCode(source, index, "Fo"); -// }); -// }); -//} \ No newline at end of file From 3d4445c645792e12c05a431c0caaaaf12d800a02 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 12:42:40 -0700 Subject: [PATCH 20/51] Add contents for editTest --- tests/cases/unittests/versionCache.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 8a4d1b1af0d..2a39442e4ec 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -92,14 +92,17 @@ module ts{ } function editTest() { - var fname = testDataDir + 'editme'; - var content = ts.sys.readFile(fname); - var lm = server.LineIndex.linesFromText(content); - var lines = lm.lines; + var content = `in this story: +the lazy brown fox +jumped over the cow +that ate the grass +that was purple at the tips +and grew 1cm per day`; + + var {lines, lineMap} = server.LineIndex.linesFromText(content); if (lines.length == 0) { return; } - var lineMap = lm.lineMap; var lineIndex = new server.LineIndex(); lineIndex.load(lines); @@ -420,11 +423,11 @@ module ts{ } } - function edTest() { - editTest(); - tstTest(); - bigTest(); - } + //function edTest() { + // editTest(); + // tstTest(); + // bigTest(); + //} - edTest(); + //edTest(); } From cb00b472543f7774c739c3f52b406e73d3056127 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 13:32:53 -0700 Subject: [PATCH 21/51] use descript and it to run tests --- tests/cases/unittests/versionCache.ts | 220 ++++++++++++++------------ 1 file changed, 122 insertions(+), 98 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 2a39442e4ec..0a93fcb55cf 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -1,9 +1,9 @@ /// /// -module ts{ - function editFlat(s: number, dl: number, nt: string, source: string) { - return source.substring(0, s) + nt + source.substring(s + dl, source.length); +module ts { + function editFlat(position: number, deletedLength: number, newText: string, source: string) { + return source.substring(0, position) + newText + source.substring(position + deletedLength, source.length); } var testDataDir = "..\..\..\src\compiler"; @@ -91,7 +91,8 @@ module ts{ } } - function editTest() { + describe('versionCache -- Edit test', () => { + var content = `in this story: the lazy brown fox jumped over the cow @@ -113,137 +114,160 @@ and grew 1cm per day`; var checkText: string; var insertString: string; - // Case VII: insert at end of file - insertString = "hmmmm...\r\n"; - checkText = editFlat(content.length, 0, insertString, content); - snapshot = lineIndex.edit(content.length, 0, insertString); - editedText = snapshot.getText(0, checkText.length); + it('Case VII: insert at end of file', () => { + insertString = "hmmmm...\r\n"; + checkText = editFlat(content.length, 0, insertString, content); + snapshot = lineIndex.edit(content.length, 0, insertString); + editedText = snapshot.getText(0, checkText.length); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case IV: unusual line endings merge - snapshot = lineIndex.edit(lines[0].length - 1, lines[1].length, ""); - editedText = snapshot.getText(0, content.length - lines[1].length); - checkText = editFlat(lines[0].length - 1, lines[1].length, "", content); + it('Case IV: unusual line endings merge', () => { + snapshot = lineIndex.edit(lines[0].length - 1, lines[1].length, ""); + editedText = snapshot.getText(0, content.length - lines[1].length); + checkText = editFlat(lines[0].length - 1, lines[1].length, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case VIIa: delete whole line and nothing but line (last line) - var llpos = lm.lineMap[lm.lineMap.length - 2]; - snapshot = lineIndex.edit(llpos, lines[lines.length - 1].length, ""); - checkText = editFlat(llpos, lines[lines.length - 1].length, "", content); - editedText = snapshot.getText(0, checkText.length); + it('Case VIIa: delete whole line and nothing but line (last line)', () => { + var llpos = lineMap[lineMap.length - 2]; + snapshot = lineIndex.edit(llpos, lines[lines.length - 1].length, ""); + checkText = editFlat(llpos, lines[lines.length - 1].length, "", content); + editedText = snapshot.getText(0, checkText.length); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case VIIb: delete whole line and nothing but line (first line) - snapshot = lineIndex.edit(0, lines[0].length, ""); - editedText = snapshot.getText(0, content.length - lines[0].length); - checkText = editFlat(0, lines[0].length, "", content); + it('Case VIIb: delete whole line and nothing but line (first line)', () => { + snapshot = lineIndex.edit(0, lines[0].length, ""); + editedText = snapshot.getText(0, content.length - lines[0].length); + checkText = editFlat(0, lines[0].length, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // and insert with no line breaks - insertString = "moo, moo, moo! "; - snapshot = lineIndex.edit(0, lines[0].length, insertString); - editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); - checkText = editFlat(0, lines[0].length, insertString, content); + it('Case VIIc: delete whole line (first line) and insert with no line breaks', () => { + insertString = "moo, moo, moo! "; + snapshot = lineIndex.edit(0, lines[0].length, insertString); + editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); + checkText = editFlat(0, lines[0].length, insertString, content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // and insert with multiple line breaks - insertString = "moo, \r\nmoo, \r\nmoo! "; - snapshot = lineIndex.edit(0, lines[0].length, insertString); - editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); - checkText = editFlat(0, lines[0].length, insertString, content); + it('Case VIIc: delete whole line (first line) and insert with multiple line breaks', () => { + insertString = "moo, \r\nmoo, \r\nmoo! "; + snapshot = lineIndex.edit(0, lines[0].length, insertString); + editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); + checkText = editFlat(0, lines[0].length, insertString, content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - snapshot = lineIndex.edit(0, lines[0].length + lines[1].length, ""); - editedText = snapshot.getText(0, content.length - (lines[0].length + lines[1].length)); - checkText = editFlat(0, lines[0].length + lines[1].length, "", content); + it('Case VIId: delete multiple lines and nothing but lines (first and second lines)', () => { + snapshot = lineIndex.edit(0, lines[0].length + lines[1].length, ""); + editedText = snapshot.getText(0, content.length - (lines[0].length + lines[1].length)); + checkText = editFlat(0, lines[0].length + lines[1].length, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - snapshot = lineIndex.edit(lines[0].length, lines[1].length + lines[2].length, ""); + it('Case VIIe: delete multiple lines and nothing but lines (second and third lines)', () => { + snapshot = lineIndex.edit(lines[0].length, lines[1].length + lines[2].length, ""); - editedText = snapshot.getText(0, content.length - (lines[1].length + lines[2].length)); - checkText = editFlat(lines[0].length, lines[1].length + lines[2].length, "", content); + editedText = snapshot.getText(0, content.length - (lines[1].length + lines[2].length)); + checkText = editFlat(lines[0].length, lines[1].length + lines[2].length, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case VI: insert multiple line breaks + it('Case VI: insert multiple line breaks', () => { + insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); - insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); + assert.equal(editedText, checkText); + }); - assert.equal(editedText, checkText); + it('Case VIb: insert multiple line breaks', () => { - insertString = "cr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); + insertString = "cr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // leading '\n' - insertString = "\ncr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); + it('Case VIc: insert multiple line breaks with leading \\n', () => { + insertString = "\ncr...\r\ncr...\r\ncr"; + snapshot = lineIndex.edit(21, 1, insertString); + editedText = snapshot.getText(0, content.length + insertString.length - 1); + checkText = editFlat(21, 1, insertString, content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case I: single line no line breaks deleted or inserted - // delete 1 char - snapshot = lineIndex.edit(21, 1); - editedText = snapshot.getText(0, content.length - 1); - checkText = editFlat(21, 1, "", content); + it('Case I: single line no line breaks deleted or inserted, delete 1 char', () => { + snapshot = lineIndex.edit(21, 1); + editedText = snapshot.getText(0, content.length - 1); + checkText = editFlat(21, 1, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // insert 1 char - snapshot = lineIndex.edit(21, 0, "b"); - editedText = snapshot.getText(0, content.length + 1); - checkText = editFlat(21, 0, "b", content); + it('Case Ib: single line no line breaks deleted or inserted, insert 1 char', () => { + snapshot = lineIndex.edit(21, 0, "b"); + editedText = snapshot.getText(0, content.length + 1); + checkText = editFlat(21, 0, "b", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // delete 1, insert 2 - snapshot = lineIndex.edit(21, 1, "cr"); - editedText = snapshot.getText(0, content.length + 1); - checkText = editFlat(21, 1, "cr", content); + it('Case Ib: single line no line breaks deleted or inserted, delete 1, insert 2 chars', () => { + snapshot = lineIndex.edit(21, 1, "cr"); + editedText = snapshot.getText(0, content.length + 1); + checkText = editFlat(21, 1, "cr", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - // Case II: delete across line break - snapshot = lineIndex.edit(21, 22); - editedText = snapshot.getText(0, content.length - 22); - checkText = editFlat(21, 22, "", content); + it('Case II: delete across line break (just the line break)', () => { + snapshot = lineIndex.edit(21, 22); + editedText = snapshot.getText(0, content.length - 22); + checkText = editFlat(21, 22, "", content); - assert.equal(editedText, checkText); + assert.equal(editedText, checkText); + }); - snapshot = lineIndex.edit(21, 32); - editedText = snapshot.getText(0, content.length - 32); - checkText = editFlat(21, 32, "", content); + it('Case IIb: delete across line break', () => { - assert.equal(editedText, checkText); + snapshot = lineIndex.edit(21, 32); + editedText = snapshot.getText(0, content.length - 32); + checkText = editFlat(21, 32, "", content); - // Case III: delete across multiple line breaks and insert no line breaks - snapshot = lineIndex.edit(21, 42); - editedText = snapshot.getText(0, content.length - 42); - checkText = editFlat(21, 42, "", content); + assert.equal(editedText, checkText); + }); - assert.equal(editedText, checkText); + it('Case III: delete across multiple line breaks and insert no line breaks', () => { + snapshot = lineIndex.edit(21, 42); + editedText = snapshot.getText(0, content.length - 42); + checkText = editFlat(21, 42, "", content); - snapshot = lineIndex.edit(21, 42, "slithery "); - editedText = snapshot.getText(0, content.length - 33); - checkText = editFlat(21, 42, "slithery ", content); + assert.equal(editedText, checkText); + }); - assert.equal(editedText, checkText); - } + it('Case IIIb: delete across multiple line breaks and insert text', () => { + snapshot = lineIndex.edit(21, 42, "slithery "); + editedText = snapshot.getText(0, content.length - 33); + checkText = editFlat(21, 42, "slithery ", content); + + assert.equal(editedText, checkText); + }); + }); function editStress(fname: string, timing: boolean) { var content = ts.sys.readFile(testDataDir + fname); From 7f5337701f2fe3d11bf6449b92c4f74ed52d1482 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 13:40:17 -0700 Subject: [PATCH 22/51] Consolidate test logic in one helper function --- src/server/editorServices.ts | 4 + tests/cases/unittests/versionCache.ts | 119 ++++++-------------------- 2 files changed, 30 insertions(+), 93 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index a3814c8fec1..366e4dbfd84 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1466,6 +1466,10 @@ module ts.server { return accum; } + getLength(): number { + return this.root.charCount(); + } + every(f: (ll: LineLeaf, s: number, len: number) => boolean, rangeStart: number, rangeEnd?: number) { if (!rangeEnd) { rangeEnd = this.root.charCount(); diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 0a93fcb55cf..c739b0e9f32 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -114,158 +114,91 @@ and grew 1cm per day`; var checkText: string; var insertString: string; - it('Case VII: insert at end of file', () => { - insertString = "hmmmm...\r\n"; - checkText = editFlat(content.length, 0, insertString, content); - snapshot = lineIndex.edit(content.length, 0, insertString); - editedText = snapshot.getText(0, checkText.length); + function testEdit(position: number, deleteLength: number, insertString: string): void { + var checkText = editFlat(position, deleteLength, insertString, content); + snapshot = lineIndex.edit(position, deleteLength, insertString); + var editedText = snapshot.getText(0, snapshot.getLength()); assert.equal(editedText, checkText); + } + + it('Case VII: insert at end of file', () => { + insertString = "hmmmm...\r\n"; + testEdit(content.length, 0, insertString); }); it('Case IV: unusual line endings merge', () => { - snapshot = lineIndex.edit(lines[0].length - 1, lines[1].length, ""); - editedText = snapshot.getText(0, content.length - lines[1].length); - checkText = editFlat(lines[0].length - 1, lines[1].length, "", content); - - assert.equal(editedText, checkText); + testEdit(lines[0].length - 1, lines[1].length, ""); }); it('Case VIIa: delete whole line and nothing but line (last line)', () => { var llpos = lineMap[lineMap.length - 2]; - snapshot = lineIndex.edit(llpos, lines[lines.length - 1].length, ""); - checkText = editFlat(llpos, lines[lines.length - 1].length, "", content); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); + testEdit(llpos, lines[lines.length - 1].length, ""); }); it('Case VIIb: delete whole line and nothing but line (first line)', () => { - snapshot = lineIndex.edit(0, lines[0].length, ""); - editedText = snapshot.getText(0, content.length - lines[0].length); - checkText = editFlat(0, lines[0].length, "", content); - - assert.equal(editedText, checkText); + testEdit(0, lines[0].length, ""); }); it('Case VIIc: delete whole line (first line) and insert with no line breaks', () => { insertString = "moo, moo, moo! "; - snapshot = lineIndex.edit(0, lines[0].length, insertString); - editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); - checkText = editFlat(0, lines[0].length, insertString, content); - - assert.equal(editedText, checkText); + testEdit(0, lines[0].length, insertString); }); it('Case VIIc: delete whole line (first line) and insert with multiple line breaks', () => { insertString = "moo, \r\nmoo, \r\nmoo! "; - snapshot = lineIndex.edit(0, lines[0].length, insertString); - editedText = snapshot.getText(0, content.length - lines[0].length + insertString.length); - checkText = editFlat(0, lines[0].length, insertString, content); - - assert.equal(editedText, checkText); + testEdit(0, lines[0].length, insertString); }); it('Case VIId: delete multiple lines and nothing but lines (first and second lines)', () => { - snapshot = lineIndex.edit(0, lines[0].length + lines[1].length, ""); - editedText = snapshot.getText(0, content.length - (lines[0].length + lines[1].length)); - checkText = editFlat(0, lines[0].length + lines[1].length, "", content); - - assert.equal(editedText, checkText); + testEdit(0, lines[0].length + lines[1].length, ""); }); it('Case VIIe: delete multiple lines and nothing but lines (second and third lines)', () => { - snapshot = lineIndex.edit(lines[0].length, lines[1].length + lines[2].length, ""); - - editedText = snapshot.getText(0, content.length - (lines[1].length + lines[2].length)); - checkText = editFlat(lines[0].length, lines[1].length + lines[2].length, "", content); - - assert.equal(editedText, checkText); + testEdit(lines[0].length, lines[1].length + lines[2].length, ""); }); it('Case VI: insert multiple line breaks', () => { insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); - - assert.equal(editedText, checkText); + testEdit(21, 1, insertString); }); it('Case VIb: insert multiple line breaks', () => { - insertString = "cr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); - - assert.equal(editedText, checkText); + testEdit(21, 1, insertString); }); it('Case VIc: insert multiple line breaks with leading \\n', () => { insertString = "\ncr...\r\ncr...\r\ncr"; - snapshot = lineIndex.edit(21, 1, insertString); - editedText = snapshot.getText(0, content.length + insertString.length - 1); - checkText = editFlat(21, 1, insertString, content); - - assert.equal(editedText, checkText); + testEdit(21, 1, insertString); }); it('Case I: single line no line breaks deleted or inserted, delete 1 char', () => { - snapshot = lineIndex.edit(21, 1); - editedText = snapshot.getText(0, content.length - 1); - checkText = editFlat(21, 1, "", content); - - assert.equal(editedText, checkText); + testEdit(21, 1, ""); }); it('Case Ib: single line no line breaks deleted or inserted, insert 1 char', () => { - snapshot = lineIndex.edit(21, 0, "b"); - editedText = snapshot.getText(0, content.length + 1); - checkText = editFlat(21, 0, "b", content); - - assert.equal(editedText, checkText); + testEdit(21, 0, "b"); }); it('Case Ib: single line no line breaks deleted or inserted, delete 1, insert 2 chars', () => { - snapshot = lineIndex.edit(21, 1, "cr"); - editedText = snapshot.getText(0, content.length + 1); - checkText = editFlat(21, 1, "cr", content); - - assert.equal(editedText, checkText); + testEdit(21, 1, "cr"); }); it('Case II: delete across line break (just the line break)', () => { - snapshot = lineIndex.edit(21, 22); - editedText = snapshot.getText(0, content.length - 22); - checkText = editFlat(21, 22, "", content); - - assert.equal(editedText, checkText); + testEdit(21, 22, ""); }); it('Case IIb: delete across line break', () => { - - snapshot = lineIndex.edit(21, 32); - editedText = snapshot.getText(0, content.length - 32); - checkText = editFlat(21, 32, "", content); - - assert.equal(editedText, checkText); + testEdit(21, 32, ""); }); it('Case III: delete across multiple line breaks and insert no line breaks', () => { - snapshot = lineIndex.edit(21, 42); - editedText = snapshot.getText(0, content.length - 42); - checkText = editFlat(21, 42, "", content); - - assert.equal(editedText, checkText); + testEdit(21, 42, ""); }); it('Case IIIb: delete across multiple line breaks and insert text', () => { - snapshot = lineIndex.edit(21, 42, "slithery "); - editedText = snapshot.getText(0, content.length - 33); - checkText = editFlat(21, 42, "slithery ", content); - - assert.equal(editedText, checkText); + testEdit(21, 42, "slithery "); }); }); From 79af91a8e9d027a9f612eb49b37428ee20b98737 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 13:45:11 -0700 Subject: [PATCH 23/51] Cleanup --- tests/cases/unittests/versionCache.ts | 46 +++++++++------------------ 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index c739b0e9f32..8fe8109315e 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -92,39 +92,29 @@ module ts { } describe('versionCache -- Edit test', () => { - - var content = `in this story: + let testContent = `in this story: the lazy brown fox jumped over the cow that ate the grass that was purple at the tips and grew 1cm per day`; - var {lines, lineMap} = server.LineIndex.linesFromText(content); - if (lines.length == 0) { - return; - } + let {lines, lineMap} = server.LineIndex.linesFromText(testContent); + assert.isTrue(lines.length > 0, "Failed to initialize test text. Expected text to have at least one line"); - var lineIndex = new server.LineIndex(); + let lineIndex = new server.LineIndex(); lineIndex.load(lines); - var editedText = lineIndex.getText(0, content.length); - - var snapshot: server.LineIndex; - var checkText: string; - var insertString: string; - function testEdit(position: number, deleteLength: number, insertString: string): void { - var checkText = editFlat(position, deleteLength, insertString, content); - snapshot = lineIndex.edit(position, deleteLength, insertString); - var editedText = snapshot.getText(0, snapshot.getLength()); + let checkText = editFlat(position, deleteLength, insertString, testContent); + let snapshot = lineIndex.edit(position, deleteLength, insertString); + let editedText = snapshot.getText(0, snapshot.getLength()); assert.equal(editedText, checkText); } - + it('Case VII: insert at end of file', () => { - insertString = "hmmmm...\r\n"; - testEdit(content.length, 0, insertString); + testEdit(testContent.length, 0, "hmmmm...\r\n"); }); it('Case IV: unusual line endings merge', () => { @@ -132,8 +122,7 @@ and grew 1cm per day`; }); it('Case VIIa: delete whole line and nothing but line (last line)', () => { - var llpos = lineMap[lineMap.length - 2]; - testEdit(llpos, lines[lines.length - 1].length, ""); + testEdit(lineMap[lineMap.length - 2], lines[lines.length - 1].length, ""); }); it('Case VIIb: delete whole line and nothing but line (first line)', () => { @@ -141,13 +130,11 @@ and grew 1cm per day`; }); it('Case VIIc: delete whole line (first line) and insert with no line breaks', () => { - insertString = "moo, moo, moo! "; - testEdit(0, lines[0].length, insertString); + testEdit(0, lines[0].length, "moo, moo, moo! "); }); it('Case VIIc: delete whole line (first line) and insert with multiple line breaks', () => { - insertString = "moo, \r\nmoo, \r\nmoo! "; - testEdit(0, lines[0].length, insertString); + testEdit(0, lines[0].length, "moo, \r\nmoo, \r\nmoo! "); }); it('Case VIId: delete multiple lines and nothing but lines (first and second lines)', () => { @@ -159,18 +146,15 @@ and grew 1cm per day`; }); it('Case VI: insert multiple line breaks', () => { - insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"; - testEdit(21, 1, insertString); + testEdit(21, 1, "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"); }); it('Case VIb: insert multiple line breaks', () => { - insertString = "cr...\r\ncr...\r\ncr"; - testEdit(21, 1, insertString); + testEdit(21, 1, "cr...\r\ncr...\r\ncr"); }); it('Case VIc: insert multiple line breaks with leading \\n', () => { - insertString = "\ncr...\r\ncr...\r\ncr"; - testEdit(21, 1, insertString); + testEdit(21, 1, "\ncr...\r\ncr...\r\ncr"); }); it('Case I: single line no line breaks deleted or inserted, delete 1 char', () => { From 1f75c0388409cf0369e8117a3d559a4611e14aed Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 13:48:53 -0700 Subject: [PATCH 24/51] Update test names --- tests/cases/unittests/versionCache.ts | 39 +++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 8fe8109315e..3a9d9bd5a9f 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -91,7 +91,7 @@ module ts { } } - describe('versionCache -- Edit test', () => { + describe('VersionCache edit', () => { let testContent = `in this story: the lazy brown fox jumped over the cow @@ -113,75 +113,75 @@ and grew 1cm per day`; assert.equal(editedText, checkText); } - it('Case VII: insert at end of file', () => { + it('Insert at end of file', () => { testEdit(testContent.length, 0, "hmmmm...\r\n"); }); - it('Case IV: unusual line endings merge', () => { + it('Unusual line endings merge', () => { testEdit(lines[0].length - 1, lines[1].length, ""); }); - it('Case VIIa: delete whole line and nothing but line (last line)', () => { + it('Delete whole line and nothing but line (last line)', () => { testEdit(lineMap[lineMap.length - 2], lines[lines.length - 1].length, ""); }); - it('Case VIIb: delete whole line and nothing but line (first line)', () => { + it('Delete whole line and nothing but line (first line)', () => { testEdit(0, lines[0].length, ""); }); - it('Case VIIc: delete whole line (first line) and insert with no line breaks', () => { + it('Delete whole line (first line) and insert with no line breaks', () => { testEdit(0, lines[0].length, "moo, moo, moo! "); }); - it('Case VIIc: delete whole line (first line) and insert with multiple line breaks', () => { + it('Delete whole line (first line) and insert with multiple line breaks', () => { testEdit(0, lines[0].length, "moo, \r\nmoo, \r\nmoo! "); }); - it('Case VIId: delete multiple lines and nothing but lines (first and second lines)', () => { + it('Delete multiple lines and nothing but lines (first and second lines)', () => { testEdit(0, lines[0].length + lines[1].length, ""); }); - it('Case VIIe: delete multiple lines and nothing but lines (second and third lines)', () => { + it('Delete multiple lines and nothing but lines (second and third lines)', () => { testEdit(lines[0].length, lines[1].length + lines[2].length, ""); }); - it('Case VI: insert multiple line breaks', () => { + it('Insert multiple line breaks', () => { testEdit(21, 1, "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"); }); - it('Case VIb: insert multiple line breaks', () => { + it('Insert multiple line breaks', () => { testEdit(21, 1, "cr...\r\ncr...\r\ncr"); }); - it('Case VIc: insert multiple line breaks with leading \\n', () => { + it('Insert multiple line breaks with leading \\n', () => { testEdit(21, 1, "\ncr...\r\ncr...\r\ncr"); }); - it('Case I: single line no line breaks deleted or inserted, delete 1 char', () => { + it('Single line no line breaks deleted or inserted, delete 1 char', () => { testEdit(21, 1, ""); }); - it('Case Ib: single line no line breaks deleted or inserted, insert 1 char', () => { + it('Single line no line breaks deleted or inserted, insert 1 char', () => { testEdit(21, 0, "b"); }); - it('Case Ib: single line no line breaks deleted or inserted, delete 1, insert 2 chars', () => { + it('Single line no line breaks deleted or inserted, delete 1, insert 2 chars', () => { testEdit(21, 1, "cr"); }); - it('Case II: delete across line break (just the line break)', () => { + it('Delete across line break (just the line break)', () => { testEdit(21, 22, ""); }); - it('Case IIb: delete across line break', () => { + it('Delete across line break', () => { testEdit(21, 32, ""); }); - it('Case III: delete across multiple line breaks and insert no line breaks', () => { + it('Delete across multiple line breaks and insert no line breaks', () => { testEdit(21, 42, ""); }); - it('Case IIIb: delete across multiple line breaks and insert text', () => { + it('Delete across multiple line breaks and insert text', () => { testEdit(21, 42, "slithery "); }); }); @@ -365,7 +365,6 @@ and grew 1cm per day`; } //function edTest() { - // editTest(); // tstTest(); // bigTest(); //} From 82884e8f26e20c4ce6a572ece7cb8df130fb70f8 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 14:43:36 -0700 Subject: [PATCH 25/51] wire tst tests --- tests/cases/unittests/versionCache.ts | 181 ++++++++++++-------------- 1 file changed, 80 insertions(+), 101 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 3a9d9bd5a9f..f0848828ac5 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -14,84 +14,68 @@ module ts { editStress("binder.ts", false); } - function tstTest() { - var fname = testDataDir + 'tst.ts'; - var content = ts.sys.readFile(fname); - var lm = server.LineIndex.linesFromText(content); - var lines = lm.lines; - if (lines.length == 0) { - return; - } - var lineMap = lm.lineMap; - - var lineIndex = new server.LineIndex(); - lineIndex.load(lines); - - var editedText = lineIndex.getText(0, content.length); - - var snapshot: server.LineIndex; - var checkText: string; - var insertString: string; - - // change 9 1 0 1 {"y"} - var pos = lineColToPosition(lineIndex, 9, 1); - insertString = "y"; - checkText = editFlat(pos, 0, insertString, content); - snapshot = lineIndex.edit(pos, 0, insertString); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - // change 9 2 0 1 {"."} - var pos = lineColToPosition(snapshot, 9, 2); - insertString = "."; - checkText = editFlat(pos, 0, insertString, checkText); - snapshot = snapshot.edit(pos, 0, insertString); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - // change 9 3 0 1 {"\n"} - var pos = lineColToPosition(snapshot, 9, 3); - insertString = "\n"; - checkText = editFlat(pos, 0, insertString, checkText); - snapshot = snapshot.edit(pos, 0, insertString); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - // change 10 1 0 10 {"\n\n\n\n\n\n\n\n\n\n"} - pos = lineColToPosition(snapshot, 10, 1); - insertString = "\n\n\n\n\n\n\n\n\n\n"; - checkText = editFlat(pos, 0, insertString, checkText); - snapshot = snapshot.edit(pos, 0, insertString); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - // change 19 1 1 0 - pos = lineColToPosition(snapshot, 19, 1); - checkText = editFlat(pos, 1, "", checkText); - snapshot = snapshot.edit(pos, 1); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - // change 18 1 1 0 - pos = lineColToPosition(snapshot, 18, 1); - checkText = editFlat(pos, 1, "", checkText); - snapshot = snapshot.edit(pos, 1); - editedText = snapshot.getText(0, checkText.length); - - assert.equal(editedText, checkText); - - function lineColToPosition(lineIndex: server.LineIndex, line: number, col: number) { - var lineInfo = lineIndex.lineNumberToInfo(line); - return (lineInfo.offset + col - 1); - } + function lineColToPosition(lineIndex: server.LineIndex, line: number, col: number) { + var lineInfo = lineIndex.lineNumberToInfo(line); + return (lineInfo.offset + col - 1); } - describe('VersionCache edit', () => { + function validateEdit(lineIndex: server.LineIndex, sourceText: string, position: number, deleteLength: number, insertString: string): void { + let checkText = editFlat(position, deleteLength, insertString, sourceText); + let snapshot = lineIndex.edit(position, deleteLength, insertString); + let editedText = snapshot.getText(0, snapshot.getLength()); + + assert.equal(editedText, checkText); + } + + describe('VersionCache TS code', () => { + var testContent = `/// +var x = 10; +var y = { zebra: 12, giraffe: "ell" }; +z.a; +class Point { + x: number; +} +k=y; +var p:Point=new Point(); +var q:Point=p;` + + let {lines, lineMap} = server.LineIndex.linesFromText(testContent); + assert.isTrue(lines.length > 0, "Failed to initialize test text. Expected text to have at least one line"); + + let lineIndex = new server.LineIndex(); + lineIndex.load(lines); + + function validateEditAtLineCharIndex(line: number, char: number, deleteLength: number, insertString: string): void { + let position = lineColToPosition(lineIndex, line, char); + validateEdit(lineIndex, testContent, position, deleteLength, insertString); + } + + it('change 9 1 0 1 {"y"}', () => { + validateEditAtLineCharIndex(9, 1, 0, "y"); + }); + + it('change 9 2 0 1 {"."}', () => { + validateEditAtLineCharIndex(9, 2, 0, "."); + }); + + it('change 9 3 0 1 {"\\n"}', () => { + validateEditAtLineCharIndex(9, 3, 0, "\n"); + }); + + it('change 10 1 0 10 {"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n"}', () => { + validateEditAtLineCharIndex(10, 1, 0, "\n\n\n\n\n\n\n\n\n\n"); + }); + + it('change 19 1 1 0', () => { + validateEditAtLineCharIndex(19, 1, 1, ""); + }); + + it('change 18 1 1 0', () => { + validateEditAtLineCharIndex(18, 1, 1, ""); + }); + }); + + describe('VersionCache simple text', () => { let testContent = `in this story: the lazy brown fox jumped over the cow @@ -105,84 +89,80 @@ and grew 1cm per day`; let lineIndex = new server.LineIndex(); lineIndex.load(lines); - function testEdit(position: number, deleteLength: number, insertString: string): void { - let checkText = editFlat(position, deleteLength, insertString, testContent); - let snapshot = lineIndex.edit(position, deleteLength, insertString); - let editedText = snapshot.getText(0, snapshot.getLength()); - - assert.equal(editedText, checkText); + function validateEditAtPosition(position: number, deleteLength: number, insertString: string): void { + validateEdit(lineIndex, testContent, position, deleteLength, insertString); } it('Insert at end of file', () => { - testEdit(testContent.length, 0, "hmmmm...\r\n"); + validateEditAtPosition(testContent.length, 0, "hmmmm...\r\n"); }); it('Unusual line endings merge', () => { - testEdit(lines[0].length - 1, lines[1].length, ""); + validateEditAtPosition(lines[0].length - 1, lines[1].length, ""); }); it('Delete whole line and nothing but line (last line)', () => { - testEdit(lineMap[lineMap.length - 2], lines[lines.length - 1].length, ""); + validateEditAtPosition(lineMap[lineMap.length - 2], lines[lines.length - 1].length, ""); }); it('Delete whole line and nothing but line (first line)', () => { - testEdit(0, lines[0].length, ""); + validateEditAtPosition(0, lines[0].length, ""); }); it('Delete whole line (first line) and insert with no line breaks', () => { - testEdit(0, lines[0].length, "moo, moo, moo! "); + validateEditAtPosition(0, lines[0].length, "moo, moo, moo! "); }); it('Delete whole line (first line) and insert with multiple line breaks', () => { - testEdit(0, lines[0].length, "moo, \r\nmoo, \r\nmoo! "); + validateEditAtPosition(0, lines[0].length, "moo, \r\nmoo, \r\nmoo! "); }); it('Delete multiple lines and nothing but lines (first and second lines)', () => { - testEdit(0, lines[0].length + lines[1].length, ""); + validateEditAtPosition(0, lines[0].length + lines[1].length, ""); }); it('Delete multiple lines and nothing but lines (second and third lines)', () => { - testEdit(lines[0].length, lines[1].length + lines[2].length, ""); + validateEditAtPosition(lines[0].length, lines[1].length + lines[2].length, ""); }); it('Insert multiple line breaks', () => { - testEdit(21, 1, "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"); + validateEditAtPosition(21, 1, "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr"); }); it('Insert multiple line breaks', () => { - testEdit(21, 1, "cr...\r\ncr...\r\ncr"); + validateEditAtPosition(21, 1, "cr...\r\ncr...\r\ncr"); }); it('Insert multiple line breaks with leading \\n', () => { - testEdit(21, 1, "\ncr...\r\ncr...\r\ncr"); + validateEditAtPosition(21, 1, "\ncr...\r\ncr...\r\ncr"); }); it('Single line no line breaks deleted or inserted, delete 1 char', () => { - testEdit(21, 1, ""); + validateEditAtPosition(21, 1, ""); }); it('Single line no line breaks deleted or inserted, insert 1 char', () => { - testEdit(21, 0, "b"); + validateEditAtPosition(21, 0, "b"); }); it('Single line no line breaks deleted or inserted, delete 1, insert 2 chars', () => { - testEdit(21, 1, "cr"); + validateEditAtPosition(21, 1, "cr"); }); it('Delete across line break (just the line break)', () => { - testEdit(21, 22, ""); + validateEditAtPosition(21, 22, ""); }); it('Delete across line break', () => { - testEdit(21, 32, ""); + validateEditAtPosition(21, 32, ""); }); it('Delete across multiple line breaks and insert no line breaks', () => { - testEdit(21, 42, ""); + validateEditAtPosition(21, 42, ""); }); it('Delete across multiple line breaks and insert text', () => { - testEdit(21, 42, "slithery "); + validateEditAtPosition(21, 42, "slithery "); }); }); @@ -365,7 +345,6 @@ and grew 1cm per day`; } //function edTest() { - // tstTest(); // bigTest(); //} From 4bf91fd4ce6ef06265ae1702df2ac4d6d69ea5f8 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 17:30:48 -0700 Subject: [PATCH 26/51] Wire stress tests --- tests/cases/unittests/versionCache.ts | 235 +++++++++----------------- 1 file changed, 81 insertions(+), 154 deletions(-) diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index f0848828ac5..5d10ed5006a 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -6,14 +6,6 @@ module ts { return source.substring(0, position) + newText + source.substring(position + deletedLength, source.length); } - var testDataDir = "..\..\..\src\compiler"; - - function bigTest() { - editStress("scanner.ts", false); - editStress("sys.ts", false); - editStress("binder.ts", false); - } - function lineColToPosition(lineIndex: server.LineIndex, line: number, col: number) { var lineInfo = lineIndex.lineNumberToInfo(line); return (lineInfo.offset + col - 1); @@ -166,29 +158,31 @@ and grew 1cm per day`; }); }); - function editStress(fname: string, timing: boolean) { - var content = ts.sys.readFile(testDataDir + fname); - var lm = server.LineIndex.linesFromText(content); - var lines = lm.lines; - if (lines.length == 0) { - return; - } - var lineMap = lm.lineMap; + describe('VersionCache stress test', () => { + const interationCount = 20; + //const interationCount = 20000; // uncomment for testing - var lineIndex = new server.LineIndex(); + // Use scanner.ts, decent size, does not change frequentlly + let testFileName = "src/compiler/scanner.ts"; + let testContent = Harness.IO.readFile(testFileName); + let totalChars = testContent.length; + assert.isTrue(totalChars > 0, "Failed to read test file."); + + let {lines, lineMap} = server.LineIndex.linesFromText(testContent); + assert.isTrue(lines.length > 0, "Failed to initialize test text. Expected text to have at least one line"); + + let lineIndex = new server.LineIndex(); lineIndex.load(lines); - var totalChars = content.length; - var rsa: number[] = []; - var la: number[] = []; - var las: number[] = []; - var elas: number[] = []; - var ersa: number[] = []; - var ela: number[] = []; - var etotalChars = totalChars; - var j: number; - var startTime: number; - for (j = 0; j < 100000; j++) { + let rsa: number[] = []; + let la: number[] = []; + let las: number[] = []; + let elas: number[] = []; + let ersa: number[] = []; + let ela: number[] = []; + let etotalChars = totalChars; + + for (let j = 0; j < 100000; j++) { rsa[j] = Math.floor(Math.random() * totalChars); la[j] = Math.floor(Math.random() * (totalChars - rsa[j])); if (la[j] > 4) { @@ -209,144 +203,77 @@ and grew 1cm per day`; etotalChars += (las[j] - elas[j]); } } - if (timing) { - startTime = Date.now(); - } - for (j = 0; j < 2000; j++) { - var s2 = lineIndex.getText(rsa[j], la[j]); - if (!timing) { - var s1 = content.substring(rsa[j], rsa[j] + la[j]); + + it("Range (average length 1/4 file size)", () => { + for (let i = 0; i < interationCount; i++) { + let s2 = lineIndex.getText(rsa[i], la[i]); + let s1 = testContent.substring(rsa[i], rsa[i] + la[i]); assert.equal(s1, s2); } - } - if (timing) { - console.log("range (average length 1/4 file size): " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); - } - // console.log("check1"); - if (timing) { - startTime = Date.now(); - } - for (j = 0; j < 10000; j++) { - var s2 = lineIndex.getText(rsa[j], las[j]); - if (!timing) { - var s1 = content.substring(rsa[j], rsa[j] + las[j]); + }); + + it("Range (average length 4 chars)", () => { + for (let j = 0; j < interationCount; j++) { + let s2 = lineIndex.getText(rsa[j], las[j]); + let s1 = testContent.substring(rsa[j], rsa[j] + las[j]); assert.equal(s1, s2); } - } - // console.log("check2"); - if (timing) { - console.log("range (average length 4 chars): " + ((Date.now() - startTime) / 10).toFixed(3) + " us"); - } + }); - if (timing) { - startTime = Date.now(); - } - var snapshot: server.LineIndex; - for (j = 0; j < 2000; j++) { - var insertString = content.substring(rsa[100000 - j], rsa[100000 - j] + las[100000 - j]); - snapshot = lineIndex.edit(rsa[j], las[j], insertString); - if (!timing) { - var checkText = editFlat(rsa[j], las[j], insertString, content); - var snapText = snapshot.getText(0, checkText.length); - if (checkText != snapText) { - assert.equal(s1, s2); + it("Edit (average length 4)", () => { + for (let i = 0; i < interationCount; i++) { + let insertString = testContent.substring(rsa[100000 - i], rsa[100000 - i] + las[100000 - i]); + let snapshot = lineIndex.edit(rsa[i], las[i], insertString); + let checkText = editFlat(rsa[i], las[i], insertString, testContent); + let snapText = snapshot.getText(0, checkText.length); + assert.equal(checkText, snapText); + } + }); + + it("Edit ScriptVersionCache ", () => { + let svc = server.ScriptVersionCache.fromString(testContent); + let checkText = testContent; + + for (let i = 0; i < interationCount; i++) { + let insertString = testContent.substring(rsa[i], rsa[i] + las[i]); + svc.edit(ersa[i], elas[i], insertString); + checkText = editFlat(ersa[i], elas[i], insertString, checkText); + if (0 == (i % 4)) { + let snap = svc.getSnapshot(); + let snapText = snap.getText(0, checkText.length); + assert.equal(checkText, snapText); } } - } - // console.log("check3"); - if (timing) { - console.log("edit (average length 4): " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); - } + }); - var svc = server.ScriptVersionCache.fromString(content); - checkText = content; - if (timing) { - startTime = Date.now(); - } - for (j = 0; j < 2000; j++) { - insertString = content.substring(rsa[j], rsa[j] + las[j]); - svc.edit(ersa[j], elas[j], insertString); - if (!timing) { - checkText = editFlat(ersa[j], elas[j], insertString, checkText); + it("Edit (average length 1/4th file size)", () => { + for (let i = 0; i < interationCount; i++) { + let insertString = testContent.substring(rsa[100000 - i], rsa[100000 - i] + la[100000 - i]); + let snapshot = lineIndex.edit(rsa[i], la[i], insertString); + let checkText = editFlat(rsa[i], la[i], insertString, testContent); + let snapText = snapshot.getText(0, checkText.length); + assert.equal(checkText, snapText); } - if (0 == (j % 4)) { - var snap = svc.getSnapshot(); - if (!timing) { - snapText = snap.getText(0, checkText.length); - if (checkText != snapText) { - assert.equal(s1, s2); - } - } + }); + + it("Line/offset from pos", () => { + for (let i = 0; i < interationCount; i++) { + let lp = lineIndex.charOffsetToLineNumberAndPos(rsa[i]); + let lac = ts.computeLineAndCharacterOfPosition(lineMap, rsa[i]); + assert.equal(lac.line + 1, lp.line, "Line number mismatch " + (lac.line + 1) + " " + lp.line + " " + i); + assert.equal(lac.character, (lp.offset), "Charachter offset mismatch " + lac.character + " " + lp.offset + " " + i); } - } - if (timing) { - console.log("edit ScriptVersionCache: " + ((Date.now() - startTime) / 2).toFixed(3) + " us"); - } + }); - // console.log("check4"); - if (timing) { - startTime = Date.now(); - } - for (j = 0; j < 5000; j++) { - insertString = content.substring(rsa[100000 - j], rsa[100000 - j] + la[100000 - j]); - snapshot = lineIndex.edit(rsa[j], la[j], insertString); - if (!timing) { - checkText = editFlat(rsa[j], la[j], insertString, content); - snapText = snapshot.getText(0, checkText.length); - if (checkText != snapText) { - assert.equal(s1, s2); - } - } - } - if (timing) { - console.log("edit (average length 1/4th file size): " + ((Date.now() - startTime) / 5).toFixed(3) + " us"); - } - - var t: ts.LineAndCharacter; - var errorCount = 0; - if (timing) { - startTime = Date.now(); - } - // console.log("check5"); - for (j = 0; j < 100000; j++) { - var lp = lineIndex.charOffsetToLineNumberAndPos(rsa[j]); - if (!timing) { - var lac = ts.computeLineAndCharacterOfPosition(lineMap, rsa[j]); - assert.equal(lac.line, lp.line, "Line number mismatch " + lac.line + " " + lp.line + " " + j); - assert.equal(lac.character, (lp.offset + 1), "Charachter offset mismatch " + lac.character + " " + (lp.offset + 1) + " " + j); - } - } - // console.log("check6"); - if (timing) { - console.log("line/offset from pos: " + ((Date.now() - startTime) / 100).toFixed(3) + " us"); - } - - if (timing) { - startTime = Date.now(); - } - - var outer = 1; - if (timing) { - outer = 100; - } - for (var ko = 0; ko < outer; ko++) { - for (var k = 0, llen = lines.length; k < llen; k++) { - var lineInfo = lineIndex.lineNumberToInfo(k + 1); - var lineIndexOffset = lineInfo.offset; - if (!timing) { - var lineMapOffset = lineMap[k]; + it("Start pos from line", () => { + for (let i = 0; i < interationCount; i++) { + for (let j = 0, llen = lines.length; j < llen; j++) { + let lineInfo = lineIndex.lineNumberToInfo(j + 1); + let lineIndexOffset = lineInfo.offset; + let lineMapOffset = lineMap[j]; assert.equal(lineIndexOffset, lineMapOffset); } } - } - if (timing) { - console.log("start pos from line: " + (((Date.now() - startTime) / lines.length) * 10).toFixed(3) + " us"); - } - } - - //function edTest() { - // bigTest(); - //} - - //edTest(); + }); + }); } From 82bc91467c0d44156984813680548e0602a94d18 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 17:30:57 -0700 Subject: [PATCH 27/51] Add to build --- Jakefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jakefile b/Jakefile index 665bb807b43..a777e134dfd 100644 --- a/Jakefile +++ b/Jakefile @@ -143,7 +143,8 @@ var harnessSources = [ "services/colorization.ts", "services/documentRegistry.ts", "services/preProcessFile.ts", - "services/patternMatcher.ts" + "services/patternMatcher.ts", + "versionCache.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })).concat([ From 72d23c7937f270db2e23b5daa600757d8bbb62d5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 31 Mar 2015 17:48:07 -0700 Subject: [PATCH 28/51] Remove unnecessary code. --- src/services/services.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index a518c3a94d0..19c545019a8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5369,12 +5369,6 @@ module ts { function getEmitOutput(fileName: string): EmitOutput { synchronizeHostData(); - // If the option is set to not emit on errors, and there are any errors, then we don't - // want to proceed. - if (program.getCompilerOptions().noEmitOnError && getPreEmitDiagnostics(program).length > 0) { - return { outputFiles: [], emitSkipped: true }; - } - let sourceFile = getValidSourceFile(fileName); let outputFiles: OutputFile[] = []; From 434764329324f38f43c3e02b1003cbd119105d2c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 31 Mar 2015 18:17:35 -0700 Subject: [PATCH 29/51] CR feedback. --- src/harness/fourslash.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 1f233a4bfb8..7269b2db75d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -116,7 +116,7 @@ module FourSlash { // Name of testcase metadata including ts.CompilerOptions properties that will be used by globalOptions // To add additional option, add property into the testOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames // Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data - var testOptMetadataNames = { + var metadataOptionNames = { baselineFile: 'BaselineFile', declaration: 'declaration', emitThisFile: 'emitThisFile', // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project @@ -132,10 +132,10 @@ module FourSlash { }; // List of allowed metadata names - var fileMetadataNames = [testOptMetadataNames.fileName, testOptMetadataNames.emitThisFile, testOptMetadataNames.resolveReference]; - var globalMetadataNames = [testOptMetadataNames.allowNonTsExtensions, testOptMetadataNames.baselineFile, testOptMetadataNames.declaration, - testOptMetadataNames.mapRoot, testOptMetadataNames.module, testOptMetadataNames.out, - testOptMetadataNames.outDir, testOptMetadataNames.sourceMap, testOptMetadataNames.sourceRoot] + var fileMetadataNames = [metadataOptionNames.fileName, metadataOptionNames.emitThisFile, metadataOptionNames.resolveReference]; + var globalMetadataNames = [metadataOptionNames.allowNonTsExtensions, metadataOptionNames.baselineFile, metadataOptionNames.declaration, + metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out, + metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot] function convertGlobalOptionsToCompilerOptions(globalOptions: { [idx: string]: string }): ts.CompilerOptions { var settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5 }; @@ -143,16 +143,16 @@ module FourSlash { for (var prop in globalOptions) { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { - case testOptMetadataNames.allowNonTsExtensions: + case metadataOptionNames.allowNonTsExtensions: settings.allowNonTsExtensions = true; break; - case testOptMetadataNames.declaration: + case metadataOptionNames.declaration: settings.declaration = true; break; - case testOptMetadataNames.mapRoot: + case metadataOptionNames.mapRoot: settings.mapRoot = globalOptions[prop]; break; - case testOptMetadataNames.module: + case metadataOptionNames.module: // create appropriate external module target for CompilationSettings switch (globalOptions[prop]) { case "AMD": @@ -167,16 +167,16 @@ module FourSlash { break; } break; - case testOptMetadataNames.out: + case metadataOptionNames.out: settings.out = globalOptions[prop]; break; - case testOptMetadataNames.outDir: + case metadataOptionNames.outDir: settings.outDir = globalOptions[prop]; break; - case testOptMetadataNames.sourceMap: + case metadataOptionNames.sourceMap: settings.sourceMap = true; break; - case testOptMetadataNames.sourceRoot: + case metadataOptionNames.sourceRoot: settings.sourceRoot = globalOptions[prop]; break; } @@ -308,7 +308,7 @@ module FourSlash { ts.forEach(testData.files, file => { // Create map between fileName and its content for easily looking up when resolveReference flag is specified this.inputFiles[file.fileName] = file.content; - if (!startResolveFileRef && file.fileOptions[testOptMetadataNames.resolveReference]) { + if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference]) { startResolveFileRef = file; } else if (startResolveFileRef) { // If entry point for resolving file references is already specified, report duplication error @@ -1143,7 +1143,7 @@ module FourSlash { Harness.Baseline.runBaseline( "Breakpoint Locations for " + this.activeFile.fileName, - this.testData.globalOptions[testOptMetadataNames.baselineFile], + this.testData.globalOptions[metadataOptionNames.baselineFile], () => { return this.baselineCurrentFileLocations(pos => this.getBreakpointStatementLocation(pos)); }, @@ -1158,7 +1158,7 @@ module FourSlash { var allFourSlashFiles = this.testData.files; for (var idx = 0; idx < allFourSlashFiles.length; ++idx) { var file = allFourSlashFiles[idx]; - if (file.fileOptions[testOptMetadataNames.emitThisFile]) { + if (file.fileOptions[metadataOptionNames.emitThisFile]) { // Find a file with the flag emitThisFile turned on emitFiles.push(file); } @@ -1171,7 +1171,7 @@ module FourSlash { Harness.Baseline.runBaseline( "Generate getEmitOutput baseline : " + emitFiles.join(" "), - this.testData.globalOptions[testOptMetadataNames.baselineFile], + this.testData.globalOptions[metadataOptionNames.baselineFile], () => { var resultString = ""; // Loop through all the emittedFiles and emit them one by one @@ -1716,7 +1716,7 @@ module FourSlash { Harness.Baseline.runBaseline( "Name OrDottedNameSpans for " + this.activeFile.fileName, - this.testData.globalOptions[testOptMetadataNames.baselineFile], + this.testData.globalOptions[metadataOptionNames.baselineFile], () => { return this.baselineCurrentFileLocations(pos => this.getNameOrDottedNameSpan(pos)); @@ -2292,7 +2292,7 @@ module FourSlash { if (globalMetadataNamesIndex === -1) { if (fileMetadataNamesIndex === -1) { throw new Error('Unrecognized metadata name "' + match[1] + '". Available global metadata names are: ' + globalMetadataNames.join(', ') + '; file metadata names are: ' + fileMetadataNames.join(', ')); - } else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(testOptMetadataNames.fileName)) { + } else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(metadataOptionNames.fileName)) { // Found an @FileName directive, if this is not the first then create a new subfile if (currentFileContent) { var file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges); From 54e1928b2ac048bc3a69ea1ec7516cd5cc04a62d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 31 Mar 2015 18:34:43 -0700 Subject: [PATCH 30/51] Moved arrow function to function declaration. --- src/compiler/checker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6bd75c5d283..b2f6e1634c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -74,7 +74,7 @@ module ts { isImplementationOfOverload, getAliasedSymbol: resolveAlias, getEmitResolver, - getExportsOfModule: moduleSymbol => symbolsToArray(getExportsOfModule(moduleSymbol)), + getExportsOfModule: getExportsOfModuleAsArray, }; let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); @@ -872,6 +872,10 @@ module ts { return moduleSymbol.exports["export="]; } + function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] { + return symbolsToArray(getExportsOfModule(moduleSymbol)); + } + function getExportsOfSymbol(symbol: Symbol): SymbolTable { return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports || emptySymbols; } From d06f3aa22478e4f5d1065dcd2ddc7b6f020aa105 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 31 Mar 2015 19:07:45 -0700 Subject: [PATCH 31/51] Update test. --- tests/baselines/reference/APISample_linter.types.pull | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/baselines/reference/APISample_linter.types.pull b/tests/baselines/reference/APISample_linter.types.pull index 759a8390d60..252478fb73a 100644 --- a/tests/baselines/reference/APISample_linter.types.pull +++ b/tests/baselines/reference/APISample_linter.types.pull @@ -5883,6 +5883,9 @@ declare module "typescript" { kindModifiers: string; >kindModifiers : string + + sortText: string; +>sortText : string } interface CompletionEntryDetails { >CompletionEntryDetails : CompletionEntryDetails @@ -6152,6 +6155,9 @@ declare module "typescript" { static unknown: string; >unknown : string + static warning: string; +>warning : string + static keyword: string; >keyword : string From 4f78695740159ed9cb93cace0ac78b7db044254f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 20:42:45 -0700 Subject: [PATCH 32/51] Respond to code review comments --- Jakefile | 2 +- tests/cases/unittests/versionCache.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Jakefile b/Jakefile index a777e134dfd..3d733c4c5ae 100644 --- a/Jakefile +++ b/Jakefile @@ -144,7 +144,7 @@ var harnessSources = [ "services/documentRegistry.ts", "services/preProcessFile.ts", "services/patternMatcher.ts", - "versionCache.ts" + "versionCache.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })).concat([ diff --git a/tests/cases/unittests/versionCache.ts b/tests/cases/unittests/versionCache.ts index 5d10ed5006a..12cf9c1b817 100644 --- a/tests/cases/unittests/versionCache.ts +++ b/tests/cases/unittests/versionCache.ts @@ -159,7 +159,7 @@ and grew 1cm per day`; }); describe('VersionCache stress test', () => { - const interationCount = 20; + const iterationCount = 20; //const interationCount = 20000; // uncomment for testing // Use scanner.ts, decent size, does not change frequentlly @@ -205,7 +205,7 @@ and grew 1cm per day`; } it("Range (average length 1/4 file size)", () => { - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { let s2 = lineIndex.getText(rsa[i], la[i]); let s1 = testContent.substring(rsa[i], rsa[i] + la[i]); assert.equal(s1, s2); @@ -213,7 +213,7 @@ and grew 1cm per day`; }); it("Range (average length 4 chars)", () => { - for (let j = 0; j < interationCount; j++) { + for (let j = 0; j < iterationCount; j++) { let s2 = lineIndex.getText(rsa[j], las[j]); let s1 = testContent.substring(rsa[j], rsa[j] + las[j]); assert.equal(s1, s2); @@ -221,7 +221,7 @@ and grew 1cm per day`; }); it("Edit (average length 4)", () => { - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { let insertString = testContent.substring(rsa[100000 - i], rsa[100000 - i] + las[100000 - i]); let snapshot = lineIndex.edit(rsa[i], las[i], insertString); let checkText = editFlat(rsa[i], las[i], insertString, testContent); @@ -234,7 +234,7 @@ and grew 1cm per day`; let svc = server.ScriptVersionCache.fromString(testContent); let checkText = testContent; - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { let insertString = testContent.substring(rsa[i], rsa[i] + las[i]); svc.edit(ersa[i], elas[i], insertString); checkText = editFlat(ersa[i], elas[i], insertString, checkText); @@ -247,7 +247,7 @@ and grew 1cm per day`; }); it("Edit (average length 1/4th file size)", () => { - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { let insertString = testContent.substring(rsa[100000 - i], rsa[100000 - i] + la[100000 - i]); let snapshot = lineIndex.edit(rsa[i], la[i], insertString); let checkText = editFlat(rsa[i], la[i], insertString, testContent); @@ -257,7 +257,7 @@ and grew 1cm per day`; }); it("Line/offset from pos", () => { - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { let lp = lineIndex.charOffsetToLineNumberAndPos(rsa[i]); let lac = ts.computeLineAndCharacterOfPosition(lineMap, rsa[i]); assert.equal(lac.line + 1, lp.line, "Line number mismatch " + (lac.line + 1) + " " + lp.line + " " + i); @@ -266,7 +266,7 @@ and grew 1cm per day`; }); it("Start pos from line", () => { - for (let i = 0; i < interationCount; i++) { + for (let i = 0; i < iterationCount; i++) { for (let j = 0, llen = lines.length; j < llen; j++) { let lineInfo = lineIndex.lineNumberToInfo(j + 1); let lineIndexOffset = lineInfo.offset; From 27f5a28d0121df4cab76364546a97fe29a0ebb2d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 31 Mar 2015 21:49:31 -0700 Subject: [PATCH 33/51] mend --- .../reference/APISample_linter.types.pull | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/baselines/reference/APISample_linter.types.pull b/tests/baselines/reference/APISample_linter.types.pull index 759a8390d60..e2a29716fcc 100644 --- a/tests/baselines/reference/APISample_linter.types.pull +++ b/tests/baselines/reference/APISample_linter.types.pull @@ -4984,6 +4984,27 @@ declare module "typescript" { >CompilerHost : CompilerHost >Program : Program } +declare module "typescript" { + /** + * Read tsconfig.json file + * @param fileName The path to the config file + */ + function readConfigFile(fileName: string): any; +>readConfigFile : (fileName: string) => any +>fileName : string + + /** + * Parse the contents of a config file (tsconfig.json). + * @param json The contents of the config file to parse + * @param basePath A root directory to resolve relative path entries in the config + * file to. e.g. outDir + */ + function parseConfigFile(json: any, basePath?: string): ParsedCommandLine; +>parseConfigFile : (json: any, basePath?: string) => ParsedCommandLine +>json : any +>basePath : string +>ParsedCommandLine : ParsedCommandLine +} declare module "typescript" { /** The version of the language service API */ let servicesVersion: string; From 3290814b714b932a2e842c6988b62cd085008d10 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 1 Apr 2015 12:31:39 -0700 Subject: [PATCH 34/51] Update test. --- tests/baselines/reference/APISample_linter.types.pull | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/APISample_linter.types.pull b/tests/baselines/reference/APISample_linter.types.pull index e2a29716fcc..68ff796104b 100644 --- a/tests/baselines/reference/APISample_linter.types.pull +++ b/tests/baselines/reference/APISample_linter.types.pull @@ -2453,9 +2453,8 @@ declare module "typescript" { >expression : Expression >Expression : Expression } - interface ImportDeclaration extends Statement, ModuleElement { + interface ImportDeclaration extends ModuleElement { >ImportDeclaration : ImportDeclaration ->Statement : Statement >ModuleElement : ModuleElement importClause?: ImportClause; @@ -2964,10 +2963,10 @@ declare module "typescript" { >Symbol : Symbol >Symbol : Symbol - getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; ->getExportsOfExternalModule : (node: ImportDeclaration) => Symbol[] ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + getExportsOfModule(moduleSymbol: Symbol): Symbol[]; +>getExportsOfModule : (moduleSymbol: Symbol) => Symbol[] +>moduleSymbol : Symbol +>Symbol : Symbol >Symbol : Symbol } interface SymbolDisplayBuilder { From 22a87fb9cafce07e2701d15a95415349e161154a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2015 16:24:51 -0700 Subject: [PATCH 35/51] Class declarations should be block scoped. --- src/compiler/binder.ts | 17 +++++++---- .../classDeclarationBlockScoping1.errors.txt | 13 +++++++++ .../classDeclarationBlockScoping1.js | 22 ++++++++++++++ .../classDeclarationBlockScoping2.errors.txt | 18 ++++++++++++ .../classDeclarationBlockScoping2.js | 29 +++++++++++++++++++ .../reference/externModule.errors.txt | 14 ++++++++- .../compiler/classDeclarationBlockScoping1.ts | 7 +++++ .../compiler/classDeclarationBlockScoping2.ts | 9 ++++++ 8 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/classDeclarationBlockScoping1.errors.txt create mode 100644 tests/baselines/reference/classDeclarationBlockScoping1.js create mode 100644 tests/baselines/reference/classDeclarationBlockScoping2.errors.txt create mode 100644 tests/baselines/reference/classDeclarationBlockScoping2.js create mode 100644 tests/cases/compiler/classDeclarationBlockScoping1.ts create mode 100644 tests/cases/compiler/classDeclarationBlockScoping2.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0ae33d08fd6..494570c85c1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -388,23 +388,28 @@ module ts { bindChildren(node, /*symbolKind:*/ 0, /*isBlockScopeContainer:*/ true); } - function bindBlockScopedVariableDeclaration(node: Declaration) { + function bindBlockScopedDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { switch (blockScopeContainer.kind) { case SyntaxKind.ModuleDeclaration: - declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + declareModuleMember(node, symbolKind, symbolExcludes); break; case SyntaxKind.SourceFile: if (isExternalModule(container)) { - declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + declareModuleMember(node, symbolKind, symbolExcludes); break; } + // fall through. default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = {}; } - declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); } - bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false); + bindChildren(node, symbolKind, /*isBlockScopeContainer*/ false); + } + + function bindBlockScopedVariableDeclaration(node: Declaration) { + bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); } function getDestructuringParameterName(node: Declaration) { @@ -493,7 +498,7 @@ module ts { bindCatchVariableDeclaration(node); break; case SyntaxKind.ClassDeclaration: - bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false); + bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); break; case SyntaxKind.InterfaceDeclaration: bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false); diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt new file mode 100644 index 00000000000..4f15007bb2a --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/classDeclarationBlockScoping1.ts(5,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. + + +==== tests/cases/compiler/classDeclarationBlockScoping1.ts (1 errors) ==== + class C { + } + + { + class C { + ~ +!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.js b/tests/baselines/reference/classDeclarationBlockScoping1.js new file mode 100644 index 00000000000..717c2f788c3 --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping1.js @@ -0,0 +1,22 @@ +//// [classDeclarationBlockScoping1.ts] +class C { +} + +{ + class C { + } +} + +//// [classDeclarationBlockScoping1.js] +var C = (function () { + function C() { + } + return C; +})(); +{ + var C = (function () { + function C() { + } + return C; + })(); +} diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt new file mode 100644 index 00000000000..2a9885e110b --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/classDeclarationBlockScoping2.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping2.ts(5,15): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. + + +==== tests/cases/compiler/classDeclarationBlockScoping2.ts (2 errors) ==== + function f() { + class C {} + ~ +!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. + var c1 = C; + { + class C {} + ~ +!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. + var c2 = C; + } + return C === c1; + } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.js b/tests/baselines/reference/classDeclarationBlockScoping2.js new file mode 100644 index 00000000000..9e468077119 --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping2.js @@ -0,0 +1,29 @@ +//// [classDeclarationBlockScoping2.ts] +function f() { + class C {} + var c1 = C; + { + class C {} + var c2 = C; + } + return C === c1; +} + +//// [classDeclarationBlockScoping2.js] +function f() { + var C = (function () { + function C() { + } + return C; + })(); + var c1 = C; + { + var C = (function () { + function C() { + } + return C; + })(); + var c2 = C; + } + return C === c1; +} diff --git a/tests/baselines/reference/externModule.errors.txt b/tests/baselines/reference/externModule.errors.txt index d16c71ab05b..8d4126350c1 100644 --- a/tests/baselines/reference/externModule.errors.txt +++ b/tests/baselines/reference/externModule.errors.txt @@ -8,9 +8,13 @@ tests/cases/compiler/externModule.ts(18,6): error TS2390: Constructor implementa tests/cases/compiler/externModule.ts(20,13): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/compiler/externModule.ts(26,13): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/compiler/externModule.ts(28,13): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/externModule.ts(32,11): error TS2304: Cannot find name 'XDate'. +tests/cases/compiler/externModule.ts(34,7): error TS2304: Cannot find name 'XDate'. +tests/cases/compiler/externModule.ts(36,7): error TS2304: Cannot find name 'XDate'. +tests/cases/compiler/externModule.ts(37,3): error TS2304: Cannot find name 'XDate'. -==== tests/cases/compiler/externModule.ts (10 errors) ==== +==== tests/cases/compiler/externModule.ts (14 errors) ==== declare module { ~~~~~~~ !!! error TS2304: Cannot find name 'declare'. @@ -63,10 +67,18 @@ tests/cases/compiler/externModule.ts(28,13): error TS2391: Function implementati } var d=new XDate(); + ~~~~~ +!!! error TS2304: Cannot find name 'XDate'. d.getDay(); d=new XDate(1978,2); + ~~~~~ +!!! error TS2304: Cannot find name 'XDate'. d.getXDate(); var n=XDate.parse("3/2/2004"); + ~~~~~ +!!! error TS2304: Cannot find name 'XDate'. n=XDate.UTC(1964,2,1); + ~~~~~ +!!! error TS2304: Cannot find name 'XDate'. \ No newline at end of file diff --git a/tests/cases/compiler/classDeclarationBlockScoping1.ts b/tests/cases/compiler/classDeclarationBlockScoping1.ts new file mode 100644 index 00000000000..b6012f785b6 --- /dev/null +++ b/tests/cases/compiler/classDeclarationBlockScoping1.ts @@ -0,0 +1,7 @@ +class C { +} + +{ + class C { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/classDeclarationBlockScoping2.ts b/tests/cases/compiler/classDeclarationBlockScoping2.ts new file mode 100644 index 00000000000..2a0c4c1213f --- /dev/null +++ b/tests/cases/compiler/classDeclarationBlockScoping2.ts @@ -0,0 +1,9 @@ +function f() { + class C {} + var c1 = C; + { + class C {} + var c2 = C; + } + return C === c1; +} \ No newline at end of file From ba8be9eef4a8e0a17467609f143e741ed8f9317f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2015 17:20:20 -0700 Subject: [PATCH 36/51] Support classes without names in our AST. Report any issues with this at 'check' time. --- src/compiler/checker.ts | 7 ++++++- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/parser.ts | 2 +- src/services/navigationBar.ts | 6 +++--- .../reference/anonymousClassExpression1.errors.txt | 9 +++++++++ .../reference/anonymousClassExpression1.js | 13 +++++++++++++ .../classDeclarationBlockScoping1.errors.txt | 4 ++-- .../classDeclarationBlockScoping2.errors.txt | 8 ++++---- .../reference/classExpressionTest1.errors.txt | 4 ++-- .../baselines/reference/classInsideBlock.errors.txt | 4 ++-- .../classWithPredefinedTypesAsNames2.errors.txt | 4 ++-- .../reference/classWithPredefinedTypesAsNames2.js | 6 +++--- ...objectTypesWithPredefinedTypesAsName2.errors.txt | 4 ++-- .../objectTypesWithPredefinedTypesAsName2.js | 6 +++--- ...validIdentifiersInVariableStatements1.errors.txt | 4 ++-- ...parserInvalidIdentifiersInVariableStatements1.js | 6 +++--- tests/cases/compiler/anonymousClassExpression1.ts | 3 +++ .../cases/fourslash/scriptLexicalStructureItems2.ts | 2 +- .../fourslash/scriptLexicalStructureMissingName2.ts | 2 +- 20 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 tests/baselines/reference/anonymousClassExpression1.errors.txt create mode 100644 tests/baselines/reference/anonymousClassExpression1.js create mode 100644 tests/cases/compiler/anonymousClassExpression1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ce7fe5e1cf..f9d91ab083c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9757,7 +9757,12 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking if (node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { - grammarErrorOnNode(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); + grammarErrorOnFirstToken(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); + } + + // node.flags & NodeFlags.Default || kind === SyntaxKind.ClassExpression + if (!node.name && !(node.flags & NodeFlags.Default)) { + grammarErrorOnNode(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } checkGrammarClassDeclarationHeritageClauses(node); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 3e9017786e5..b141ce607f2 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -167,6 +167,7 @@ module ts { Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." }, Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1210, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f6edb3150b6..cafc1f5efa9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -659,6 +659,10 @@ "category": "Error", "code": 1209 }, + "A class declaration without the 'default' modifier must have a name": { + "category": "Error", + "code": 1210 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2972fba3979..7a28ad0441b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4764,7 +4764,7 @@ module ts { node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); - node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); + node.name = parseOptionalIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause:*/ true); diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index c6463aba733..e475827837c 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -418,10 +418,10 @@ module ts.NavigationBar { } function createFunctionItem(node: FunctionDeclaration) { - if ((node.name || node.flags & NodeFlags.Default) && node.body && node.body.kind === SyntaxKind.Block) { + if (node.body && node.body.kind === SyntaxKind.Block) { let childItems = getItemsWorker(sortNodes((node.body).statements), createChildItem); - return getNavigationBarItem((!node.name && node.flags & NodeFlags.Default) ? "default": node.name.text , + return getNavigationBarItem(!node.name ? "default": node.name.text , ts.ScriptElementKind.functionElement, getNodeModifiers(node), [getNodeSpan(node)], @@ -470,7 +470,7 @@ module ts.NavigationBar { childItems = getItemsWorker(sortNodes(nodes), createChildItem); } - var nodeName = !node.name && (node.flags & NodeFlags.Default) ? "default" : node.name.text; + var nodeName = !node.name ? "default" : node.name.text; return getNavigationBarItem( nodeName, diff --git a/tests/baselines/reference/anonymousClassExpression1.errors.txt b/tests/baselines/reference/anonymousClassExpression1.errors.txt new file mode 100644 index 00000000000..db4c5b4ce3d --- /dev/null +++ b/tests/baselines/reference/anonymousClassExpression1.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/anonymousClassExpression1.ts(2,19): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/anonymousClassExpression1.ts (1 errors) ==== + function f() { + return typeof class {} === "function"; + ~~~~~ +!!! error TS9003: 'class' expressions are not currently supported. + } \ No newline at end of file diff --git a/tests/baselines/reference/anonymousClassExpression1.js b/tests/baselines/reference/anonymousClassExpression1.js new file mode 100644 index 00000000000..a796b126a0e --- /dev/null +++ b/tests/baselines/reference/anonymousClassExpression1.js @@ -0,0 +1,13 @@ +//// [anonymousClassExpression1.ts] +function f() { + return typeof class {} === "function"; +} + +//// [anonymousClassExpression1.js] +function f() { + return typeof (function () { + function () { + } + return ; + })() === "function"; +} diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt index 4f15007bb2a..367e53c0660 100644 --- a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt +++ b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classDeclarationBlockScoping1.ts(5,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping1.ts(5,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classDeclarationBlockScoping1.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/classDeclarationBlockScoping1.ts(5,11): error TS9004: 'clas { class C { - ~ + ~~~~~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. } } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt index 2a9885e110b..a6d320fa415 100644 --- a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt +++ b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/classDeclarationBlockScoping2.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. -tests/cases/compiler/classDeclarationBlockScoping2.ts(5,15): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping2.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping2.ts(5,9): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classDeclarationBlockScoping2.ts (2 errors) ==== function f() { class C {} - ~ + ~~~~~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. var c1 = C; { class C {} - ~ + ~~~~~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. var c2 = C; } diff --git a/tests/baselines/reference/classExpressionTest1.errors.txt b/tests/baselines/reference/classExpressionTest1.errors.txt index 4d7e1cda639..2da1f0427c3 100644 --- a/tests/baselines/reference/classExpressionTest1.errors.txt +++ b/tests/baselines/reference/classExpressionTest1.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/classExpressionTest1.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classExpressionTest1.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classExpressionTest1.ts (1 errors) ==== function M() { class C { - ~ + ~~~~~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. f() { var t: T; diff --git a/tests/baselines/reference/classInsideBlock.errors.txt b/tests/baselines/reference/classInsideBlock.errors.txt index 369e77735e2..8fb8e165b1d 100644 --- a/tests/baselines/reference/classInsideBlock.errors.txt +++ b/tests/baselines/reference/classInsideBlock.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts (1 errors) ==== function foo() { class C { } - ~ + ~~~~~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. } \ No newline at end of file diff --git a/tests/baselines/reference/classWithPredefinedTypesAsNames2.errors.txt b/tests/baselines/reference/classWithPredefinedTypesAsNames2.errors.txt index 73cb373180c..84c258b550d 100644 --- a/tests/baselines/reference/classWithPredefinedTypesAsNames2.errors.txt +++ b/tests/baselines/reference/classWithPredefinedTypesAsNames2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/classDeclarations/classWithPredefinedTypesAsNames2.ts(3,7): error TS1003: Identifier expected. +tests/cases/conformance/classes/classDeclarations/classWithPredefinedTypesAsNames2.ts(3,7): error TS1005: '{' expected. ==== tests/cases/conformance/classes/classDeclarations/classWithPredefinedTypesAsNames2.ts (1 errors) ==== @@ -6,4 +6,4 @@ tests/cases/conformance/classes/classDeclarations/classWithPredefinedTypesAsName class void {} ~~~~ -!!! error TS1003: Identifier expected. \ No newline at end of file +!!! error TS1005: '{' expected. \ No newline at end of file diff --git a/tests/baselines/reference/classWithPredefinedTypesAsNames2.js b/tests/baselines/reference/classWithPredefinedTypesAsNames2.js index a47adcbe32f..91ff735accc 100644 --- a/tests/baselines/reference/classWithPredefinedTypesAsNames2.js +++ b/tests/baselines/reference/classWithPredefinedTypesAsNames2.js @@ -5,9 +5,9 @@ class void {} //// [classWithPredefinedTypesAsNames2.js] // classes cannot use predefined types as names -var = (function () { - function () { +var default_1 = (function () { + function default_1() { } - return ; + return default_1; })(); void {}; diff --git a/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.errors.txt b/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.errors.txt index 32a693abdcb..f2dbd672300 100644 --- a/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.errors.txt +++ b/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/specifyingTypes/predefinedTypes/objectTypesWithPredefinedTypesAsName2.ts(3,7): error TS1003: Identifier expected. +tests/cases/conformance/types/specifyingTypes/predefinedTypes/objectTypesWithPredefinedTypesAsName2.ts(3,7): error TS1005: '{' expected. ==== tests/cases/conformance/types/specifyingTypes/predefinedTypes/objectTypesWithPredefinedTypesAsName2.ts (1 errors) ==== @@ -6,4 +6,4 @@ tests/cases/conformance/types/specifyingTypes/predefinedTypes/objectTypesWithPre class void {} // parse error unlike the others ~~~~ -!!! error TS1003: Identifier expected. \ No newline at end of file +!!! error TS1005: '{' expected. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.js b/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.js index b47901b2f0c..974744f1870 100644 --- a/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.js +++ b/tests/baselines/reference/objectTypesWithPredefinedTypesAsName2.js @@ -5,9 +5,9 @@ class void {} // parse error unlike the others //// [objectTypesWithPredefinedTypesAsName2.js] // it is an error to use a predefined type as a type name -var = (function () { - function () { +var default_1 = (function () { + function default_1() { } - return ; + return default_1; })(); void {}; // parse error unlike the others diff --git a/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.errors.txt b/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.errors.txt index 35b279b4437..d7245fc7082 100644 --- a/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.errors.txt +++ b/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInvalidIdentifiersInVariableStatements1.ts(1,5): error TS1134: Variable declaration expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInvalidIdentifiersInVariableStatements1.ts(3,5): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInvalidIdentifiersInVariableStatements1.ts(3,10): error TS1003: Identifier expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInvalidIdentifiersInVariableStatements1.ts(3,10): error TS1005: '{' expected. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInvalidIdentifiersInVariableStatements1.ts (3 errors) ==== @@ -12,6 +12,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserInv ~~~~~ !!! error TS1134: Variable declaration expected. ~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. var bar; \ No newline at end of file diff --git a/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.js b/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.js index 422b0122466..e6b9c9fa1b8 100644 --- a/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.js +++ b/tests/baselines/reference/parserInvalidIdentifiersInVariableStatements1.js @@ -9,10 +9,10 @@ var bar; var ; var foo; var ; -var = (function () { - function () { +var default_1 = (function () { + function default_1() { } - return ; + return default_1; })(); ; var bar; diff --git a/tests/cases/compiler/anonymousClassExpression1.ts b/tests/cases/compiler/anonymousClassExpression1.ts new file mode 100644 index 00000000000..594ac092512 --- /dev/null +++ b/tests/cases/compiler/anonymousClassExpression1.ts @@ -0,0 +1,3 @@ +function f() { + return typeof class {} === "function"; +} \ No newline at end of file diff --git a/tests/cases/fourslash/scriptLexicalStructureItems2.ts b/tests/cases/fourslash/scriptLexicalStructureItems2.ts index 7022c082ced..3b94260ddbd 100644 --- a/tests/cases/fourslash/scriptLexicalStructureItems2.ts +++ b/tests/cases/fourslash/scriptLexicalStructureItems2.ts @@ -8,5 +8,5 @@ edit.insertLine("module A"); edit.insert("export class "); // should not crash -verify.getScriptLexicalStructureListCount(1); +verify.getScriptLexicalStructureListCount(2); diff --git a/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts b/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts index b805427ff63..bf0dc038991 100644 --- a/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts +++ b/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts @@ -8,4 +8,4 @@ // The class is unnamed, so its method is not included either. -verify.getScriptLexicalStructureListCount(0); +verify.getScriptLexicalStructureListCount(2); From 189482e730bbb4cc5b5b081923ebefb141ca15c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Apr 2015 17:28:59 -0700 Subject: [PATCH 37/51] Produce a name for anonymous class expressions when we perform downlevel emit. --- src/compiler/emitter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6ec4ea23898..5d4bf9df3e1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -262,6 +262,7 @@ module ts { switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: generateNameForFunctionOrClassDeclaration(node); break; case SyntaxKind.ModuleDeclaration: From 2eddf310dc37c4d4f6982da3c5a65f69bba3dc07 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 1 Apr 2015 18:56:57 -0700 Subject: [PATCH 38/51] Fix error spans for classes. --- src/compiler/checker.ts | 5 ++--- .../reference/classDeclarationBlockScoping1.errors.txt | 4 ++-- .../reference/classDeclarationBlockScoping2.errors.txt | 8 ++++---- tests/baselines/reference/classExpressionTest1.errors.txt | 4 ++-- tests/baselines/reference/classInsideBlock.errors.txt | 4 ++-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f9d91ab083c..f0882a51c4f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9757,12 +9757,11 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking if (node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { - grammarErrorOnFirstToken(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); + grammarErrorOnNode(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); } - // node.flags & NodeFlags.Default || kind === SyntaxKind.ClassExpression if (!node.name && !(node.flags & NodeFlags.Default)) { - grammarErrorOnNode(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); + grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } checkGrammarClassDeclarationHeritageClauses(node); diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt index 367e53c0660..4f15007bb2a 100644 --- a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt +++ b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classDeclarationBlockScoping1.ts(5,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping1.ts(5,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classDeclarationBlockScoping1.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/classDeclarationBlockScoping1.ts(5,5): error TS9004: 'class { class C { - ~~~~~ + ~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. } } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt index a6d320fa415..2a9885e110b 100644 --- a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt +++ b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/classDeclarationBlockScoping2.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. -tests/cases/compiler/classDeclarationBlockScoping2.ts(5,9): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping2.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classDeclarationBlockScoping2.ts(5,15): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classDeclarationBlockScoping2.ts (2 errors) ==== function f() { class C {} - ~~~~~ + ~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. var c1 = C; { class C {} - ~~~~~ + ~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. var c2 = C; } diff --git a/tests/baselines/reference/classExpressionTest1.errors.txt b/tests/baselines/reference/classExpressionTest1.errors.txt index 2da1f0427c3..4d7e1cda639 100644 --- a/tests/baselines/reference/classExpressionTest1.errors.txt +++ b/tests/baselines/reference/classExpressionTest1.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/classExpressionTest1.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/compiler/classExpressionTest1.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/compiler/classExpressionTest1.ts (1 errors) ==== function M() { class C { - ~~~~~ + ~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. f() { var t: T; diff --git a/tests/baselines/reference/classInsideBlock.errors.txt b/tests/baselines/reference/classInsideBlock.errors.txt index 8fb8e165b1d..369e77735e2 100644 --- a/tests/baselines/reference/classInsideBlock.errors.txt +++ b/tests/baselines/reference/classInsideBlock.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts(2,5): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. +tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. ==== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts (1 errors) ==== function foo() { class C { } - ~~~~~ + ~ !!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. } \ No newline at end of file From 64427a9df141bff6392f11f650b8852f8d9d4b74 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Apr 2015 18:28:13 -0700 Subject: [PATCH 39/51] Remove checking for scriptTarget before setting parsing context for classLikeDeclaration --- src/compiler/parser.ts | 4 +--- src/server/client.ts | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2972fba3979..e00c0c8d251 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4756,9 +4756,7 @@ module ts { function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration { // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code let savedStrictModeContext = inStrictModeContext(); - if (languageVersion >= ScriptTarget.ES6) { - setStrictModeContext(true); - } + setStrictModeContext(true); var node = createNode(kind, fullStart); node.decorators = decorators; diff --git a/src/server/client.ts b/src/server/client.ts index 60421421780..d395d2a832c 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -68,12 +68,12 @@ module ts.server { }; } - private processRequest(command: string, arguments?: any): T { + private processRequest(command: string, args?: any): T { var request: protocol.Request = { seq: this.sequence++, type: "request", - command: command, - arguments: arguments + arguments: args, + command }; this.writeMessage(JSON.stringify(request)); From 696e6a30fcb89be4c43dbbd3255210ee00efff61 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Apr 2015 18:28:43 -0700 Subject: [PATCH 40/51] Update test and baseliens from parsing classLikeDeclaration in strict mode --- ...lisionArgumentsClassConstructor.errors.txt | 101 +- .../collisionArgumentsClassMethod.errors.txt | 89 +- .../computedPropertyNames3_ES5.errors.txt | 5 +- .../constructorStaticParamName.errors.txt | 12 + .../reference/constructorStaticParamName.js | 2 +- .../constructorStaticParamName.types | 10 - ...torWithIncompleteTypeAnnotation.errors.txt | 99 +- ...constructorWithIncompleteTypeAnnotation.js | 217 +++-- .../reference/convertKeywordsYes.errors.txt | 383 ++++++++ .../baselines/reference/convertKeywordsYes.js | 69 +- .../reference/convertKeywordsYes.types | 879 ------------------ .../decoratorOnClassAccessor3.errors.txt | 28 +- .../reference/decoratorOnClassAccessor3.js | 25 +- .../decoratorOnClassAccessor6.errors.txt | 37 +- .../reference/decoratorOnClassAccessor6.js | 23 +- ...torOnClassConstructorParameter4.errors.txt | 5 +- .../decoratorOnClassConstructorParameter4.js | 2 +- .../decoratorOnClassMethod3.errors.txt | 22 +- .../reference/decoratorOnClassMethod3.js | 18 +- .../decoratorOnClassProperty3.errors.txt | 19 +- .../reference/decoratorOnClassProperty3.js | 16 +- .../reference/parser509668.errors.txt | 5 +- tests/baselines/reference/parser509668.js | 2 +- .../reference/parser553699.errors.txt | 4 +- tests/baselines/reference/parser553699.js | 2 +- .../reference/parser642331.errors.txt | 10 + tests/baselines/reference/parser642331.js | 2 +- tests/baselines/reference/parser642331.types | 8 - .../reference/parserRealSource11.errors.txt | 8 +- .../superCallsInConstructor.errors.txt | 5 +- ...arArgConstructorMemberParameter.errors.txt | 5 +- .../varArgConstructorMemberParameter.js | 2 +- .../cases/fourslash/getOccurrencesDeclare1.ts | 1 - .../cases/fourslash/getOccurrencesDeclare3.ts | 1 - .../cases/fourslash/getOccurrencesExport1.ts | 1 - .../cases/fourslash/getOccurrencesExport3.ts | 1 - 36 files changed, 925 insertions(+), 1193 deletions(-) create mode 100644 tests/baselines/reference/constructorStaticParamName.errors.txt delete mode 100644 tests/baselines/reference/constructorStaticParamName.types create mode 100644 tests/baselines/reference/convertKeywordsYes.errors.txt delete mode 100644 tests/baselines/reference/convertKeywordsYes.types create mode 100644 tests/baselines/reference/parser642331.errors.txt delete mode 100644 tests/baselines/reference/parser642331.types diff --git a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt index f2ec9429eb7..7e145688bac 100644 --- a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt @@ -1,40 +1,89 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,28): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(4,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(13,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(20,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(25,13): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(31,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(36,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,25): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,28): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(54,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(59,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(60,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(62,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(70,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: Invalid use of 'arguments' in strict mode. -==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (5 errors) ==== +==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (38 errors) ==== // Constructors class c1 { constructor(i: number, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any[]; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c12 { constructor(arguments: number, ...rest) { // error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c1NoError { constructor(arguments: number) { // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c2 { constructor(...restParameters) { var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c2NoError { constructor() { var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } @@ -42,63 +91,113 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS2396: constructor(public arguments: number, ...restParameters) { //arguments is error ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c3NoError { constructor(public arguments: number) { // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } declare class c4 { constructor(i: number, ...arguments); // No error - no code gen + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } declare class c42 { constructor(arguments: number, ...rest); // No error - no code gen + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } declare class c4NoError { constructor(arguments: number); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } class c5 { constructor(i: number, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(i: string, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any[]; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c52 { constructor(arguments: number, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: string, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: any, ...rest) { // error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } class c5NoError { constructor(arguments: number); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: string); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: any) { // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } declare class c6 { constructor(i: number, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(i: string, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } declare class c62 { constructor(arguments: number, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: string, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } declare class c6NoError { constructor(arguments: number); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. constructor(arguments: string); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt index 38ad6867200..34b92990c79 100644 --- a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt @@ -1,63 +1,150 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(2,27): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassMethod.ts(2,30): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(3,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassMethod.ts(6,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(8,23): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(11,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(12,29): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(13,23): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassMethod.ts(13,26): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(16,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(17,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. +tests/cases/compiler/collisionArgumentsClassMethod.ts(19,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(24,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(43,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Invalid use of 'arguments' in strict mode. -==== tests/cases/compiler/collisionArgumentsClassMethod.ts (4 errors) ==== +==== tests/cases/compiler/collisionArgumentsClassMethod.ts (33 errors) ==== class c1 { public foo(i: number, ...arguments) { //arguments is error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any[]; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public foo1(arguments: number, ...rest) { //arguments is error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public fooNoError(arguments: number) { // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public f4(i: number, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4(i: string, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any[]; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public f41(arguments: number, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f41(arguments: string, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f41(arguments: any, ...rest) { // error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public f4NoError(arguments: number); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4NoError(arguments: string); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4NoError(arguments: any) { // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. var arguments: any; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } declare class c2 { public foo(i: number, ...arguments); // No error - no code gen + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public foo1(arguments: number, ...rest); // No error - no code gen + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public fooNoError(arguments: number); // No error - no code gen + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4(i: number, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4(i: string, ...arguments); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f41(arguments: number, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f41(arguments: string, ...rest); // no codegen no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4NoError(arguments: number); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. public f4NoError(arguments: string); // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } class c3 { public foo(...restParameters) { var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } public fooNoError() { var arguments = 10; // no error + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames3_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames3_ES5.errors.txt index 82e4b71b33b..a31965dc69e 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3_ES5.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts (6 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts (7 errors) ==== var id; class C { [0 + 1]() { } @@ -18,6 +19,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,1 !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~~ +!!! error TS1102: 'delete' cannot be called on an identifier in strict mode. set [[0, 1]](v) { } ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. diff --git a/tests/baselines/reference/constructorStaticParamName.errors.txt b/tests/baselines/reference/constructorStaticParamName.errors.txt new file mode 100644 index 00000000000..ac50edd22f1 --- /dev/null +++ b/tests/baselines/reference/constructorStaticParamName.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1003: Identifier expected. + + +==== tests/cases/compiler/constructorStaticParamName.ts (1 errors) ==== + // static as constructor parameter name should only give error if 'use strict' + + class test { + constructor (static) { } + ~~~~~~ +!!! error TS1003: Identifier expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/constructorStaticParamName.js b/tests/baselines/reference/constructorStaticParamName.js index cf74aed2ebc..85b22867442 100644 --- a/tests/baselines/reference/constructorStaticParamName.js +++ b/tests/baselines/reference/constructorStaticParamName.js @@ -9,7 +9,7 @@ class test { //// [constructorStaticParamName.js] // static as constructor parameter name should only give error if 'use strict' var test = (function () { - function test(static) { + function test() { } return test; })(); diff --git a/tests/baselines/reference/constructorStaticParamName.types b/tests/baselines/reference/constructorStaticParamName.types deleted file mode 100644 index 9fdc94e4a73..00000000000 --- a/tests/baselines/reference/constructorStaticParamName.types +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/constructorStaticParamName.ts === -// static as constructor parameter name should only give error if 'use strict' - -class test { ->test : test - - constructor (static) { } ->static : any -} - diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index fa1c6bea381..75de7c32ebc 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -21,27 +21,47 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(49,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(65,29): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(81,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,13): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(94,17): error TS1134: Variable declaration expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(95,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(105,29): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(106,13): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,24): error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,24): error TS2304: Cannot find name 'any'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,30): error TS2304: Cannot find name 'bool'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,37): error TS2304: Cannot find name 'declare'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,47): error TS2304: Cannot find name 'constructor'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,61): error TS2304: Cannot find name 'get'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,67): error TS2304: Cannot find name 'implements'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(111,9): error TS1128: Declaration or statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,9): error TS2304: Cannot find name 'STATEMENTS'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,21): error TS1005: ',' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,30): error TS1005: ';' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,39): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(138,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(141,32): error TS1005: '{' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(143,13): error TS1005: 'try' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,9): error TS1128: Declaration or statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,16): error TS2304: Cannot find name 'TYPES'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,23): error TS1005: ';' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,32): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,24): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,30): error TS1005: '(' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,31): error TS2304: Cannot find name 'Property'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(166,13): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,9): error TS1128: Declaration or statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,16): error TS2304: Cannot find name 'OPERATOR'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,26): error TS1005: ';' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,35): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(180,40): error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(205,28): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(210,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(213,16): error TS2304: Cannot find name 'bool'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,10): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,29): error TS2304: Cannot find name 'yield'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,36): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(223,23): error TS2304: Cannot find name 'bool'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(227,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(234,14): error TS1005: '{' expected. @@ -49,7 +69,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,16): error TS2304: Cannot find name 'method1'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2304: Cannot find name 'val'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,27): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,28): error TS2304: Cannot find name 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,36): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,16): error TS2304: Cannot find name 'method2'. @@ -64,27 +83,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,9): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,26): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,31): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error TS1135: Argument expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,52): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected. 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,35): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2322: Type 'string' is not assignable to type 'boolean'. 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 (84 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (99 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -199,6 +214,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// public VARIABLES(): number { + ~~~~~~ +!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. var local = Number.MAX_VALUE; var min = Number.MIN_VALUE; var inf = Number.NEGATIVE_INFINITY - @@ -238,7 +255,11 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS var constructor = 0; var get = 0; var implements = 0; + ~~~~~~~~~~ +!!! error TS1134: Variable declaration expected. var interface = 0; + ~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. var let = 0; var module = 0; var number = 0; @@ -256,11 +277,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS1109: Expression expected. var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. + ~~~ +!!! error TS2304: Cannot find name 'any'. + ~~~~ +!!! error TS2304: Cannot find name 'bool'. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'constructor'. + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~~~~~~~~~~ +!!! error TS2304: Cannot find name 'implements'. return 0; } + ~ +!!! error TS1128: Declaration or statement expected. /// /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally @@ -268,6 +301,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// STATEMENTS(i: number): number { + ~~~~~~~~~~ +!!! error TS2304: Cannot find name 'STATEMENTS'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. var retVal = 0; if (i == 1) retVal = 1; @@ -311,6 +352,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// public TYPES(): number { + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~~ +!!! error TS2304: Cannot find name 'TYPES'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. var retVal = 0; var c = new CLASS(); var xx: IF = c; @@ -340,6 +389,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS ///// ///// public OPERATOR(): number { + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'OPERATOR'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: ';' expected. var a: number[] = [1, 2, 3, 4, 5, ];/*[] bug*/ // YES [] var i = a[1];/*[]*/ i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/ @@ -378,6 +435,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS } } + ~ +!!! error TS1128: Declaration or statement expected. interface IF { Foo(): bool; @@ -390,10 +449,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS case d = () => { yield 0; }; ~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~ -!!! error TS2304: Cannot find name 'yield'. - ~ -!!! error TS1005: ';' expected. public get Property() { return 0; } public Member() { return 0; @@ -425,8 +480,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS2304: Cannot find name 'val'. ~ !!! error TS1005: ',' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'number'. ~ !!! error TS1005: ';' expected. return val; @@ -476,8 +529,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS2304: Cannot find name 'value'. ~ !!! error TS1005: ',' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. public Overloads( while : string, ...rest: string[]) { & ~~~~~~ !!! error TS1128: Declaration or statement expected. @@ -487,20 +538,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS1135: Argument expression expected. ~ !!! error TS1005: '(' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. ~~~ !!! error TS1109: Expression expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. ~ !!! error TS1005: ';' expected. ~ !!! error TS1109: Expression expected. public DefaultValue(value?: string = "Hello") { } - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. ~~~~~~~~~~~~ !!! error TS1005: ';' expected. ~~~~~~~~~~~~ @@ -510,7 +555,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS ~ !!! error TS1109: Expression expected. ~~~~~~ -!!! error TS2304: Cannot find name 'string'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. ~ !!! error TS1005: ';' expected. } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index 64c70273872..4fb940bc9ec 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -342,6 +342,7 @@ var TypeScriptAllInOne; })(TypeScriptAllInOne || (TypeScriptAllInOne = {})); var BasicFeatures = (function () { function BasicFeatures() { + this.implements = 0; } /// /// Test various of variables. Including nullable,key world as variable,special format @@ -374,120 +375,118 @@ var BasicFeatures = (function () { var declare = 0; var constructor = 0; var get = 0; - var implements = 0; - var interface = 0; - var let = 0; - var module = 0; - var number = 0; - var package = 0; - var private = 0; - var protected = 0; - var public = 0; - var set = 0; - var static = 0; - var string = 0 / > - ; - var yield = 0; - var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; - return 0; - }; - /// - /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally - /// - /// - /// - BasicFeatures.prototype.STATEMENTS = function (i) { - var retVal = 0; - if (i == 1) - retVal = 1; - else - retVal = 0; - switch (i) { - case 2: - retVal = 1; - break; - case 3: - retVal = 1; - break; - default: - break; - } - for (var x in { x: 0, y: 1 }) { - !; - try { - throw null; - } - catch (Exception) { } - } - try { - } - finally { - try { } - catch (Exception) { } - } - return retVal; - }; - /// - /// Test types in ts language. Including class,struct,interface,delegate,anonymous type - /// - /// - BasicFeatures.prototype.TYPES = function () { - var retVal = 0; - var c = new CLASS(); - var xx = c; - retVal += ; - try { } - catch () { } - Property; - retVal += c.Member(); - retVal += xx.Foo() ? 0 : 1; - //anonymous type - var anony = { a: new CLASS() }; - retVal += anony.a.d(); - return retVal; - }; - ///// - ///// Test different operators - ///// - ///// - BasicFeatures.prototype.OPERATOR = function () { - var a = [1, 2, 3, 4, 5,]; /*[] bug*/ // YES [] - var i = a[1]; /*[]*/ - i = i + i - i * i / i % i & i | i ^ i; /*+ - * / % & | ^*/ - var b = true && false || true ^ false; /*& | ^*/ - b = !b; /*!*/ - i = ~i; /*~i*/ - b = i < (i - 1) && (i + 1) > i; /*< && >*/ - var f = true ? 1 : 0; /*? :*/ // YES : - i++; /*++*/ - i--; /*--*/ - b = true && false || true; /*&& ||*/ - i = i << 5; /*<<*/ - i = i >> 5; /*>>*/ - var j = i; - b = i == j && i != j && i <= j && i >= j; /*= == && != <= >=*/ - i += 5.0; /*+=*/ - i -= i; /*-=*/ - i *= i; /**=*/ - if (i == 0) - i++; - i /= i; /*/=*/ - i %= i; /*%=*/ - i &= i; /*&=*/ - i |= i; /*|=*/ - i ^= i; /*^=*/ - i <<= i; /*<<=*/ - i >>= i; /*>>=*/ - if (i == 0 && != b && f == 1) - return 0; - else - return 1; + var ; }; return BasicFeatures; })(); +var interface = 0; +var let = 0; +var module = 0; +var number = 0; +var package = 0; +var private = 0; +var protected = 0; +var public = 0; +var set = 0; +var static = 0; +var string = 0 / > +; +var yield = 0; +var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; +return 0; +/// +/// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally +/// +/// +/// +STATEMENTS(i, number); +number; +{ + var retVal = 0; + if (i == 1) + retVal = 1; + else + retVal = 0; + switch (i) { + case 2: + retVal = 1; + break; + case 3: + retVal = 1; + break; + default: + break; + } + for (var x in { x: 0, y: 1 }) { + !; + try { + throw null; + } + catch (Exception) { } + } + try { + } + finally { + try { } + catch (Exception) { } + } + return retVal; +} +TYPES(); +number; +{ + var retVal = 0; + var c = new CLASS(); + var xx = c; + retVal += ; + try { } + catch () { } + Property; + retVal += c.Member(); + retVal += xx.Foo() ? 0 : 1; + //anonymous type + var anony = { a: new CLASS() }; + retVal += anony.a.d(); + return retVal; +} +OPERATOR(); +number; +{ + var a = [1, 2, 3, 4, 5,]; /*[] bug*/ // YES [] + var i = a[1]; /*[]*/ + i = i + i - i * i / i % i & i | i ^ i; /*+ - * / % & | ^*/ + var b = true && false || true ^ false; /*& | ^*/ + b = !b; /*!*/ + i = ~i; /*~i*/ + b = i < (i - 1) && (i + 1) > i; /*< && >*/ + var f = true ? 1 : 0; /*? :*/ // YES : + i++; /*++*/ + i--; /*--*/ + b = true && false || true; /*&& ||*/ + i = i << 5; /*<<*/ + i = i >> 5; /*>>*/ + var j = i; + b = i == j && i != j && i <= j && i >= j; /*= == && != <= >=*/ + i += 5.0; /*+=*/ + i -= i; /*-=*/ + i *= i; /**=*/ + if (i == 0) + i++; + i /= i; /*/=*/ + i %= i; /*%=*/ + i &= i; /*&=*/ + i |= i; /*|=*/ + i ^= i; /*^=*/ + i <<= i; /*<<=*/ + i >>= i; /*>>=*/ + if (i == 0 && != b && f == 1) + return 0; + else + return 1; +} var CLASS = (function () { function CLASS() { - this.d = function () { yield; 0; }; + this.d = function () { ; }; } Object.defineProperty(CLASS.prototype, "Property", { get: function () { return 0; }, diff --git a/tests/baselines/reference/convertKeywordsYes.errors.txt b/tests/baselines/reference/convertKeywordsYes.errors.txt new file mode 100644 index 00000000000..1a54e3615b4 --- /dev/null +++ b/tests/baselines/reference/convertKeywordsYes.errors.txt @@ -0,0 +1,383 @@ +tests/cases/compiler/convertKeywordsYes.ts(292,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(293,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(293,21): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(294,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(296,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(296,19): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(297,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(297,19): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(298,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(298,21): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(299,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(299,18): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(301,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(301,18): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(303,10): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(303,17): error TS1005: ';' expected. + + +==== tests/cases/compiler/convertKeywordsYes.ts (25 errors) ==== + // reserved ES5 future in strict mode + + var constructor = 0; + var any = 0; + var boolean = 0; + var implements = 0; + var interface = 0; + var let = 0; + var module = 0; + var number = 0; + var package = 0; + var private = 0; + var protected = 0; + var public = 0; + var set = 0; + var static = 0; + var string = 0; + var get = 0; + var yield = 0; + var declare = 0; + + function bigGeneric< + constructor, + implements , + interface , + let, + module , + package, + private , + protected, + public , + set , + static , + get , + yield, + declare + >(c: constructor, + a: any, + b2: boolean, + i: implements , + i2: interface , + l: let, + m: module , + n: number, + p: package, + p2: private , + p3: protected, + p4: public , + s: set , + s2: static , + s3: string, + g: get , + y: yield, + d: declare ) { } + + var bigObject = { + constructor: 0, + any: 0, + boolean: 0, + implements: 0, + interface: 0, + let: 0, + module: 0, + number: 0, + package: 0, + private: 0, + protected: 0, + public: 0, + set: 0, + static: 0, + string: 0, + get: 0, + yield: 0, + break: 0, + case: 0, + catch: 0, + class: 0, + continue: 0, + const: 0, + + debugger: 0, + declare: 0, + default: 0, + delete: 0, + do: 0, + else: 0, + enum: 0, + export: 0, + extends: 0, + false: 0, + finally: 0, + for: 0, + function: 0, + if: 0, + + import: 0, + in: 0, + instanceof: 0, + new: 0, + null: 0, + return: 0, + super: 0, + switch: 0, + this: 0, + throw: 0, + true: 0, + try: 0, + typeof: 0, + var: 0, + void: 0, + while: 0, + with: 0, + }; + + interface bigInterface { + constructor; + any; + boolean; + implements; + interface; + let; + module; + number; + package; + private; + protected; + public; + set; + static; + string; + get; + yield; + break; + case; + catch; + class; + continue; + const; + + debugger; + declare; + default; + delete; + do; + else; + enum; + export; + extends; + false; + finally; + for; + function; + if; + + import; + in; + instanceof; + new; + null; + return; + super; + switch; + this; + throw; + true; + try; + typeof; + var; + void; + while; + with; + } + + class bigClass { + public "constructor" = 0; + public any = 0; + public boolean = 0; + public implements = 0; + public interface = 0; + public let = 0; + public module = 0; + public number = 0; + public package = 0; + public private = 0; + public protected = 0; + public public = 0; + public set = 0; + public static = 0; + public string = 0; + public get = 0; + public yield = 0; + public break = 0; + public case = 0; + public catch = 0; + public class = 0; + public continue = 0; + public const = 0; + public debugger = 0; + public declare = 0; + public default = 0; + public delete = 0; + public do = 0; + public else = 0; + public enum = 0; + public export = 0; + public extends = 0; + public false = 0; + public finally = 0; + public for = 0; + public function = 0; + public if = 0; + public import = 0; + public in = 0; + public instanceof = 0; + public new = 0; + public null = 0; + public return = 0; + public super = 0; + public switch = 0; + public this = 0; + public throw = 0; + public true = 0; + public try = 0; + public typeof = 0; + public var = 0; + public void = 0; + public while = 0; + public with = 0; + } + + enum bigEnum { + constructor, + any, + boolean, + implements, + interface, + let, + module, + number, + package, + private, + protected, + public, + set, + static, + string, + get, + yield, + break, + case, + catch, + class, + continue, + const, + + debugger, + declare, + default, + delete, + do, + else, + enum, + export, + extends, + false, + finally, + for, + function, + if, + + import, + in, + instanceof, + new, + null, + return, + super, + switch, + this, + throw, + true, + try, + typeof, + var, + void, + while, + with, + } + + module bigModule { + class constructor { } + class implements { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~~~~~ +!!! error TS1003: Identifier expected. + class interface { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class let { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~ +!!! error TS1003: Identifier expected. + class module { } + class package { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class private { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class protected { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class public { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class set { } + class static { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class get { } + class yield { } + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: ';' expected. + class declare { } + } \ No newline at end of file diff --git a/tests/baselines/reference/convertKeywordsYes.js b/tests/baselines/reference/convertKeywordsYes.js index a68f751f434..174ff31fc17 100644 --- a/tests/baselines/reference/convertKeywordsYes.js +++ b/tests/baselines/reference/convertKeywordsYes.js @@ -505,66 +505,81 @@ var bigModule; } return constructor; })(); - var implements = (function () { - function implements() { + var = (function () { + function () { } - return implements; + return ; })(); - var interface = (function () { - function interface() { + var = (function () { + function () { } - return interface; + return ; })(); - var let = (function () { - function let() { + interface; + { } + var = (function () { + function () { } - return let; + return ; })(); + var _a = void 0; var module = (function () { function module() { } return module; })(); - var package = (function () { - function package() { + var = (function () { + function () { } - return package; + return ; })(); - var private = (function () { - function private() { + package; + { } + var = (function () { + function () { } - return private; + return ; })(); - var protected = (function () { - function protected() { + private; + { } + var = (function () { + function () { } - return protected; + return ; })(); - var public = (function () { - function public() { + protected; + { } + var = (function () { + function () { } - return public; + return ; })(); + public; + { } var set = (function () { function set() { } return set; })(); - var static = (function () { - function static() { + var = (function () { + function () { } - return static; + return ; })(); + static; + { } var get = (function () { function get() { } return get; })(); - var yield = (function () { - function yield() { + var = (function () { + function () { } - return yield; + return ; })(); + yield; + { } var declare = (function () { function declare() { } diff --git a/tests/baselines/reference/convertKeywordsYes.types b/tests/baselines/reference/convertKeywordsYes.types deleted file mode 100644 index af2e0766181..00000000000 --- a/tests/baselines/reference/convertKeywordsYes.types +++ /dev/null @@ -1,879 +0,0 @@ -=== tests/cases/compiler/convertKeywordsYes.ts === -// reserved ES5 future in strict mode - -var constructor = 0; ->constructor : number - -var any = 0; ->any : number - -var boolean = 0; ->boolean : number - -var implements = 0; ->implements : number - -var interface = 0; ->interface : number - -var let = 0; ->let : number - -var module = 0; ->module : number - -var number = 0; ->number : number - -var package = 0; ->package : number - -var private = 0; ->private : number - -var protected = 0; ->protected : number - -var public = 0; ->public : number - -var set = 0; ->set : number - -var static = 0; ->static : number - -var string = 0; ->string : number - -var get = 0; ->get : number - -var yield = 0; ->yield : number - -var declare = 0; ->declare : number - -function bigGeneric< ->bigGeneric : (c: constructor, a: any, b2: boolean, i: implements, i2: interface, l: let, m: module, n: number, p: package, p2: private, p3: protected, p4: public, s: set, s2: static, s3: string, g: get, y: yield, d: declare) => void - - constructor, ->constructor : constructor - - implements , ->implements : implements - - interface , ->interface : interface - - let, ->let : let - - module , ->module : module - - package, ->package : package - - private , ->private : private - - protected, ->protected : protected - - public , ->public : public - - set , ->set : set - - static , ->static : static - - get , ->get : get - - yield, ->yield : yield - - declare ->declare : declare - - >(c: constructor, ->c : constructor ->constructor : constructor - - a: any, ->a : any - - b2: boolean, ->b2 : boolean - - i: implements , ->i : implements ->implements : implements - - i2: interface , ->i2 : interface ->interface : interface - - l: let, ->l : let ->let : let - - m: module , ->m : module ->module : module - - n: number, ->n : number - - p: package, ->p : package ->package : package - - p2: private , ->p2 : private ->private : private - - p3: protected, ->p3 : protected ->protected : protected - - p4: public , ->p4 : public ->public : public - - s: set , ->s : set ->set : set - - s2: static , ->s2 : static ->static : static - - s3: string, ->s3 : string - - g: get , ->g : get ->get : get - - y: yield, ->y : yield ->yield : yield - - d: declare ) { } ->d : declare ->declare : declare - -var bigObject = { ->bigObject : { constructor: number; any: number; boolean: number; implements: number; interface: number; let: number; module: number; number: number; package: number; private: number; protected: number; public: number; set: number; static: number; string: number; get: number; yield: number; break: number; case: number; catch: number; class: number; continue: number; const: number; debugger: number; declare: number; default: number; delete: number; do: number; else: number; enum: number; export: number; extends: number; false: number; finally: number; for: number; function: number; if: number; import: number; in: number; instanceof: number; new: number; null: number; return: number; super: number; switch: number; this: number; throw: number; true: number; try: number; typeof: number; var: number; void: number; while: number; with: number; } ->{ constructor: 0, any: 0, boolean: 0, implements: 0, interface: 0, let: 0, module: 0, number: 0, package: 0, private: 0, protected: 0, public: 0, set: 0, static: 0, string: 0, get: 0, yield: 0, break: 0, case: 0, catch: 0, class: 0, continue: 0, const: 0, debugger: 0, declare: 0, default: 0, delete: 0, do: 0, else: 0, enum: 0, export: 0, extends: 0, false: 0, finally: 0, for: 0, function: 0, if: 0, import: 0, in: 0, instanceof: 0, new: 0, null: 0, return: 0, super: 0, switch: 0, this: 0, throw: 0, true: 0, try: 0, typeof: 0, var: 0, void: 0, while: 0, with: 0,} : { constructor: number; any: number; boolean: number; implements: number; interface: number; let: number; module: number; number: number; package: number; private: number; protected: number; public: number; set: number; static: number; string: number; get: number; yield: number; break: number; case: number; catch: number; class: number; continue: number; const: number; debugger: number; declare: number; default: number; delete: number; do: number; else: number; enum: number; export: number; extends: number; false: number; finally: number; for: number; function: number; if: number; import: number; in: number; instanceof: number; new: number; null: number; return: number; super: number; switch: number; this: number; throw: number; true: number; try: number; typeof: number; var: number; void: number; while: number; with: number; } - - constructor: 0, ->constructor : number - - any: 0, ->any : number - - boolean: 0, ->boolean : number - - implements: 0, ->implements : number - - interface: 0, ->interface : number - - let: 0, ->let : number - - module: 0, ->module : number - - number: 0, ->number : number - - package: 0, ->package : number - - private: 0, ->private : number - - protected: 0, ->protected : number - - public: 0, ->public : number - - set: 0, ->set : number - - static: 0, ->static : number - - string: 0, ->string : number - - get: 0, ->get : number - - yield: 0, ->yield : number - - break: 0, ->break : number - - case: 0, ->case : number - - catch: 0, ->catch : number - - class: 0, ->class : number - - continue: 0, ->continue : number - - const: 0, ->const : number - - debugger: 0, ->debugger : number - - declare: 0, ->declare : number - - default: 0, ->default : number - - delete: 0, ->delete : number - - do: 0, ->do : number - - else: 0, ->else : number - - enum: 0, ->enum : number - - export: 0, ->export : number - - extends: 0, ->extends : number - - false: 0, ->false : number - - finally: 0, ->finally : number - - for: 0, ->for : number - - function: 0, ->function : number - - if: 0, ->if : number - - import: 0, ->import : number - - in: 0, ->in : number - - instanceof: 0, ->instanceof : number - - new: 0, ->new : number - - null: 0, ->null : number - - return: 0, ->return : number - - super: 0, ->super : number - - switch: 0, ->switch : number - - this: 0, ->this : number - - throw: 0, ->throw : number - - true: 0, ->true : number - - try: 0, ->try : number - - typeof: 0, ->typeof : number - - var: 0, ->var : number - - void: 0, ->void : number - - while: 0, ->while : number - - with: 0, ->with : number - -}; - -interface bigInterface { ->bigInterface : bigInterface - - constructor; ->constructor : any - - any; ->any : any - - boolean; ->boolean : any - - implements; ->implements : any - - interface; ->interface : any - - let; ->let : any - - module; ->module : any - - number; ->number : any - - package; ->package : any - - private; ->private : any - - protected; ->protected : any - - public; ->public : any - - set; ->set : any - - static; ->static : any - - string; ->string : any - - get; ->get : any - - yield; ->yield : any - - break; ->break : any - - case; ->case : any - - catch; ->catch : any - - class; ->class : any - - continue; ->continue : any - - const; ->const : any - - debugger; ->debugger : any - - declare; ->declare : any - - default; ->default : any - - delete; ->delete : any - - do; ->do : any - - else; ->else : any - - enum; ->enum : any - - export; ->export : any - - extends; ->extends : any - - false; ->false : any - - finally; ->finally : any - - for; ->for : any - - function; ->function : any - - if; ->if : any - - import; ->import : any - - in; ->in : any - - instanceof; ->instanceof : any - - new; ->new : any - - null; ->null : any - - return; ->return : any - - super; ->super : any - - switch; ->switch : any - - this; ->this : any - - throw; ->throw : any - - true; ->true : any - - try; ->try : any - - typeof; ->typeof : any - - var; ->var : any - - void; ->void : any - - while; ->while : any - - with; ->with : any -} - -class bigClass { ->bigClass : bigClass - - public "constructor" = 0; - public any = 0; ->any : number - - public boolean = 0; ->boolean : number - - public implements = 0; ->implements : number - - public interface = 0; ->interface : number - - public let = 0; ->let : number - - public module = 0; ->module : number - - public number = 0; ->number : number - - public package = 0; ->package : number - - public private = 0; ->private : number - - public protected = 0; ->protected : number - - public public = 0; ->public : number - - public set = 0; ->set : number - - public static = 0; ->static : number - - public string = 0; ->string : number - - public get = 0; ->get : number - - public yield = 0; ->yield : number - - public break = 0; ->break : number - - public case = 0; ->case : number - - public catch = 0; ->catch : number - - public class = 0; ->class : number - - public continue = 0; ->continue : number - - public const = 0; ->const : number - - public debugger = 0; ->debugger : number - - public declare = 0; ->declare : number - - public default = 0; ->default : number - - public delete = 0; ->delete : number - - public do = 0; ->do : number - - public else = 0; ->else : number - - public enum = 0; ->enum : number - - public export = 0; ->export : number - - public extends = 0; ->extends : number - - public false = 0; ->false : number - - public finally = 0; ->finally : number - - public for = 0; ->for : number - - public function = 0; ->function : number - - public if = 0; ->if : number - - public import = 0; ->import : number - - public in = 0; ->in : number - - public instanceof = 0; ->instanceof : number - - public new = 0; ->new : number - - public null = 0; ->null : number - - public return = 0; ->return : number - - public super = 0; ->super : number - - public switch = 0; ->switch : number - - public this = 0; ->this : number - - public throw = 0; ->throw : number - - public true = 0; ->true : number - - public try = 0; ->try : number - - public typeof = 0; ->typeof : number - - public var = 0; ->var : number - - public void = 0; ->void : number - - public while = 0; ->while : number - - public with = 0; ->with : number -} - -enum bigEnum { ->bigEnum : bigEnum - - constructor, ->constructor : bigEnum - - any, ->any : bigEnum - - boolean, ->boolean : bigEnum - - implements, ->implements : bigEnum - - interface, ->interface : bigEnum - - let, ->let : bigEnum - - module, ->module : bigEnum - - number, ->number : bigEnum - - package, ->package : bigEnum - - private, ->private : bigEnum - - protected, ->protected : bigEnum - - public, ->public : bigEnum - - set, ->set : bigEnum - - static, ->static : bigEnum - - string, ->string : bigEnum - - get, ->get : bigEnum - - yield, ->yield : bigEnum - - break, ->break : bigEnum - - case, ->case : bigEnum - - catch, ->catch : bigEnum - - class, ->class : bigEnum - - continue, ->continue : bigEnum - - const, ->const : bigEnum - - debugger, ->debugger : bigEnum - - declare, ->declare : bigEnum - - default, ->default : bigEnum - - delete, ->delete : bigEnum - - do, ->do : bigEnum - - else, ->else : bigEnum - - enum, ->enum : bigEnum - - export, ->export : bigEnum - - extends, ->extends : bigEnum - - false, ->false : bigEnum - - finally, ->finally : bigEnum - - for, ->for : bigEnum - - function, ->function : bigEnum - - if, ->if : bigEnum - - import, ->import : bigEnum - - in, ->in : bigEnum - - instanceof, ->instanceof : bigEnum - - new, ->new : bigEnum - - null, ->null : bigEnum - - return, ->return : bigEnum - - super, ->super : bigEnum - - switch, ->switch : bigEnum - - this, ->this : bigEnum - - throw, ->throw : bigEnum - - true, ->true : bigEnum - - try, ->try : bigEnum - - typeof, ->typeof : bigEnum - - var, ->var : bigEnum - - void, ->void : bigEnum - - while, ->while : bigEnum - - with, ->with : bigEnum -} - -module bigModule { ->bigModule : typeof bigModule - - class constructor { } ->constructor : constructor - - class implements { } ->implements : implements - - class interface { } ->interface : interface - - class let { } ->let : let - - class module { } ->module : module - - class package { } ->package : package - - class private { } ->private : private - - class protected { } ->protected : protected - - class public { } ->public : public - - class set { } ->set : set - - class static { } ->static : static - - class get { } ->get : get - - class yield { } ->yield : yield - - class declare { } ->declare : declare -} diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt index b75b7e0d8b6..1a1e6503355 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -1,35 +1,11 @@ tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec get accessor() { return 1; } ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'get'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~ -!!! error TS1005: ';' 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/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js index f48a755953f..a2a2221a119 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.js +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -6,14 +6,27 @@ class C { } //// [decoratorOnClassAccessor3.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; var C = (function () { function C() { } + Object.defineProperty(C.prototype, "accessor", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); -public; -get; -accessor(); -{ - return 1; -} diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt index ec22ae0b3e1..f43827c0e4b 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -1,44 +1,11 @@ tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec set accessor(value: number) { } ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'set'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~~~~~ -!!! error TS2304: Cannot find name 'value'. - ~ -!!! error TS1005: ',' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'number'. - ~ -!!! error TS1005: ';' 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/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js index 771d937634f..ce9776bfc61 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.js +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -6,12 +6,27 @@ class C { } //// [decoratorOnClassAccessor6.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; var C = (function () { function C() { } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); -public; -set; -accessor(value, number); -{ } diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt index 5969cfca069..61ff1433662 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt @@ -1,11 +1,14 @@ +tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,17): error TS1003: Identifier expected. tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,24): error TS1005: ',' expected. -==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (1 errors) ==== +==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (2 errors) ==== declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; class C { constructor(public @dec p: number) {} + ~~~~~~ +!!! error TS1003: Identifier expected. ~ !!! error TS1005: ',' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js index 07dc7cae075..3ab9829e72a 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -20,7 +20,7 @@ var __decorate = this.__decorate || function (decorators, target, key, value) { return value; }; var C = (function () { - function C(public, p) { + function C(, p) { } __decorate([dec], C, void 0, 1); return C; diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt index b2173dedf9e..2775ab9f144 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -1,29 +1,11 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec method() {} ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' 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/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js index 3ac97697e80..7e13f91d86c 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.js +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -6,11 +6,23 @@ class C { } //// [decoratorOnClassMethod3.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; var C = (function () { function C() { } + C.prototype.method = function () { }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); return C; })(); -public; -method(); -{ } diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt index 29438bd67a9..a6321c55426 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -1,26 +1,11 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string): void; class C { public @dec prop; ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~~ -!!! error TS2304: Cannot find name 'prop'. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js index 6c9945677ca..f8a2cce27df 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.js +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -6,10 +6,22 @@ class C { } //// [decoratorOnClassProperty3.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; var C = (function () { function C() { } + __decorate([dec], C.prototype, "prop"); return C; })(); -public; -prop; diff --git a/tests/baselines/reference/parser509668.errors.txt b/tests/baselines/reference/parser509668.errors.txt index 5ea380592ef..588bda6d91c 100644 --- a/tests/baselines/reference/parser509668.errors.txt +++ b/tests/baselines/reference/parser509668.errors.txt @@ -1,10 +1,13 @@ +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,16): error TS1003: Identifier expected. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,23): error TS1005: ',' expected. -==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (2 errors) ==== class Foo3 { // Doesn't work, but should constructor (public ...args: string[]) { } + ~~~~~~ +!!! error TS1003: Identifier expected. ~~~ !!! error TS1005: ',' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/parser509668.js b/tests/baselines/reference/parser509668.js index 63c5d8a1a95..a64c9c7b5b0 100644 --- a/tests/baselines/reference/parser509668.js +++ b/tests/baselines/reference/parser509668.js @@ -7,7 +7,7 @@ class Foo3 { //// [parser509668.js] var Foo3 = (function () { // Doesn't work, but should - function Foo3(public) { + function Foo3() { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; diff --git a/tests/baselines/reference/parser553699.errors.txt b/tests/baselines/reference/parser553699.errors.txt index 5a0b9e2fba9..84bc6e60707 100644 --- a/tests/baselines/reference/parser553699.errors.txt +++ b/tests/baselines/reference/parser553699.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS2304: Cannot find name 'public'. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1110: Type expected. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts (1 errors) ==== @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21) constructor() { } public banana (x: public) { } ~~~~~~ -!!! error TS2304: Cannot find name 'public'. +!!! error TS1110: Type expected. } class Bar { diff --git a/tests/baselines/reference/parser553699.js b/tests/baselines/reference/parser553699.js index 8570780e74a..c4cc51bf5af 100644 --- a/tests/baselines/reference/parser553699.js +++ b/tests/baselines/reference/parser553699.js @@ -12,7 +12,7 @@ class Bar { var Foo = (function () { function Foo() { } - Foo.prototype.banana = function (x) { }; + Foo.prototype.banana = function (x, ) { }; return Foo; })(); var Bar = (function () { diff --git a/tests/baselines/reference/parser642331.errors.txt b/tests/baselines/reference/parser642331.errors.txt new file mode 100644 index 00000000000..fad38e66513 --- /dev/null +++ b/tests/baselines/reference/parser642331.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1003: Identifier expected. + + +==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts (1 errors) ==== + class test { + constructor (static) { } + ~~~~~~ +!!! error TS1003: Identifier expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/parser642331.js b/tests/baselines/reference/parser642331.js index 056ea7dd384..3d88c096af3 100644 --- a/tests/baselines/reference/parser642331.js +++ b/tests/baselines/reference/parser642331.js @@ -6,7 +6,7 @@ class test { //// [parser642331.js] var test = (function () { - function test(static) { + function test() { } return test; })(); diff --git a/tests/baselines/reference/parser642331.types b/tests/baselines/reference/parser642331.types deleted file mode 100644 index 19cd40b76b8..00000000000 --- a/tests/baselines/reference/parser642331.types +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts === -class test { ->test : test - - constructor (static) { } ->static : any -} - diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index bf5432062b0..9b09e6d3b9d 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -115,6 +115,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(504,58): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(506,22): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(507,58): error TS2304: Cannot find name 'TokenID'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(518,32): error TS2304: Cannot find name 'NodeType'. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(525,27): error TS2304: Cannot find name 'Signature'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(527,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(528,34): error TS2304: Cannot find name 'NodeType'. @@ -246,6 +247,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(963,27): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(969,31): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(977,32): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(981,27): error TS2304: Cannot find name 'Type'. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,44): error TS2304: Cannot find name 'hasFlag'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,67): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1005,57): error TS2304: Cannot find name 'FncFlags'. @@ -515,7 +517,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,30): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error TS2304: Cannot find name 'TokenID'. -==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (515 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (517 errors) ==== // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. @@ -1270,6 +1272,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error !!! error TS2304: Cannot find name 'NodeType'. public target: AST, public arguments: ASTList) { + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. super(nodeType); this.minChar = this.target.minChar; } @@ -1997,6 +2001,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error constructor (public name: Identifier, public bod: ASTList, public isConstructor: boolean, public arguments: ASTList, public vars: ASTList, public scopes: ASTList, public statics: ASTList, + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. nodeType: number) { super(nodeType); diff --git a/tests/baselines/reference/superCallsInConstructor.errors.txt b/tests/baselines/reference/superCallsInConstructor.errors.txt index 0e7b1577bc0..eee7c06b671 100644 --- a/tests/baselines/reference/superCallsInConstructor.errors.txt +++ b/tests/baselines/reference/superCallsInConstructor.errors.txt @@ -1,7 +1,8 @@ +tests/cases/compiler/superCallsInConstructor.ts(12,9): error TS1101: 'with' statements are not allowed in strict mode. tests/cases/compiler/superCallsInConstructor.ts(12,14): error TS2410: All symbols within a 'with' block will be resolved to 'any'. -==== tests/cases/compiler/superCallsInConstructor.ts (1 errors) ==== +==== tests/cases/compiler/superCallsInConstructor.ts (2 errors) ==== class C { foo() {} bar() {} @@ -14,6 +15,8 @@ tests/cases/compiler/superCallsInConstructor.ts(12,14): error TS2410: All symbol class Derived extends Base { constructor() { with(new C()) { + ~~~~ +!!! error TS1101: 'with' statements are not allowed in strict mode. ~~~~~~~ !!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. foo(); diff --git a/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt b/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt index e3257b870d6..19bd0396bed 100644 --- a/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt +++ b/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt @@ -1,7 +1,8 @@ +tests/cases/compiler/varArgConstructorMemberParameter.ts(10,18): error TS1003: Identifier expected. tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ',' expected. -==== tests/cases/compiler/varArgConstructorMemberParameter.ts (1 errors) ==== +==== tests/cases/compiler/varArgConstructorMemberParameter.ts (2 errors) ==== class Foo1 { constructor (...args: string[]) { } } @@ -12,6 +13,8 @@ tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ' class Foo3 { constructor (public ...args: string[]) { } + ~~~~~~ +!!! error TS1003: Identifier expected. ~~~ !!! error TS1005: ',' expected. } diff --git a/tests/baselines/reference/varArgConstructorMemberParameter.js b/tests/baselines/reference/varArgConstructorMemberParameter.js index 7f1ef8d5b3a..100a4b07899 100644 --- a/tests/baselines/reference/varArgConstructorMemberParameter.js +++ b/tests/baselines/reference/varArgConstructorMemberParameter.js @@ -29,7 +29,7 @@ var Foo2 = (function () { return Foo2; })(); var Foo3 = (function () { - function Foo3(public) { + function Foo3() { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; diff --git a/tests/cases/fourslash/getOccurrencesDeclare1.ts b/tests/cases/fourslash/getOccurrencesDeclare1.ts index 1cdad07eb7e..4207a92b5a6 100644 --- a/tests/cases/fourslash/getOccurrencesDeclare1.ts +++ b/tests/cases/fourslash/getOccurrencesDeclare1.ts @@ -44,7 +44,6 @@ //// protected prot1; //// //// protected constructor(public public, protected protected, private private) { -//// public = private = protected; //// } //// } //// } diff --git a/tests/cases/fourslash/getOccurrencesDeclare3.ts b/tests/cases/fourslash/getOccurrencesDeclare3.ts index 048dd8efeac..2dee0af4b14 100644 --- a/tests/cases/fourslash/getOccurrencesDeclare3.ts +++ b/tests/cases/fourslash/getOccurrencesDeclare3.ts @@ -48,7 +48,6 @@ //// protected prot1; //// //// protected constructor(public public, protected protected, private private) { -//// public = private = protected; //// } //// } //// } diff --git a/tests/cases/fourslash/getOccurrencesExport1.ts b/tests/cases/fourslash/getOccurrencesExport1.ts index c47c39cf548..bc82e8a1bea 100644 --- a/tests/cases/fourslash/getOccurrencesExport1.ts +++ b/tests/cases/fourslash/getOccurrencesExport1.ts @@ -44,7 +44,6 @@ //// protected prot1; //// //// protected constructor(public public, protected protected, private private) { -//// public = private = protected; //// } //// } //// } diff --git a/tests/cases/fourslash/getOccurrencesExport3.ts b/tests/cases/fourslash/getOccurrencesExport3.ts index 009b891992f..215cbf8f48a 100644 --- a/tests/cases/fourslash/getOccurrencesExport3.ts +++ b/tests/cases/fourslash/getOccurrencesExport3.ts @@ -48,7 +48,6 @@ //// protected prot1; //// //// protected constructor(public public, protected protected, private private) { -//// public = private = protected; //// } //// } //// } From d048d7d3d27a6eb61837b221ad73538a83b29397 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 13:59:53 -0700 Subject: [PATCH 41/51] Fix tests. --- tests/baselines/reference/anonymousClassExpression1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/anonymousClassExpression1.js b/tests/baselines/reference/anonymousClassExpression1.js index a796b126a0e..78cf5b05c51 100644 --- a/tests/baselines/reference/anonymousClassExpression1.js +++ b/tests/baselines/reference/anonymousClassExpression1.js @@ -6,8 +6,8 @@ function f() { //// [anonymousClassExpression1.js] function f() { return typeof (function () { - function () { + function default_1() { } - return ; + return default_1; })() === "function"; } From 0f079632b9642568f09f23ae94ec81bf109a733a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 14:58:43 -0700 Subject: [PATCH 42/51] PR feedback. --- .../diagnosticInformationMap.generated.ts | 31 ++++---- src/compiler/diagnosticMessages.json | 34 +++++---- src/services/services.ts | 75 ++++++++++--------- .../getJavaScriptSemanticDiagnostics1.ts | 2 +- .../getJavaScriptSemanticDiagnostics10.ts | 2 +- .../getJavaScriptSemanticDiagnostics11.ts | 2 +- .../getJavaScriptSemanticDiagnostics12.ts | 2 +- .../getJavaScriptSemanticDiagnostics13.ts | 2 +- .../getJavaScriptSemanticDiagnostics14.ts | 2 +- .../getJavaScriptSemanticDiagnostics15.ts | 2 +- .../getJavaScriptSemanticDiagnostics16.ts | 2 +- .../getJavaScriptSemanticDiagnostics17.ts | 2 +- .../getJavaScriptSemanticDiagnostics18.ts | 2 +- .../getJavaScriptSemanticDiagnostics19.ts | 2 +- .../getJavaScriptSemanticDiagnostics2.ts | 2 +- .../getJavaScriptSemanticDiagnostics20.ts | 2 +- .../getJavaScriptSemanticDiagnostics21.ts | 15 ++++ .../getJavaScriptSemanticDiagnostics3.ts | 2 +- .../getJavaScriptSemanticDiagnostics4.ts | 2 +- .../getJavaScriptSemanticDiagnostics5.ts | 2 +- .../getJavaScriptSemanticDiagnostics6.ts | 2 +- .../getJavaScriptSemanticDiagnostics7.ts | 2 +- .../getJavaScriptSemanticDiagnostics8.ts | 2 +- .../getJavaScriptSemanticDiagnostics9.ts | 2 +- 24 files changed, 109 insertions(+), 86 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5f0ca431aa2..64a2515e774 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -506,21 +506,22 @@ module ts { Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, - import_can_only_be_used_in_TypeScript: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in TypeScript." }, - export_can_only_be_used_in_TypeScript: { code: 8003, category: DiagnosticCategory.Error, key: "'export=' can only be used in TypeScript." }, - type_parameter_declarations_can_only_be_used_in_TypeScript: { code: 8004, category: DiagnosticCategory.Error, key: "'type parameter declarations' can only be used in TypeScript." }, - implements_clauses_can_only_be_used_in_TypeScript: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in TypeScript." }, - interface_declarations_can_only_be_used_in_TypeScript: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in TypeScript." }, - module_declarations_can_only_be_used_in_TypeScript: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in TypeScript." }, - type_aliases_can_only_be_used_in_TypeScript: { code: 8008, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in TypeScript." }, - _0_can_only_be_used_in_TypeScript: { code: 8009, category: DiagnosticCategory.Error, key: "'{0}' can only be used in TypeScript." }, - types_can_only_be_used_in_TypeScript: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in TypeScript." }, - type_arguments_can_only_be_used_in_TypeScript: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in TypeScript." }, - parameter_modifiers_can_only_be_used_in_TypeScript: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in TypeScript." }, - can_only_be_used_in_TypeScript: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in TypeScript." }, - property_declarations_can_only_be_used_in_TypeScript: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in TypeScript." }, - enum_declarations_can_only_be_used_in_TypeScript: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in TypeScript." }, - type_assertion_expressions_can_only_be_used_in_TypeScript: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in TypeScript." }, + import_can_only_be_used_in_a_ts_file: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, + export_can_only_be_used_in_a_ts_file: { code: 8003, category: DiagnosticCategory.Error, key: "'export=' can only be used in a .ts file." }, + type_parameter_declarations_can_only_be_used_in_a_ts_file: { code: 8004, category: DiagnosticCategory.Error, key: "'type parameter declarations' can only be used in a .ts file." }, + implements_clauses_can_only_be_used_in_a_ts_file: { code: 8005, category: DiagnosticCategory.Error, key: "'implements clauses' can only be used in a .ts file." }, + interface_declarations_can_only_be_used_in_a_ts_file: { code: 8006, category: DiagnosticCategory.Error, key: "'interface declarations' can only be used in a .ts file." }, + module_declarations_can_only_be_used_in_a_ts_file: { code: 8007, category: DiagnosticCategory.Error, key: "'module declarations' can only be used in a .ts file." }, + type_aliases_can_only_be_used_in_a_ts_file: { code: 8008, category: DiagnosticCategory.Error, key: "'type aliases' can only be used in a .ts file." }, + _0_can_only_be_used_in_a_ts_file: { code: 8009, category: DiagnosticCategory.Error, key: "'{0}' can only be used in a .ts file." }, + types_can_only_be_used_in_a_ts_file: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, + type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, + parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, + can_only_be_used_in_a_ts_file: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, + property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, + enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, + type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, + decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 085d4ccb33d..79b652619b5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2017,66 +2017,70 @@ "category": "Error", "code": 8001 }, - "'import ... =' can only be used in TypeScript.": { + "'import ... =' can only be used in a .ts file.": { "category": "Error", "code": 8002 }, - "'export=' can only be used in TypeScript.": { + "'export=' can only be used in a .ts file.": { "category": "Error", "code": 8003 }, - "'type parameter declarations' can only be used in TypeScript.": { + "'type parameter declarations' can only be used in a .ts file.": { "category": "Error", "code": 8004 }, - "'implements clauses' can only be used in TypeScript.": { + "'implements clauses' can only be used in a .ts file.": { "category": "Error", "code": 8005 }, - "'interface declarations' can only be used in TypeScript.": { + "'interface declarations' can only be used in a .ts file.": { "category": "Error", "code": 8006 }, - "'module declarations' can only be used in TypeScript.": { + "'module declarations' can only be used in a .ts file.": { "category": "Error", "code": 8007 }, - "'type aliases' can only be used in TypeScript.": { + "'type aliases' can only be used in a .ts file.": { "category": "Error", "code": 8008 }, - "'{0}' can only be used in TypeScript.": { + "'{0}' can only be used in a .ts file.": { "category": "Error", "code": 8009 }, - "'types' can only be used in TypeScript.": { + "'types' can only be used in a .ts file.": { "category": "Error", "code": 8010 }, - "'type arguments' can only be used in TypeScript.": { + "'type arguments' can only be used in a .ts file.": { "category": "Error", "code": 8011 }, - "'parameter modifiers' can only be used in TypeScript.": { + "'parameter modifiers' can only be used in a .ts file.": { "category": "Error", "code": 8012 }, - "'?' can only be used in TypeScript.": { + "'?' can only be used in a .ts file.": { "category": "Error", "code": 8013 }, - "'property declarations' can only be used in TypeScript.": { + "'property declarations' can only be used in a .ts file.": { "category": "Error", "code": 8014 }, - "'enum declarations' can only be used in TypeScript.": { + "'enum declarations' can only be used in a .ts file.": { "category": "Error", "code": 8015 }, - "'type assertion expressions' can only be used in TypeScript.": { + "'type assertion expressions' can only be used in a .ts file.": { "category": "Error", "code": 8016 }, + "'decorators' can only be used in a .ts file.": { + "category": "Error", + "code": 8017 + }, "'yield' expressions are not currently supported.": { "category": "Error", diff --git a/src/services/services.ts b/src/services/services.ts index 4c0d3e751c0..831e8a95de3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2472,41 +2472,41 @@ module ts { return diagnostics; - function walk(node: Node) { + function walk(node: Node): boolean { if (!node) { - return; + return false; } switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.ExportAssignment: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.ClassDeclaration: let classDeclaration = node; if (checkModifiers(classDeclaration.modifiers) || checkTypeParameters(classDeclaration.typeParameters)) { - return; + return true; } break; case SyntaxKind.HeritageClause: let heritageClause = node; if (heritageClause.token === SyntaxKind.ImplementsKeyword) { - diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); + return true; } break; case SyntaxKind.InterfaceDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.ModuleDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.TypeAliasDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -2520,19 +2520,19 @@ module ts { if (checkModifiers(functionDeclaration.modifiers) || checkTypeParameters(functionDeclaration.typeParameters) || checkTypeAnnotation(functionDeclaration.type)) { - return; + return true; } break; case SyntaxKind.VariableStatement: let variableStatement = node; if (checkModifiers(variableStatement.modifiers)) { - return; + return true; } break; case SyntaxKind.VariableDeclaration: let variableDeclaration = node; if (checkTypeAnnotation(variableDeclaration.type)) { - return; + return true; } break; case SyntaxKind.CallExpression: @@ -2541,8 +2541,8 @@ module ts { if (expression.typeArguments && expression.typeArguments.length > 0) { let start = expression.typeArguments.pos; diagnostics.push(createFileDiagnostic(sourceFile, start, expression.typeArguments.end - start, - Diagnostics.type_arguments_can_only_be_used_in_TypeScript)); - return; + Diagnostics.type_arguments_can_only_be_used_in_a_ts_file)); + return true; } break; case SyntaxKind.Parameter: @@ -2550,37 +2550,40 @@ module ts { if (parameter.modifiers) { let start = parameter.modifiers.pos; diagnostics.push(createFileDiagnostic(sourceFile, start, parameter.modifiers.end - start, - Diagnostics.parameter_modifiers_can_only_be_used_in_TypeScript)); - return; + Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file)); + return true; } if (parameter.questionToken) { - diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics.can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics.can_only_be_used_in_a_ts_file)); + return true; } if (parameter.type) { - diagnostics.push(createDiagnosticForNode(parameter.type, Diagnostics.types_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(parameter.type, Diagnostics.types_can_only_be_used_in_a_ts_file)); + return true; } break; case SyntaxKind.PropertyDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.property_declarations_can_only_be_used_in_TypeScript)); - return + diagnostics.push(createDiagnosticForNode(node, Diagnostics.property_declarations_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.EnumDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); + return true; case SyntaxKind.TypeAssertionExpression: let typeAssertionExpression = node; - diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_TypeScript)); - return; + diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); + return true; + case SyntaxKind.Decorator: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.decorators_can_only_be_used_in_a_ts_file)); + return true; } - forEachChild(node, walk); + return forEachChild(node, walk); } function checkTypeParameters(typeParameters: NodeArray): boolean { if (typeParameters) { let start = typeParameters.pos; - diagnostics.push(createFileDiagnostic(sourceFile, start, typeParameters.end - start, Diagnostics.type_parameter_declarations_can_only_be_used_in_TypeScript)); + diagnostics.push(createFileDiagnostic(sourceFile, start, typeParameters.end - start, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); return true; } return false; @@ -2588,7 +2591,7 @@ module ts { function checkTypeAnnotation(type: TypeNode): boolean { if (type) { - diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_TypeScript)); + diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_a_ts_file)); return true; } @@ -2603,7 +2606,7 @@ module ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.DeclareKeyword: - diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_TypeScript, tokenToString(modifier.kind))); + diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); return true; // These are all legal modifiers. diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts index 5fbe669de30..05bc6727710 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'import ... =' can only be used in TypeScript.", + "message": "'import ... =' can only be used in a .ts file.", "start": 0, "length": 13, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts index ecefb25d218..84c6c45f870 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'type parameter declarations' can only be used in TypeScript.", + "message": "'type parameter declarations' can only be used in a .ts file.", "start": 11, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts index da468d59f3b..7dfd3c4965b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'types' can only be used in TypeScript.", + "message": "'types' can only be used in a .ts file.", "start": 14, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts index 89e459d2a5b..88a1331ef23 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'declare' can only be used in TypeScript.", + "message": "'declare' can only be used in a .ts file.", "start": 0, "length": 7, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts index c3c0fc9ef7b..21a5e9cdcaa 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'types' can only be used in TypeScript.", + "message": "'types' can only be used in a .ts file.", "start": 7, "length": 12, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts index 5e7c2010480..8cd178ffec1 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'type arguments' can only be used in TypeScript.", + "message": "'type arguments' can only be used in a .ts file.", "start": 4, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts index 2c7d87a74e2..d1c3a8c6e63 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'parameter modifiers' can only be used in TypeScript.", + "message": "'parameter modifiers' can only be used in a .ts file.", "start": 11, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts index 3bc3030e2b1..2ccac13dbf9 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'?' can only be used in TypeScript.", + "message": "'?' can only be used in a .ts file.", "start": 12, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts index 39b67b13ea8..5e94c806c60 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'types' can only be used in TypeScript.", + "message": "'types' can only be used in a .ts file.", "start": 14, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts index 96dc2bce892..a2859060cde 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'property declarations' can only be used in TypeScript.", + "message": "'property declarations' can only be used in a .ts file.", "start": 10, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts index efbe1694419..34dbbc0271d 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'enum declarations' can only be used in TypeScript.", + "message": "'enum declarations' can only be used in a .ts file.", "start": 5, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts index abf9f693b0c..b26d16f9017 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'export=' can only be used in TypeScript.", + "message": "'export=' can only be used in a .ts file.", "start": 0, "length": 11, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts index d0f6cef468e..790f02bac92 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'type assertion expressions' can only be used in TypeScript.", + "message": "'type assertion expressions' can only be used in a .ts file.", "start": 9, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts new file mode 100644 index 00000000000..23e3274261c --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.js +//// @internal class C {} + +verify.getSemanticDiagnostics(`[ + { + "message": "'decorators' can only be used in a .ts file.", + "start": 0, + "length": 9, + "category": "error", + "code": 8017 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts index 4e424281dfd..c7b6c6a80cf 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'type parameter declarations' can only be used in TypeScript.", + "message": "'type parameter declarations' can only be used in a .ts file.", "start": 8, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts index 80e8873b01a..f32ee5c4b68 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'public' can only be used in TypeScript.", + "message": "'public' can only be used in a .ts file.", "start": 0, "length": 6, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts index 411bef8a82f..e405624c9b0 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'implements clauses' can only be used in TypeScript.", + "message": "'implements clauses' can only be used in a .ts file.", "start": 8, "length": 12, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts index f86d26ba723..918eb035a8b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'interface declarations' can only be used in TypeScript.", + "message": "'interface declarations' can only be used in a .ts file.", "start": 10, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts index ccd9450f49b..cdec262f699 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'module declarations' can only be used in TypeScript.", + "message": "'module declarations' can only be used in a .ts file.", "start": 7, "length": 1, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts index 11105a44197..a71a2cf2bc7 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'type aliases' can only be used in TypeScript.", + "message": "'type aliases' can only be used in a .ts file.", "start": 0, "length": 11, "category": "error", diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts index 81016fd8ba7..4bd4ce706b9 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts @@ -6,7 +6,7 @@ verify.getSemanticDiagnostics(`[ { - "message": "'public' can only be used in TypeScript.", + "message": "'public' can only be used in a .ts file.", "start": 0, "length": 6, "category": "error", From 5ecfafd32bc8094140cf229b67971e2ba20c08b7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 15:14:41 -0700 Subject: [PATCH 43/51] PR feedback. --- src/services/services.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 831e8a95de3..12ea84eafc1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3238,26 +3238,25 @@ module ts { function getJavaScriptCompletionEntries(): CompletionEntry[] { let entries: CompletionEntry[] = []; - let allIdentifiers: Map = {}; + let allNames: Map = {}; + let target = program.getCompilerOptions().target; for (let sourceFile of program.getSourceFiles()) { let nameTable = getNameTable(sourceFile); for (let name in nameTable) { - allIdentifiers[name] = name; - } - } - - var target = program.getCompilerOptions().target; - for (let name in allIdentifiers) { - let displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks:*/ true); - if (displayName) { - // Use '1' so that all javascript identifier entries sort after Symbol entries. - entries.push({ - name: displayName, - kind: ScriptElementKind.warning, - kindModifiers: "", - sortText: "1" - }); + if (!allNames[name]) { + allNames[name] = name; + let displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks:*/ true); + if (displayName) { + let entry = { + name: displayName, + kind: ScriptElementKind.warning, + kindModifiers: "", + sortText: "1" + }; + entries.push(entry); + } + } } } From 0bf65e4c672d2f37f44bb41790b09d6b6690cc66 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 2 Apr 2015 15:36:45 -0700 Subject: [PATCH 44/51] Fix annoying spellin errors. --- src/compiler/parser.ts | 8 ++++---- src/services/navigateTo.ts | 2 +- src/services/patternMatcher.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 14311ccbc52..13dbccbe4b1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -824,7 +824,7 @@ module ts { // to reuse are already at the appropriate position in the new text. That way when we // reuse them, we don't have to figure out if they need to be adjusted. Second, it makes // it very easy to determine if we can reuse a node. If the node's position is at where - // we are in the text, then we can reuse it. Otherwise we can't. If hte node's position + // we are in the text, then we can reuse it. Otherwise we can't. If the node's position // is ahead of us, then we'll need to rescan tokens. If the node's position is behind // us, then we'll need to skip it or crumble it as appropriate // @@ -1029,7 +1029,7 @@ module ts { // 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 + // flag will be in. This should be the 'false' state for that flag. The reason for this is // that we don't store data in our nodes unless the value is in the *non-default* state. So, // for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for // 'disallow-in' set to 'false'. Otherwise, if we had 'allowsIn' set to 'true', then almost @@ -1040,7 +1040,7 @@ module ts { // // An important thing about these context concepts. By default they are effectively inherited // while parsing through every grammar production. i.e. if you don't change them, then when - // you parse a sub-production, it will have the same context values as hte parent production. + // you parse a sub-production, it will have the same context values as the parent production. // This is great most of the time. After all, consider all the 'expression' grammar productions // and how nearly all of them pass along the 'in' and 'yield' context values: // @@ -1793,7 +1793,7 @@ module ts { // some node, then we cannot get a node from the old source tree. This is because we // want to mark the next node we encounter as being unusable. // - // Note: This may be too conservative. Perhaps we could reuse hte node and set the bit + // Note: This may be too conservative. Perhaps we could reuse the node and set the bit // on it (or its leftmost child) as having the error. For now though, being conservative // is nice and likely won't ever affect perf. if (parseErrorBeforeNextFinishedNode) { diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index 9871a447c05..54f87d8e50b 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -22,7 +22,7 @@ module ts.NavigateTo { continue; } - // It was a match! If the pattern has dots in it, then also see if hte + // It was a match! If the pattern has dots in it, then also see if the // declaration container matches as well. if (patternMatcher.patternContainsDots) { let containers = getContainers(declaration); diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index 61642552cab..646782b2cf0 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -471,7 +471,7 @@ module ts { // Helper function to compare two matches to determine which is better. Matches are first // ordered by kind (so all prefix matches always beat all substring matches). Then, if the - // match is a camel case match, the relative weights of hte match are used to determine + // match is a camel case match, the relative weights of the match are used to determine // which is better (with a greater weight being better). Then if the match is of the same // type, then a case sensitive match is considered better than an insensitive one. function patternMatchCompareTo(match1: PatternMatch, match2: PatternMatch): number { From 105936f1982da73e97fc10fcb044b1534c5376ab Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 17:02:26 -0700 Subject: [PATCH 45/51] Break out acquisition of class properties vs. emitting them. --- src/compiler/emitter.ts | 61 +++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5d4bf9df3e1..40f23b5140f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3199,28 +3199,41 @@ module ts { } } - function emitMemberAssignments(node: ClassLikeDeclaration, staticFlag: NodeFlags) { - forEach(node.members, member => { - if (member.kind === SyntaxKind.PropertyDeclaration && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart((member).name); - if (staticFlag) { - emitDeclarationName(node); - } - else { - write("this"); - } - emitMemberAccessForPropertyName((member).name); - emitEnd((member).name); - write(" = "); - emit((member).initializer); - write(";"); - emitEnd(member); - emitTrailingComments(member); + function getInitializedProperties(node: ClassLikeDeclaration, static: boolean) { + let properties: PropertyDeclaration[] = []; + for (let member of node.members) { + if (member.kind === SyntaxKind.PropertyDeclaration && static === ((member.flags & NodeFlags.Static) !== 0) && (member).initializer) { + properties.push(member); } - }); + } + + return properties; + } + + function emitPropertyDeclarations(node: ClassLikeDeclaration, properties: PropertyDeclaration[]) { + for (let property of properties) { + emitPropertyDeclaration(node, property); + } + } + + function emitPropertyDeclaration(node: ClassLikeDeclaration, property: PropertyDeclaration) { + writeLine(); + emitLeadingComments(property); + emitStart(property); + emitStart(property.name); + if (property.flags & NodeFlags.Static) { + emitDeclarationName(node); + } + else { + write("this"); + } + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + emit(property.initializer); + write(";"); + emitEnd(property); + emitTrailingComments(property); } function emitMemberFunctionsForES5AndLower(node: ClassLikeDeclaration) { @@ -3425,7 +3438,7 @@ module ts { emitEnd(baseTypeElement); } } - emitMemberAssignments(node, /*staticFlag*/0); + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); if (ctor) { var statements: Node[] = (ctor.body).statements; if (superCall) { @@ -3591,7 +3604,7 @@ module ts { // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. writeLine(); - emitMemberAssignments(node, NodeFlags.Static); + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); emitDecoratorsOfClass(node); // If this is an exported class, but not on the top level (i.e. on an internal @@ -3648,7 +3661,7 @@ module ts { writeLine(); emitConstructor(node, baseTypeNode); emitMemberFunctionsForES5AndLower(node); - emitMemberAssignments(node, NodeFlags.Static); + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); writeLine(); emitDecoratorsOfClass(node); writeLine(); From aef37f1e41f5fdcfdf78f35f726296a4685ac6d6 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 2 Apr 2015 17:42:24 -0700 Subject: [PATCH 46/51] Address code review: have more explicit error --- src/compiler/checker.ts | 10 +- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + ...lisionArgumentsClassConstructor.errors.txt | 92 +++++++++---------- .../collisionArgumentsClassMethod.errors.txt | 84 ++++++++--------- ...ationInStrictModeByDefaultInES6.errors.txt | 8 +- .../reference/parserRealSource11.errors.txt | 8 +- 7 files changed, 110 insertions(+), 97 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ce7fe5e1cf..ed32686e794 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12441,7 +12441,15 @@ module ts { let identifier = name; if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { let nameText = declarationNameToString(identifier); - return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + + // We are checking if this parameter's name is of method or constructor so that we can give more explicit errors because + // invalid usage error particularly of "arguments" is very common mistake + if (contextNode && (contextNode.parent.kind === SyntaxKind.MethodDeclaration || contextNode.parent.kind === SyntaxKind.Constructor)) { + return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code, nameText); + } + else { + return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + } } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 3e9017786e5..c24b3fe174c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -167,6 +167,7 @@ module ts { Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." }, Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}' because class definition is considered a strict mode code " }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f6edb3150b6..0c7708ad2f0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -659,6 +659,10 @@ "category": "Error", "code": 1209 }, + "Invalid use of '{0}' because class definition is considered a strict mode code ": { + "category": "Error", + "code": 1210 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt index 7e145688bac..391e4ad24d4 100644 --- a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt @@ -1,41 +1,41 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,28): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(4,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. tests/cases/compiler/collisionArgumentsClassConstructor.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(13,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(13,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(20,13): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(25,13): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(31,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(36,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,25): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,28): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,28): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(54,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(59,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(60,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(59,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(60,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. tests/cases/compiler/collisionArgumentsClassConstructor.ts(62,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassConstructor.ts(70,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code ==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (38 errors) ==== @@ -45,7 +45,7 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any[]; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -54,7 +54,7 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: class c12 { constructor(arguments: number, ...rest) { // error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error @@ -65,7 +65,7 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: class c1NoError { constructor(arguments: number) { // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments = 10; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -92,7 +92,7 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments = 10; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -101,7 +101,7 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: class c3NoError { constructor(public arguments: number) { // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments = 10; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -111,31 +111,31 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: declare class c4 { constructor(i: number, ...arguments); // No error - no code gen ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } declare class c42 { constructor(arguments: number, ...rest); // No error - no code gen ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } declare class c4NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } class c5 { constructor(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any[]; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -145,13 +145,13 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: class c52 { constructor(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: any, ...rest) { // error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error @@ -163,13 +163,13 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: class c5NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: string); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: any) { // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -179,25 +179,25 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1100: declare class c6 { constructor(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } declare class c62 { constructor(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } declare class c6NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code constructor(arguments: string); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } \ No newline at end of file diff --git a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt index 34b92990c79..67ec1309366 100644 --- a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt @@ -1,34 +1,34 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(2,27): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(2,30): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(2,30): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(3,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. tests/cases/compiler/collisionArgumentsClassMethod.ts(6,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(8,23): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(8,23): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(11,29): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(12,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(11,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(12,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(13,23): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(13,26): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(13,26): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(16,16): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(17,16): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(16,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(17,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. tests/cases/compiler/collisionArgumentsClassMethod.ts(19,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(24,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/compiler/collisionArgumentsClassMethod.ts(43,13): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Invalid use of 'arguments' in strict mode. @@ -39,14 +39,14 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Inva ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any[]; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. } public foo1(arguments: number, ...rest) { //arguments is error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error @@ -55,35 +55,35 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Inva } public fooNoError(arguments: number) { // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments = 10; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. } public f4(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any[]; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. } public f41(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f41(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f41(arguments: any, ...rest) { // error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error @@ -92,13 +92,13 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Inva } public f4NoError(arguments: number); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4NoError(arguments: string); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4NoError(arguments: any) { // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code var arguments: any; // no error ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -108,32 +108,32 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Inva declare class c2 { public foo(i: number, ...arguments); // No error - no code gen ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public foo1(arguments: number, ...rest); // No error - no code gen ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public fooNoError(arguments: number); // No error - no code gen ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f41(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f41(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4NoError(arguments: number); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code public f4NoError(arguments: string); // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code } class c3 { diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt index d109b048085..024716f91fc 100644 --- a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Invalid use of 'eval' because class definition is considered a strict mode code tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'. Property 'callee' is missing in type 'String'. @@ -11,10 +11,10 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy public implements() { } public foo(arguments: any) { } ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code private bar(eval:any) { ~~~~ -!!! error TS1100: Invalid use of 'eval' in strict mode. +!!! error TS1210: Invalid use of 'eval' because class definition is considered a strict mode code arguments = "hello"; ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index 9b09e6d3b9d..1ed2ee93933 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -115,7 +115,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(504,58): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(506,22): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(507,58): error TS2304: Cannot find name 'TokenID'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(518,32): error TS2304: Cannot find name 'NodeType'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(525,27): error TS2304: Cannot find name 'Signature'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(527,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(528,34): error TS2304: Cannot find name 'NodeType'. @@ -247,7 +247,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(963,27): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(969,31): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(977,32): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(981,27): error TS2304: Cannot find name 'Type'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,44): error TS2304: Cannot find name 'hasFlag'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,67): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1005,57): error TS2304: Cannot find name 'FncFlags'. @@ -1273,7 +1273,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error public target: AST, public arguments: ASTList) { ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code super(nodeType); this.minChar = this.target.minChar; } @@ -2002,7 +2002,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error constructor (public name: Identifier, public bod: ASTList, public isConstructor: boolean, public arguments: ASTList, public vars: ASTList, public scopes: ASTList, public statics: ASTList, ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code nodeType: number) { super(nodeType); From 7562a34ae851c6b104ca7b86dc0469626fd9d7be Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 17:23:25 -0700 Subject: [PATCH 47/51] Add support for emitting static properties in class expressions in ES6. --- src/compiler/emitter.ts | 74 ++++++++++++++++--- ...ressionWithStaticPropertiesES61.errors.txt | 7 ++ ...classExpressionWithStaticPropertiesES61.js | 10 +++ ...classExpressionWithStaticPropertiesES61.ts | 2 + 4 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithStaticPropertiesES61.js create mode 100644 tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 40f23b5140f..86c0bfe1ac5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3216,22 +3216,30 @@ module ts { } } - function emitPropertyDeclaration(node: ClassLikeDeclaration, property: PropertyDeclaration) { + function emitPropertyDeclaration(node: ClassLikeDeclaration, property: PropertyDeclaration, receiver?: Identifier, isExpression?: boolean) { writeLine(); emitLeadingComments(property); emitStart(property); emitStart(property.name); - if (property.flags & NodeFlags.Static) { - emitDeclarationName(node); + if (receiver) { + emit(receiver); } else { - write("this"); + if (property.flags & NodeFlags.Static) { + emitDeclarationName(node); + } + else { + write("this"); + } } emitMemberAccessForPropertyName(property.name); emitEnd(property.name); write(" = "); emit(property.initializer); - write(";"); + if (!isExpression) { + write(";"); + } + emitEnd(property); emitTrailingComments(property); } @@ -3351,6 +3359,14 @@ module ts { tempVariables = undefined; tempParameters = undefined; + emitConstructorWorker(node, baseTypeElement); + + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + + function emitConstructorWorker(node: ClassLikeDeclaration, baseTypeElement: HeritageClauseElement) { // Check if we have property assignment inside class declaration. // If there is property assignment, we need to emit constructor whether users define it or not // If there is no property assignment, we can omit constructor if users do not define it @@ -3458,10 +3474,6 @@ module ts { if (ctor) { emitTrailingComments(ctor); } - - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; } function emitClassExpression(node: ClassExpression) { @@ -3553,6 +3565,29 @@ module ts { } } + // If the class has static properties, and it's a class expression, then we'll need + // to specialize the emit a bit. for a class expression of the form: + // + // class C { static a = 1; static b = 2; ... } + // + // We'll emit: + // + // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // + // This keeps the expression as an expression, while ensuring that the static parts + // of it have been initialized by the time it is used. + let staticProperties = getInitializedProperties(node, /*static:*/ true); + let isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === SyntaxKind.ClassExpression; + let tempVariable: Identifier; + + if (isClassExpressionWithStaticProperties) { + tempVariable = createAndRecordTempVariable(TempFlags.Auto); + write("("); + increaseIndent(); + emit(tempVariable); + write(" = ") + } + write("class"); // check if this is an "export default class" as it may not have a name. Do not emit the name if the class is decorated. @@ -3603,9 +3638,24 @@ module ts { // From ES6 specification: // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - writeLine(); - emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); - emitDecoratorsOfClass(node); + + if (isClassExpressionWithStaticProperties) { + for (var property of staticProperties) { + write(","); + writeLine(); + emitPropertyDeclaration(node, property, /*receiver:*/ tempVariable, /*isExpression:*/ true); + } + write(","); + writeLine(); + emit(tempVariable); + decreaseIndent(); + write(")"); + } + else { + writeLine(); + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node); + } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt new file mode 100644 index 00000000000..bc015a3d8f0 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts(1,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts (1 errors) ==== + var v = class C { static a = 1; static b = 2 }; + ~ +!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.js b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.js new file mode 100644 index 00000000000..43f5e7415c4 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.js @@ -0,0 +1,10 @@ +//// [classExpressionWithStaticPropertiesES61.ts] +var v = class C { static a = 1; static b = 2 }; + +//// [classExpressionWithStaticPropertiesES61.js] +var v = (_a = class C { + }, + _a.a = 1, + _a.b = 2, + _a); +var _a; diff --git a/tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts b/tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts new file mode 100644 index 00000000000..8df07b9569a --- /dev/null +++ b/tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts @@ -0,0 +1,2 @@ +//@target: es6 +var v = class C { static a = 1; static b = 2 }; \ No newline at end of file From be26d417a3dea206b6dbd121e762c2ddd7ab0cd1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 17:50:11 -0700 Subject: [PATCH 48/51] Add additional tests. --- .../classExpressionWithStaticProperties1.errors.txt | 7 +++++++ .../reference/classExpressionWithStaticProperties1.js | 11 +++++++++++ .../classExpressionWithStaticProperties2.errors.txt | 7 +++++++ .../reference/classExpressionWithStaticProperties2.js | 10 ++++++++++ ...classExpressionWithStaticPropertiesES62.errors.txt | 7 +++++++ .../classExpressionWithStaticPropertiesES62.js | 9 +++++++++ .../compiler/classExpressionWithStaticProperties1.ts | 1 + .../compiler/classExpressionWithStaticProperties2.ts | 1 + .../classExpressionWithStaticPropertiesES62.ts | 2 ++ 9 files changed, 55 insertions(+) create mode 100644 tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithStaticProperties1.js create mode 100644 tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithStaticProperties2.js create mode 100644 tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithStaticPropertiesES62.js create mode 100644 tests/cases/compiler/classExpressionWithStaticProperties1.ts create mode 100644 tests/cases/compiler/classExpressionWithStaticProperties2.ts create mode 100644 tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt b/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt new file mode 100644 index 00000000000..28e42dd33f1 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/classExpressionWithStaticProperties1.ts(1,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithStaticProperties1.ts (1 errors) ==== + var v = class C { static a = 1; static b = 2 }; + ~ +!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.js b/tests/baselines/reference/classExpressionWithStaticProperties1.js new file mode 100644 index 00000000000..344dbff50ed --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties1.js @@ -0,0 +1,11 @@ +//// [classExpressionWithStaticProperties1.ts] +var v = class C { static a = 1; static b = 2 }; + +//// [classExpressionWithStaticProperties1.js] +var v = (function () { + function C() { + } + C.a = 1; + C.b = 2; + return C; +})(); diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt b/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt new file mode 100644 index 00000000000..9a915f70193 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/classExpressionWithStaticProperties2.ts(1,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithStaticProperties2.ts (1 errors) ==== + var v = class C { static a = 1; static b }; + ~ +!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.js b/tests/baselines/reference/classExpressionWithStaticProperties2.js new file mode 100644 index 00000000000..9ff9c06ffe4 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties2.js @@ -0,0 +1,10 @@ +//// [classExpressionWithStaticProperties2.ts] +var v = class C { static a = 1; static b }; + +//// [classExpressionWithStaticProperties2.js] +var v = (function () { + function C() { + } + C.a = 1; + return C; +})(); diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt new file mode 100644 index 00000000000..bed4b2c01aa --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts(1,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts (1 errors) ==== + var v = class C { static a = 1; static b }; + ~ +!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.js b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.js new file mode 100644 index 00000000000..1efa56ecaa2 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.js @@ -0,0 +1,9 @@ +//// [classExpressionWithStaticPropertiesES62.ts] +var v = class C { static a = 1; static b }; + +//// [classExpressionWithStaticPropertiesES62.js] +var v = (_a = class C { + }, + _a.a = 1, + _a); +var _a; diff --git a/tests/cases/compiler/classExpressionWithStaticProperties1.ts b/tests/cases/compiler/classExpressionWithStaticProperties1.ts new file mode 100644 index 00000000000..19fe035e6a7 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithStaticProperties1.ts @@ -0,0 +1 @@ +var v = class C { static a = 1; static b = 2 }; \ No newline at end of file diff --git a/tests/cases/compiler/classExpressionWithStaticProperties2.ts b/tests/cases/compiler/classExpressionWithStaticProperties2.ts new file mode 100644 index 00000000000..f7b9606b6e0 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithStaticProperties2.ts @@ -0,0 +1 @@ +var v = class C { static a = 1; static b }; \ No newline at end of file diff --git a/tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts b/tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts new file mode 100644 index 00000000000..ee0430eb793 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts @@ -0,0 +1,2 @@ +//@target: es6 +var v = class C { static a = 1; static b }; \ No newline at end of file From 8537232d32180f61dbd1bac35cde67932de692f6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 3 Apr 2015 13:04:56 -0700 Subject: [PATCH 49/51] Add decorator test for a decorator on a class expression. --- .../classExpressionWithDecorator1.errors.txt | 10 +++++++ .../classExpressionWithDecorator1.js | 26 +++++++++++++++++++ .../compiler/classExpressionWithDecorator1.ts | 1 + 3 files changed, 37 insertions(+) create mode 100644 tests/baselines/reference/classExpressionWithDecorator1.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithDecorator1.js create mode 100644 tests/cases/compiler/classExpressionWithDecorator1.ts diff --git a/tests/baselines/reference/classExpressionWithDecorator1.errors.txt b/tests/baselines/reference/classExpressionWithDecorator1.errors.txt new file mode 100644 index 00000000000..10f0d8aa376 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithDecorator1.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/classExpressionWithDecorator1.ts(1,9): error TS1109: Expression expected. +tests/cases/compiler/classExpressionWithDecorator1.ts(1,10): error TS2304: Cannot find name 'decorate'. + + +==== tests/cases/compiler/classExpressionWithDecorator1.ts (2 errors) ==== + var v = @decorate class C { static p = 1 }; + ~ +!!! error TS1109: Expression expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'decorate'. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithDecorator1.js b/tests/baselines/reference/classExpressionWithDecorator1.js new file mode 100644 index 00000000000..fd15941996a --- /dev/null +++ b/tests/baselines/reference/classExpressionWithDecorator1.js @@ -0,0 +1,26 @@ +//// [classExpressionWithDecorator1.ts] +var v = @decorate class C { static p = 1 }; + +//// [classExpressionWithDecorator1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var v = ; +var C = (function () { + function C() { + } + C.p = 1; + C = __decorate([decorate], C); + return C; +})(); +; diff --git a/tests/cases/compiler/classExpressionWithDecorator1.ts b/tests/cases/compiler/classExpressionWithDecorator1.ts new file mode 100644 index 00000000000..74b49456a36 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithDecorator1.ts @@ -0,0 +1 @@ +var v = @decorate class C { static p = 1 }; \ No newline at end of file From 4824e966b28a23d037a8e30b3759ff8e0407d75c Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 3 Apr 2015 17:35:42 -0700 Subject: [PATCH 50/51] Update baseline --- .../reference/convertKeywordsYes.errors.txt | 64 +++++-------------- .../baselines/reference/convertKeywordsYes.js | 54 ++++++++-------- 2 files changed, 44 insertions(+), 74 deletions(-) diff --git a/tests/baselines/reference/convertKeywordsYes.errors.txt b/tests/baselines/reference/convertKeywordsYes.errors.txt index 1a54e3615b4..932fda09be8 100644 --- a/tests/baselines/reference/convertKeywordsYes.errors.txt +++ b/tests/baselines/reference/convertKeywordsYes.errors.txt @@ -1,31 +1,21 @@ -tests/cases/compiler/convertKeywordsYes.ts(292,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1003: Identifier expected. -tests/cases/compiler/convertKeywordsYes.ts(293,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(293,21): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(294,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1003: Identifier expected. -tests/cases/compiler/convertKeywordsYes.ts(296,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1005: '{' expected. +tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(296,19): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(297,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(297,19): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(298,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(298,21): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(299,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(299,18): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(301,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(301,18): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(303,10): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1003: Identifier expected. +tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1005: '{' expected. tests/cases/compiler/convertKeywordsYes.ts(303,17): error TS1005: ';' expected. -==== tests/cases/compiler/convertKeywordsYes.ts (25 errors) ==== +==== tests/cases/compiler/convertKeywordsYes.ts (15 errors) ==== // reserved ES5 future in strict mode var constructor = 0; @@ -318,65 +308,45 @@ tests/cases/compiler/convertKeywordsYes.ts(303,17): error TS1005: ';' expected. module bigModule { class constructor { } class implements { } - -!!! error TS2300: Duplicate identifier '(Missing)'. - ~~~~~~~~~~ -!!! error TS1003: Identifier expected. class interface { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class let { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. class module { } class package { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class private { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class protected { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class public { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class set { } class static { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class get { } class yield { } - -!!! error TS2300: Duplicate identifier '(Missing)'. ~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: '{' expected. ~ !!! error TS1005: ';' expected. class declare { } diff --git a/tests/baselines/reference/convertKeywordsYes.js b/tests/baselines/reference/convertKeywordsYes.js index 174ff31fc17..2b17e744b66 100644 --- a/tests/baselines/reference/convertKeywordsYes.js +++ b/tests/baselines/reference/convertKeywordsYes.js @@ -505,22 +505,22 @@ var bigModule; } return constructor; })(); - var = (function () { - function () { + var default_1 = (function () { + function default_1() { } - return ; + return default_1; })(); - var = (function () { - function () { + var default_2 = (function () { + function default_2() { } - return ; + return default_2; })(); interface; { } - var = (function () { - function () { + var default_3 = (function () { + function default_3() { } - return ; + return default_3; })(); var _a = void 0; var module = (function () { @@ -528,31 +528,31 @@ var bigModule; } return module; })(); - var = (function () { - function () { + var default_4 = (function () { + function default_4() { } - return ; + return default_4; })(); package; { } - var = (function () { - function () { + var default_5 = (function () { + function default_5() { } - return ; + return default_5; })(); private; { } - var = (function () { - function () { + var default_6 = (function () { + function default_6() { } - return ; + return default_6; })(); protected; { } - var = (function () { - function () { + var default_7 = (function () { + function default_7() { } - return ; + return default_7; })(); public; { } @@ -561,10 +561,10 @@ var bigModule; } return set; })(); - var = (function () { - function () { + var default_8 = (function () { + function default_8() { } - return ; + return default_8; })(); static; { } @@ -573,10 +573,10 @@ var bigModule; } return get; })(); - var = (function () { - function () { + var default_9 = (function () { + function default_9() { } - return ; + return default_9; })(); yield; { } From 09d037fb6fd5de58ea91f7bc7ccb79d72d057e01 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 3 Apr 2015 17:59:40 -0700 Subject: [PATCH 51/51] Address code review --- src/compiler/checker.ts | 9 +- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...lisionArgumentsClassConstructor.errors.txt | 132 +++++++++--------- .../collisionArgumentsClassMethod.errors.txt | 116 +++++++-------- ...ationInStrictModeByDefaultInES6.errors.txt | 12 +- .../reference/parserRealSource11.errors.txt | 8 +- 7 files changed, 141 insertions(+), 140 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b4b3f956fc5..58e3a71a680 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12446,10 +12446,11 @@ module ts { if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { let nameText = declarationNameToString(identifier); - // We are checking if this parameter's name is of method or constructor so that we can give more explicit errors because - // invalid usage error particularly of "arguments" is very common mistake - if (contextNode && (contextNode.parent.kind === SyntaxKind.MethodDeclaration || contextNode.parent.kind === SyntaxKind.Constructor)) { - return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code, nameText); + // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) + // if so, we would like to give more explicit invalid usage error. + // This will be particularly helpful in the case of "arguments" as such case is very common mistake. + if (getAncestor(name, SyntaxKind.ClassDeclaration) || getAncestor(name, SyntaxKind.ClassExpression)) { + return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); } else { return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c01834293a6..b4380f4d2de 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -167,7 +167,7 @@ module ts { Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." }, Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, - Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}' because class definition is considered a strict mode code " }, + Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fdf469bb0a6..fe349b78343 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -659,7 +659,7 @@ "category": "Error", "code": 1209 }, - "Invalid use of '{0}' because class definition is considered a strict mode code ": { + "Invalid use of '{0}'. Class definitions are automatically in strict mode.": { "category": "Error", "code": 1210 }, diff --git a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt index 391e4ad24d4..03bf4f9e38b 100644 --- a/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassConstructor.errors.txt @@ -1,41 +1,41 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,28): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(4,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(3,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(4,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(8,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(13,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(20,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(25,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(9,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(13,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(14,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(20,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(25,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(31,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(36,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(30,24): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(31,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(35,24): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(36,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(41,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(44,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(47,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(51,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(52,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,25): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,28): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(54,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(59,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(60,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(53,28): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(54,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(59,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(60,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassConstructor.ts(61,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(62,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(70,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassConstructor.ts(62,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(67,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(68,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(69,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(70,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(75,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(76,31): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(79,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(80,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(84,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ==== tests/cases/compiler/collisionArgumentsClassConstructor.ts (38 errors) ==== @@ -45,30 +45,30 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any[]; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c12 { constructor(arguments: number, ...rest) { // error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c1NoError { constructor(arguments: number) { // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } @@ -76,14 +76,14 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: constructor(...restParameters) { var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c2NoError { constructor() { var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } @@ -92,112 +92,112 @@ tests/cases/compiler/collisionArgumentsClassConstructor.ts(85,17): error TS1210: ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c3NoError { constructor(public arguments: number) { // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } declare class c4 { constructor(i: number, ...arguments); // No error - no code gen ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } declare class c42 { constructor(arguments: number, ...rest); // No error - no code gen ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } declare class c4NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } class c5 { constructor(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any[]; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c52 { constructor(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: any, ...rest) { // error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } class c5NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: string); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: any) { // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } declare class c6 { constructor(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } declare class c62 { constructor(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } declare class c6NoError { constructor(arguments: number); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. constructor(arguments: string); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt index 67ec1309366..ea699414f17 100644 --- a/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt +++ b/tests/baselines/reference/collisionArgumentsClassMethod.errors.txt @@ -1,36 +1,36 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(2,27): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(2,30): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(3,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(2,30): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(3,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(5,17): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(6,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(8,23): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(9,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(11,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(12,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(6,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(8,23): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(9,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(11,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(12,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(13,23): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(13,26): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(14,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(16,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(17,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/compiler/collisionArgumentsClassMethod.ts(13,26): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(14,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(16,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(17,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/compiler/collisionArgumentsClassMethod.ts(18,16): error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. -tests/cases/compiler/collisionArgumentsClassMethod.ts(19,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(24,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/compiler/collisionArgumentsClassMethod.ts(43,13): error TS1100: Invalid use of 'arguments' in strict mode. -tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(19,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(21,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(22,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(23,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(24,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(29,30): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(30,17): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(31,23): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(33,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(34,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(35,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(36,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(37,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(38,22): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(43,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ==== tests/cases/compiler/collisionArgumentsClassMethod.ts (33 errors) ==== @@ -39,112 +39,112 @@ tests/cases/compiler/collisionArgumentsClassMethod.ts(46,13): error TS1100: Inva ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any[]; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public foo1(arguments: number, ...rest) { //arguments is error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ~~~~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public fooNoError(arguments: number) { // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public f4(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4(i: any, ...arguments) { // error ~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any[]; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public f41(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f41(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f41(arguments: any, ...rest) { // error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ~~~~~~~~~~~~~~ !!! error TS2396: Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters. var arguments: any; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public f4NoError(arguments: number); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4NoError(arguments: string); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4NoError(arguments: any) { // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. var arguments: any; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } declare class c2 { public foo(i: number, ...arguments); // No error - no code gen ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public foo1(arguments: number, ...rest); // No error - no code gen ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public fooNoError(arguments: number); // No error - no code gen ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4(i: number, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4(i: string, ...arguments); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f41(arguments: number, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f41(arguments: string, ...rest); // no codegen no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4NoError(arguments: number); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. public f4NoError(arguments: string); // no error ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } class c3 { public foo(...restParameters) { var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } public fooNoError() { var arguments = 10; // no error ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. } } \ No newline at end of file diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt index 024716f91fc..e1b0bb34529 100644 --- a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Invalid use of 'eval' because class definition is considered a strict mode code -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'. Property 'callee' is missing in type 'String'. @@ -11,13 +11,13 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy public implements() { } public foo(arguments: any) { } ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. private bar(eval:any) { ~~~~ -!!! error TS1210: Invalid use of 'eval' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. arguments = "hello"; ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. ~~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type 'IArguments'. !!! error TS2322: Property 'callee' is missing in type 'String'. diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index 1ed2ee93933..718bda19a67 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -115,7 +115,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(504,58): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(506,22): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(507,58): error TS2304: Cannot find name 'TokenID'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(518,32): error TS2304: Cannot find name 'NodeType'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(520,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(525,27): error TS2304: Cannot find name 'Signature'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(527,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(528,34): error TS2304: Cannot find name 'NodeType'. @@ -247,7 +247,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(963,27): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(969,31): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(977,32): error TS2304: Cannot find name 'Symbol'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(981,27): error TS2304: Cannot find name 'Type'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(985,29): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,44): error TS2304: Cannot find name 'hasFlag'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1004,67): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1005,57): error TS2304: Cannot find name 'FncFlags'. @@ -1273,7 +1273,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error public target: AST, public arguments: ASTList) { ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. super(nodeType); this.minChar = this.target.minChar; } @@ -2002,7 +2002,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error constructor (public name: Identifier, public bod: ASTList, public isConstructor: boolean, public arguments: ASTList, public vars: ASTList, public scopes: ASTList, public statics: ASTList, ~~~~~~~~~ -!!! error TS1210: Invalid use of 'arguments' because class definition is considered a strict mode code +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. nodeType: number) { super(nodeType);