Skip to content

Commit

Permalink
fix(es/module): Allow TypeScript nodes for Rewriter (#9606)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9592
  • Loading branch information
kdy1 authored Oct 2, 2024
1 parent 866af6c commit 4ee45ac
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/tall-rocks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_transforms_module: patch
---

fix(es/modules): Allow TypeScript nodes for `Rewriter`
36 changes: 36 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9592/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://swc.rs/schema.json",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true,
"dts": true,
"tsx": false
},
"target": "es5",
"baseUrl": "./",
"preserveAllComments": false,
"experimental": {
"emitIsolatedDts": true
},
"paths": {
"@lib/*": [
"src/*"
],
"@tests/*": [
"tests/*"
]
},
"loose": false
},
"module": {
"type": "commonjs",
"strict": true,
"strictMode": true,
"lazy": false,
"noInterop": false
},
"minify": false,
"isModule": true
}
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9592/input/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type SafeResult<T> = { data: T; error: undefined } | { data: undefined; error: any };

export const safe = <T>(fn: () => T): SafeResult<T> => {
try {
const data = fn();
return { data, error: undefined };
} catch (error) {
return { data: undefined, error };
}
};
8 changes: 8 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9592/output/1.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type SafeResult<T> = {
data: T;
error: undefined;
} | {
data: undefined;
error: any;
};
export declare const safe: <T>(fn: () => T) => SafeResult<T>;
24 changes: 24 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9592/output/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "safe", {
enumerable: true,
get: function() {
return safe;
}
});
var safe = function(fn) {
try {
var data = fn();
return {
data: data,
error: undefined
};
} catch (error) {
return {
data: undefined,
error: error
};
}
};
4 changes: 1 addition & 3 deletions crates/swc_ecma_transforms_module/src/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::Context;
use swc_common::FileName;
use swc_ecma_ast::*;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith};

use crate::path::ImportResolver;

Expand All @@ -18,8 +18,6 @@ struct Rewriter {
}

impl VisitMut for Rewriter {
noop_visit_mut_type!(fail);

fn visit_mut_call_expr(&mut self, e: &mut CallExpr) {
e.visit_mut_children_with(self);

Expand Down

0 comments on commit 4ee45ac

Please sign in to comment.