From 6f28290529a2f4e943eb3dab5cd365a2c46103f2 Mon Sep 17 00:00:00 2001 From: proteriax <8125011+proteriax@users.noreply.github.com> Date: Thu, 22 Jul 2021 11:10:02 -0400 Subject: [PATCH] Add more tests --- src/index.ts | 5 +++++ test/index.ts | 13 +++++++++++-- test/snapshots/properties/input.txt | 7 +++++++ test/snapshots/properties/output.txt | 12 +++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7510b2c..82dbb4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,11 @@ interface State { export default ({ types: t }: typeof babel): babel.PluginObj => ({ name: "tsc-decorators", + manipulateOptions(_, { plugins }) { + if (!plugins.includes("decorators-legacy")) { + plugins.push("decorators-legacy") + } + }, visitor: { Program: { enter(path, state) { diff --git a/test/index.ts b/test/index.ts index 61abd7d..f8869ce 100644 --- a/test/index.ts +++ b/test/index.ts @@ -20,9 +20,18 @@ const equal = (name: Snapshot) => { }, babelrc: false, configFile: false, - plugins: [plugin], + plugins: [ + plugin, + { + visitor: { + ClassProperty(path) { + delete path.node.definite + }, + }, + }, + ], })!.code! - expect(canonize(transformed)).to.deep.equal(canonize(expected)) + expect(canonize(transformed) + "\n").to.deep.equal(canonize(expected) + "\n") } describe("tsc-decorator", () => { diff --git a/test/snapshots/properties/input.txt b/test/snapshots/properties/input.txt index 0bfec8e..7066fa5 100644 --- a/test/snapshots/properties/input.txt +++ b/test/snapshots/properties/input.txt @@ -2,4 +2,11 @@ class A { @dec prop: string @dec @dec2 prop2: string @dec static staticProp: number + @called() service: Service + ignored: boolean } + +@Service() +export class B { + @Service() remote!: Service +} \ No newline at end of file diff --git a/test/snapshots/properties/output.txt b/test/snapshots/properties/output.txt index 635fa00..4a4e7d3 100644 --- a/test/snapshots/properties/output.txt +++ b/test/snapshots/properties/output.txt @@ -4,8 +4,18 @@ class A { prop: string; prop2: string; static staticProp: number; + service: Service; + ignored: boolean; } __decorate([dec], A.prototype, "prop", void 0); __decorate([dec, dec2], A.prototype, "prop2", void 0); -__decorate([dec], A, "staticProp", void 0); \ No newline at end of file +__decorate([dec], A, "staticProp", void 0); +__decorate([called()], A.prototype, "service", void 0); + +let B = class B { + remote: Service; +}; +__decorate([Service()], B.prototype, "remote", void 0); +B = __decorate([Service()], B); +export { B }; \ No newline at end of file