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

ng-annotate-patched

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-annotate-patched - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

4

CHANGES.md

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

## 1.10.0 2019-06-22
* Added support for arrow functions, e.g. annotating
`var controller = ($scope) => { ngInject"; }`.
## 1.9.0 2019-01-25

@@ -2,0 +6,0 @@ * Added support for ES6 classes with explicit `ngInject` annotations.

2

package.json
{
"name": "ng-annotate-patched",
"version": "1.9.0",
"version": "1.10.0",
"description": "add, remove and rebuild angularjs dependency injection annotations",

@@ -5,0 +5,0 @@ "main": "src/ng-annotate-main.js",

@@ -23,12 +23,16 @@ # Fork details

- Added support for ES6 classes with explicit `ngInject` annotations.
- Added support for annotating ES6 classes with explicit `ngInject`
annotations.
The support may not be perfect yet. For more information please see
[ES6 test file](tests/es6-classes.js).
- Added support for dynamic `import()` syntax. If you use Webpack or a similar
module loader you would probably like to compile to `esnext` modules for
dynamic import support. To do that you will need to pass the
`dynamicImport` flag which will switch from the default acorn package,
to the upgraded `acorn-dynamic-import`.
- Added support for annotating arrow functions in most places where
old-style function expressions are accepted.
- Added support for parsing dynamic `import()` syntax. If you use Webpack
or a similar module loader you would probably like to compile to
`esnext` modules for dynamic import support. To do that you will need to
pass the `dynamicImport` flag which will switch from the default acorn
package, to the upgraded `acorn-dynamic-import`.
- Published to npm under the name `ng-annotate-patched`.

@@ -35,0 +39,0 @@

@@ -66,9 +66,28 @@ // ng-annotate-main.js

function getObjectExpressionReturnProperties(node) {
// matches object return via `return`:
// 1. function() { return {} }
// 2. () => { return {} }
if (node.type === "ReturnStatement" &&
node.argument && node.argument.type === "ObjectExpression") {
return node.argument.properties;
}
// matches object return via arrow function shortcut:
// 1. () => ({})
if (node.type === "ArrowFunctionExpression" && node.expression === true &&
node.body.type === "ObjectExpression") {
return node.body.properties;
}
return undefined;
}
function matchDirectiveReturnObject(node) {
// only matches inside directives
// return { .. controller: function($scope, $timeout), ...}
// { .. controller: function($scope, $timeout), ...}
const properties = getObjectExpressionReturnProperties(node);
return limit("directive", node.type === "ReturnStatement" &&
node.argument && node.argument.type === "ObjectExpression" &&
matchProp("controller", node.argument.properties));
return limit("directive", properties &&
matchProp("controller", properties));
}

@@ -610,3 +629,3 @@

removeArray(target, fragments);
} else if (["add", "rebuild"].includes(mode) && isFunctionExpressionWithArgs(target)) {
} else if (["add", "rebuild"].includes(mode) && isFunctionOrArrowFunctionExpressionWithArgs(target)) {
insertArray(ctx, target, target, fragments, quot);

@@ -715,3 +734,3 @@ } else if (["add", "rebuild"].includes(mode) && isClassExpression(target) && (constructor = findClassConstructorWithArgs(target))) {

} else if (kind === "fun") {
assert(ptype === "FunctionDeclaration" || ptype === "FunctionExpression")
assert(ptype === "FunctionDeclaration" || isFunctionOrArrowFunctionExpression(ptype))
// FunctionDeclaration is the common case, i.e.

@@ -849,3 +868,7 @@ // function foo(a, b) {}

} else if (ctx.isFunctionExpressionWithArgs(node)) {
} else if (node.type === "ArrowFunctionExpression" && onode.type === "ExportDefaultDeclaration") {
// not implemented
// this is a default exported arrow function like:
// - export default (a, b) => {}
} else if (ctx.isFunctionOrArrowFunctionExpressionWithArgs(node)) {
// var x = 1, y = function(a,b) {}, z;

@@ -871,3 +894,3 @@

} else if (node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" &&
ctx.isFunctionExpressionWithArgs(node.expression.right)) {
ctx.isFunctionOrArrowFunctionExpressionWithArgs(node.expression.right)) {
// /*@ngInject*/ foo.bar[0] = function($scope) {}

@@ -1012,12 +1035,31 @@

function jumpOverIife(node) {
let outerfn;
if (!(node.type === "CallExpression" && (outerfn = node.callee).type === "FunctionExpression")) {
if (node.type !== "CallExpression") {
return node;
}
const outerbody = outerfn.body.body;
for (let i = 0; i < outerbody.length; i++) {
const statement = outerbody[i];
if (statement.type === "ReturnStatement") {
return statement.argument;
const outerfn = node.callee;
/**
* IIFE as in:
* - (() => 'value')()
*/
if (outerfn.type === "ArrowFunctionExpression" && outerfn.expression) {
return outerfn.body;
}
/**
* IIFE as in:
* - (() => { return 'value' })()
* - (function { return 'value' })()
*
* needs to loop over children, as the return could be anywhere inside the body, as in:
* - (function { console.log('something before'); return 'value'; console.log('something behind, but valid javascript'); }()
*/
if (isFunctionOrArrowFunctionExpression(outerfn.type)) {
const outerbody = outerfn.body.body;
for (let i = 0; i < outerbody.length; i++) {
const statement = outerbody[i];
if (statement.type === "ReturnStatement") {
return statement.argument;
}
}

@@ -1045,3 +1087,3 @@ }

// last should be a function expression
if (elements.length === 0 || last(elements).type !== "FunctionExpression") {
if (elements.length === 0 || !isFunctionOrArrowFunctionExpression(last(elements).type)) {
return false;

@@ -1070,5 +1112,8 @@ }

}
function isFunctionExpressionWithArgs(node) {
return node.type === "FunctionExpression" && node.params.length >= 1;
function isFunctionOrArrowFunctionExpression(type) {
return type === "FunctionExpression" || type === "ArrowFunctionExpression";
}
function isFunctionOrArrowFunctionExpressionWithArgs(node) {
return isFunctionOrArrowFunctionExpression(node.type) && node.params.length >= 1;
}
function isFunctionDeclarationWithArgs(node) {

@@ -1233,3 +1278,3 @@ // For `export default function() {...}`, `id` is null, which means

isClassDeclaration: isClassDeclaration,
isFunctionExpressionWithArgs: isFunctionExpressionWithArgs,
isFunctionOrArrowFunctionExpressionWithArgs: isFunctionOrArrowFunctionExpressionWithArgs,
isFunctionDeclarationWithArgs: isFunctionDeclarationWithArgs,

@@ -1236,0 +1281,0 @@ isAnnotatedArray: isAnnotatedArray,

@@ -17,3 +17,3 @@ // nginject.js

// Ignore method function, constructor is processed below
} else if (node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
} else if (node.type === "FunctionExpression" || (node.type === "ArrowFunctionExpression" && !node.expression) || node.type === "FunctionDeclaration") {
inspectFunction(node, ctx);

@@ -212,3 +212,3 @@ } else if (node.type === "MethodDefinition" && node.kind === 'constructor') {

const v = prop.value;
if (["FunctionExpression", "ArrayExpression"].includes(v.type)) {
if (["FunctionExpression", "ArrowFunctionExpression", "ArrayExpression"].includes(v.type)) {
res.push(v);

@@ -215,0 +215,0 @@ } else if (v.type === "ObjectExpression") {

@@ -174,3 +174,3 @@ // scopetools.js

function isNonFunctionBlock(node, parent) {
return node.type === "BlockStatement" && parent.type !== "FunctionDeclaration" && parent.type !== "FunctionExpression";
return node.type === "BlockStatement" && parent.type !== "FunctionDeclaration" && parent.type !== "FunctionExpression" && parent.type !== "ArrowFunctionExpression";
}

@@ -191,3 +191,3 @@

function isFunction(node) {
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
}

@@ -194,0 +194,0 @@

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