Skip to content

Commit 2058ba3

Browse files
authored
Do not emit declaration files when they contain a declaration emit error (#4015)
1 parent f44fe42 commit 2058ba3

138 files changed

Lines changed: 306 additions & 235104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/compiler/emitter.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ func (e *emitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFil
217217
return
218218
}
219219

220-
if e.emitOnly != EmitOnlyForcedDts && (options.NoEmit == core.TSTrue || e.host.IsEmitBlocked(declarationFilePath)) {
221-
e.emitResult.EmitSkipped = true
222-
return
223-
}
224-
225220
if e.tr != nil {
226221
defer e.tr.Push(tracing.PhaseEmit, "emitDeclarationFileOrBundle", map[string]any{"declarationFilePath": declarationFilePath}, true)()
227222
}
@@ -230,7 +225,21 @@ func (e *emitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFil
230225
defer putEmitContext()
231226
sourceFile, diags := e.runDeclarationTransformers(emitContext, sourceFile, declarationFilePath, declarationMapPath)
232227

233-
// !!! strada skipped emit if there were diagnostics
228+
for _, elem := range diags {
229+
// Add declaration transform diagnostics to emit diagnostics
230+
e.emitterDiagnostics.Add(elem)
231+
}
232+
233+
if e.emitOnly != EmitOnlyForcedDts && (options.NoEmit == core.TSTrue || e.host.IsEmitBlocked(declarationFilePath)) {
234+
e.emitResult.EmitSkipped = true
235+
return
236+
}
237+
238+
declBlocked := len(diags) > 0 && e.emitOnly != EmitOnlyForcedDts
239+
if declBlocked {
240+
e.emitResult.EmitSkipped = true
241+
return
242+
}
234243

235244
printerOptions := printer.PrinterOptions{
236245
RemoveComments: options.RemoveComments.IsTrue(),
@@ -252,10 +261,6 @@ func (e *emitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFil
252261
// !!!
253262
}, emitContext)
254263

255-
for _, elem := range diags {
256-
// Add declaration transform diagnostics to emit diagnostics
257-
e.emitterDiagnostics.Add(elem)
258-
}
259264
e.printSourceFile(declarationFilePath, declarationMapPath, sourceFile, printer, e.emitOnly != EmitOnlyForcedDts && shouldEmitDeclarationSourceMaps(options, sourceFile))
260265
}
261266

internal/execute/incremental/emitfileshandler.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,27 @@ func (h *emitFilesHandler) emitAllAffectedFiles(options compiler.EmitOptions) *c
5353
if options.TargetSourceFile != nil {
5454
// Result from cache
5555
diagnostics, _ := h.program.snapshot.emitDiagnosticsPerFile.Load(options.TargetSourceFile.Path())
56-
return &compiler.EmitResult{
56+
result := &compiler.EmitResult{
5757
EmitSkipped: true,
5858
Diagnostics: diagnostics.getDiagnostics(h.program.program, options.TargetSourceFile),
5959
}
60+
h.updateHasEmitDiagnostics(result)
61+
return result
62+
}
63+
for _, result := range results {
64+
h.updateHasEmitDiagnostics(result)
6065
}
6166
return compiler.CombineEmitResults(results)
6267
} else {
6368
// Combine results and update buildInfo
6469
result := compiler.CombineEmitResults(results)
70+
h.updateHasEmitDiagnostics(result)
6571
h.emitBuildInfo(options, result)
6672
return result
6773
}
6874
} else if !h.isForDtsErrors {
6975
result := h.program.program.Emit(h.ctx, h.getEmitOptions(options))
76+
h.updateHasEmitDiagnostics(result)
7077
h.updateSnapshot()
7178
h.emitBuildInfo(options, result)
7279
return result
@@ -76,12 +83,19 @@ func (h *emitFilesHandler) emitAllAffectedFiles(options compiler.EmitOptions) *c
7683
Diagnostics: h.program.program.GetDeclarationDiagnostics(h.ctx, options.TargetSourceFile),
7784
}
7885
if len(result.Diagnostics) != 0 {
86+
h.updateHasEmitDiagnostics(result)
7987
h.program.snapshot.hasEmitDiagnostics = true
8088
}
8189
return result
8290
}
8391
}
8492

93+
func (h *emitFilesHandler) updateHasEmitDiagnostics(result *compiler.EmitResult) {
94+
if result != nil && len(result.Diagnostics) != 0 {
95+
h.hasEmitDiagnostics.Store(true)
96+
}
97+
}
98+
8599
func (h *emitFilesHandler) emitBuildInfo(options compiler.EmitOptions, result *compiler.EmitResult) {
86100
buildInfoResult := h.program.emitBuildInfo(h.ctx, options)
87101
if buildInfoResult != nil {
@@ -132,6 +146,7 @@ func (h *emitFilesHandler) emitFilesIncremental(options compiler.EmitOptions) []
132146
Diagnostics: h.program.program.GetDeclarationDiagnostics(h.ctx, affectedFile),
133147
}
134148
}
149+
h.updateHasEmitDiagnostics(result)
135150

