Skip to content

Commit 4ee45ac

Browse files
authoredOct 2, 2024··
fix(es/module): Allow TypeScript nodes for Rewriter (#9606)
**Related issue:** - Closes #9592
1 parent 866af6c commit 4ee45ac

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed
 

‎.changeset/tall-rocks-jam.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_transforms_module: patch
4+
---
5+
6+
fix(es/modules): Allow TypeScript nodes for `Rewriter`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://swc.rs/schema.json",
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true,
8+
"dts": true,
9+
"tsx": false
10+
},
11+
"target": "es5",
12+
"baseUrl": "./",
13+
"preserveAllComments": false,
14+
"experimental": {
15+
"emitIsolatedDts": true
16+
},
17+
"paths": {
18+
"@lib/*": [
19+
"src/*"
20+
],
21+
"@tests/*": [
22+
"tests/*"
23+
]
24+
},
25+
"loose": false
26+
},
27+
"module": {
28+
"type": "commonjs",
29+
"strict": true,
30+
"strictMode": true,
31+
"lazy": false,
32+
"noInterop": false
33+
},
34+
"minify": false,
35+
"isModule": true
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type SafeResult<T> = { data: T; error: undefined } | { data: undefined; error: any };
2+
3+
export const safe = <T>(fn: () => T): SafeResult<T> => {
4+
try {
5+
const data = fn();
6+
return { data, error: undefined };
7+
} catch (error) {
8+
return { data: undefined, error };
9+
}
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type SafeResult<T> = {
2+
data: T;
3+
error: undefined;
4+
} | {
5+
data: undefined;
6+
error: any;
7+
};
8+
export declare const safe: <T>(fn: () => T) => SafeResult<T>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", {
3+
value: true
4+
});
5+
Object.defineProperty(exports, "safe", {
6+
enumerable: true,
7+
get: function() {
8+
return safe;
9+
}
10+
});
11+
var safe = function(fn) {
12+
try {
13+
var data = fn();
14+
return {
15+
data: data,
16+
error: undefined
17+
};
18+
} catch (error) {
19+
return {
20+
data: undefined,
21+
error: error
22+
};
23+
}
24+
};

‎crates/swc_ecma_transforms_module/src/rewriter.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use anyhow::Context;
44
use swc_common::FileName;
55
use swc_ecma_ast::*;
6-
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
6+
use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith};
77

88
use crate::path::ImportResolver;
99

@@ -18,8 +18,6 @@ struct Rewriter {
1818
}
1919

2020
impl VisitMut for Rewriter {
21-
noop_visit_mut_type!(fail);
22-
2321
fn visit_mut_call_expr(&mut self, e: &mut CallExpr) {
2422
e.visit_mut_children_with(self);
2523

0 commit comments

Comments
 (0)
Please sign in to comment.