forked from btford/ngmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (29 loc) · 817 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var esprima = require('esprima'),
escodegen = require('escodegen'),
dynamic = require('ngmin-dynamic'),
astral = require('astral')();
// register angular annotator in astral
require('astral-angular-annotate')(astral);
var annotate = exports.annotate = function (inputCode, options) {
if (options && options.dynamic) {
return dynamic(inputCode);
}
var ast = esprima.parse(inputCode, {
tolerant: true,
comment: true,
range: true,
tokens: true
});
// TODO: unstable API, see https://github.com/Constellation/escodegen/issues/10
ast = escodegen.attachComments(ast, ast.comments, ast.tokens);
astral.run(ast);
var generatedCode = escodegen.generate(ast, {
format: {
indent: {
style: ' '
}
},
comment: true
});
return generatedCode;
};