Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ fn test() {
(
"
class A {
a!: number = 1;
a: number = 1;
}
",
Some(serde_json::json!([ { "ignoreProperties": false, }, ])),
Expand Down Expand Up @@ -604,7 +604,7 @@ fn test() {
(
"
class A {
a!: number = 1;
a: number = 1;
}
",
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ source: crates/oxc_linter/src/tester.rs
╰────

⚠ typescript(no-inferrable-types): Type can be trivially inferred from the initializer
╭─[no_inferrable_types.tsx:3:17]
╭─[no_inferrable_types.tsx:3:16]
2 │ class A {
3 │ a!: number = 1;
· ────────
3 │ a: number = 1;
· ────────
4 │ }
╰────
help: Remove the type annotation
Expand Down
12 changes: 8 additions & 4 deletions crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,14 @@ impl<'a, C: Config> ParserImpl<'a, C> {
initializer.span(),
));
}
if definite && (self.ctx.has_ambient() || r#abstract) {
self.error(diagnostics::definite_assignment_assertion_not_permitted(
self.end_span(span),
));
if definite {
if initializer.is_some() {
self.error(diagnostics::variable_declarator_definite(self.end_span(span)));
} else if self.ctx.has_ambient() || r#abstract {
self.error(diagnostics::definite_assignment_assertion_not_permitted(
self.end_span(span),
));
}
Comment thread
camc314 marked this conversation as resolved.
}
self.ast.class_element_property_definition(
self.end_span(span),
Expand Down
16 changes: 16 additions & 0 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17821,6 +17821,22 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/types/wit
╰────
help: Only 'readonly' modifier is allowed here.

× TS(1263): Declarations with initializers cannot also have definite assignment assertions.
╭─[typescript/tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts:20:5]
19 │ class C3 {
20 │ a! = 1;
· ───────
21 │ b!: number = 1;
╰────

× TS(1263): Declarations with initializers cannot also have definite assignment assertions.
╭─[typescript/tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts:21:5]
20 │ a! = 1;
21 │ b!: number = 1;
· ───────────────
22 │ static c!: number;
╰────

× TS(1255): A definite assignment assertion '!' is not permitted in this context.
╭─[typescript/tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts:29:5]
28 │ declare class C4 {
Expand Down
26 changes: 24 additions & 2 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 2688fbd1

Passed: 237/395
Passed: 236/395

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -63,7 +63,7 @@ after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), R
rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), ReferenceId(10)]


# babel-plugin-transform-typescript (24/60)
# babel-plugin-transform-typescript (23/60)
* allow-declare-fields-false/input.ts
Unresolved references mismatch:
after transform: ["dce"]
Expand Down Expand Up @@ -140,6 +140,28 @@ Symbol flags mismatch for "Phase":
after transform: SymbolId(0): SymbolFlags(ConstEnum)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)

* declare-and-definite-with-initializer/input.ts

x TS(1263): Declarations with initializers cannot also have definite
| assignment assertions.
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/declare-and-definite-with-initializer/input.ts:8:4]
7 | class DefiniteExample {
8 | readonly bar! = "test";
: ^^^^^^^^^^^^^^^^^^^^^^^
9 | readonly foo! = 1;
`----


x TS(1263): Declarations with initializers cannot also have definite
| assignment assertions.
,-[tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/declare-and-definite-with-initializer/input.ts:9:4]
8 | readonly bar! = "test";
9 | readonly foo! = 1;
: ^^^^^^^^^^^^^^^^^^
10 | }
`----


Comment thread
camc314 marked this conversation as resolved.
* elimination-declare/input.ts
Bindings mismatch:
after transform: ScopeId(0): ["A", "ReactiveMarker", "ReactiveMarkerSymbol"]
Expand Down
Loading