Completed
Pull Request — master (#11)
by Anton
02:01
created

public/js/vendor/jsx.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 52
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 4
dl 0
loc 52
rs 10
wmc 9
mnd 2
bc 10
fnc 5
bpm 2
cpm 1.8
noi 0
1
/**
2
 * @license The MIT License (MIT)
3
 *
4
 * Copyright (c) 2014 Felipe O. Carvalho
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
define(['JSXTransformer', 'text'], function (JSXTransformer, text) {
25
26
  'use strict';
27
28
  var buildMap = {};
29
30
  var jsx = {
31
    version: '0.6.2',
32
33
    load: function (name, req, onLoadNative, config) {
34
      var jsxOptions = config.jsx || {};
35
      var fileExtension = jsxOptions.fileExtension || '.js';
36
37
      var transformOptions = {
38
        harmony: !!jsxOptions.harmony,
39
        stripTypes: !!jsxOptions.stripTypes
40
      };
41
42
      var onLoad = function(content) {
43
        try {
44
          content = JSXTransformer.transform(content, transformOptions).code;
45
        } catch (err) {
46
          onLoadNative.error(err);
47
        }
48
49
        if (config.isBuild) {
50
          buildMap[name] = content;
51
        } else if (typeof location !== 'undefined') { // Do not create sourcemap when loaded in Node
52
          content += '\n//# sourceURL=' + location.protocol + '//' + location.hostname +
53
            config.baseUrl + name + fileExtension;
54
        }
55
56
        onLoadNative.fromText(content);
57
      };
58
59
      onLoad.error = function(err) {
60
        onLoadNative.error(err);
61
      };
62
63
      text.load(name + fileExtension, req, onLoad, config);
64
    },
65
66
    write: function (pluginName, moduleName, write) {
67
      if (buildMap.hasOwnProperty(moduleName)) {
68
        var content = buildMap[moduleName];
69
        write.asModule(pluginName + '!' + moduleName, content);
70
      }
71
    }
72
  };
73
74
  return jsx;
75
});
76