forked from SitePen/dojo-amd-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessScript.js
44 lines (40 loc) · 897 Bytes
/
processScript.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
38
39
40
41
42
43
44
define([
"./Module",
"./util",
"./handlers",
"esprima/esprima"
], function (Module, util, handlers, esprima) {
return function (code, path, config) {
// summary:
// Processes a JavaScript file.
var operations = [],
tree = esprima.parse(code, {
range: true,
loc: true
}),
module = new Module({ code: code, path: path });
util.traverse(tree, function (object, parent) {
try {
var operation = handlers.match(object, parent, module);
if (operation) {
if (operation.pre) {
operation.pre(module, config);
operations.push(operation.post);
}
else {
operations.push(operation);
}
}
}
catch (e) {
if (e.message !== "No match found") {
throw e;
}
}
});
for (var i = operations.length - 1; i >= 0; --i) {
operations[i] && operations[i](module, config);
}
return module.toString();
};
});