Skip to content

Commit 210df1d

Browse files
author
Andrew Schmadel
committed
make some of those tests pass
1 parent 8df4fc0 commit 210df1d

6 files changed

Lines changed: 13 additions & 916 deletions

File tree

babel-ng-annotate.js

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
11
import { match, isFunctionExpressionWithArgs, isFunctionDeclarationWithArgs,
22
isAnnotatedArray, addModuleContextDependentSuspect, addModuleContextIndependentSuspect,
3-
stringify, matchResolve, matchProp, last, allOptionals, judgeSuspects, matchDirectiveReturnObject,
3+
stringify, matchResolve, matchProp, last, judgeSuspects, matchDirectiveReturnObject,
44
matchProviderGet } from './ng-annotate-main.js'
55

66
import ngInject from './nginject';
7-
import stringmap from 'stringmap';
87
import is from 'simple-is';
98

109
export default function({ types: t }) {
1110

1211
var options = {};
1312

14-
if (options.list) {
15-
return {
16-
list: Object.keys(allOptionals).sort(),
17-
};
18-
}
19-
2013
const quot = options.single_quotes ? "'" : '"';
2114
const re = (options.regexp ? new RegExp(options.regexp) : /^[a-zA-Z0-9_\$\.\s]+$/);
2215

23-
const stats = {};
24-
25-
// [{type: "Block"|"Line", value: str, range: [from,to]}, ..]
26-
let comments = [];
27-
28-
stats.parser_parse_t1 = Date.now();
29-
30-
// // append a dummy-node to ast so that lut.findNodeFromPos(lastPos) returns something
31-
// ast.body.push({
32-
// type: "DebuggerStatement",
33-
// range: [ast.range[1], ast.range[1]],
34-
// loc: {
35-
// start: ast.loc.end,
36-
// end: ast.loc.end
37-
// }
38-
// });
39-
40-
// all source modifications are built up as operations in the
41-
// fragments array, later sent to alter in one shot
42-
const fragments = [];
43-
4416
// suspects is built up with suspect nodes by match.
4517
// A suspect node will get annotations added / removed if it
4618
// fulfills the arrayexpression or functionexpression look,
@@ -53,83 +25,25 @@ export default function({ types: t }) {
5325
// in blocked will be ignored by judgeSuspects
5426
const blocked = [];
5527

56-
// Position information for all nodes in the AST,
57-
// used for sourcemap generation
58-
const nodePositions = [];
59-
60-
// const lut = new Lut(ast, src);
61-
6228
// scopeTools.setupScopeAndReferences(ast);
6329

6430
const ctx = {
6531
mode: "add",
6632
quot: quot,
6733
re: re,
68-
comments: comments,
69-
fragments: fragments,
7034
suspects: suspects,
7135
blocked: blocked,
72-
// lut: lut,
7336
isFunctionExpressionWithArgs: isFunctionExpressionWithArgs,
7437
isFunctionDeclarationWithArgs: isFunctionDeclarationWithArgs,
7538
isAnnotatedArray: isAnnotatedArray,
7639
addModuleContextDependentSuspect: addModuleContextDependentSuspect,
7740
addModuleContextIndependentSuspect: addModuleContextIndependentSuspect,
7841
stringify: stringify,
79-
nodePositions: nodePositions,
8042
matchResolve: matchResolve,
8143
matchProp: matchProp,
8244
last: last
8345
};
8446

85-
// setup optionals
86-
const optionals = options.enable || [];
87-
for (let i = 0; i < optionals.length; i++) {
88-
const optional = String(optionals[i]);
89-
if (!allOptionals.hasOwnProperty(optional)) {
90-
return {
91-
errors: ["error: found no optional named " + optional],
92-
};
93-
}
94-
}
95-
const optionalsPlugins = optionals.map(function(optional) {
96-
return allOptionals[optional];
97-
});
98-
99-
const plugins = [].concat(optionalsPlugins, options.plugin || []);
100-
101-
function matchPlugins(node, isMethodCall) {
102-
for (let i = 0; i < plugins.length; i++) {
103-
const res = plugins[i].match(node, isMethodCall);
104-
if (res) {
105-
return res;
106-
}
107-
}
108-
return false;
109-
}
110-
const matchPluginsOrNull = (plugins.length === 0 ? null : matchPlugins);
111-
112-
ngInject.inspectComments(ctx);
113-
plugins.forEach(function(plugin) {
114-
plugin.init(ctx);
115-
});
116-
117-
// try {
118-
// judgeSuspects(ctx);
119-
// } catch(e) {
120-
// return {
121-
// errors: ["error: " + e],
122-
// };
123-
// }
124-
125-
// uniqifyFragments(ctx.fragments);
126-
127-
// const out = alter(src, fragments);
128-
// const result = {
129-
// src: out,
130-
// _stats: stats,
131-
// };
132-
//
13347
var addTargets = function(targets) {
13448
if (!targets) {
13549
return;
@@ -189,22 +103,22 @@ export default function({ types: t }) {
189103
ngInject.inspectCallExpression(path, ctx);
190104
},
191105
exit(path) {
192-
if(path.node.loc){
193-
ctx.nodePositions.push(path.node.loc.start);
194-
}
195-
let targets = match(path, ctx, matchPluginsOrNull);
106+
let targets = match(path, ctx);
196107
addTargets(targets);
197108
}
198109
},
199110
Program: {
200111
enter(path, file) {
112+
ctx.suspects = [];
113+
ctx.blocked = [];
114+
ctx.fragments = [];
115+
201116
ctx.srcForRange = function(node) {
202117
return file.file.code.slice(node.start, node.end);
203118
};
204119
},
205120
exit(path, file) {
206121
judgeSuspects(ctx);
207-
// console.log(path);
208122
}
209123
}
210124
}

generate-sourcemap.js

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)