Skip to content

Commit 0bfe46b

Browse files
✨ Support Babel 8
1 parent 3a52ff7 commit 0bfe46b

File tree

23 files changed

+1708
-164
lines changed

23 files changed

+1708
-164
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ on:
88

99
jobs:
1010
build:
11-
name: Check TypeScript and Test
11+
name: Check TypeScript and Test (Node.js ${{ matrix.node-version }})
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [16, 22]
1316
steps:
1417
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
18+
- uses: actions/setup-node@v6
1619
with:
17-
node-version: '16'
20+
node-version: ${{ matrix.node-version }}
1821
cache: 'yarn'
1922
- run: yarn install
23+
- run: yarn pretest
24+
if: matrix.node-version >= 22
2025
- run: yarn build
2126
- run: yarn check-types
2227
- run: yarn test:ci

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"build:types": "tsc --emitDeclarationOnly",
2626
"check-types": "tsc --noEmit",
2727
"release": "yarn test && yarn build && release-it",
28+
"pretest": "cd test/__helpers__/babel-8 && yarn",
2829
"test": "jest --forceExit",
2930
"test:dev": "jest --watch",
3031
"test:ci": "jest --ci --runInBand --coverage --forceExit"
@@ -55,11 +56,12 @@
5556
"devDependencies": {
5657
"@babel/cli": "^7.6.4",
5758
"@babel/core": "^7.6.4",
58-
"@babel/plugin-proposal-class-properties": "^7.5.5",
5959
"@babel/plugin-proposal-decorators": "^7.6.0",
60+
"@babel/plugin-transform-class-properties": "^7.27.1",
6061
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
62+
"@babel/plugin-transform-object-rest-spread": "^7.28.4",
6163
"@babel/preset-env": "^7.6.3",
62-
"@babel/preset-typescript": "^7.6.0",
64+
"@babel/preset-typescript": "^7.28.5",
6365
"@babel/template": "^7.6.0",
6466
"@babel/traverse": "^7.6.4",
6567
"@babel/types": "^7.6.3",
@@ -79,15 +81,11 @@
7981
"@babel/helper-plugin-utils": "^7.0.0"
8082
},
8183
"peerDependencies": {
82-
"@babel/core": "^7",
83-
"@babel/traverse": "^7"
84+
"@babel/core": "^7.0.0 || ^8.0.0-0"
8485
},
8586
"peerDependenciesMeta": {
8687
"@babel/core": {
8788
"optional": false
88-
},
89-
"@babel/traverse": {
90-
"optional": true
9189
}
9290
}
93-
}
91+
}

src/metadata/metadataVisitor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { NodePath } from '@babel/traverse';
2-
import { types as t } from '@babel/core';
1+
import { types as t, NodePath } from '@babel/core';
32
import { serializeType } from './serializeType';
43

