From 4a346045ce89137c76cda3436abba5603abdb686 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 15:38:26 -0700 Subject: [PATCH 01/15] 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/15] 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/15] 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/15] 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/15] 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/15] 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/15] 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/15] 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/15] 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 72d23c7937f270db2e23b5daa600757d8bbb62d5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 31 Mar 2015 17:48:07 -0700 Subject: [PATCH 10/15] 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 11/15] 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 d06f3aa22478e4f5d1065dcd2ddc7b6f020aa105 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 31 Mar 2015 19:07:45 -0700 Subject: [PATCH 12/15] 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 0f079632b9642568f09f23ae94ec81bf109a733a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 2 Apr 2015 14:58:43 -0700 Subject: [PATCH 13/15] 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 14/15] 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 15/15] 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 {