Skip to content

Commit 181d126

Browse files
committed
diagnostic messages conflicts resolved
1 parent 2eea216 commit 181d126

File tree

7 files changed

+39
-5
lines changed

7 files changed

+39
-5
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ namespace ts {
22402240
const namespaceMeaning = SymbolFlags.Namespace | (isInJSFile(name) ? meaning & SymbolFlags.Value : 0);
22412241
let symbol: Symbol | undefined;
22422242
if (name.kind === SyntaxKind.Identifier) {
2243-
const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name).escapedText);
2243+
const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name));
22442244
const symbolFromJSPrototype = isInJSFile(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : undefined;
22452245
symbol = resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true);
22462246
if (!symbol) {
@@ -15271,8 +15271,8 @@ namespace ts {
1527115271

1527215272
// EXPRESSION TYPE CHECKING
1527315273

15274-
function getCannotFindNameDiagnosticForName(name: __String): DiagnosticMessage {
15275-
switch (name) {
15274+
function getCannotFindNameDiagnosticForName(node: Identifier): DiagnosticMessage {
15275+
switch (node.escapedText) {
1527615276
case "document":
1527715277
case "console":
1527815278
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 {
1530315303
case "Iterator":
1530415304
case "AsyncIterator":
1530515305
return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later;
15306-
default: return Diagnostics.Cannot_find_name_0;
15306+
default:
15307+
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
15308+
return Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
15309+
}
15310+
else {
15311+
return Diagnostics.Cannot_find_name_0;
15312+
}
1530715313
}
1530815314
}
1530915315

@@ -15315,7 +15321,7 @@ namespace ts {
1531515321
node,
1531615322
node.escapedText,
1531715323
SymbolFlags.Value | SymbolFlags.ExportValue,
15318-
getCannotFindNameDiagnosticForName(node.escapedText),
15324+
getCannotFindNameDiagnosticForName(node),
1531915325
node,
1532015326
!isWriteOnlyAccess(node),
1532115327
/*excludeGlobals*/ false,

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4950,5 +4950,9 @@
49504950
"Allow accessing UMD globals from modules.": {
49514951
"category": "Message",
49524952
"code": 95076
4953+
},
4954+
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer." :{
4955+
"category": "Error",
4956+
"code": 18004
49534957
}
49544958
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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.
2+
3+
4+
==== tests/cases/compiler/shorthandPropertyUndefined.ts (1 errors) ====
5+
var a = { b };
6+
~
7+
!!! error TS18004: No value exists in scope for the shorthand property 'b'. Either declare one or provide an initializer.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [shorthandPropertyUndefined.ts]
2+
var a = { b };
3+
4+
//// [shorthandPropertyUndefined.js]
5+
var a = { b: b };
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/shorthandPropertyUndefined.ts ===
2+
var a = { b };
3+
>a : Symbol(a, Decl(shorthandPropertyUndefined.ts, 0, 3))
4+
>b : Symbol(b, Decl(shorthandPropertyUndefined.ts, 0, 9))
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/shorthandPropertyUndefined.ts ===
2+
var a = { b };
3+
>a : { b: any; }
4+
>{ b } : { b: any; }
5+
>b : any
6+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var a = { b };

0 commit comments

Comments
 (0)