Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/module): Allow TypeScript nodes for Rewriter #9606

Merged
merged 5 commits into from
Oct 2, 2024
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
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
Loading