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
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ on:

jobs:
build:
name: Check TypeScript and Test
name: Check TypeScript and Test (Node.js ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 22]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2 doesn't work anymore, I'm getting error 400 🤷

with:
node-version: '16'
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn build
- run: yarn check-types
- run: yarn pretest
if: matrix.node-version >= 22
- run: yarn test:ci
- uses: codecov/codecov-action@v2
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"build:types": "tsc --emitDeclarationOnly",
"check-types": "tsc --noEmit",
"release": "yarn test && yarn build && release-it",
"pretest": "cd test/__helpers__/babel-8 && yarn",
"test": "jest --forceExit",
"test:dev": "jest --watch",
"test:ci": "jest --ci --runInBand --coverage --forceExit"
Expand Down Expand Up @@ -55,11 +56,12 @@
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/plugin-transform-class-properties": "^7.27.1",
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
"@babel/plugin-transform-object-rest-spread": "^7.28.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@babel/preset-typescript": "^7.28.5",
"@babel/template": "^7.6.0",
"@babel/traverse": "^7.6.4",
"@babel/types": "^7.6.3",
Expand All @@ -79,15 +81,11 @@
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {
"@babel/core": "^7",
"@babel/traverse": "^7"
"@babel/core": "^7.0.0 || ^8.0.0-0"
},
"peerDependenciesMeta": {
"@babel/core": {
"optional": false
},
"@babel/traverse": {
"optional": true
}
}
}
}
3 changes: 1 addition & 2 deletions src/metadata/metadataVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NodePath } from '@babel/traverse';
import { types as t } from '@babel/core';
import { types as t, NodePath } from '@babel/core';
import { serializeType } from './serializeType';

function createMetadataDesignDecorator(
Expand Down
3 changes: 1 addition & 2 deletions src/metadata/serializeType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { types as t } from '@babel/core';
import { NodePath } from '@babel/traverse';
import { types as t, NodePath } from '@babel/core';

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

Expand Down
3 changes: 1 addition & 2 deletions src/parameter/parameterVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NodePath } from '@babel/traverse';
import { types as t } from '@babel/core';
import { types as t, NodePath } from '@babel/core';

/**
* Helper function to create a field/class decorator from a parameter decorator.
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { metadataVisitor } from './metadata/metadataVisitor';

export default declare(
(api: any): PluginObj => {
api.assertVersion(7);
api.assertVersion("^7.0.0 || ^8.0.0-0");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change that makes the plugin work in Babel 8. No changes needed, other than not asserting that we are not using it :)


return {
visitor: {
Expand Down
8 changes: 2 additions & 6 deletions test/__fixtures__/generics/output.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 7 additions & 15 deletions test/__fixtures__/nest-injection/output.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _class, _class2, _descriptor, _descriptor2;

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 }); }

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; }

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.'); }

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec0, _class, _class2, _descriptor, _descriptor2;
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 }); }
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; }
function _initializerWarningHelper(r, e) { throw Error("Decorating class property failed. Please ensure that transform-class-properties is enabled and runs after the decorators transform."); }
import { AppService } from './app.service';
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 {
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 {
constructor(appService) {
this.appService = appService;

_initializerDefineProperty(this, "appService", _descriptor, this);

_initializerDefineProperty(this, "appService2", _descriptor2, this);
}

getHello() {
return this.appService.getHello();
}

}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "appService", [_dec4, _dec5], {
}, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "appService", [_dec4, _dec5], {
configurable: true,
enumerable: true,
writable: true,
Expand All @@ -30,4 +22,4 @@ export let AppController = (_dec = Controller(), _dec2 = Reflect.metadata("desig
enumerable: true,
writable: true,
initializer: null
}), _applyDecoratedDescriptor(_class2.prototype, "getHello", [_dec8, _dec9, _dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "getHello"), _class2.prototype)), _class2)) || _class) || _class) || _class);
}), _applyDecoratedDescriptor(_class2.prototype, "getHello", [_dec8, _dec9, _dec0], Object.getOwnPropertyDescriptor(_class2.prototype, "getHello"), _class2.prototype), _class2)) || _class) || _class) || _class);
34 changes: 12 additions & 22 deletions test/__fixtures__/parameter-decorator-typed/output.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,42 @@
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;

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; }

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;
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; }
class Injected {}

let MyClass = (_dec = function (target, key) {
return inject()(target, undefined, 0);
}, _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof Injected === "undefined" ? Object : Injected]), _dec(_class = _dec2(_class = _dec3(_class = class MyClass {
constructor(parameter) {}

}) || _class) || _class) || _class);
let MyOtherClass = (_dec4 = function (target, key) {
return inject()(target, undefined, 0);
}, _dec5 = function (target, key) {
return inject('KIND')(target, undefined, 1);
}, _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) {
return demo()(target, key, 0);
}, _dec9 = Reflect.metadata("design:type", Function), _dec10 = Reflect.metadata("design:paramtypes", [String, void 0]), _dec11 = decorate('named'), _dec12 = function (target, key) {
}, _dec9 = Reflect.metadata("design:type", Function), _dec0 = Reflect.metadata("design:paramtypes", [String, void 0]), _dec1 = decorate('named'), _dec10 = function (target, key) {
return inject()(target, key, 0);
}, _dec13 = function (target, key) {
}, _dec11 = function (target, key) {
return arg()(target, key, 1);
}, _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) {
}, _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) {
return argObjectSpread()(target, key, 0);
}, _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 {
}, _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 {
constructor(parameter, otherParam) {
this.parameter = parameter;
}

methodUndecorated(param, otherParam) {}

method(param, schema) {}

methodWithObjectSpread({
name
}) {}

}, (_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);
let DecoratedClass = (_dec19 = function (target, key) {
}, _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);
let DecoratedClass = (_dec17 = function (target, key) {
return inject()(target, undefined, 0);
}, _dec20 = function (target, key) {
}, _dec18 = function (target, key) {
return inject()(target, undefined, 1);
}, _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) {
}, _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) {
return inject()(target, key, 0);
}, _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 {
}, _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 {
constructor(module, otherModule) {
this.module = module;
}

method(param) {}

}, (_applyDecoratedDescriptor(_class5.prototype, "method", [_dec23, _dec24, _dec25, _dec26], Object.getOwnPropertyDescriptor(_class5.prototype, "method"), _class5.prototype)), _class5)) || _class4) || _class4) || _class4) || _class4) || _class4);
}, _applyDecoratedDescriptor(_class5.prototype, "method", [_dec21, _dec22, _dec23, _dec24], Object.getOwnPropertyDescriptor(_class5.prototype, "method"), _class5.prototype), _class5)) || _class4) || _class4) || _class4) || _class4) || _class4);
1 change: 0 additions & 1 deletion test/__fixtures__/type-serialization/code.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Service } from './service';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable was unused in the test, both in types and values, and Babel 7 and 8 have different behavior (Babel 7 removes it, Babel 8 keeps it). Given that it's not relevant for the test, I deleted it from the input just to avoid having two different outputs.

import { Decorate } from './Decorate';

const sym = Symbol();
Expand Down
Loading