Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@ class A {
}
babelHelpers.decorate([
dec,
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:type", Number),
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], A.prototype, "x", null);
class B {
get x() { return 0; }
set x(value) { }
}
babelHelpers.decorate([
dec,
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:type", Number),
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], B.prototype, "x", null);
class C {
set x(value) { }
get x() { return 0; }
}
babelHelpers.decorate([
dec,
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:type", Number),
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], C.prototype, "x", null);
class D {
set x(value) { }
get x() { return 0; }
}
babelHelpers.decorate([
dec,
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:type", Number),
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], D.prototype, "x", null);
class E {
get x() { return 0; }
}
babelHelpers.decorate([
dec,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
babelHelpers.decorateMetadata("design:type", Object),
babelHelpers.decorateMetadata("design:paramtypes", [])
], E.prototype, "x", null);
class F {
set x(value) { }
}
babelHelpers.decorate([
dec,
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:type", Number),
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], F.prototype, "x", null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let B = class B {
};
B = babelHelpers.decorate([
dec,
__metadata("design:paramtypes", [Number])
babelHelpers.decorateMetadata("design:paramtypes", [Number])
], B);
let C = class C extends A {
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Foo {
}
babelHelpers.decorate([
decorator,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", []),
babelHelpers.decorateMetadata("design:returntype", void 0)
], Foo.prototype, "foo", null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Foo {
}
babelHelpers.decorate([
decorator,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", []),
babelHelpers.decorateMetadata("design:returntype", void 0)
], Foo.prototype, "foo", null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Foo {
}
babelHelpers.decorate([
decorator,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", []),
babelHelpers.decorateMetadata("design:returntype", void 0)
], Foo.prototype, "foo", null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Foo {
}
babelHelpers.decorate([
decorator,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", []),
babelHelpers.decorateMetadata("design:returntype", void 0)
], Foo.prototype, "foo", null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class Foo {
}
babelHelpers.decorate([
decorator(),
__metadata("design:type", Object)
babelHelpers.decorateMetadata("design:type", Object)
], Foo.prototype, "p2", void 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class C1 {
static {
babelHelpers.decorate([
decorator((x) => x.#x),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", []),
babelHelpers.decorateMetadata("design:returntype", void 0)
], C1.prototype, "y", null);
}
}
Expand All @@ -19,9 +19,9 @@ class C2 {
static {
babelHelpers.decorate([
babelHelpers.decorateParam(0, decorator((x) => x.#x)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
babelHelpers.decorateMetadata("design:type", Function),
babelHelpers.decorateMetadata("design:paramtypes", [Object]),
babelHelpers.decorateMetadata("design:returntype", void 0)
], C2.prototype, "y", null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-legacy-decorator",
{
"emitDecoratorMetadata": true
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ class A {
}
babelHelpers.decorate([
dec(),
__metadata("design:type", String)
babelHelpers.decorateMetadata("design:type", String)
], A.prototype, "foo", void 0);
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ function copyTestsFromTypeScript() {
}
}

function writeBabelOptions(folder) {
function writeBabelOptions(folder, emitDecoratorMetadata = false) {
const optionsFile = join(folder, "options.json");
const content = JSON.stringify({
plugins: ["transform-legacy-decorator"],
}, null, 2);
const legacyDecoratorPlugin = [
"transform-legacy-decorator",
emitDecoratorMetadata ? { emitDecoratorMetadata: true } : null,
].filter(Boolean);
const content = JSON.stringify(
{
plugins: [legacyDecoratorPlugin.length === 1 ? legacyDecoratorPlugin[0] : legacyDecoratorPlugin],
},
null,
2,
);
writeFileSync(optionsFile, content);
}

Expand All @@ -75,6 +83,10 @@ async function generateOutputFiles() {

const emitDecoratorMetadata = /\@emitDecoratorMetadata/gi.test(source);

if (emitDecoratorMetadata) {
writeBabelOptions(dirname(inputFile), true);
}

/// Generate the output file path by using `typescript` library, and we need to set target to esnext
const output = transpileModule(source, {
compilerOptions: {
Expand All @@ -88,7 +100,8 @@ async function generateOutputFiles() {
// Rename helper functions to our own
const outputText = output.outputText
.replaceAll("__decorate(", "babelHelpers.decorate(")
.replaceAll("__param(", "babelHelpers.decorateParam(");
.replaceAll("__param(", "babelHelpers.decorateParam(")
.replaceAll("__metadata(", "babelHelpers.decorateMetadata(");

const outputFile = join(dirname(inputFile), "output.js");
writeFileSync(outputFile, outputText);
Expand Down
Loading