Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/di

Package Overview
Dependencies
Maintainers
1
Versions
313
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/di - npm Package Compare versions

Comparing version 0.1.6 to 0.2.0

tslint.json

8

package.json

@@ -7,8 +7,8 @@ {

"dependencies": {
"@travetto/config": "^0.1.4",
"@travetto/registry": "^0.1.5"
"@travetto/config": "^0.2.0",
"@travetto/registry": "^0.2.0"
},
"description": "Dependency registration/management and injection support.",
"devDependencies": {
"@travetto/test": "^0.1.6"
"@travetto/test": "^0.2.0"
},

@@ -33,3 +33,3 @@ "homepage": "https://travetto.io",

},
"version": "0.1.6"
"version": "0.2.0"
}

@@ -1,5 +0,6 @@

import * as ts from 'typescript';
import { TransformUtil, State } from '@travetto/compiler';
import { TransformUtil, TransformerState } from '@travetto/compiler';
import { ConfigLoader } from '@travetto/config';
const INJECTABLE_MOD = require.resolve('../src/decorator/injectable');
const INJECTABLES = TransformUtil.buildImportAliasMap({

@@ -10,13 +11,11 @@ ...ConfigLoader.get('registry.injectable'),

interface DiState extends State {
interface DiState extends TransformerState {
inInjectable: boolean;
decorators: { [key: string]: ts.Expression };
import?: ts.Identifier;
}
function processDeclaration(state: State, param: ts.ParameterDeclaration | ts.PropertyDeclaration) {
const injection = TransformUtil.findAnyDecorator(param, { Inject: new Set(['@travetto/di']) }, state);
function processDeclaration(state: TransformerState, param: ts.ParameterDeclaration | ts.PropertyDeclaration) {
const injection = TransformUtil.findAnyDecorator(state, param, { Inject: new Set(['@travetto/di']) });
if (injection || ts.isParameter(param)) {
const finalTarget = TransformUtil.importIfExternal(param.type!, state);
const finalTarget = TransformUtil.importTypeIfExternal(state, param.type!);

@@ -57,26 +56,5 @@ let injectConfig = TransformUtil.getPrimaryArgument<ts.ObjectLiteralExpression>(injection);

function createInjectDecorator(state: DiState, name: string, contents?: ts.Expression) {
if (!state.decorators[name]) {
if (!state.import) {
state.import = ts.createIdentifier(`import_Injectable`);
state.newImports.push({
ident: state.import,
path: require.resolve('../src/decorator/injectable')
});
}
const ident = ts.createIdentifier(name);
state.decorators[name] = ts.createPropertyAccess(state.import, ident);
}
return ts.createDecorator(
ts.createCall(
state.decorators[name],
undefined,
contents ? [contents] : []
)
);
}
function visitNode<T extends ts.Node>(context: ts.TransformationContext, node: T, state: DiState): T {
if (ts.isClassDeclaration(node)) { // Class declaration
const foundDec = TransformUtil.findAnyDecorator(node, INJECTABLES, state);
const foundDec = TransformUtil.findAnyDecorator(state, node, INJECTABLES);

@@ -106,8 +84,8 @@ if (foundDec) { // Constructor

declTemp.push(createInjectDecorator(state, 'InjectArgs', injectArgs));
declTemp.push(TransformUtil.createDecorator(state, INJECTABLE_MOD, 'InjectArgs', injectArgs));
// Add injectable decorator if not there (for aliased decorators)
let injectable = TransformUtil.findAnyDecorator(node, { Injectable: new Set(['@travetto/di']) }, state);
let injectable = TransformUtil.findAnyDecorator(state, node, { Injectable: new Set(['@travetto/di']) });
if (!injectable) {
injectable = createInjectDecorator(state, 'Injectable');
injectable = TransformUtil.createDecorator(state, INJECTABLE_MOD, 'Injectable');
declTemp.push(injectable);

@@ -157,3 +135,3 @@ } else {

if (expr) {
const final = createInjectDecorator(state, 'Inject', expr);
const final = TransformUtil.createDecorator(state, INJECTABLE_MOD, 'Inject', expr);
const finalDecs = ((node.decorators as any as ts.Decorator[]) || [])

@@ -179,3 +157,3 @@ .filter(x => TransformUtil.getDecoratorIdent(x).text !== 'Inject');

// Factory for static methods
const foundDec = TransformUtil.findAnyDecorator(node, { InjectableFactory: new Set(['@travetto/di']) }, state);
const foundDec = TransformUtil.findAnyDecorator(state, node, { InjectableFactory: new Set(['@travetto/di']) });
const decls = node.decorators;

@@ -215,3 +193,3 @@

if (node.type && target === undefined) { // TODO: infer from typings, not just text?
target = TransformUtil.importIfExternal(node.type!, state);
target = TransformUtil.importTypeIfExternal(state, node.type!);
}

@@ -258,3 +236,2 @@ const args = TransformUtil.extendObjectLiteral({

inInjectable: false,
decorators: {}
}), visitNode),

@@ -261,0 +238,0 @@ priority: 11,

{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"target": "es2018",
"strict": true,

@@ -6,0 +6,0 @@ "noStrictGenericChecks": true,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc