b59f1ee62de1011781952d025cd55b89efc3162e
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Prevent missing React when using JSX
3  * @author Glen Mailer
4  */
5 'use strict';
6
7 var variableUtil = require('../util/variable');
8
9 // -----------------------------------------------------------------------------
10 // Rule Definition
11 // -----------------------------------------------------------------------------
12
13 var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
14
15 module.exports = function(context) {
16
17   var id = 'React';
18   var NOT_DEFINED_MESSAGE = '\'{{name}}\' must be in scope when using JSX';
19
20   return {
21
22     JSXOpeningElement: function(node) {
23       var variables = variableUtil.variablesInScope(context);
24       if (variableUtil.findVariable(variables, id)) {
25         return;
26       }
27       context.report(node, NOT_DEFINED_MESSAGE, {
28         name: id
29       });
30     },
31
32     BlockComment: function(node) {
33       var matches = JSX_ANNOTATION_REGEX.exec(node.value);
34       if (!matches) {
35         return;
36       }
37       id = matches[1].split('.')[0];
38     }
39
40   };
41
42 };