mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
fix(es/typescript): Collect all bindings in strip
(#4118)
This commit is contained in:
parent
77722c4943
commit
13b2f38cdd
19
crates/swc/tests/fixture/issue-3686/1/input/.swcrc
Normal file
19
crates/swc/tests/fixture/issue-3686/1/input/.swcrc
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"tsx": false
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": false,
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
},
|
||||
"minify": false
|
||||
}
|
36
crates/swc/tests/fixture/issue-3686/1/input/index.ts
Normal file
36
crates/swc/tests/fixture/issue-3686/1/input/index.ts
Normal file
@ -0,0 +1,36 @@
|
||||
const CD: ClassDecorator = () => { }
|
||||
const PD: PropertyDecorator = () => { }
|
||||
|
||||
// Commenting out the decorators creates valid ouput.
|
||||
@CD
|
||||
export class ServiceError extends Error {
|
||||
@PD
|
||||
readonly code: ServiceError.Code = ServiceError.Code.badResponse
|
||||
readonly name: string = "ServiceError.BadResponse"
|
||||
}
|
||||
|
||||
export namespace ServiceError {
|
||||
export const enum Code {
|
||||
serviceNotFound = 404,
|
||||
serviceNotCompatible = 426,
|
||||
serviceGone = 410,
|
||||
implementation = 500,
|
||||
timedOut = 504,
|
||||
badRequest = 400,
|
||||
badResponse = 422,
|
||||
}
|
||||
|
||||
export class ServiceNotFound extends ServiceError {
|
||||
// Service was probably not registered, or using the wrong channel
|
||||
readonly code = Code.serviceNotFound
|
||||
readonly name = "ServiceError.ServiceNotFound"
|
||||
}
|
||||
|
||||
export function toMessageBody(error: unknown): {
|
||||
code: number
|
||||
message?: string
|
||||
stack?: string
|
||||
} {
|
||||
return { code: ServiceError.Code.implementation }
|
||||
}
|
||||
}
|
49
crates/swc/tests/fixture/issue-3686/1/output/index.ts
Normal file
49
crates/swc/tests/fixture/issue-3686/1/output/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ServiceError = void 0;
|
||||
var swcHelpers = require("@swc/helpers");
|
||||
var _class, _descriptor;
|
||||
const CD = ()=>{};
|
||||
const PD = ()=>{};
|
||||
let ServiceError = _class = CD(((_class = class ServiceError extends Error {
|
||||
name = "ServiceError.BadResponse";
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.initializerDefineProperty(this, "code", _descriptor, this);
|
||||
}
|
||||
}) || _class, _descriptor = swcHelpers.applyDecoratedDescriptor(_class.prototype, "code", [
|
||||
PD
|
||||
], {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
initializer: function() {
|
||||
return ServiceError.Code.badResponse;
|
||||
}
|
||||
}), _class)) || _class;
|
||||
exports.ServiceError = ServiceError;
|
||||
(function(ServiceError1) {
|
||||
let Code;
|
||||
(function(Code) {
|
||||
Code[Code["serviceNotFound"] = 404] = "serviceNotFound";
|
||||
Code[Code["serviceNotCompatible"] = 426] = "serviceNotCompatible";
|
||||
Code[Code["serviceGone"] = 410] = "serviceGone";
|
||||
Code[Code["implementation"] = 500] = "implementation";
|
||||
Code[Code["timedOut"] = 504] = "timedOut";
|
||||
Code[Code["badRequest"] = 400] = "badRequest";
|
||||
Code[Code["badResponse"] = 422] = "badResponse";
|
||||
})(Code = ServiceError1.Code || (ServiceError1.Code = {}));
|
||||
class ServiceNotFound extends ServiceError {
|
||||
code = 404;
|
||||
name = "ServiceError.ServiceNotFound";
|
||||
}
|
||||
ServiceError1.ServiceNotFound = ServiceNotFound;
|
||||
function toMessageBody(error) {
|
||||
return {
|
||||
code: ServiceError.Code.implementation
|
||||
};
|
||||
}
|
||||
ServiceError1.toMessageBody = toMessageBody;
|
||||
})(ServiceError || (exports.ServiceError = ServiceError = {}));
|
@ -185,7 +185,7 @@ impl VisitMut for PartialInliner {
|
||||
span: s.span,
|
||||
tail: true,
|
||||
// TODO possible bug for quotes
|
||||
raw: s.value.clone().into(),
|
||||
raw: s.value.clone(),
|
||||
cooked: Some(s.value),
|
||||
};
|
||||
tt.tpl = Tpl {
|
||||
|
@ -1489,6 +1489,8 @@ where
|
||||
fn visit_assign_pat_prop(&mut self, n: &AssignPatProp) {
|
||||
if !self.in_var_pat {
|
||||
n.key.visit_with(self);
|
||||
} else {
|
||||
self.decl_names.insert(n.key.to_id());
|
||||
}
|
||||
n.value.visit_with(self);
|
||||
}
|
||||
@ -1500,6 +1502,8 @@ where
|
||||
fn visit_binding_ident(&mut self, n: &BindingIdent) {
|
||||
if !self.in_var_pat {
|
||||
n.visit_children_with(self)
|
||||
} else {
|
||||
self.decl_names.insert(n.to_id());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1521,12 +1525,14 @@ where
|
||||
f.function.visit_with(self)
|
||||
}
|
||||
Decl::Var(ref var) => {
|
||||
let old = self.in_var_pat;
|
||||
for decl in &var.decls {
|
||||
self.in_var_pat = true;
|
||||
decl.name.visit_with(self);
|
||||
self.in_var_pat = false;
|
||||
decl.init.visit_with(self);
|
||||
}
|
||||
self.in_var_pat = old;
|
||||
}
|
||||
Decl::TsEnum(e) => {
|
||||
e.members.visit_with(self);
|
||||
@ -1609,6 +1615,13 @@ where
|
||||
self.non_top_level = old;
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, n: &Expr) {
|
||||
let old = self.in_var_pat;
|
||||
self.in_var_pat = false;
|
||||
n.visit_children_with(self);
|
||||
self.in_var_pat = old;
|
||||
}
|
||||
|
||||
fn visit_ts_entity_name(&mut self, _: &TsEntityName) {}
|
||||
|
||||
// these may contain expr
|
||||
|
Loading…
Reference in New Issue
Block a user