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.7.0 to 1.8.1

src/utils.js

9

CHANGES.md

@@ -0,1 +1,9 @@

## 1.8.1 2019-01-19
* Remove a big and useless ctags file accidentally included in the 1.8.0
archive published to npm.
## 1.8.0 2019-01-19
* Require node>=6.0.0.
* Remove a lot of trivial dependencies.
## 1.7.0 2018-01-18

@@ -5,2 +13,3 @@ * Require node>=4.0.0.

`src/ng-annotate-main.js`.
* Add basic support for ES6 property shorthand and destructuring.
* Don't fail upon encountering dynamic `import()`.

@@ -7,0 +16,0 @@

14

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

@@ -13,17 +13,9 @@ "main": "src/ng-annotate-main.js",

"acorn-dynamic-import": "^3.0.0",
"alter": "^0.2.0",
"convert-source-map": "^1.1.2",
"optimist": "^0.6.1",
"simple-fmt": "^0.1.0",
"simple-is": "^0.2.0",
"source-map": "^0.5.3",
"stable": "^0.1.5",
"stringmap": "^0.2.2",
"stringset": "^0.2.1",
"tryor": "^0.1.2"
"source-map": "^0.5.3"
},
"devDependencies": {
"coffee-script": "^1.10.0",
"diff": "^2.2.1",
"find-line-column": "^0.5.2"
"diff": "^4.0.0"
},

