diagnostic messages conflicts resolved

This commit is contained in:
karthikkp
2019-04-20 00:48:21 +05:30
parent 2eea21636b
commit 181d126b02
7 changed files with 39 additions and 5 deletions

View File

@@ -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,

View File

@@ -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
}
}

View File

@@ -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.

View File

@@ -0,0 +1,5 @@
//// [shorthandPropertyUndefined.ts]
var a = { b };
//// [shorthandPropertyUndefined.js]
var a = { b: b };

View File

@@ -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))

View File

@@ -0,0 +1,6 @@
=== tests/cases/compiler/shorthandPropertyUndefined.ts ===
var a = { b };
>a : { b: any; }
>{ b } : { b: any; }
>b : any

View File

@@ -0,0 +1 @@
var a = { b };