Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,11 @@ func (p *Program) Emit(ctx context.Context, options EmitOptions) *EmitResult {
}

if options.EmitOnly != EmitOnlyForcedDts {
if p.Options().NoEmit.IsTrue() {
// Mirror handleNoEmitOptions: a single-file noEmit is skipped, but a whole-program
// noEmit is not, so a program with diagnostics reports DiagnosticsPresent_OutputsGenerated.
return &EmitResult{EmitSkipped: options.TargetSourceFile != nil}
}
result := HandleNoEmitOnError(
ctx,
p,
Expand Down
5 changes: 5 additions & 0 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func TestTscCommandline(t *testing.T) {
files: FileMap{"/home/src/workspaces/project/first.ts": `export const Key = Symbol()`},
commandLineArgs: []string{"--lib", "es6 ", "first.ts"},
},
{
subScenario: "noEmit with type error",
files: FileMap{"/home/src/workspaces/project/index.ts": `x = 5;`},
commandLineArgs: []string{"--noEmit", "index.ts"},
},
{
subScenario: "option diagnostics are suppressed when there are syntactic errors",
files: FileMap{"/home/src/workspaces/project/a.ts": `const x: = 1;`},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
currentDirectory::/home/src/workspaces/project
useCaseSensitiveFileNames::true
Input::
//// [/home/src/workspaces/project/index.ts] *new*
x = 5;

tsgo --noEmit index.ts
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
index.ts:1:1 - error TS2304: Cannot find name 'x'.

1 x = 5;
  ~


Found 1 error in index.ts:1

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
interface SymbolConstructor {
(desc?: string | number): symbol;
for(name: string): symbol;
readonly toStringTag: symbol;
}
declare var Symbol: SymbolConstructor;
interface Symbol {
readonly [Symbol.toStringTag]: string;
}
declare const console: { log(msg: any): void; };

Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ declare const console: { log(msg: any): void; };
{"pid":1,"tid":2,"ph":"E","cat":"check","ts":18,"name":"checkSourceFile","args":{"checkerId":0,"path":"/home/src/workspaces/project/a.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":19,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":20,"name":"emit"},
{"pid":1,"tid":354130385,"ph":"B","cat":"emit","ts":21,"name":"emit","args":{"path":"/home/src/workspaces/project/a.ts"}},
{"pid":1,"tid":354130385,"ph":"E","cat":"emit","ts":22,"name":"emit","args":{"path":"/home/src/workspaces/project/a.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":23,"name":"emit"}
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":21,"name":"emit"}
]

//// [/home/src/workspaces/project/trace/types_0.json] *new*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Container<T> {
export type Nullable<T> = T | null | undefined;

tsgo --generateTrace /home/src/workspaces/project/trace --singleThreaded
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
main.ts:2:74 - error TS2322: Type '<U>(fn: (x: number) => U) => Container<U>' is not assignable to type '<U>(fn: (x: U) => U) => Container<U>'.
Types of parameters 'fn' and 'fn' are incompatible.
Expand Down Expand Up @@ -104,11 +104,7 @@ declare const console: { log(msg: any): void; };
{"pid":1,"tid":2,"ph":"E","cat":"check","ts":24,"name":"checkSourceFile","args":{"checkerId":0,"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":25,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":26,"name":"emit"},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":27,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":28,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":553096334,"ph":"B","cat":"emit","ts":29,"name":"emit","args":{"path":"/home/src/workspaces/project/types.ts"}},
{"pid":1,"tid":553096334,"ph":"E","cat":"emit","ts":30,"name":"emit","args":{"path":"/home/src/workspaces/project/types.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":31,"name":"emit"}
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":27,"name":"emit"}
]

//// [/home/src/workspaces/project/trace/types_0.json] *new*
Expand Down
8 changes: 4 additions & 4 deletions testdata/baselines/reference/tsc/noEmit/dts-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const a = class { private p = 10; };
}

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS4094: Property 'p' of exported anonymous class type may not be private or protected.

Expand Down Expand Up @@ -55,7 +55,7 @@ declare const console: { log(msg: any): void; };
Edit [0]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS4094: Property 'p' of exported anonymous class type may not be private or protected.

Expand Down Expand Up @@ -118,7 +118,7 @@ Edit [5]:: Introduce error
const a = class { private p = 10; };

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS4094: Property 'p' of exported anonymous class type may not be private or protected.

Expand Down Expand Up @@ -164,7 +164,7 @@ const a = class {
Edit [7]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS4094: Property 'p' of exported anonymous class type may not be private or protected.

Expand Down
8 changes: 4 additions & 4 deletions testdata/baselines/reference/tsc/noEmit/semantic-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const a: number = "hello"
}

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS2322: Type 'string' is not assignable to type 'number'.

Expand Down Expand Up @@ -51,7 +51,7 @@ declare const console: { log(msg: any): void; };
Edit [0]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS2322: Type 'string' is not assignable to type 'number'.

Expand Down Expand Up @@ -107,7 +107,7 @@ Edit [5]:: Introduce error
const a: number = "hello"

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS2322: Type 'string' is not assignable to type 'number'.

Expand Down Expand Up @@ -140,7 +140,7 @@ Found 1 error in a.ts:1
Edit [7]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:7 - error TS2322: Type 'string' is not assignable to type 'number'.

Expand Down
8 changes: 4 additions & 4 deletions testdata/baselines/reference/tsc/noEmit/syntax-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const a = "hello
}

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:17 - error TS1002: Unterminated string literal.

Expand Down Expand Up @@ -51,7 +51,7 @@ declare const console: { log(msg: any): void; };
Edit [0]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:17 - error TS1002: Unterminated string literal.

Expand Down Expand Up @@ -107,7 +107,7 @@ Edit [5]:: Introduce error
const a = "hello

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:17 - error TS1002: Unterminated string literal.

Expand Down Expand Up @@ -143,7 +143,7 @@ const a = "hello;
Edit [7]:: no change

tsgo --noEmit
ExitStatus:: DiagnosticsPresent_OutputsSkipped
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
a.ts:1:17 - error TS1002: Unterminated string literal.

Expand Down