mirror of
https://github.com/bluetech/ng-annotate-patched.git
synced 2026-07-02 00:17:42 +08:00
add new option for using single quotes arond dependency injection annotations
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.idea/
|
||||
node_modules/
|
||||
+6
-5
@@ -84,16 +84,16 @@ function matchProp(name, props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function stringify(arr) {
|
||||
function stringify(arr, quot) {
|
||||
return "[" + arr.map(function(arg) {
|
||||
return '"' + arg.name + '"';
|
||||
return quot + arg.name + quot;
|
||||
}).join(", ") + "]";
|
||||
}
|
||||
|
||||
function insertArray(functionExpression, fragments) {
|
||||
function insertArray(functionExpression, fragments, quot) {
|
||||
const range = functionExpression.range;
|
||||
|
||||
const args = stringify(functionExpression.params);
|
||||
const args = stringify(functionExpression.params, quot);
|
||||
fragments.push({
|
||||
start: range[0],
|
||||
end: range[0],
|
||||
@@ -151,6 +151,7 @@ module.exports = function ngAnnotate(src, options) {
|
||||
return {src: src};
|
||||
}
|
||||
|
||||
const quot = options.single ? '\'' : '"';
|
||||
const re = (options.regexp && new RegExp(options.regexp));
|
||||
const ast = esprima(src, {
|
||||
range: true,
|
||||
@@ -169,7 +170,7 @@ module.exports = function ngAnnotate(src, options) {
|
||||
} else if (mode === "remove" && isAnnotatedArray(target)) {
|
||||
removeArray(target, fragments);
|
||||
} else if (is.someof(mode, ["add", "rebuild"]) && isFunctionWithArgs(target)) {
|
||||
insertArray(target, fragments);
|
||||
insertArray(target, fragments, quot);
|
||||
}
|
||||
}});
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ const optimist = require("optimist")
|
||||
.options("regexp", {
|
||||
describe: "detect short form myMod.controller(...) iff myMod matches regexp",
|
||||
})
|
||||
.options("single", {
|
||||
describe: "use single quotes for dependency injection annotations"})
|
||||
const argv = optimist.argv;
|
||||
|
||||
function exit(msg) {
|
||||
|
||||
@@ -21,6 +21,9 @@ const original = slurp("tests/original.js");
|
||||
const annotated = ngAnnotate(original, {add: true}).src;
|
||||
test(slurp("tests/with_annotations.js"), annotated, "with_annotations.js");
|
||||
|
||||
console.log("testing adding annotations using single quotes");
|
||||
const annotated2 = ngAnnotate(original, {add: true, single: true}).src;
|
||||
test(slurp("tests/with_annotations_single.js"), annotated2, "with_annotations_single.js");
|
||||
console.log("testing removing annotations");
|
||||
const deAnnotated = ngAnnotate(annotated, {remove: true}).src;
|
||||
test(original, deAnnotated, "original.js");
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
|
||||
// long form
|
||||
angular.module("MyMod").controller("MyCtrl", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
|
||||
// w/ dependencies
|
||||
angular.module("MyMod", ["OtherMod"]).controller("MyCtrl", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
|
||||
// simple
|
||||
myMod.controller("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
myMod.service("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
myMod.factory("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
myMod.directive("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
myMod.filter("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
myMod.animation("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
|
||||
// no dependencies => no need to wrap the function in an array
|
||||
myMod.controller("foo", function() {
|
||||
});
|
||||
myMod.service("foo", function() {
|
||||
});
|
||||
myMod.factory("foo", function() {
|
||||
});
|
||||
myMod.directive("foo", function() {
|
||||
});
|
||||
myMod.filter("foo", function() {
|
||||
});
|
||||
myMod.animation("foo", function() {
|
||||
});
|
||||
|
||||
// run, config don't take names
|
||||
myMod.run(['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
angular.module("MyMod").run(['$scope', function($scope) {
|
||||
}]);
|
||||
myMod.config(['$scope', '$timeout', function($scope, $timeout) {
|
||||
}]);
|
||||
angular.module("MyMod").config(function() {
|
||||
});
|
||||
|
||||
// directive return object
|
||||
myMod.directive("foo", ['$scope', function($scope) {
|
||||
return {
|
||||
controller: ['$scope', '$timeout', function($scope, $timeout) {
|
||||
bar;
|
||||
}]
|
||||
}
|
||||
}]);
|
||||
myMod.directive("foo", ['$scope', function($scope) {
|
||||
return {
|
||||
controller: function() {
|
||||
bar;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
// provider, provider $get
|
||||
myMod.provider("foo", ['$scope', function($scope) {
|
||||
this.$get = ['$scope', '$timeout', function($scope, $timeout) {
|
||||
bar;
|
||||
}];
|
||||
}]);
|
||||
myMod.provider("foo", function() {
|
||||
this.$get = function() {
|
||||
bar;
|
||||
};
|
||||
});
|
||||
myMod.provider("foo", function() {
|
||||
return {
|
||||
$get: ['$scope', '$timeout', function($scope, $timeout) {
|
||||
bar;
|
||||
}]};
|
||||
});
|
||||
myMod.provider("foo", function() {
|
||||
return {
|
||||
$get: function() {
|
||||
bar;
|
||||
}};
|
||||
});
|
||||
myMod.provider("foo", {
|
||||
$get: ['$scope', '$timeout', function($scope, $timeout) {
|
||||
bar;
|
||||
}]
|
||||
});
|
||||
myMod.provider("foo", {
|
||||
$get: function() {
|
||||
bar;
|
||||
}
|
||||
});
|
||||
|
||||
// chaining
|
||||
myMod.directive("foo", ['$a', '$b', function($a, $b) {
|
||||
a;
|
||||
}]).factory("foo", function() {
|
||||
b;
|
||||
}).config(['$c', function($c) {
|
||||
c;
|
||||
}]).filter("foo", ['$d', '$e', function($d, $e) {
|
||||
d;
|
||||
}]).animation("foo", ['$f', '$g', function($f, $g) {
|
||||
e;
|
||||
}]);
|
||||
|
||||
angular.module("MyMod").directive("foo", ['$a', '$b', function($a, $b) {
|
||||
a;
|
||||
}]).provider("foo", function() {
|
||||
return {
|
||||
$get: ['$scope', '$timeout', function($scope, $timeout) {
|
||||
bar;
|
||||
}]};
|
||||
}).value("foo", "bar")
|
||||
.constant("foo", "bar")
|
||||
.factory("foo", function() {
|
||||
b;
|
||||
}).config(['$c', function($c) {
|
||||
c;
|
||||
}]).filter("foo", ['$d', '$e', function($d, $e) {
|
||||
d;
|
||||
}]).animation("foo", ['$f', '$g', function($f, $g) {
|
||||
e;
|
||||
}]);
|
||||
|
||||
// $provide
|
||||
angular.module("MyMod").directive("foo", ['$a', '$b', function($a, $b) {
|
||||
$provide.decorator("foo", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
a;
|
||||
}]);
|
||||
$provide.factory("bar", ['$timeout', '$scope', function($timeout, $scope) {
|
||||
b;
|
||||
}]);
|
||||
$provide.animation("baz", ['$scope', '$timeout', function($scope, $timeout) {
|
||||
c;
|
||||
}]);
|
||||
}]);
|
||||
Reference in New Issue
Block a user