Skip to content

Commit b0780f2

Browse files
authored
Turbopack: don't ignore TS parse errors (#84597)
`no_early_errors: true` was causing parse errors to be discarded. For example with swc-project/swc#11142 where there was a parse error (though it was a bug in this case), that left a `Invalid` AST node in the output, which only broke minification/SSG later on in the build (and potentially would have resulted in some error at runtime, if that specific chunk was never executed during SSG).
1 parent 640d7bc commit b0780f2

11 files changed

+75
-8
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ test/development/mcp-server/fixtures/default-template/app/build-error/page.tsx
6565
/turbopack/crates/turbopack-tests/tests/execution/turbopack/basic/error/input/broken.js
6666
/turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export-parse-error/input/invalid-export/broken.js
6767
/turbopack/crates/turbopack-tests/tests/execution/turbopack/**/not-compiled.js
68+
/turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts
6869
/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs
6970
/turbopack/crates/turbopack-tests/tests/snapshot/source_maps/*
7071
/turbopack/crates/turbopack-tests/tests/**/output*

turbopack/crates/turbopack-ecmascript/src/parse.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,16 @@ async fn parse_file_content(
348348
Syntax::Typescript(TsSyntax {
349349
decorators: true,
350350
dts: false,
351-
no_early_errors: true,
352351
tsx,
353-
disallow_ambiguous_jsx_like: false,
352+
..Default::default()
354353
})
355354
}
356355
EcmascriptModuleAssetType::TypescriptDeclaration => {
357356
Syntax::Typescript(TsSyntax {
358357
decorators: true,
359358
dts: true,
360-
no_early_errors: true,
361359
tsx: false,
362-
disallow_ambiguous_jsx_like: false,
360+
..Default::default()
363361
})
364362
}
365363
},

turbopack/crates/turbopack-swc-ast-explorer/src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ fn main() -> Result<()> {
3535
let target = EsVersion::latest();
3636
let syntax = Syntax::Typescript(TsSyntax {
3737
tsx: true,
38-
decorators: false,
39-
dts: false,
40-
no_early_errors: true,
41-
disallow_ambiguous_jsx_like: false,
38+
..Default::default()
4239
});
4340

4441
let compiler = Compiler::new(sm.clone());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './other.ts'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function x() {
2+
;[1, 2] = [1, 2]
3+
}
4+
5+
console.log(x());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:7 Parsing ecmascript source code failed
2+
1 | function x() {
3+
+ v
4+
2 + ;[1, 2] = [1, 2]
5+
+ ^
6+
3 | }
7+
4 |
8+
5 | console.log(x());
9+
6 |
10+
11+
Cannot assign to this
12+
13+
Import trace:
14+
test:
15+
./turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts
16+
./turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/index.js
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts:2:4 Parsing ecmascript source code failed
2+
1 | function x() {
3+
+ v
4+
2 + ;[1, 2] = [1, 2]
5+
+ ^
6+
3 | }
7+
4 |
8+
5 | console.log(x());
9+
6 |
10+
11+
Cannot assign to this
12+
13+
Import trace:
14+
test:
15+
./turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/other.ts
16+
./turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/input/index.js

turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_ts-parse-error_input_0fc6be51._.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_ts-parse-error_input_0fc6be51._.js.map

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/basic/ts-parse-error/output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_ts-parse-error_input_index_15722878.js.map

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)