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

@jymfony/autoloader

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jymfony/autoloader - npm Package Compare versions

Comparing version 0.1.0-alpha.9 to 0.1.0-alpha.10

README.md

11

fixtures/BarClass.js
const FooClass = Foo.FooClass;
module.exports = class BarClass {
class BarClass {
/**
* Constructor.
*
* @param {FooClass} fooClass
*/
__construct(fooClass) {

@@ -11,2 +16,4 @@ this.fooClass = fooClass;

}
};
}
module.exports = BarClass;
const BarClass = Foo.BarClass;
class FooClass {
/**
* Constructor.
*/
__construct() {

@@ -5,0 +8,0 @@ this.bar = new BarClass(this);

6

package.json
{
"name": "@jymfony/autoloader",
"version": "0.1.0-alpha.9",
"version": "0.1.0-alpha.10",
"description": "Jymfony Autoloader",

@@ -17,6 +17,6 @@ "main": "index.js",

"engines": {
"node": ">=6.0.0"
"node": ">=8.10.0"
},
"dependencies": {
"@jymfony/util": "0.1.0-alpha.9"
"@jymfony/util": "0.1.0-alpha.10"
},

@@ -23,0 +23,0 @@ "devDependencies": {

@@ -16,4 +16,4 @@ const Finder = require('./Finder');

*
* @param {undefined|Jymfony.Component.Autoloader.Finder} finder
* @param {Object} globalObject
* @param {undefined|Jymfony.Component.Autoloader.Finder} [finder]
* @param {Object} [globalObject = global]
*/

@@ -31,2 +31,3 @@ constructor(finder = undefined, globalObject = global) {

* @type {boolean}
*
* @private

@@ -38,2 +39,3 @@ */

* @type {boolean}
*
* @private

@@ -45,2 +47,3 @@ */

* @type {Jymfony.Component.Autoloader.Finder}
*
* @private

@@ -52,2 +55,3 @@ */

* @type {Object}
*
* @private

@@ -112,3 +116,53 @@ */

constructor(...$args) {
return this.__construct(...$args);
const retVal = this.__construct(...$args);
if (undefined !== retVal && this !== retVal) {
return retVal;
}
if (undefined !== this.__invoke) {
return new Proxy(this.__invoke, {
get: (target, key) => {
return Reflect.get(this, key);
},
set: (target, key, value) => {
return Reflect.set(this, key, value);
},
has: (target, key) => {
return Reflect.has(this, key);
},
deleteProperty: (target, key) => {
return Reflect.deleteProperty(this, key);
},
defineProperty: (target, key, descriptor) => {
return Reflect.defineProperty(this, key, descriptor);
},
enumerate: () => {
return Reflect.enumerate(this);
},
ownKeys: () => {
return Reflect.ownKeys(this);
},
apply: (target, ctx, args) => {
return this.__invoke(...args);
},
construct: (target, argumentsList, newTarget) => {
return Reflect.construct(this, argumentsList, newTarget);
},
getPrototypeOf: () => {
return Reflect.getPrototypeOf(this);
},
setPrototypeOf: (target, proto) => {
return Reflect.setPrototypeOf(this, proto);
},
isExtensible: () => {
return Reflect.isExtensible(this);
},
preventExtensions: () => {
return Reflect.preventExtensions(this);
},
getOwnPropertyDescriptor: (target, key) => {
return Reflect.getOwnPropertyDescriptor(this, key);
},
});
}
}

@@ -119,4 +173,4 @@

Symbol.reflection = Symbol('reflection');
Symbol.docblock = Symbol('docblock');
this._global.Symbol.reflection = Symbol('reflection');
this._global.Symbol.docblock = Symbol('docblock');

@@ -141,2 +195,8 @@ const rootDir = this._finder.findRoot();

/**
* @param {Object} packageInfo
* @param {string} baseDir
*
* @private
*/
_processPackageInfo(packageInfo, baseDir) {

@@ -157,2 +217,8 @@ if (! packageInfo.config || ! packageInfo.config['jymfony-autoload']) {

/**
* @param {Object} config
* @param {string} baseDir
*
* @private
*/
_processNamespaces(config, baseDir) {

@@ -181,2 +247,8 @@ for (const namespace in config) {

/**
* @param {Object} config
* @param {string} baseDir
*
* @private
*/
_processIncludes(config, baseDir) {

@@ -188,2 +260,10 @@ for (const fileName of config) {

/**
* @param {Object} namespace
* @param {Object} parent
*
* @returns {Object}
*
* @private
*/
_ensureNamespace(namespace, parent) {

@@ -197,2 +277,10 @@ if (parent[namespace] === undefined) {

/**
* @param {Object} parent
* @param {Object} namespace
*
* @returns {string}
*
* @private
*/
_generateFqn(parent, namespace) {

@@ -199,0 +287,0 @@ return (parent === this._global ? '' : parent.__namespace.name + '.') + namespace;

@@ -15,2 +15,4 @@ const Patcher = require('./Parser/Patcher');

/**
* Constructor
*
* @param {Finder} finder

@@ -23,2 +25,3 @@ * @param {path} path

* @type {Finder}
*
* @private

@@ -30,2 +33,3 @@ */

* @type {path}
*
* @private

@@ -37,2 +41,3 @@ */

* @type {vm}
*
* @private

@@ -44,2 +49,3 @@ */

* @type {Object}
*
* @private

@@ -50,2 +56,8 @@ */

/**
* @param {string} fn
* @param {*} self
*
* @returns {*}
*/
load(fn, self) {

@@ -52,0 +64,0 @@ if (this._cache[fn]) {

@@ -5,2 +5,9 @@ /**

class Finder {
/**
* Constructor.
*
* @param {fs} fs
* @param {path} path
* @param {module} [currentModule = module]
*/
constructor(fs = require('fs'), path = require('path'), currentModule = module) {

@@ -18,6 +25,6 @@ this._fs = fs;

*
* @param baseDir
* @param name
* @param {string} baseDir
* @param {string} name
*
* @returns object
* @returns {Object}
*/

@@ -52,2 +59,5 @@ find(baseDir, name) {

/**
* @param {string} fn
*/
load(fn) {

@@ -152,2 +162,7 @@ return this._fs.readFileSync(fn, 'utf-8');

/**
* @returns {Object}
*
* @private
*/
_getMainModule() {

@@ -162,2 +177,10 @@ let current = this._currentModule;

/**
* @param {string[]} parts
* @param {string} fileName
*
* @returns {string}
*
* @private
*/
_normalizePath(parts, fileName) {

@@ -164,0 +187,0 @@ const joined = this._path.join(...parts, (fileName || ''));

@@ -11,3 +11,3 @@ const ClassLoader = require('./ClassLoader');

/**
* Namespace constructor
* Constructor.
*

@@ -60,3 +60,3 @@ * @param {Jymfony.Component.Autoloader.Autoloader} autoloader

*
* @param directory
* @param {string} directory
*

@@ -121,2 +121,3 @@ * @returns {Jymfony.Component.Autoloader.Namespace}

* @param {string} name
*
* @returns {*}

@@ -147,2 +148,9 @@ *

/**
* @param {string} filename
*
* @returns {Function}
*
* @private
*/
_require(filename) {

@@ -149,0 +157,0 @@ const fn = this._internalRequire.resolve(filename);

@@ -11,2 +11,5 @@ const ValueHolder = require('./ValueHolder');

class Lexer {
/**
* Constructor.
*/
constructor() {

@@ -240,2 +243,5 @@ /**

/**
* @returns {string[]}
*/
getPatterns() {

@@ -258,2 +264,7 @@ return [

/**
* @param {Object} holder
*
* @returns {number}
*/
getType(holder) {

@@ -260,0 +271,0 @@ if (holder.value.match(this._spaces)) {

@@ -5,2 +5,7 @@ const Lexer = require('./Lexer');

class Patcher {
/**
* Constructor.
*
* @param {string} code
*/
constructor(code) {

@@ -14,2 +19,3 @@ lexer.input = code;

* @param {Jymfony.Component.Autoloader.Parser.Lexer} lexer
*
* @private

@@ -47,2 +53,3 @@ */

* @param {undefined|string} classDocblock
*
* @private

@@ -54,2 +61,3 @@ */

methods: {},
properties: {},
};

@@ -101,2 +109,3 @@

let level = 1;
let currentMethodName;
while (level && false !== lexer.moveNext()) {

@@ -122,3 +131,6 @@ const token = lexer.token;

case Lexer.T_CLOSED_PARENTHESIS:
level--;
if (0 === --level) {
currentMethodName = undefined;
}
docblock = undefined;

@@ -144,2 +156,3 @@ break;

classDocblock.methods[methodName] = docblock;
currentMethodName = methodName;
}

@@ -159,2 +172,15 @@

if (docblock && 'this' === token.value &&
('__construct' === currentMethodName || 'constructor' === currentMethodName)) {
let next;
while ((next = lexer.peek()).type === Lexer.T_SPACE) { }
if (next.type === Lexer.T_DOT) {
while ((next = lexer.peek()).type === Lexer.T_SPACE) { }
if (next.type === Lexer.T_IDENTIFIER) {
classDocblock.properties[next.value] = docblock;
}
}
}
default:

@@ -174,7 +200,3 @@ if (1 !== level || ('*' !== token.value && 'async' !== token.value)) {

const docblock = JSON.stringify(classDocblock);
code += `
static [Symbol.docblock]() {
return ${docblock};
}
`;
code += ` static [Symbol.docblock]() { return ${docblock}; } `;
}

@@ -192,2 +214,5 @@

/**
* @private
*/
_parse() {

@@ -200,2 +225,5 @@ this._code = '';

/**
* @returns {string}
*/
get code() {

@@ -202,0 +230,0 @@ return this._code;

@@ -8,2 +8,7 @@ /**

class ValueHolder {
/**
* Constructor.
*
* @param {*} value
*/
constructor(value) {

@@ -13,2 +18,5 @@ this.value = value;

/**
* @returns {*}
*/
get value() {

@@ -18,2 +26,5 @@ return this._value;

/**
* @param {*} value
*/
set value(value) {

@@ -20,0 +31,0 @@ this._value = value.toString();

@@ -49,2 +49,7 @@ const ReflectionMethod = require('./ReflectionMethod');

class ReflectionClass {
/**
* Constructor.
*
* @param {string|Object} value
*/
constructor(value) {

@@ -97,3 +102,3 @@ this._isInterface = false;

*
* @param className
* @param {string|Object} className
*/

@@ -107,3 +112,3 @@ static getClass(className) {

*
* @param className
* @param {string|Object} className
*

@@ -123,8 +128,8 @@ * @returns {string}

*
* @param {...*} var_args Arguments to constructor
* @param {...*} varArgs Arguments to constructor
*
* @returns {*}
*/
newInstance(...var_args) {
return new this._constructor(...var_args);
newInstance(...varArgs) {
return new this._constructor(...varArgs);
}

@@ -180,3 +185,3 @@

*
* @param name
* @param {string} name
*

@@ -192,3 +197,3 @@ * @returns {boolean}

*
* @param name
* @param {string} name
*

@@ -261,3 +266,3 @@ * @returns {boolean}

*
* @return {boolean}
* @returns {boolean}
*/

@@ -325,3 +330,3 @@ get isInterface() {

*
* @return {string}
* @returns {string}
*/

@@ -355,3 +360,3 @@ get docblock() {

*
* @returns {[ReflectionClass]}
* @returns {ReflectionClass[]}
*/

@@ -362,2 +367,7 @@ get interfaces() {

/**
* @param {Object} value
*
* @private
*/
_loadFromMetadata(value) {

@@ -397,2 +407,5 @@ const metadata = value[Symbol.reflection];

/**
* @private
*/
_loadFromCache() {

@@ -418,2 +431,5 @@ const data = TheBigReflectionDataCache.data[this._className];

/**
* @private
*/
_loadWithoutMetadata(value) {

@@ -430,2 +446,5 @@ this._className = undefined;

/**
* @private
*/
_loadProperties() {

@@ -478,2 +497,5 @@ const loadFromPrototype = (proto) => {

/**
* @private
*/
_loadStatics() {

@@ -521,2 +543,5 @@ const FunctionProps = Object.getOwnPropertyNames(Function.prototype);

/**
* @private
*/
static _recursiveGet(start, parts) {

@@ -548,2 +573,5 @@ let part;

/**
* @private
*/
static _searchModule(value) {

@@ -550,0 +578,0 @@ for (const moduleName of Object.keys(require.cache)) {

@@ -14,2 +14,3 @@ /**

* @type {ReflectionClass}
*
* @private

@@ -21,2 +22,3 @@ */

* @type {string}
*
* @private

@@ -28,2 +30,3 @@ */

* @type {Function}
*
* @private

@@ -35,2 +38,3 @@ */

* @type {boolean}
*
* @private

@@ -52,2 +56,3 @@ */

* @type {string}
*
* @private

@@ -59,2 +64,3 @@ */

* @type {boolean}
*
* @private

@@ -66,2 +72,3 @@ */

* @type {string}
*
* @private

@@ -75,3 +82,3 @@ */

*
* @return {ReflectionClass}
* @returns {ReflectionClass}
*/

@@ -85,3 +92,3 @@ get reflectionClass() {

*
* @return {string}
* @returns {string}
*/

@@ -88,0 +95,0 @@ get name() {

@@ -17,2 +17,67 @@ const expect = require('chai').expect;

});
it('JObject should call __construct', () => {
const glob = {
Symbol: {},
};
const autoloader = new Autoloader({
findRoot: () => {
return __dirname + '/..';
},
listModules: () => [],
}, glob);
autoloader.register();
let called = false;
const cl = class TestClass extends glob.__jymfony.JObject {
__construct() {
called = true;
}
};
new cl();
expect(called).to.be.true;
});
it('JObject should call __invoke when needed', () => {
const glob = {
Symbol: {},
};
const autoloader = new Autoloader({
findRoot: () => {
return __dirname + '/..';
},
listModules: () => [],
}, glob);
autoloader.register();
let ConstructCalled = false;
let InvokeCalled = false;
let MethodCalled = false;
const cl = class TestClass extends glob.__jymfony.JObject {
__construct() {
ConstructCalled = true;
}
__invoke(arg1, arg2) {
InvokeCalled = [ arg1, arg2 ];
}
method() {
MethodCalled = true;
}
};
const obj = new cl();
obj('foo', 'bar');
obj.method();
expect(obj instanceof cl).to.be.true;
expect(ConstructCalled).to.be.true;
expect(InvokeCalled).to.be.deep.equal([ 'foo', 'bar' ]);
expect(MethodCalled).to.be.true;
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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