diff --git a/LICENSE.md b/LICENSE.md
index fa59072..34bdda7 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright © 2020 [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))
+Copyright © 2021 [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 209ceaf..abf5404 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,20 @@ This has been implemented as a TypeScript Custom Transformer in order to be so l
+
+
+## Backers
+
+| | | | |
+| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
+| [Bubbles](https://usebubbles.com)
Twitter: [@usebubbles](https://twitter.com/usebubbles) | [Christopher Blanchard](https://github.com/cblanc) | [Ideal Postcodes](https://github.com/ideal-postcodes) | [Xerox](https://www.xerox.com) |
+
+### Patreon
+
+
+
+
+
## Table of Contents
@@ -70,12 +84,12 @@ This has been implemented as a TypeScript Custom Transformer in order to be so l
- [Usage with ava](#usage-with-ava)
- [Options](#options)
- [Contributing](#contributing)
-- [Maintainers](#maintainers)
-- [Backers](#backers)
- - [Patreon](#patreon)
- [FAQ](#faq)
- [How does it work, exactly?](#how-does-it-work-exactly)
- [License](#license)
+- [Backers](#backers)
+ - [Patreon](#patreon)
+- [Maintainers](#maintainers)
@@ -103,7 +117,7 @@ $ pnpm add @wessberg/di-compiler
### Peer Dependencies
-`@wessberg/di-compiler` depends on `typescript`, so you need to manually install these as well.
+`@wessberg/di-compiler` depends on `typescript`, so you need to manually install this as well.
@@ -321,20 +335,6 @@ Do you want to contribute? Awesome! Please follow [these recommendations](./CONT
-
-
-## Backers
-
-| |
-| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [Bubbles](https://usebubbles.com)
Twitter: [@use_bubbles](https://twitter.com/use_bubbles) |
-
-### Patreon
-
-
-
-
-
## FAQ
@@ -361,7 +361,7 @@ Will be compiled into:
```javascript
// ...
container.registerSingleton(undefined, {
- identifier: "MyInterface",
+ identifier: `MyInterface`,
implementation: MyImplementation,
});
```
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 240f0e5..1065388 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -15,7 +15,6 @@ specifiers:
eslint-plugin-import: ^2.23.2
eslint-plugin-jsdoc: ^34.8.2
husky: ^6.0.0
- longjohn: ^0.2.12
np: ^6.5.0
pnpm: ^6.4.0
prettier: ^2.3.0
@@ -63,7 +62,6 @@ devDependencies:
eslint-plugin-import: 2.23.2_eslint@7.26.0
eslint-plugin-jsdoc: 34.8.2_eslint@7.26.0
husky: 6.0.0
- longjohn: 0.2.12
np: 6.5.0
pnpm: 6.4.0
prettier: 2.3.0
@@ -5865,13 +5863,6 @@ packages:
wrap-ansi: 3.0.1
dev: true
- /longjohn/0.2.12:
- resolution: { integrity: sha1-fKdEawg2VcN351EiE9x1TVKmSn4= }
- engines: { node: ">= 0.9.3" }
- dependencies:
- source-map-support: 0.5.19
- dev: true
-
/loud-rejection/1.6.0:
resolution: { integrity: sha1-W0b4AUft7leIcPCG0Eghz5mOVR8= }
engines: { node: ">=0.10.0" }
diff --git a/src/transformer/before/util.ts b/src/transformer/before/util.ts
new file mode 100644
index 0000000..3854516
--- /dev/null
+++ b/src/transformer/before/util.ts
@@ -0,0 +1,24 @@
+import { TS } from "../../type/type";
+import { VisitorContext } from "../visitor-context";
+
+/**
+ * A TypeNode such as IFoo should still yield the service name "IFoo".
+ * This helper generates a proper service name from a TypeNode
+ */
+export function pickServiceOrImplementationName(
+ node: TS.Expression | TS.TypeNode | TS.EntityName,
+ context: VisitorContext
+): string {
+ const { typescript } = context;
+
+ if (typescript.isTypeReferenceNode(node)) {
+ return pickServiceOrImplementationName(node.typeName, context);
+ } else if (typescript.isIndexedAccessTypeNode(node)) {
+ return `${pickServiceOrImplementationName(
+ node.objectType,
+ context
+ )}[${pickServiceOrImplementationName(node.indexType, context)}]`;
+ } else {
+ return node.getFullText().trim();
+ }
+}
diff --git a/src/transformer/before/visitor/visit-call-expression.ts b/src/transformer/before/visitor/visit-call-expression.ts
index 97f167d..6418150 100644
--- a/src/transformer/before/visitor/visit-call-expression.ts
+++ b/src/transformer/before/visitor/visit-call-expression.ts
@@ -11,6 +11,7 @@ import {
moduleKindSupportsImportHelpers,
updateCallExpression,
} from "../../../util/ts-util";
+import { pickServiceOrImplementationName } from "../util";
export function visitCallExpression(
options: BeforeVisitorOptions
@@ -58,7 +59,7 @@ export function visitCallExpression(
case DiMethodKind.REGISTER_TRANSIENT: {
let [typeArg, implementationArg] = (node.typeArguments ??
[]) as unknown as [
- TS.TypeNode | TS.Expression | undefined,
+ TS.TypeNode | undefined,
TS.TypeNode | TS.Expression | undefined
];
@@ -76,8 +77,11 @@ export function visitCallExpression(
return childContinuation(node);
}
- const typeArgText = typeArg.getFullText().trim();
- const implementationArgText = implementationArg.getFullText().trim();
+ const typeArgText = pickServiceOrImplementationName(typeArg, context);
+ const implementationArgText = pickServiceOrImplementationName(
+ implementationArg,
+ context
+ );
// If the Implementation is a TypeNode, and if it originates from an ImportDeclaration, it may be stripped from the file since Typescript won't Type-check the updates from
// a CustomTransformer and such a node would normally be removed from the imports.
@@ -190,7 +194,7 @@ export function visitCallExpression(
createObjectLiteralExpression(context, [
compatFactory.createPropertyAssignment(
"identifier",
- compatFactory.createStringLiteral(typeArgText)
+ compatFactory.createNoSubstitutionTemplateLiteral(typeArgText)
),
...(!typescript.isTypeNode(implementationArg)
? []
@@ -342,7 +346,7 @@ function rewriteImplementationName(
}
default:
- // TODO: Add support for SystemJS and UMD here
+ // TODO: Add support for SystemJS here
return name;
}
}
diff --git a/src/util/semver-util.ts b/src/util/semver-util.ts
deleted file mode 100644
index df41420..0000000
--- a/src/util/semver-util.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-function splitSemverIntoParts(
- version: string,
- desiredLength?: number
-): number[] {
- // Split a given version string into three parts.
- const parts = version.split(".").map((element) => parseInt(element));
- if (
- parts.length === 0 ||
- (desiredLength != null && parts.length > desiredLength) ||
- parts.some(isNaN)
- ) {
- throw new Error(`Received invalid version string: ${version}`);
- }
-
- if (desiredLength != null) {
- for (let i = 0; i < desiredLength - parts.length; i++) {
- parts.push(0);
- }
- }
-
- return parts;
-}
-
-function splitSemverVersionsIntoEquivalentParts(
- v1: string,
- v2: string
-): [number[], number[]] {
- const v1Splitted = v1.split(".");
- const v2Splitted = v2.split(".");
- const desiredLength = Math.max(v1Splitted.length, v2Splitted.length);
-
- return [
- splitSemverIntoParts(v1, desiredLength),
- splitSemverIntoParts(v2, desiredLength),
- ];
-}
-
-export function compareSemver(v1: string, v2: string): number {
- const [v1Semver, v2Semver] = splitSemverVersionsIntoEquivalentParts(v1, v2);
-
- for (let i = 0; i < v1Semver.length; i++) {
- const v1Part = v1Semver[i];
- const v2Part = v2Semver[i];
- if (v1Part > v2Part) return 1;
- if (v1Part < v2Part) return -1;
- }
- return 0;
-}
diff --git a/test/amd.test.ts b/test/amd.test.ts
index a93da11..8d95876 100644
--- a/test/amd.test.ts
+++ b/test/amd.test.ts
@@ -47,7 +47,7 @@ test("Preserves Type-only imports. #1", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -94,7 +94,7 @@ test("Preserves type-only imports. #2", withTypeScript, (t, { typescript }) => {
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("./foo");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -141,7 +141,7 @@ test("Preserves type-only imports. #3", withTypeScript, (t, { typescript }) => {
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("./foo");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
});
`)
);
@@ -189,7 +189,7 @@ test("Preserves type-only imports. #4", withTypeScript, (t, { typescript }) => {
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("./foo");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
});
`)
);
@@ -236,7 +236,7 @@ test("Preserves type-only imports. #5", withTypeScript, (t, { typescript }) => {
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("./foo");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Bar });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Bar });
});
`)
);
@@ -283,7 +283,7 @@ test("Preserves type-only imports. #6", withTypeScript, (t, { typescript }) => {
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("./foo");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -333,7 +333,7 @@ test("Preserves type-only imports. #7", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
console.log(foo_1.Bar);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
});
`)
);
@@ -385,7 +385,7 @@ test(
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = require("tslib").__importDefault(require("./foo"));
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -438,7 +438,7 @@ test(
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = __importDefault(require("./foo"));
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -494,7 +494,7 @@ test(
foo_1 = __importDefault(foo_1);
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -548,7 +548,7 @@ test(
Object.defineProperty(exports, "__esModule", { value: true });
const Foo = __importStar(require("./foo"));
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
});
`)
);
diff --git a/test/commonjs.test.ts b/test/commonjs.test.ts
index 738e548..33eaf13 100644
--- a/test/commonjs.test.ts
+++ b/test/commonjs.test.ts
@@ -48,7 +48,7 @@ test("Preserves Type-only imports. #1", withTypeScript, (t, { typescript }) => {
const foo_1 = require("./foo");
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
});
@@ -94,7 +94,7 @@ test("Preserves type-only imports. #2", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
});
@@ -140,7 +140,7 @@ test("Preserves type-only imports. #3", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
`)
);
});
@@ -187,7 +187,7 @@ test("Preserves type-only imports. #4", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -233,7 +233,7 @@ test("Preserves type-only imports. #5", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Bar });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Bar });
`)
);
});
@@ -279,7 +279,7 @@ test("Preserves type-only imports. #6", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
});
@@ -329,7 +329,7 @@ test("Preserves type-only imports. #7", withTypeScript, (t, { typescript }) => {
const foo_1 = require("./foo");
console.log(foo_1.Bar);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
`)
);
});
@@ -380,7 +380,7 @@ test(
const Foo = require("tslib").__importDefault(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
}
@@ -432,7 +432,7 @@ test(
const Foo = __importDefault(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
}
@@ -487,7 +487,7 @@ test(
const foo_1 = __importDefault(require("./foo"));
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
`)
);
}
@@ -539,7 +539,7 @@ test(
const Foo = __importStar(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
}
diff --git a/test/container.test.ts b/test/container.test.ts
index 2079e4a..dbff95b 100644
--- a/test/container.test.ts
+++ b/test/container.test.ts
@@ -2,6 +2,7 @@ import test from "ava";
import { generateTransformerResult } from "./setup/setup-transformer";
import { formatCode } from "./util/format-code";
import { withTypeScript } from "./util/ts-macro";
+import { gte } from "semver";
test(
"Only considers containers that are instances of DIContainer. #1",
@@ -75,7 +76,7 @@ test(
class Foo {
}
const container = new DIContainer();
- container["registerSingleton"](undefined, { identifier: "Foo", implementation: Foo });
+ container["registerSingleton"](undefined, { identifier: \`Foo\`, implementation: Foo });
`)
);
}
@@ -112,7 +113,7 @@ test(
}
const container = new DIContainer();
const argumentExpression = "registerSingleton";
- container[argumentExpression](undefined, { identifier: "Foo", implementation: Foo });
+ container[argumentExpression](undefined, { identifier: \`Foo\`, implementation: Foo });
`)
);
}
@@ -150,7 +151,7 @@ test(
class Foo {
}
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
}
@@ -193,8 +194,8 @@ test(
import { Foo } from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
}
@@ -230,7 +231,7 @@ test(
formatCode(`\
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(() => ({foo: "hello"}), { identifier: "IFoo" });
+ container.registerSingleton(() => ({foo: "hello"}), { identifier: \`IFoo\` });
`)
);
}
@@ -266,7 +267,186 @@ test(
class Foo {
}
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "Foo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`Foo\`, implementation: Foo });
+ `)
+ );
+ }
+);
+
+test(
+ "When registering a service, the type arguments should be irrelevant. #1",
+ withTypeScript,
+ (t, { typescript }) => {
+ const bundle = generateTransformerResult(
+ [
+ {
+ entry: true,
+ fileName: "index.ts",
+ text: `
+ import {DIContainer} from "@wessberg/di";
+
+ interface IFoo {}
+ class Foo {}
+
+ const container = new DIContainer();
+ container.registerSingleton, Foo>();
+ `,
+ },
+ ],
+ { typescript }
+ );
+ const [file] = bundle;
+
+ t.deepEqual(
+ formatCode(file.text),
+ formatCode(`\
+ import { DIContainer } from "@wessberg/di";
+ class Foo {
+ }
+ const container = new DIContainer();
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
+ `)
+ );
+ }
+);
+
+test(
+ "When registering a service, the type arguments should be irrelevant. #2",
+ withTypeScript,
+ (t, { typescript }) => {
+ const bundle = generateTransformerResult(
+ [
+ {
+ entry: true,
+ fileName: "index.ts",
+ text: `
+ import {DIContainer} from "@wessberg/di";
+
+ interface IFoo {}
+ class Foo {}
+
+ const container = new DIContainer();
+ container.registerSingleton, Foo>(() => new Foo());
+ `,
+ },
+ ],
+ { typescript }
+ );
+ const [file] = bundle;
+
+ t.deepEqual(
+ formatCode(file.text),
+ formatCode(`\
+ import { DIContainer } from "@wessberg/di";
+ class Foo {
+ }
+ const container = new DIContainer();
+ container.registerSingleton(() => new Foo(), { identifier: \`IFoo\` });
+ `)
+ );
+ }
+);
+
+test(
+ "When registering a service, the type arguments should be irrelevant. #3",
+ withTypeScript,
+ (t, { typescript }) => {
+ const bundle = generateTransformerResult(
+ [
+ {
+ entry: true,
+ fileName: "index.ts",
+ text: `
+ import {DIContainer} from "@wessberg/di";
+
+ interface IFoo {
+ foo: {bar: T};
+ }
+ class Foo {
+ bar: T;
+ }
+
+ const container = new DIContainer();
+ container.registerSingleton["foo"], Foo>();
+ `,
+ },
+ ],
+ { typescript }
+ );
+ const [file] = bundle;
+
+ t.deepEqual(
+ formatCode(file.text),
+ formatCode(`\
+ import { DIContainer } from "@wessberg/di";
+ class Foo {${gte(typescript.version, "4.3.0") ? "\n\t\tbar" : ""}
+ }
+ const container = new DIContainer();
+ container.registerSingleton(undefined, { identifier: \`IFoo["foo"]\`, implementation: Foo });
+ `)
+ );
+ }
+);
+
+test(
+ "When registering a service, the type argument can be a PropertyAccessTypeNode. #1",
+ withTypeScript,
+ (t, { typescript }) => {
+ const bundle = generateTransformerResult(
+ [
+ {
+ entry: true,
+ fileName: "index.ts",
+ text: `
+ import {DIContainer} from "@wessberg/di";
+
+ const container = new DIContainer();
+ container.registerSingleton();
+ `,
+ },
+ ],
+ { typescript }
+ );
+ const [file] = bundle;
+
+ t.deepEqual(
+ formatCode(file.text),
+ formatCode(`\
+ import { DIContainer } from "@wessberg/di";
+ const container = new DIContainer();
+ container.registerSingleton(undefined, { identifier: \`Intl.RelativeTimeFormat\`, implementation: Intl.RelativeTimeFormat });
+ `)
+ );
+ }
+);
+
+test(
+ "When registering a service, the type argument can be a TypeQueryNode. #1",
+ withTypeScript,
+ (t, { typescript }) => {
+ const bundle = generateTransformerResult(
+ [
+ {
+ entry: true,
+ fileName: "index.ts",
+ text: `
+ import {DIContainer} from "@wessberg/di";
+
+ const container = new DIContainer();
+ container.registerSingleton();
+ `,
+ },
+ ],
+ { typescript }
+ );
+ const [file] = bundle;
+
+ t.deepEqual(
+ formatCode(file.text),
+ formatCode(`\
+ import { DIContainer } from "@wessberg/di";
+ const container = new DIContainer();
+ container.registerSingleton(undefined, { identifier: \`typeof foo\`, implementation: {} });
`)
);
}
diff --git a/test/esm.test.ts b/test/esm.test.ts
index ce58462..a883c31 100644
--- a/test/esm.test.ts
+++ b/test/esm.test.ts
@@ -37,7 +37,7 @@ test("Preserves type-only imports. #1", withTypeScript, (t, { typescript }) => {
import Foo from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -76,7 +76,7 @@ test("Preserves type-only imports. #2", withTypeScript, (t, { typescript }) => {
import {Foo} from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -116,7 +116,7 @@ test("Preserves type-only imports. #3", withTypeScript, (t, { typescript }) => {
import * as Foo from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -155,7 +155,7 @@ test("Preserves type-only imports. #4", withTypeScript, (t, { typescript }) => {
import {Bar as Foo} from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -194,7 +194,7 @@ test("Preserves type-only imports. #5", withTypeScript, (t, { typescript }) => {
import {default as Foo} from "./foo";
import { DIContainer } from "@wessberg/di";
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -237,7 +237,7 @@ test("Preserves type-only imports. #6", withTypeScript, (t, { typescript }) => {
import {Bar} from "./foo";
console.log(Bar);
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
});
@@ -281,7 +281,7 @@ test(
import Foo from "./foo";
console.log(Foo);
const container = new DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
`)
);
}
diff --git a/test/umd.test.ts b/test/umd.test.ts
index 3c24503..542fdf7 100644
--- a/test/umd.test.ts
+++ b/test/umd.test.ts
@@ -57,7 +57,7 @@ test("Preserves Type-only imports. #1", withTypeScript, (t, { typescript }) => {
const foo_1 = require("./foo");
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
@@ -114,7 +114,7 @@ test("Preserves type-only imports. #2", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -170,7 +170,7 @@ test("Preserves type-only imports. #3", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
});
`)
);
@@ -227,7 +227,7 @@ test("Preserves type-only imports. #4", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
});
`)
);
@@ -283,7 +283,7 @@ test("Preserves type-only imports. #5", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Bar });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Bar });
});
`)
);
@@ -339,7 +339,7 @@ test("Preserves type-only imports. #6", withTypeScript, (t, { typescript }) => {
const Foo = require("./foo");
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -399,7 +399,7 @@ test("Preserves type-only imports. #7", withTypeScript, (t, { typescript }) => {
const foo_1 = require("./foo");
console.log(foo_1.Bar);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.Foo });
});
`)
);
@@ -460,7 +460,7 @@ test(
const Foo = require("tslib").__importDefault(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
);
@@ -522,7 +522,7 @@ test(
const Foo = __importDefault(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
@@ -588,7 +588,7 @@ test(
const foo_1 = __importDefault(require("./foo"));
console.log(foo_1.default);
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo.default });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo.default });
});
`)
@@ -652,7 +652,7 @@ test(
const Foo = __importStar(require("./foo"));
const di_1 = require("@wessberg/di");
const container = new di_1.DIContainer();
- container.registerSingleton(undefined, { identifier: "IFoo", implementation: Foo });
+ container.registerSingleton(undefined, { identifier: \`IFoo\`, implementation: Foo });
});
`)
);