@@ -30,0 +22,0 @@ "keywords": [

@@ -23,2 +23,8 @@ # Fork details

- 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`.
- Published to npm under the name `ng-annotate-patched`.

@@ -71,3 +77,3 @@

```bash
npm install -g ng-annotate
npm install -g ng-annotate-patched
```

@@ -113,6 +119,2 @@

## Dynamic Imports
If you use webpack or 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`.

@@ -119,0 +121,0 @@ ## Highly recommended: enable ng-strict-di

@@ -7,3 +7,3 @@ "use strict";

const SourceMapGenerator = require("source-map").SourceMapGenerator;
const stableSort = require("stable");
const stableSort = require("./utils").stableSort;

@@ -10,0 +10,0 @@ class SourceMapper {

@@ -9,3 +9,2 @@ // lut.js

const traverse = require("./traverse");
const is = require("simple-is");

@@ -53,3 +52,3 @@ module.exports = class Lut {

const lut = this.begins;
assert(is.finitenumber(pos) && pos >= 0);
assert(Number.isFinite(pos) && pos >= 0);

@@ -88,3 +87,3 @@ let left = 0;

const lut = this.ends;
assert(is.finitenumber(pos) && pos >= 0);
assert(Number.isFinite(pos) && pos >= 0);

@@ -91,0 +90,0 @@ let left = 0;

@@ -6,5 +6,2 @@ // ng-annotate-main.js

"use strict";
const fmt = require("simple-fmt");
const is = require("simple-is");
const alter = require("alter");
const traverse = require("./traverse");

@@ -17,3 +14,3 @@ let EOL = require("os").EOL;

const scopeTools = require("./scopetools");
const stringmap = require("stringmap");
const stableSort = require("./utils").stableSort;
const optionalAngularDashboardFramework = require("./optionals/angular-dashboard-framework");

@@ -61,3 +58,3 @@ const require_acorn_t0 = Date.now();

if (obj.type === "Identifier" &&
((is.someof(obj.name, ["$modal", "$uibModal"]) && method.name === "open") || (is.someof(obj.name, ["$mdDialog", "$mdToast", "$mdBottomSheet"]) && method.name === "show")) &&
((["$modal", "$uibModal"].includes(obj.name) && method.name === "open") || (["$mdDialog", "$mdToast", "$mdBottomSheet"].includes(obj.name) && method.name === "show")) &&
args.length === 1 && args[0].type === "ObjectExpression") {

@@ -96,3 +93,3 @@ const props = args[0].properties;

memberExpr.property.name === "$get" &&
((self = memberExpr.object).type === "ThisExpression" || (self.type === "Identifier" && is.someof(self.name, ["self", "that"]))) &&
((self = memberExpr.object).type === "ThisExpression" || (self.type === "Identifier" && ["self", "that"].includes(self.name))) &&
node.right) ||

@@ -179,3 +176,3 @@ (node.type === "ObjectExpression" && matchProp("$get", node.properties)));

// everything below is for $stateProvider and stateHelperProvider alone
if (!(obj.$chained === chainedStateProvider || (obj.type === "Identifier" && is.someof(obj.name, ["$stateProvider", "stateHelperProvider"])))) {
if (!(obj.$chained === chainedStateProvider || (obj.type === "Identifier" && ["$stateProvider", "stateHelperProvider"].includes(obj.name)))) {
return false;

@@ -185,3 +182,3 @@ }

if (is.noneof(method.name, ["state", "setNestedState"])) {
if (!["state", "setNestedState"].includes(method.name)) {
return false;

@@ -288,3 +285,3 @@ }

obj.type === "MemberExpression" && !obj.computed &&
obj.object.name === "$httpProvider" && is.someof(obj.property.name, ["interceptors", "responseInterceptors"]) &&
obj.object.name === "$httpProvider" && ["interceptors", "responseInterceptors"].includes(obj.property.name) &&
node.arguments.length >= 1 && node.arguments);

@@ -324,3 +321,3 @@ }

const target = obj.type === "Identifier" && obj.name === "$provide" &&
is.someof(method.name, ["decorator", "service", "factory", "provider"]) &&
["decorator", "service", "factory", "provider"].includes(method.name) &&
args.length === 2 && args[1];

@@ -362,3 +359,3 @@

const matchAngularModule = (obj.$chained === chainedRegular || isReDef(obj, ctx) || isLongDef(obj)) &&
is.someof(method.name, ["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator", "component"]);
["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator", "component"].includes(method.name);
if (!matchAngularModule) {

@@ -369,3 +366,3 @@ return false;

if (is.someof(method.name, ["value", "constant", "bootstrap"])) {
if (["value", "constant", "bootstrap"].includes(method.name)) {
return false; // affects matchAngularModule because of chaining

@@ -375,5 +372,5 @@ }

const args = node.arguments;
let target = (is.someof(method.name, ["config", "run"]) ?
let target = (["config", "run"].includes(method.name) ?
args.length === 1 && args[0] :
args.length === 2 && args[0].type === "Literal" && is.string(args[0].value) && args[1]);
args.length === 2 && args[0].type === "Literal" && typeof args[0].value === "string" && args[1]);

@@ -420,17 +417,2 @@ if (method.name === "component") {

function objectAssign(target, varArgs) {
const to = Object(target);
for (let index = 1; index < arguments.length; index++) {
const nextSource = arguments[index];
if (nextSource != null) {
for (let nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
}
function matchProp(name, props) {

@@ -626,3 +608,3 @@ for (let i = 0; i < props.length; i++) {

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

@@ -724,3 +706,3 @@ } else if (isGenericProviderName(target)) {

if (is.someof(kind, ["const", "let", "var"])) {
if (["const", "let", "var"].includes(kind)) {
assert(ptype === "VariableDeclarator");

@@ -784,3 +766,3 @@ // {type: "VariableDeclarator", id: {type: "Identifier", name: "foo"}, init: ..}

if (is.someof(node.type, ["ExportDefaultDeclaration", "ExportNamedDeclaration"])) {
if (["ExportDefaultDeclaration", "ExportNamedDeclaration"].includes(node.type)) {
onode = node;

@@ -818,3 +800,3 @@ node = node.declaration;

if (onode.$parent && is.someof(onode.$parent.type, ["ExportDefaultDeclaration", "ExportNamedDeclaration"])) {
if (onode.$parent && ["ExportDefaultDeclaration", "ExportNamedDeclaration"].includes(onode.$parent.type)) {
// export var x = function($scope) { "ngInject"; }

@@ -825,3 +807,3 @@ onode = onode.$parent;

// suspect must be inside of a block or at the top-level (i.e. inside of node.$parent.body[])
if (!node || !onode.$parent || is.noneof(onode.$parent.type, ["Program", "BlockStatement"])) {
if (!node || !onode.$parent || !["Program", "BlockStatement"].includes(onode.$parent.type)) {
return;

@@ -904,5 +886,5 @@ }

if (existingExpressionStatementWithArray) {
throw fmt("conflicting inject arrays at line {0} and {1}",
posToLine(existingExpressionStatementWithArray.range[0], ctx.src),
posToLine(bnode.range[0], ctx.src));
const first = posToLine(existingExpressionStatementWithArray.range[0], ctx.src);
const second = posToLine(bnode.range[0], ctx.src);
throw `conflicting inject arrays at line ${first} and ${second}`;
}

@@ -963,3 +945,3 @@ existingExpressionStatementWithArray = bnode;

if (ctx.mode === "rebuild" && existingExpressionStatementWithArray) {
const strNoWhitespace = fmt("{2}.$inject = {3};", null, null, name, ctx.stringify(ctx, params, ctx.quot));
const strNoWhitespace = `${name}.$inject = ${ctx.stringify(ctx, params, ctx.quot)};`;
ctx.fragments.push({

@@ -985,4 +967,4 @@ start: existingExpressionStatementWithArray.range[0],

});
} else if (is.someof(ctx.mode, ["add", "rebuild"]) && !existingExpressionStatementWithArray) {
const str = fmt("{0}{1}{2}.$inject = {3};", EOL, indent, name, ctx.stringify(ctx, params, ctx.quot));
} else if (["add", "rebuild"].includes(ctx.mode) && !existingExpressionStatementWithArray) {
const str = `${EOL}${indent}${name}.$inject = ${ctx.stringify(ctx, params, ctx.quot)};`;
ctx.fragments.push({

@@ -1041,3 +1023,3 @@ start: posAfterFunctionDeclaration.pos,

const n = elements[i];
if (n.type !== "Literal" || !is.string(n.value)) {
if (n.type !== "Literal" || typeof n.value !== "string") {
return false;

@@ -1058,3 +1040,3 @@ }

function isGenericProviderName(node) {
return node.type === "Literal" && is.string(node.value);
return node.type === "Literal" && typeof node.value === "string";
}

@@ -1082,2 +1064,21 @@

// Alters a string by replacing multiple range fragments in one fast pass.
// fragments is a list of {start: index, end: index, str: string to replace with}.
// The fragments do not need to be sorted but must not overlap.
function alter(str, fragments) {
// stableSort isn't in-place so no need to copy array first
const sortedFragments = stableSort(fragments, (a, b) => a.start - b.start);
const outs = [];
let pos = 0;
for (const frag of sortedFragments) {
assert(pos <= frag.start);
assert(frag.start <= frag.end);
outs.push(str.slice(pos, frag.start));
outs.push(frag.str);
pos = frag.end;
}
outs.push(str.slice(pos));
return outs.join("");
}
module.exports = function ngAnnotate(src, options) {

@@ -1100,3 +1101,3 @@ if (options.list) {

const re = (options.regexp ? new RegExp(options.regexp) : /^[a-zA-Z0-9_\$\.\s]+$/);
const rename = new stringmap();
const rename = new Map();
if (options.rename) {

@@ -1126,3 +1127,3 @@ options.rename.forEach(function(value) {

// acorn
ast = parser(src, objectAssign({
ast = parser(src, Object.assign({
ecmaVersion: 8,

@@ -1244,3 +1245,3 @@ allowImportExportEverywhere: true,

}
if (!is.array(targets)) {
if (!Array.isArray(targets)) {
targets = [targets];

@@ -1247,0 +1248,0 @@ }

@@ -9,4 +9,2 @@ // ng-annotate.js

const fs = require("fs");
const fmt = require("simple-fmt");
const tryor = require("tryor");
const ngAnnotate = require("./ng-annotate-main");

@@ -115,3 +113,3 @@ const version = require("../package.json").version;

if (!fs.existsSync(filename)) {
cb(new Error(fmt('error: file not found {0}', filename)));
cb(new Error(`error: file not found ${filename}`));
}

@@ -129,5 +127,8 @@

const config = tryor(function() {
return JSON.parse(String(fs.readFileSync("ng-annotate-config.json")));
}, {});
let config;
try {
config = JSON.parse(String(fs.readFileSync("ng-annotate-config.json")));
} catch (e) {
config = {};
}

@@ -160,5 +161,10 @@ if (filename !== "-") {

config.plugin = config.plugin.map(function(path) {
const absPath = tryor(fs.realpathSync.bind(fs, path), null);
let absPath;
try {
absPath = fs.realpathSync.bind(fs, path);
} catch (e) {
absPath = null;
}
if (!absPath) {
exit(fmt('error: plugin file not found {0}', path));
exit(`error: plugin file not found ${path}`);
}

@@ -170,3 +176,3 @@ // the require below may throw an exception on parse-error

// node will already print file:line and offending line to stderr
exit(fmt("error: couldn't require(\"{0}\")", absPath));
exit(`error: couldn't require("${absPath}")`);
}

@@ -212,4 +218,4 @@ });

process.stderr.write(fmt("[{0} ms] parser: {1}, nga init: {2}, nga run: {3}\n", all, all_parser, nga_init, nga_run));
process.stderr.write(fmt("[%] parser: {0}, nga init: {1}, nga run: {2}\n", pct(all_parser), pct(nga_init), pct(nga_run)));
process.stderr.write(`[${all} ms] parser: ${all_parser}, nga init: ${nga_init}, nga run: ${nga_run}\n`);
process.stderr.write(`[%] parser: ${pct(all_parser)}, nga init: ${pct(nga_init)}, nga run: ${pct(nga_run)}\n`);
}

@@ -216,0 +222,0 @@

@@ -7,4 +7,2 @@ // nginject.js

const is = require("simple-is");
module.exports = {

@@ -130,3 +128,3 @@ inspectComments: inspectComments,

return node.elements.length >= 1 && node.elements.every(function(n) {
return n.type === "Literal" && is.string(n.value);
return n.type === "Literal" && typeof n.value === "string";
});

@@ -200,3 +198,3 @@ }

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

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

@@ -8,12 +8,8 @@ // scope.js

const assert = require("assert");
const stringmap = require("stringmap");
const stringset = require("stringset");
const is = require("simple-is");
const fmt = require("simple-fmt");
module.exports = class Scope {
constructor(args) {
assert(is.someof(args.kind, ["hoist", "block", "catch-block"]));
assert(is.object(args.node));
assert(args.parent === null || is.object(args.parent));
assert(["hoist", "block", "catch-block"].includes(args.kind));
assert(args.node !== null && typeof args.node === "object");
assert(args.parent === null || typeof args.parent === "object");

@@ -45,3 +41,3 @@ // kind === "hoist": function scopes, program scope, injected globals

// }
this.decls = stringmap();
this.decls = new Map();

@@ -52,3 +48,3 @@ // names of all variables declared outside this hoist scope but

// (because we currently generate lots of empty block scopes)
this.propagates = (this.kind === "hoist" ? stringset() : null);
this.propagates = (this.kind === "hoist" ? new Set() : null);

@@ -65,6 +61,6 @@ // scopes register themselves with their parents for easier traversal

const names = this.decls.keys().map(name => {
return fmt("{0} [{1}]", name, scope.decls.get(name).kind);
return `${name} [${scope.decls.get(name).kind}]`;
}).join(", ");
const propagates = this.propagates ? this.propagates.items().join(", ") : "";
console.log(fmt("{0}{1}: {2}. propagates: {3}", fmt.repeat(" ", indent), this.node.type, names, propagates));
console.log(`${fmt.repeat(" ", indent)}${this.node.type}: ${names}. propagates: ${propagates}`);
this.children.forEach(c => {

@@ -76,6 +72,6 @@ c.print(indent + 2);

add(name, kind, node, referableFromPos) {
assert(is.someof(kind, ["fun", "param", "var", "caught", "const", "let"]));
assert(["fun", "param", "var", "caught", "const", "let"].includes(kind));
// function isConstLet(kind) {
// return is.someof(kind, ["const", "let"]);
// return ["const", "let"].includes(kind);
// }

@@ -87,3 +83,3 @@

// const, let and caught variables go directly in the scope (which may be hoist, block or catch-block)
if (is.someof(kind, ["fun", "param", "var"])) {
if (["fun", "param", "var"].includes(kind)) {
while (scope.kind !== "hoist") {

@@ -106,3 +102,3 @@ // if (scope.decls.has(name) && isConstLet(scope.decls.get(name).kind)) { // could be caught

if (referableFromPos) {
assert(is.someof(kind, ["var", "const", "let"]));
assert(["var", "const", "let"].includes(kind));
declaration.from = referableFromPos;

@@ -114,3 +110,3 @@ }

getKind(name) {
assert(is.string(name));
assert(typeof name === "string");
const decl = this.decls.get(name);

@@ -121,3 +117,3 @@ return decl ? decl.kind : null;

getNode(name) {
assert(is.string(name));
assert(typeof name === "string");
const decl = this.decls.get(name);

@@ -128,3 +124,3 @@ return decl ? decl.node : null;

getFromPos(name) {
assert(is.string(name));
assert(typeof name === "string");
const decl = this.decls.get(name);

@@ -131,0 +127,0 @@ return decl ? decl.from : null;

@@ -10,3 +10,2 @@ // scopetools.js

const Scope = require("./scope");
const is = require("simple-is");

@@ -205,4 +204,4 @@ module.exports = {

!(isFunction(parent) && parent.id === node) && // function $(..
!(isFunction(parent) && is.someof(node, parent.params)) && // function f($)..
!(isFunction(parent) && parent.params.includes(node)) && // function f($)..
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