136151
// Update the pendingEmit for the file
137152
h.emitUpdates.Store(path, &emitUpdate{pendingKind: getPendingEmitKind(emitKind, pendingKind), result: result})
@@ -199,8 +214,6 @@ func (h *emitFilesHandler) getEmitOptions(options compiler.EmitOptions) compiler
199214
if h.skipDtsOutputOfComposite(options.TargetSourceFile, fileName, text, data, emitSignature, &differsOnlyInMap) {
200215
return nil
201216
}
202-
} else if len(data.Diagnostics) > 0 {
203-
h.hasEmitDiagnostics.Store(true)
204217
}
205218
}
206219

@@ -317,6 +330,7 @@ func emitFiles(ctx context.Context, program *Program, options compiler.EmitOptio
317330
// Single file emit - do direct from program
318331
if !isForDtsErrors && options.TargetSourceFile != nil {
319332
result := program.program.Emit(ctx, emitHandler.getEmitOptions(options))
333+
emitHandler.updateHasEmitDiagnostics(result)
320334
if ctx.Err() != nil {
321335
return nil
322336
}

testdata/baselines/reference/compiler/isolatedDeclarationsTypePredicate.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,3 @@ export function isString(value) {
1717
export function isExplicitString(value) {
1818
return typeof value === "string";
1919
}
20-
21-
22-
//// [isolatedDeclarationsTypePredicate.d.ts]
23-
export declare function isString(value: unknown): value is string;
24-
export declare function isExplicitString(value: unknown): value is string;

testdata/baselines/reference/compiler/multipleModuleExportsAssignments.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ const a = x.a;
2828
const b = x.b;
2929

3030

31-
//// [x.d.ts]
32-
export {};
3331
//// [y.d.ts]
3432
export {};

testdata/baselines/reference/submodule/compiler/amdLikeInputDeclarationEmit.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrayFakeFlatNoCrashInferenceDeclarations.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,3 @@ function foo<T>(arr: T[], depth: number) {
2222
function foo(arr, depth) {
2323
return flat(arr, depth);
2424
}
25-
26-
27-
//// [arrayFakeFlatNoCrashInferenceDeclarations.d.ts]
28-
type BadFlatArray<Arr, Depth extends number> = {
29-
obj: {
30-
"done": Arr;
31-
"recur": Arr extends ReadonlyArray<infer InnerArr> ? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> : Arr;
32-
}[Depth extends -1 ? "done" : "recur"];
33-
}["obj"];
34-
declare function flat<A, D extends number = 1>(arr: A, depth?: D): BadFlatArray<A, D>[];
35-
declare function foo<T>(arr: T[], depth: number): any;

testdata/baselines/reference/submodule/compiler/arrayFakeFlatNoCrashInferenceDeclarations.js.diff

Lines changed: 0 additions & 17 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/computedPropertiesNarrowed.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,3 @@ function ns() { return { v: 0 }; }
8888
export const o9 = {
8989
[ns().v]: 1
9090
};
91-
92-
93-
//// [computedPropertiesNarrowed.d.ts]
94-
export declare let o: {
95-
1: number;
96-
};
97-
export declare let o2: {
98-
0: number;
99-
};
100-
export declare let o3: {
101-
[1]: number;
102-
};
103-
export declare let o31: {
104-
[-1]: number;
105-
};
106-
export declare let o32: {
107-
[x: number]: number;
108-
};
109-
declare let u: symbol;
110-
export declare let o4: {
111-
[u]: number;
112-
};
113-
export declare let o5: {
114-
[x: symbol]: number;
115-
};
116-
declare const uu: unique symbol;
117-
export declare let o6: {
118-
[uu]: number;
119-
};
120-
export declare let o7: {
121-
1: number;
122-
};
123-
export declare const o8: {
124-
1: number;
125-
};
126-
export declare const o9: {
127-
0: number;
128-
};
129-
export {};

testdata/baselines/reference/submodule/compiler/declarationEmitCommonJsModuleReferencedType.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,3 @@ const foo_1 = require("foo");
3232
const root_1 = require("root");
3333
exports.x = (0, foo_1.foo)();
3434
exports.y = (0, root_1.bar)();
35-
36-
37-
//// [entry.d.ts]
38-
export declare const x: any;
39-
export declare const y: import("root").RootProps;

testdata/baselines/reference/submodule/compiler/declarationEmitCommonJsModuleReferencedType.js.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)