@wessberg/di-compiler
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -5,2 +5,3 @@ import { IClassConstructorArgumentsStringifier } from "./Interface/IClassConstructorArgumentsStringifier"; | ||
import { ClassIndexer } from "@wessberg/codeanalyzer"; | ||
import { IIdentifierValidator } from "@wessberg/compiler-common"; | ||
/** | ||
@@ -12,3 +13,4 @@ * This class generates a stringified map between classes and the services that their constructors depend on. | ||
private config; | ||
constructor(config: IDIConfig); | ||
private identifierValidator; | ||
constructor(config: IDIConfig, identifierValidator: IIdentifierValidator); | ||
/** | ||
@@ -15,0 +17,0 @@ * This method will generate a stringified map between service interfaces and the (ordered) identifiers for services that should be dependency injected upon their |
@@ -9,4 +9,5 @@ "use strict"; | ||
class ClassConstructorArgumentsStringifier { | ||
constructor(config) { | ||
constructor(config, identifierValidator) { | ||
this.config = config; | ||
this.identifierValidator = identifierValidator; | ||
} | ||
@@ -26,6 +27,7 @@ /** | ||
keys.forEach((key, index) => { | ||
const classDeclaration = classes[mappedInterfaces[key]]; | ||
if (classDeclaration == null) | ||
const className = mappedInterfaces[key]; | ||
const classDeclaration = classes[className]; | ||
if (classDeclaration == null && !this.identifierValidator.isBuiltIn(className)) | ||
throw new ReferenceError(`${this.constructor.name} could not get class constructor arguments: The interface "${key}" had no matching class implementation. Have you registered it as a service?`); | ||
const mappedArguments = classDeclaration.constructor == null ? [] : classDeclaration.constructor.parameters.parametersList.map(parameter => this.normalizeConstructorParameter(parameter, mappedInterfaces)).join(", "); | ||
const mappedArguments = classDeclaration == null || classDeclaration.constructor == null ? [] : classDeclaration.constructor.parameters.parametersList.map(parameter => this.normalizeConstructorParameter(parameter, mappedInterfaces)).join(", "); | ||
map += `\t${key}: `; | ||
@@ -32,0 +34,0 @@ map += `[${mappedArguments}]`; |
@@ -15,5 +15,7 @@ "use strict"; | ||
const fileloader_1 = require("@wessberg/fileloader"); | ||
const compiler_common_1 = require("@wessberg/compiler-common"); | ||
const typeDetector = new typedetector_1.TypeDetector(); | ||
const marshaller = new marshaller_1.Marshaller(typeDetector); | ||
const compiler = new Compiler_1.Compiler(new codeanalyzer_1.CodeAnalyzer(marshaller, new fileloader_1.FileLoader()), new ContainerReferenceFinder_1.ContainerReferenceFinder(DIConfig_1.DIConfig), new ServiceExpressionFinder_1.ServiceExpressionFinder(), new ServiceExpressionUpdater_1.ServiceExpressionUpdater(DIConfig_1.DIConfig, typeDetector), new ClassConstructorArgumentsValidator_1.ClassConstructorArgumentsValidator(), new ClassConstructorArgumentsStringifier_1.ClassConstructorArgumentsStringifier(DIConfig_1.DIConfig)); | ||
const identifierValidator = new compiler_common_1.IdentifierValidator(); | ||
const compiler = new Compiler_1.Compiler(new codeanalyzer_1.CodeAnalyzer(marshaller, new fileloader_1.FileLoader()), new ContainerReferenceFinder_1.ContainerReferenceFinder(DIConfig_1.DIConfig), new ServiceExpressionFinder_1.ServiceExpressionFinder(), new ServiceExpressionUpdater_1.ServiceExpressionUpdater(DIConfig_1.DIConfig, typeDetector, identifierValidator), new ClassConstructorArgumentsValidator_1.ClassConstructorArgumentsValidator(), new ClassConstructorArgumentsStringifier_1.ClassConstructorArgumentsStringifier(DIConfig_1.DIConfig, identifierValidator)); | ||
/** | ||
@@ -20,0 +22,0 @@ * The public method of DI. This is build-tool agnostic and only cares about getting an id and some code. |
import { IDIConfig } from "../DIConfig/Interface/IDIConfig"; | ||
import { IMappedInterfaceToImplementationMap, IServiceExpressionUpdater, IServiceExpressionUpdaterUpdateMethodOptions } from "./Interface/IServiceExpressionUpdater"; | ||
import { ITypeDetector } from "@wessberg/typedetector"; | ||
import { IIdentifierValidator } from "@wessberg/compiler-common"; | ||
/** | ||
@@ -12,3 +13,3 @@ * Walks through all call expressions on the DIContainer instance and upgrades their arguments. | ||
private identifierValidator; | ||
constructor(config: IDIConfig, typeDetector: ITypeDetector); | ||
constructor(config: IDIConfig, typeDetector: ITypeDetector, identifierValidator: IIdentifierValidator); | ||
/** | ||
@@ -15,0 +16,0 @@ * Walks through all expressions and delegates the update work to other methods in order to upgrade the code. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const compiler_common_1 = require("@wessberg/compiler-common"); | ||
/** | ||
@@ -9,6 +8,6 @@ * Walks through all call expressions on the DIContainer instance and upgrades their arguments. | ||
class ServiceExpressionUpdater { | ||
constructor(config, typeDetector) { | ||
constructor(config, typeDetector, identifierValidator) { | ||
this.config = config; | ||
this.typeDetector = typeDetector; | ||
this.identifierValidator = new compiler_common_1.IdentifierValidator(); | ||
this.identifierValidator = identifierValidator; | ||
} | ||
@@ -15,0 +14,0 @@ /** |
@@ -5,2 +5,3 @@ import { IClassConstructorArgumentsStringifier } from "./Interface/IClassConstructorArgumentsStringifier"; | ||
import { ClassIndexer } from "@wessberg/codeanalyzer"; | ||
import { IIdentifierValidator } from "@wessberg/compiler-common"; | ||
/** | ||
@@ -12,3 +13,4 @@ * This class generates a stringified map between classes and the services that their constructors depend on. | ||
private config; | ||
constructor(config: IDIConfig); | ||
private identifierValidator; | ||
constructor(config: IDIConfig, identifierValidator: IIdentifierValidator); | ||
/** | ||
@@ -15,0 +17,0 @@ * This method will generate a stringified map between service interfaces and the (ordered) identifiers for services that should be dependency injected upon their |
@@ -7,4 +7,5 @@ import { GlobalObjectIdentifier } from "@wessberg/globalobject"; | ||
export class ClassConstructorArgumentsStringifier { | ||
constructor(config) { | ||
constructor(config, identifierValidator) { | ||
this.config = config; | ||
this.identifierValidator = identifierValidator; | ||
} | ||
@@ -24,6 +25,7 @@ /** | ||
keys.forEach((key, index) => { | ||
const classDeclaration = classes[mappedInterfaces[key]]; | ||
if (classDeclaration == null) | ||
const className = mappedInterfaces[key]; | ||
const classDeclaration = classes[className]; | ||
if (classDeclaration == null && !this.identifierValidator.isBuiltIn(className)) | ||
throw new ReferenceError(`${this.constructor.name} could not get class constructor arguments: The interface "${key}" had no matching class implementation. Have you registered it as a service?`); | ||
const mappedArguments = classDeclaration.constructor == null ? [] : classDeclaration.constructor.parameters.parametersList.map(parameter => this.normalizeConstructorParameter(parameter, mappedInterfaces)).join(", "); | ||
const mappedArguments = classDeclaration == null || classDeclaration.constructor == null ? [] : classDeclaration.constructor.parameters.parametersList.map(parameter => this.normalizeConstructorParameter(parameter, mappedInterfaces)).join(", "); | ||
map += `\t${key}: `; | ||
@@ -30,0 +32,0 @@ map += `[${mappedArguments}]`; |
@@ -13,5 +13,7 @@ import { Marshaller } from "@wessberg/marshaller"; | ||
import { FileLoader } from "@wessberg/fileloader"; | ||
import { IdentifierValidator } from "@wessberg/compiler-common"; | ||
const typeDetector = new TypeDetector(); | ||
const marshaller = new Marshaller(typeDetector); | ||
const compiler = new Compiler(new CodeAnalyzer(marshaller, new FileLoader()), new ContainerReferenceFinder(DIConfig), new ServiceExpressionFinder(), new ServiceExpressionUpdater(DIConfig, typeDetector), new ClassConstructorArgumentsValidator(), new ClassConstructorArgumentsStringifier(DIConfig)); | ||
const identifierValidator = new IdentifierValidator(); | ||
const compiler = new Compiler(new CodeAnalyzer(marshaller, new FileLoader()), new ContainerReferenceFinder(DIConfig), new ServiceExpressionFinder(), new ServiceExpressionUpdater(DIConfig, typeDetector, identifierValidator), new ClassConstructorArgumentsValidator(), new ClassConstructorArgumentsStringifier(DIConfig, identifierValidator)); | ||
/** | ||
@@ -18,0 +20,0 @@ * The public method of DI. This is build-tool agnostic and only cares about getting an id and some code. |
import { IDIConfig } from "../DIConfig/Interface/IDIConfig"; | ||
import { IMappedInterfaceToImplementationMap, IServiceExpressionUpdater, IServiceExpressionUpdaterUpdateMethodOptions } from "./Interface/IServiceExpressionUpdater"; | ||
import { ITypeDetector } from "@wessberg/typedetector"; | ||
import { IIdentifierValidator } from "@wessberg/compiler-common"; | ||
/** | ||
@@ -12,3 +13,3 @@ * Walks through all call expressions on the DIContainer instance and upgrades their arguments. | ||
private identifierValidator; | ||
constructor(config: IDIConfig, typeDetector: ITypeDetector); | ||
constructor(config: IDIConfig, typeDetector: ITypeDetector, identifierValidator: IIdentifierValidator); | ||
/** | ||
@@ -15,0 +16,0 @@ * Walks through all expressions and delegates the update work to other methods in order to upgrade the code. |
@@ -1,2 +0,1 @@ | ||
import { IdentifierValidator } from "@wessberg/compiler-common"; | ||
/** | ||
@@ -7,6 +6,6 @@ * Walks through all call expressions on the DIContainer instance and upgrades their arguments. | ||
export class ServiceExpressionUpdater { | ||
constructor(config, typeDetector) { | ||
constructor(config, typeDetector, identifierValidator) { | ||
this.config = config; | ||
this.typeDetector = typeDetector; | ||
this.identifierValidator = new IdentifierValidator(); | ||
this.identifierValidator = identifierValidator; | ||
} | ||
@@ -13,0 +12,0 @@ /** |
{ | ||
"name": "@wessberg/di-compiler", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "The compiler for https://www.npmjs.com/package/@wessberg/di", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -27,5 +27,9 @@ # DI-Compiler (The compiler for DI) [![NPM version][npm-image]][npm-url] | ||
**v1.0.12**: | ||
- Fixed a bug. | ||
**v1.0.11**: | ||
- Built-in constructors (for example "Proxy" or anything that is a native part of the environment) can now be added as services too. | ||
- Built-in constructors can now be added as services too. | ||
@@ -32,0 +36,0 @@ **v1.0.10**: |
77237
1479
85