54
function createMetadataDesignDecorator(

src/metadata/serializeType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { types as t } from '@babel/core';
2-
import { NodePath } from '@babel/traverse';
1+
import { types as t, NodePath } from '@babel/core';
32

43
type InferArray<T> = T extends Array<infer A> ? A : never;
54

src/parameter/parameterVisitor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { NodePath } from '@babel/traverse';
2-
import { types as t } from '@babel/core';
1+
import { types as t, NodePath } from '@babel/core';
32

43
/**
54
* Helper function to create a field/class decorator from a parameter decorator.

src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { metadataVisitor } from './metadata/metadataVisitor';
55

66
export default declare(
77
(api: any): PluginObj => {
8-
api.assertVersion(7);
8+
api.assertVersion("^7.0.0 || ^8.0.0-0");
99

1010
return {
1111
visitor: {

test/__fixtures__/generics/output.js

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _class, _class2, _descriptor, _descriptor2;
2-
3-
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4-
5-
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
6-
7-
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }
8-
1+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _class, _class2, _descriptor, _descriptor2;
2+
function _initializerDefineProperty(e, i, r, l) { r && Object.defineProperty(e, i, { enumerable: r.enumerable, configurable: r.configurable, writable: r.writable, value: r.initializer ? r.initializer.call(l) : void 0 }); }
3+
function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; }
4+
function _initializerWarningHelper(r, e) { throw Error("Decorating class property failed. Please ensure that transform-class-properties is enabled and runs after the decorators transform."); }
95
import { AppService } from './app.service';
10-
export let AppController = (_dec = Controller(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof AppService === "undefined" ? Object : AppService]), _dec4 = Inject(), _dec5 = Reflect.metadata("design:type", typeof AppService === "undefined" ? Object : AppService), _dec6 = Inject(), _dec7 = Reflect.metadata("design:type", typeof AppService === "undefined" ? Object : AppService), _dec8 = Get(), _dec9 = Reflect.metadata("design:type", Function), _dec10 = Reflect.metadata("design:paramtypes", []), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class AppController {
6+
export let AppController = (_dec = Controller(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof AppService === "undefined" ? Object : AppService]), _dec4 = Inject(), _dec5 = Reflect.metadata("design:type", typeof AppService === "undefined" ? Object : AppService), _dec6 = Inject(), _dec7 = Reflect.metadata("design:type", typeof AppService === "undefined" ? Object : AppService), _dec8 = Get(), _dec9 = Reflect.metadata("design:type", Function), _dec0 = Reflect.metadata("design:paramtypes", []), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class AppController {
117
constructor(appService) {
128
this.appService = appService;
13-
149
_initializerDefineProperty(this, "appService", _descriptor, this);
15-
1610
_initializerDefineProperty(this, "appService2", _descriptor2, this);
1711
}
18-
1912
getHello() {
2013
return this.appService.getHello();
2114
}
22-
23-
}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "appService", [_dec4, _dec5], {
15+
}, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "appService", [_dec4, _dec5], {
2416
configurable: true,
2517
enumerable: true,
2618
writable: true,
@@ -30,4 +22,4 @@ export let AppController = (_dec = Controller(), _dec2 = Reflect.metadata("desig
3022
enumerable: true,
3123
writable: true,
3224
initializer: null
33-
}), _applyDecoratedDescriptor(_class2.prototype, "getHello", [_dec8, _dec9, _dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "getHello"), _class2.prototype)), _class2)) || _class) || _class) || _class);
25+
}), _applyDecoratedDescriptor(_class2.prototype, "getHello", [_dec8, _dec9, _dec0], Object.getOwnPropertyDescriptor(_class2.prototype, "getHello"), _class2.prototype), _class2)) || _class) || _class) || _class);
Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
1-
var _dec, _dec2, _dec3, _class, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _class2, _class3, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _dec25, _dec26, _class4, _class5;
2-
3-
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
4-
1+
var _dec, _dec2, _dec3, _class, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _dec1, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _class2, _class3, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _class4, _class5;
2+
function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; }
53
class Injected {}
6-
74
let MyClass = (_dec = function (target, key) {
85
return inject()(target, undefined, 0);
96
}, _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected]), _dec(_class = _dec2(_class = _dec3(_class = class MyClass {
107
constructor(parameter) {}
11-
128
}) || _class) || _class) || _class);
139
let MyOtherClass = (_dec4 = function (target, key) {
1410
return inject()(target, undefined, 0);
1511
}, _dec5 = function (target, key) {
1612
return inject('KIND')(target, undefined, 1);
1713
}, _dec6 = Reflect.metadata("design:type", Function), _dec7 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected]), _dec8 = function (target, key) {
1814
return demo()(target, key, 0);
19-
}, _dec9 = Reflect.metadata("design:type", Function), _dec10 = Reflect.metadata("design:paramtypes", [String, void 0]), _dec11 = decorate('named'), _dec12 = function (target, key) {
15+
}, _dec9 = Reflect.metadata("design:type", Function), _dec0 = Reflect.metadata("design:paramtypes", [String, void 0]), _dec1 = decorate('named'), _dec10 = function (target, key) {
2016
return inject()(target, key, 0);
21-
}, _dec13 = function (target, key) {
17+
}, _dec11 = function (target, key) {
2218
return arg()(target, key, 1);
23-
}, _dec14 = Reflect.metadata("design:type", Function), _dec15 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected, typeof Schema === "undefined" ? Object : Schema]), _dec16 = function (target, key) {
19+
}, _dec12 = Reflect.metadata("design:type", Function), _dec13 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected, typeof Schema === "undefined" ? Object : Schema]), _dec14 = function (target, key) {
2420
return argObjectSpread()(target, key, 0);
25-
}, _dec17 = Reflect.metadata("design:type", Function), _dec18 = Reflect.metadata("design:paramtypes", [typeof SchemaObjectSpread === "undefined" ? Object : SchemaObjectSpread]), _dec4(_class2 = _dec5(_class2 = _dec6(_class2 = _dec7(_class2 = (_class3 = class MyOtherClass {
21+
}, _dec15 = Reflect.metadata("design:type", Function), _dec16 = Reflect.metadata("design:paramtypes", [typeof SchemaObjectSpread === "undefined" ? Object : SchemaObjectSpread]), _dec4(_class2 = _dec5(_class2 = _dec6(_class2 = _dec7(_class2 = (_class3 = class MyOtherClass {
2622
constructor(parameter, otherParam) {
2723
this.parameter = parameter;
2824
}
29-
3025
methodUndecorated(param, otherParam) {}
31-
3226
method(param, schema) {}
33-
3427
methodWithObjectSpread({
3528
name
3629
}) {}
37-
38-
}, (_applyDecoratedDescriptor(_class3.prototype, "methodUndecorated", [_dec8, _dec9, _dec10], Object.getOwnPropertyDescriptor(_class3.prototype, "methodUndecorated"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "method", [_dec11, _dec12, _dec13, _dec14, _dec15], Object.getOwnPropertyDescriptor(_class3.prototype, "method"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "methodWithObjectSpread", [_dec16, _dec17, _dec18], Object.getOwnPropertyDescriptor(_class3.prototype, "methodWithObjectSpread"), _class3.prototype)), _class3)) || _class2) || _class2) || _class2) || _class2);
39-
let DecoratedClass = (_dec19 = function (target, key) {
30+
}, _applyDecoratedDescriptor(_class3.prototype, "methodUndecorated", [_dec8, _dec9, _dec0], Object.getOwnPropertyDescriptor(_class3.prototype, "methodUndecorated"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "method", [_dec1, _dec10, _dec11, _dec12, _dec13], Object.getOwnPropertyDescriptor(_class3.prototype, "method"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "methodWithObjectSpread", [_dec14, _dec15, _dec16], Object.getOwnPropertyDescriptor(_class3.prototype, "methodWithObjectSpread"), _class3.prototype), _class3)) || _class2) || _class2) || _class2) || _class2);
31+
let DecoratedClass = (_dec17 = function (target, key) {
4032
return inject()(target, undefined, 0);
41-
}, _dec20 = function (target, key) {
33+
}, _dec18 = function (target, key) {
4234
return inject()(target, undefined, 1);
43-
}, _dec21 = Reflect.metadata("design:type", Function), _dec22 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected]), _dec23 = decorate('example'), _dec24 = function (target, key) {
35+
}, _dec19 = Reflect.metadata("design:type", Function), _dec20 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected]), _dec21 = decorate('example'), _dec22 = function (target, key) {
4436
return inject()(target, key, 0);
45-
}, _dec25 = Reflect.metadata("design:type", Function), _dec26 = Reflect.metadata("design:paramtypes", [String]), Decorate(_class4 = _dec19(_class4 = _dec20(_class4 = _dec21(_class4 = _dec22(_class4 = (_class5 = class DecoratedClass {
37+
}, _dec23 = Reflect.metadata("design:type", Function), _dec24 = Reflect.metadata("design:paramtypes", [String]), Decorate(_class4 = _dec17(_class4 = _dec18(_class4 = _dec19(_class4 = _dec20(_class4 = (_class5 = class DecoratedClass {
4638
constructor(module, otherModule) {
4739
this.module = module;
4840
}
49-
5041
method(param) {}
51-
52-
}, (_applyDecoratedDescriptor(_class5.prototype, "method", [_dec23, _dec24, _dec25, _dec26], Object.getOwnPropertyDescriptor(_class5.prototype, "method"), _class5.prototype)), _class5)) || _class4) || _class4) || _class4) || _class4) || _class4);
42+
}, _applyDecoratedDescriptor(_class5.prototype, "method", [_dec21, _dec22, _dec23, _dec24], Object.getOwnPropertyDescriptor(_class5.prototype, "method"), _class5.prototype), _class5)) || _class4) || _class4) || _class4) || _class4) || _class4);

test/__fixtures__/type-serialization/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Service } from './service';
21
import { Decorate } from './Decorate';
32

43
const sym = Symbol();

0 commit comments

Comments
 (0)