Fix test
This commit is contained in:
parent
21003af738
commit
5257dc7ed2
15
src/index.ts
15
src/index.ts
@ -158,13 +158,14 @@ export default ({ types: t }: typeof babel): babel.PluginObj<State> => ({
|
||||
])
|
||||
)
|
||||
)
|
||||
|
||||
if (isNamedExport) {
|
||||
suffix.push(
|
||||
t.exportNamedDeclaration(undefined, [t.exportSpecifier(classID, classID)])
|
||||
)
|
||||
} else if (isDefaultExport) {
|
||||
suffix.push(t.exportDefaultDeclaration(classID))
|
||||
if (replace) {
|
||||
if (isNamedExport) {
|
||||
suffix.push(
|
||||
t.exportNamedDeclaration(undefined, [t.exportSpecifier(classID, classID)])
|
||||
)
|
||||
} else if (isDefaultExport) {
|
||||
suffix.push(t.exportDefaultDeclaration(classID))
|
||||
}
|
||||
}
|
||||
} else if (replace) {
|
||||
let node: t.Statement = path.node
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { readFileSync, existsSync } from "fs"
|
||||
import { readFileSync, existsSync, writeFileSync } from "fs"
|
||||
import { describe, it } from "mocha"
|
||||
import { resolve } from "path"
|
||||
import { expect } from "chai"
|
||||
@ -10,12 +10,14 @@ import plugin from "../src/index"
|
||||
const canonize = (code: string) =>
|
||||
format(code, { parser: "babel" }).trim().split("\n").filter(Boolean).join("\n")
|
||||
|
||||
const read = (path: string) => [path, readFileSync(path, "utf-8")] as const
|
||||
|
||||
const equal = (name: Snapshot) => {
|
||||
const folder = resolve(__dirname, "snapshots", name)
|
||||
const actual = readFileSync(resolve(folder, "input.txt"), "utf-8")
|
||||
const expected = readFileSync(resolve(folder, "output.txt"), "utf-8")
|
||||
const [, actual] = read(resolve(folder, "input.txt"))
|
||||
const [expectedPath, expected] = read(resolve(folder, "output.txt"))
|
||||
const babelrc: babel.TransformOptions = existsSync(resolve(folder, ".babelrc"))
|
||||
? JSON.parse(readFileSync(resolve(folder, ".babelrc"), "utf-8"))
|
||||
? JSON.parse(read(resolve(folder, ".babelrc"))[1])
|
||||
: {}
|
||||
|
||||
const transformed = transform(actual, {
|
||||
@ -38,7 +40,12 @@ const equal = (name: Snapshot) => {
|
||||
},
|
||||
],
|
||||
})!.code!
|
||||
expect(canonize(transformed) + "\n").to.deep.equal(canonize(expected) + "\n")
|
||||
|
||||
if (process.env.OVERWRITE) {
|
||||
writeFileSync(expectedPath, transformed)
|
||||
} else {
|
||||
expect(canonize(transformed) + "\n").to.deep.equal(canonize(expected) + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
describe("tsc-decorator", () => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { __decorate } from "tslib";
|
||||
|
||||
let A = class A {
|
||||
string: string;
|
||||
}
|
||||
};
|
||||
|
||||
__decorate([prop], A.prototype, "string", void 0);
|
||||
A = __decorate([classDecorator], A);
|
||||
|
||||
A = __decorate([classDecorator], A);
|
@ -1,15 +1,13 @@
|
||||
import { __decorate } from "tslib";
|
||||
|
||||
export class NormalDecorated {
|
||||
a: string;
|
||||
}
|
||||
|
||||
__decorate([prop], NormalDecorated.prototype, "a", void 0);
|
||||
|
||||
let ClassDecorated = class ClassDecorated {};
|
||||
ClassDecorated = __decorate([classDecorator], ClassDecorated);
|
||||
|
||||
export { ClassDecorated };
|
||||
|
||||
let DefaultExport = class DefaultExport {};
|
||||
DefaultExport = __decorate([classDecorator], DefaultExport);
|
||||
export default DefaultExport;
|
||||
export default DefaultExport;
|
@ -2,6 +2,7 @@ import { __decorate } from "tslib";
|
||||
|
||||
class A {
|
||||
method(): string {}
|
||||
|
||||
}
|
||||
|
||||
__decorate([dec], A.prototype, "method", null);
|
@ -3,13 +3,17 @@ import { __decorate } from "tslib";
|
||||
|
||||
class A {
|
||||
method1(skipped: string, b: string) {}
|
||||
|
||||
method2(a: string, b: string) {}
|
||||
|
||||
}
|
||||
|
||||
_decorate([__param(1, Arg())], A.prototype, "method1", null);
|
||||
|
||||
_decorate([__param(0, Arg()), __param(1, Arg())], A.prototype, "method2", null);
|
||||
|
||||
let B = class B {
|
||||
constructor(a: string) {}
|
||||
|
||||
};
|
||||
B = _decorate([__param(0, Arg())], B);
|
@ -1,22 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true,
|
||||
});
|
||||
|
||||
exports.B = exports.B = void 0;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.B = void 0;
|
||||
|
||||
var _tslib = require("tslib");
|
||||
var _remote = /*#__PURE__*/ new WeakMap();
|
||||
|
||||
exports.B = exports.B = B = (0, _tslib.__decorate)([Service()], B);
|
||||
var _remote = /*#__PURE__*/new WeakMap();
|
||||
|
||||
exports.B = B = (0, _tslib.__decorate)([Service()], B);
|
||||
|
||||
class B {
|
||||
constructor() {
|
||||
_remote.set(this, {
|
||||
writable: true,
|
||||
value: void 0,
|
||||
value: void 0
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.B = exports.B = B;
|
||||
exports.B = B;
|
@ -1,4 +1,4 @@
|
||||
import { __decorate } from "tslib"
|
||||
import { __decorate } from "tslib";
|
||||
|
||||
class A {
|
||||
prop: string;
|
||||
@ -9,13 +9,18 @@ class A {
|
||||
}
|
||||
|
||||
__decorate([dec], A.prototype, "prop", void 0);
|
||||
|
||||
__decorate([dec, dec2], A.prototype, "prop2", void 0);
|
||||
|
||||
__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 };
|
Loading…
x
Reference in New Issue
Block a user