fix(es/typescript): Export destructured properties in typescript namespaces (#3084)

This commit is contained in:
magic-akari 2021-12-21 13:24:20 +08:00 committed by GitHub
parent 0e5895043f
commit 31dea3dd31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 135 additions and 1 deletions

View File

@ -0,0 +1,18 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false
}

View File

@ -0,0 +1,3 @@
namespace n {
export const { a } = { a: 1 };
}

View File

@ -0,0 +1,8 @@
var n;
(function(n1) {
var ref;
ref = {
a: 1
}, n1.a = ref.a, ref;
})(n || (n = {
}));

View File

@ -0,0 +1,18 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false
}

View File

@ -0,0 +1,3 @@
namespace Foo {
export const { a: A, b: B } = { a: 1, b: 2 };
}

View File

@ -0,0 +1,9 @@
var Foo;
(function(Foo1) {
var ref;
ref = {
a: 1,
b: 2
}, Foo1.A = ref.a, Foo1.B = ref.b, ref;
})(Foo || (Foo = {
}));

View File

@ -2699,7 +2699,15 @@ fn create_prop_pat(obj: &Ident, pat: Pat) -> Pat {
value: Box::new(create_prop_pat(obj, *kv.value)), value: Box::new(create_prop_pat(obj, *kv.value)),
..kv ..kv
}), }),
ObjectPatProp::Assign(..) => prop, ObjectPatProp::Assign(assign) => ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Ident(assign.key.clone()),
value: Box::new(Pat::Expr(Box::new(Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: ExprOrSuper::Expr(Box::new(Expr::Ident(obj.clone()))),
prop: Box::new(Expr::Ident(assign.key.into())),
computed: false,
})))),
}),
ObjectPatProp::Rest(_) => { ObjectPatProp::Rest(_) => {
todo!("Rest pattern property in an exported variable from namespace") todo!("Rest pattern property in an exported variable from namespace")
} }

View File

@ -0,0 +1,3 @@
namespace Foo {
export const { a } = { a: 1 };
}

View File

@ -0,0 +1,7 @@
var Foo;
(function(Foo1) {
({ a: Foo1.a } = {
a: 1
});
})(Foo || (Foo = {
}));

View File

@ -0,0 +1,3 @@
namespace Bar {
export const { a, b } = { a: 1, b: 2 };
}

View File

@ -0,0 +1,8 @@
var Bar;
(function(Bar1) {
({ a: Bar1.a , b: Bar1.b } = {
a: 1,
b: 2
});
})(Bar || (Bar = {
}));

View File

@ -0,0 +1,3 @@
namespace Baz {
export const baz = { a: 1, b: 2 };
}

View File

@ -0,0 +1,8 @@
var Baz;
(function(Baz1) {
Baz1.baz = {
a: 1,
b: 2
};
})(Baz || (Baz = {
}));

View File

@ -0,0 +1,12 @@
module A {
const a = 1;
const b = 2;
export const { a: A } = { a };
export const { b: B } = { b };
}
namespace A {
const c = 3;
const d = 4;
export const { c: C } = { c: c };
export const { d: D } = { d: d };
}

View File

@ -0,0 +1,23 @@
var A;
(function(A1) {
const a = 1;
const b = 2;
({ a: A1.A } = {
a
});
({ b: A1.B } = {
b
});
})(A || (A = {
}));
(function(A2) {
const c = 3;
const d = 4;
({ c: A2.C } = {
c: c
});
({ d: A2.D } = {
d: d
});
})(A || (A = {
}));