From 181d126b027e9b80687549e73864a187551ee573 Mon Sep 17 00:00:00 2001 From: karthikkp Date: Sat, 20 Apr 2019 00:48:21 +0530 Subject: [PATCH] diagnostic messages conflicts resolved --- src/compiler/checker.ts | 16 +++++++++++----- src/compiler/diagnosticMessages.json | 4 ++++ .../shorthandPropertyUndefined.errors.txt | 7 +++++++ .../reference/shorthandPropertyUndefined.js | 5 +++++ .../reference/shorthandPropertyUndefined.symbols | 5 +++++ .../reference/shorthandPropertyUndefined.types | 6 ++++++ .../cases/compiler/shorthandPropertyUndefined.ts | 1 + 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/shorthandPropertyUndefined.errors.txt create mode 100644 tests/baselines/reference/shorthandPropertyUndefined.js create mode 100644 tests/baselines/reference/shorthandPropertyUndefined.symbols create mode 100644 tests/baselines/reference/shorthandPropertyUndefined.types create mode 100644 tests/cases/compiler/shorthandPropertyUndefined.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 800f78ecad6..a886802049c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2240,7 +2240,7 @@ namespace ts { const namespaceMeaning = SymbolFlags.Namespace | (isInJSFile(name) ? meaning & SymbolFlags.Value : 0); let symbol: Symbol | undefined; if (name.kind === SyntaxKind.Identifier) { - const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name).escapedText); + const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name)); const symbolFromJSPrototype = isInJSFile(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : undefined; symbol = resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true); if (!symbol) { @@ -15271,8 +15271,8 @@ namespace ts { // EXPRESSION TYPE CHECKING - function getCannotFindNameDiagnosticForName(name: __String): DiagnosticMessage { - switch (name) { + function getCannotFindNameDiagnosticForName(node: Identifier): DiagnosticMessage { + switch (node.escapedText) { case "document": case "console": return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom; @@ -15303,7 +15303,13 @@ namespace ts { case "Iterator": case "AsyncIterator": return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later; - default: return Diagnostics.Cannot_find_name_0; + default: + if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { + return Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer; + } + else { + return Diagnostics.Cannot_find_name_0; + } } } @@ -15315,7 +15321,7 @@ namespace ts { node, node.escapedText, SymbolFlags.Value | SymbolFlags.ExportValue, - getCannotFindNameDiagnosticForName(node.escapedText), + getCannotFindNameDiagnosticForName(node), node, !isWriteOnlyAccess(node), /*excludeGlobals*/ false, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4c06a233eb7..cd08731be02 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4950,5 +4950,9 @@ "Allow accessing UMD globals from modules.": { "category": "Message", "code": 95076 + }, + "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer." :{ + "category": "Error", + "code": 18004 } } diff --git a/tests/baselines/reference/shorthandPropertyUndefined.errors.txt b/tests/baselines/reference/shorthandPropertyUndefined.errors.txt new file mode 100644 index 00000000000..da6f9ad5984 --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyUndefined.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/shorthandPropertyUndefined.ts(1,11): error TS18004: No value exists in scope for the shorthand property 'b'. Either declare one or provide an initializer. + + +==== tests/cases/compiler/shorthandPropertyUndefined.ts (1 errors) ==== + var a = { b }; + ~ +!!! error TS18004: No value exists in scope for the shorthand property 'b'. Either declare one or provide an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/shorthandPropertyUndefined.js b/tests/baselines/reference/shorthandPropertyUndefined.js new file mode 100644 index 00000000000..643b75bb054 --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyUndefined.js @@ -0,0 +1,5 @@ +//// [shorthandPropertyUndefined.ts] +var a = { b }; + +//// [shorthandPropertyUndefined.js] +var a = { b: b }; diff --git a/tests/baselines/reference/shorthandPropertyUndefined.symbols b/tests/baselines/reference/shorthandPropertyUndefined.symbols new file mode 100644 index 00000000000..fd7c0fe4c23 --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyUndefined.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/shorthandPropertyUndefined.ts === +var a = { b }; +>a : Symbol(a, Decl(shorthandPropertyUndefined.ts, 0, 3)) +>b : Symbol(b, Decl(shorthandPropertyUndefined.ts, 0, 9)) + diff --git a/tests/baselines/reference/shorthandPropertyUndefined.types b/tests/baselines/reference/shorthandPropertyUndefined.types new file mode 100644 index 00000000000..7ed8983dc3c --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyUndefined.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/shorthandPropertyUndefined.ts === +var a = { b }; +>a : { b: any; } +>{ b } : { b: any; } +>b : any + diff --git a/tests/cases/compiler/shorthandPropertyUndefined.ts b/tests/cases/compiler/shorthandPropertyUndefined.ts new file mode 100644 index 00000000000..0b9ac3fcbef --- /dev/null +++ b/tests/cases/compiler/shorthandPropertyUndefined.ts @@ -0,0 +1 @@ +var a = { b }; \ No newline at end of file