|
Lines 1204-1209
Link Here
|
| 1204 |
}; |
1204 |
}; |
| 1205 |
}, |
1205 |
}, |
| 1206 |
/** @callback */ |
1206 |
/** @callback */ |
|
|
1207 |
'no-undef-expression': function(context){ |
| 1208 |
return { |
| 1209 |
'MemberExpression': function(node){ |
| 1210 |
try { |
| 1211 |
if (node.property && node.object && node.object.type !== 'ThisExpression'){ |
| 1212 |
if (node.parent && node.parent.type === 'CallExpression' && node.parent.callee && node.parent.callee === node){ |
| 1213 |
var tern = context.getTern(); |
| 1214 |
var query = tern.query; |
| 1215 |
query.end = node.property.start; |
| 1216 |
var foundType = null; |
| 1217 |
try { |
| 1218 |
var expr = tern.findExpr(tern.file, query); |
| 1219 |
var type = tern.findExprType(tern.server, query, tern.file, expr); |
| 1220 |
if (type && type.origin){ |
| 1221 |
foundType = type; |
| 1222 |
} |
| 1223 |
} catch(e) { |
| 1224 |
//ignore |
| 1225 |
} |
| 1226 |
if (!foundType){ |
| 1227 |
// If the object cannot be found, there is no way the property could be known |
| 1228 |
query.end = node.object.end; |
| 1229 |
try { |
| 1230 |
expr = tern.findExpr(tern.file, query); |
| 1231 |
type = tern.findExprType(tern.server, query, tern.file, expr); |
| 1232 |
// if (!type || !type.origin || !type.types || type.types.length === 0){ |
| 1233 |
// foundType = true; // TODO type might be null so can't save it |
| 1234 |
// } else { |
| 1235 |
if (type && type.types){ |
| 1236 |
// If the type has no known properties assume Tern doens't know enough about it to find the declaration |
| 1237 |
foundType = true; |
| 1238 |
for (var i=0; i<type.types.length; i++) { |
| 1239 |
var currentProps = type.types[i].props; |
| 1240 |
if (currentProps && Object.keys(currentProps).length > 0){ |
| 1241 |
foundType = false; |
| 1242 |
break; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
} |
| 1246 |
} catch (e) { |
| 1247 |
//ignore |
| 1248 |
} |
| 1249 |
if (!foundType){ |
| 1250 |
context.report(node.property, ProblemMessages['no-undef-defined'], {0:node.property.name, nls: 'no-undef-defined'}); //$NON-NLS-1$ |
| 1251 |
} |
| 1252 |
|
| 1253 |
} |
| 1254 |
} |
| 1255 |
} |
| 1256 |
} catch (ex) { |
| 1257 |
Logger.log(ex); |
| 1258 |
} |
| 1259 |
|
| 1260 |
} |
| 1261 |
}; |
| 1262 |
}, |
| 1207 |
'no-undef-init': function(context) { |
1263 |
'no-undef-init': function(context) { |
| 1208 |
return { |
1264 |
return { |
| 1209 |
'VariableDeclarator': function(node) { |
1265 |
'VariableDeclarator': function(node) { |