Skip to content

Commit

Permalink
fix(typescript): Fix wrong check for super class (#9822)
Browse files Browse the repository at this point in the history
 - Closes #9817
  • Loading branch information
CPunisher authored Dec 31, 2024
1 parent 512c91f commit 2307a4d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-rules-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_typescript: patch
---

fix(typescript): Fix wrong check for super class
7 changes: 5 additions & 2 deletions crates/swc_typescript/examples/isolated_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{env, path::Path};

use swc_common::{comments::SingleThreadedComments, Mark};
use swc_ecma_codegen::to_code_with_comments;
use swc_ecma_parser::{parse_file_as_program, Syntax};
use swc_ecma_parser::{parse_file_as_program, Syntax, TsSyntax};
use swc_ecma_transforms_base::{fixer::paren_remover, resolver};
use swc_typescript::fast_dts::{FastDts, FastDtsOptions};

Expand All @@ -18,7 +18,10 @@ pub fn main() {
let comments = SingleThreadedComments::default();
let mut program = parse_file_as_program(
&fm,
Syntax::Typescript(Default::default()),
Syntax::Typescript(TsSyntax {
tsx: true,
..Default::default()
}),
Default::default(),
Some(&comments),
&mut Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_typescript/src/fast_dts/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl FastDts {
}
_ => {}
}
break object.is_ident();
break !object.is_ident();
}
}
_ => true,
Expand Down
10 changes: 10 additions & 0 deletions crates/swc_typescript/tests/fixture/issues/9817.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```==================== .D.TS ====================
import React from "react";
export declare class Component<T> extends React.PureComponent<{
}, {
}> {
render(): React.ReactNode;
}
8 changes: 8 additions & 0 deletions crates/swc_typescript/tests/fixture/issues/9817.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";

export class Component<T> extends React.PureComponent<{}, {}> {

render(): React.ReactNode {
return <div>Hello world</div>;
}
}
8 changes: 6 additions & 2 deletions crates/swc_typescript/tests/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::path::PathBuf;

use swc_common::{comments::SingleThreadedComments, Mark};
use swc_ecma_codegen::to_code_with_comments;
use swc_ecma_parser::{parse_file_as_program, Syntax};
use swc_ecma_parser::{parse_file_as_program, Syntax, TsSyntax};
use swc_ecma_transforms_base::{fixer::paren_remover, resolver};
use swc_typescript::fast_dts::{FastDts, FastDtsOptions};
use testing::NormalizedOutput;

#[testing::fixture("tests/**/*.ts")]
#[testing::fixture("tests/**/*.tsx")]
fn fixture(input: PathBuf) {
let mut dts_code = String::new();
let res = testing::run_test2(false, |cm, handler| {
Expand All @@ -18,7 +19,10 @@ fn fixture(input: PathBuf) {
let comments = SingleThreadedComments::default();
let mut program = parse_file_as_program(
&fm,
Syntax::Typescript(Default::default()),
Syntax::Typescript(TsSyntax {
tsx: true,
..Default::default()
}),
Default::default(),
Some(&comments),
&mut Vec::new(),
Expand Down

0 comments on commit 2307a4d

Please sign in to comment.