diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.errors.txt b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.errors.txt
new file mode 100644
index 00000000000..97013301618
--- /dev/null
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.errors.txt
@@ -0,0 +1,29 @@
+tests/cases/compiler/declFile.d.ts(3,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(4,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(6,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(8,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+
+==== tests/cases/compiler/client.ts (0 errors) ====
+ ///
+ var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
+
+==== tests/cases/compiler/declFile.d.ts (4 errors) ====
+
+ declare module M {
+ declare var x;
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+ declare function f();
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+ declare module N { }
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+ declare class C { }
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+ }
+
\ No newline at end of file
diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js
new file mode 100644
index 00000000000..e97312893ad
--- /dev/null
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFile.js
@@ -0,0 +1,21 @@
+//// [tests/cases/compiler/declFileWithErrorsInInputDeclarationFile.ts] ////
+
+//// [declFile.d.ts]
+
+declare module M {
+ declare var x;
+ declare function f();
+
+ declare module N { }
+
+ declare class C { }
+}
+
+//// [client.ts]
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
+
+
+//// [client.js]
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.errors.txt b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.errors.txt
new file mode 100644
index 00000000000..97013301618
--- /dev/null
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.errors.txt
@@ -0,0 +1,29 @@
+tests/cases/compiler/declFile.d.ts(3,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(4,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(6,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+tests/cases/compiler/declFile.d.ts(8,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+
+==== tests/cases/compiler/client.ts (0 errors) ====
+ ///
+ var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
+
+==== tests/cases/compiler/declFile.d.ts (4 errors) ====
+
+ declare module M {
+ declare var x;
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+ declare function f();
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+ declare module N { }
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+
+ declare class C { }
+ ~~~~~~~
+!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
+ }
+
\ No newline at end of file
diff --git a/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js
new file mode 100644
index 00000000000..11dcc06380c
--- /dev/null
+++ b/tests/baselines/reference/declFileWithErrorsInInputDeclarationFileWithOut.js
@@ -0,0 +1,21 @@
+//// [tests/cases/compiler/declFileWithErrorsInInputDeclarationFileWithOut.ts] ////
+
+//// [declFile.d.ts]
+
+declare module M {
+ declare var x;
+ declare function f();
+
+ declare module N { }
+
+ declare class C { }
+}
+
+//// [client.ts]
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
+
+
+//// [out.js]
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
diff --git a/tests/cases/compiler/declFileWithErrorsInInputDeclarationFile.ts b/tests/cases/compiler/declFileWithErrorsInInputDeclarationFile.ts
new file mode 100644
index 00000000000..e7d3b592932
--- /dev/null
+++ b/tests/cases/compiler/declFileWithErrorsInInputDeclarationFile.ts
@@ -0,0 +1,15 @@
+// @declaration: true
+
+// @Filename: declFile.d.ts
+declare module M {
+ declare var x;
+ declare function f();
+
+ declare module N { }
+
+ declare class C { }
+}
+
+// @Filename: client.ts
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file
diff --git a/tests/cases/compiler/declFileWithErrorsInInputDeclarationFileWithOut.ts b/tests/cases/compiler/declFileWithErrorsInInputDeclarationFileWithOut.ts
new file mode 100644
index 00000000000..005b52d5bc9
--- /dev/null
+++ b/tests/cases/compiler/declFileWithErrorsInInputDeclarationFileWithOut.ts
@@ -0,0 +1,16 @@
+// @declaration: true
+// @out: out.js
+
+// @Filename: declFile.d.ts
+declare module M {
+ declare var x;
+ declare function f();
+
+ declare module N { }
+
+ declare class C { }
+}
+
+// @Filename: client.ts
+///
+var x = new M.C(); // Declaration file wont get emitted because there are errors in declaration file