Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 4bb7a3c

Browse files
committed
Call gatherDiagnostics to perform syntax/semantic/type checks
This was accidentally removed in recent refactoring 1b33eba which caused TS compilations to incorrectly succeed when the code contains errors. Restore missing tests which would have caught the regression; these were also accidentally disabled when Bazel BUILD files were refactored. PiperOrigin-RevId: 224869541
1 parent 41fb7f0 commit 4bb7a3c

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed

internal/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package(default_visibility = ["//visibility:public"])
1818

1919
exports_files([
20-
"tsconfig.json",
2120
# Exported to be consumed for generating skydoc.
2221
"build_defs.bzl",
2322
"ts_config.bzl",
2423
"ts_repositories.bzl",
24+
"tsetse/tsconfig.json",
2525
])
2626

2727
load("//internal:defaults.bzl", "ts_library")
@@ -98,6 +98,7 @@ ts_library(
9898
":tsc_wrapped",
9999
"@npm//@types/jasmine",
100100
"@npm//@types/node",
101+
"@npm//tsickle",
101102
"@npm//typescript",
102103
],
103104
)

internal/tsc_wrapped/tsc_wrapped.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ function runFromOptions(
205205
compilerHost.inputFiles, options, compilerHost, oldProgram));
206206
cache.putProgram(bazelOpts.target, program);
207207

208+
if (!bazelOpts.isJsTranspilation) {
209+
// If there are any TypeScript type errors abort now, so the error
210+
// messages refer to the original source. After any subsequent passes
211+
// (decorator downleveling or tsickle) we do not type check.
212+
let diagnostics =
213+
gatherDiagnostics(options, bazelOpts, program, disabledTsetseRules);
214+
if (!expectDiagnosticsWhitelist.length ||
215+
expectDiagnosticsWhitelist.some(p => bazelOpts.target.startsWith(p))) {
216+
diagnostics = bazelDiagnostics.filterExpected(
217+
bazelOpts, diagnostics, bazelDiagnostics.uglyFormat);
218+
} else if (bazelOpts.expectedDiagnostics.length > 0) {
219+
console.error(
220+
`Only targets under ${
221+
expectDiagnosticsWhitelist.join(', ')} can use ` +
222+
'expected_diagnostics, but got',
223+
bazelOpts.target);
224+
}
225+
226+
if (diagnostics.length > 0) {
227+
console.error(bazelDiagnostics.format(bazelOpts.target, diagnostics));
228+
debug('compilation failed at', new Error().stack!);
229+
return false;
230+
}
231+
}
208232

209233
const compilationTargets = program.getSourceFiles().filter(
210234
fileName => isCompilationTarget(bazelOpts, fileName));

internal/tsetse/tests/ban_expect_truthy_promise/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ts_library(
2929
ts_library(
3030
name = "positives",
3131
testonly = 1,
32-
tsconfig = "//internal/tsetse:tsconfig.json",
32+
tsconfig = "//internal:tsetse/tsconfig.json",
3333
srcs = [
3434
"positives.ts",
3535
],
@@ -50,7 +50,7 @@ ts_library(
5050
ts_library(
5151
name = "negatives",
5252
testonly = 1,
53-
tsconfig = "//internal/tsetse:tsconfig.json",
53+
tsconfig = "//internal:tsetse/tsconfig.json",
5454
srcs = [
5555
"negatives.ts",
5656
],

internal/tsetse/tests/ban_promise_as_condition/BUILD

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ load("//internal:defaults.bzl", "ts_library")
1818

1919
error_message = "error TS21226: Found a thenable.*"
2020

21-
ts_library(
22-
name = "jasmine",
23-
testonly = 1,
24-
)
25-
2621
ts_library(
2722
name = "positives",
2823
testonly = 1,
29-
tsconfig = "//internal/tsetse:tsconfig.json",
24+
tsconfig = "//internal:tsetse/tsconfig.json",
3025
srcs = [
3126
"positives.ts",
3227
],
@@ -49,7 +44,7 @@ ts_library(
4944
ts_library(
5045
name = "negatives",
5146
testonly = 1,
52-
tsconfig = "//internal/tsetse:tsconfig.json",
47+
tsconfig = "//internal:tsetse/tsconfig.json",
5348
srcs = ["negatives.ts"],
5449
deps = [
5550
],

internal/tsetse/tests/check_return_value/BUILD

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ts_library(
2323
name = "no_expected_diagnostics_test",
2424
testonly = 1,
2525
srcs = ["no_expected_diagnostics.ts"],
26-
tsconfig = "//third_party/bazel_rules/rules_typescript/internal/tsetse:tsconfig.json",
26+
tsconfig = "//internal:tsetse/tsconfig.json",
2727
)
2828

2929
ts_library(
@@ -37,14 +37,14 @@ ts_library(
3737
"\(16,1\).*" + error_message,
3838
"\(19,1\).*" + error_message,
3939
],
40-
tsconfig = "//third_party/bazel_rules/rules_typescript/internal/tsetse:tsconfig.json",
40+
tsconfig = "//internal:tsetse/tsconfig.json",
4141
)
4242

4343
ts_library(
4444
name = "user_defined_check_return_value",
4545
testonly = 1,
4646
srcs = ["user_defined_check_return_value.ts"],
47-
tsconfig = "//third_party/bazel_rules/rules_typescript/internal/tsetse:tsconfig.json",
47+
tsconfig = "//internal:tsetse/tsconfig.json",
4848
)
4949

5050
ts_library(
@@ -57,9 +57,8 @@ ts_library(
5757
"\(7,1\).*" + error_message,
5858
"\(9,1\).*" + error_message,
5959
"\(15,1\).*" + error_message,
60-
"\(16,1\).*" + error_message,
6160
],
62-
tsconfig = "//third_party/bazel_rules/rules_typescript/internal/tsetse:tsconfig.json",
61+
tsconfig = "//internal:tsetse/tsconfig.json",
6362
deps = [
6463
":user_defined_check_return_value",
6564
"@npm//@types/jasmine",

internal/tsetse/tests/must_use_promises/BUILD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ ts_library(
2525
srcs = [
2626
"positives.ts",
2727
],
28-
tsconfig = "//third_party/bazel_rules/rules_typescript/internal/tsetse:tsconfig.json",
28+
tsconfig = "//internal:tsetse/tsconfig.json",
2929
expected_diagnostics = [
3030
"\(29,3\)" + error_message,
3131
"\(30,3\)" + error_message,
3232
"\(31,3\)" + error_message,
3333
"\(32,3\)" + error_message,
3434
"\(34,3\)" + error_message,
3535
],
36-
deps = ["//third_party/javascript/node_modules/typescript:es2015.promise"],
36+
deps = [
37+
],
3738
)

internal/tsetse/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"compilerOptions": {
33
"strict": true,
44
"types": [
5-
"node"
65
],
76
"lib": [
87
"dom",

0 commit comments

Comments
 (0)