Skip to content

Commit

Permalink
Reland denoland#9774
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Apr 10, 2021
1 parent 8d55d8b commit 75f948a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ fn strip_config_from_emit_options(
typescript::strip::ImportsNotUsedAsValues::Remove
}
},
use_define_for_class_fields: true,
..Default::default()
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ impl Inner {
"noEmit": true,
"strict": true,
"target": "esnext",
"useDefineForClassFields": true,
}));
let (maybe_config, maybe_root_uri) = {
let config = &self.config;
Expand Down
2 changes: 2 additions & 0 deletions cli/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ impl Graph {
"strict": true,
"target": "esnext",
"tsBuildInfoFile": "deno:///.tsbuildinfo",
"useDefineForClassFields": true,
}));
if options.emit {
config.merge(&json!({
Expand Down Expand Up @@ -948,6 +949,7 @@ impl Graph {
"module": "esnext",
"strict": true,
"target": "esnext",
"useDefineForClassFields": true,
}));
let opts = match options.bundle_type {
BundleType::Esm | BundleType::Iife => json!({
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/091_use_define_for_class_fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class A {
b = this.a;
constructor(public a: unknown) {}
}
4 changes: 4 additions & 0 deletions cli/tests/091_use_define_for_class_fields.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[WILDCARD]error: TS2729 [ERROR]: Property 'a' is used before its initialization.
b = this.a;
^
[WILDCARD]
6 changes: 6 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2867,6 +2867,12 @@ console.log("finish");
util::test_pty(args, output, input);
}

itest!(_091_use_define_for_class_fields {
args: "run 091_use_define_for_class_fields.ts",
output: "091_use_define_for_class_fields.ts.out",
exit_code: 1,
});

itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out",
Expand Down
1 change: 1 addition & 0 deletions cli/tsc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub const IGNORED_RUNTIME_COMPILER_OPTIONS: &[&str] = &[
"traceResolution",
"tsBuildInfoFile",
"typeRoots",
"useDefineForClassFields",
"version",
"watch",
];
Expand Down

0 comments on commit 75f948a

Please sign in to comment.