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