Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #20 from danwrong/translations

Translations & Esprima
  • Loading branch information...
commit 45043535372e0facdbe432bfd716e293a3430685 2 parents ddf032f + faff313
Kenneth Kufluk authored June 18, 2012
49  lib/loadbuilder/analyzer.js
... ...
@@ -1,21 +1,26 @@
1  
-var parser = require('uglify-js').parser;
  1
+var parser = require('esprima'),
  2
+    file   = require('./file');
2 3
 
3 4
 function match(fragment, tree) {
4 5
   var matches = [];
  6
+  if (fragment && tree && Object.keys(fragment).every(function(fragmentKey, i) {
  7
+    var item = fragment[fragmentKey],
  8
+        subMatches;
5 9
 
6  
-  if ((fragment.length <= tree.length) && fragment.every(function(item, i) {
7  
-    var subMatches;
  10
+    if ((typeof tree[fragmentKey] == 'undefined') || (tree[fragmentKey] === null)) {
  11
+      return false;
  12
+    }
8 13
 
9 14
     if (item === null) {
10  
-      matches.push(tree[i]);
  15
+      matches.push(tree[fragmentKey]);
11 16
       return true;
12 17
     }
13 18
 
14  
-    if (item === tree[i]) {
  19
+    if (item === tree[fragmentKey]) {
15 20
       return true;
16 21
     }
17 22
 
18  
-    if (Array.isArray(tree[i]) && Array.isArray(item) && (subMatches = match(item, tree[i]))) {
  23
+    if (typeof tree[fragmentKey] === 'object' && typeof item === 'object' && (subMatches = match(item, tree[fragmentKey]))) {
19 24
       matches = matches.concat(subMatches);
20 25
       return true;
21 26
     }
@@ -30,18 +35,17 @@ function match(fragment, tree) {
30 35
 
31 36
 function walk(matcher, tree, parent, index) {
32 37
   var matches = [], m;
33  
-
34  
-  if (Array.isArray(tree)) {
35  
-    if (m = match(matcher, tree)) {
36  
-      matches.push({
37  
-        parent: parent || null,
38  
-        index: index || 0,
39  
-        values: m
40  
-      });
41  
-    }
42  
-
43  
-    tree.forEach(function(node, i) {
44  
-      matches = matches.concat(walk(matcher, node, tree, i));
  38
+  if (m = match(matcher, tree)) {
  39
+    matches.push({
  40
+      parent: parent || null,
  41
+      index: index || 0,
  42
+      values: m
  43
+    });
  44
+  }
  45
+  if (typeof tree == 'object') {
  46
+    Object.keys(tree).forEach(function(node, i) {
  47
+      if (tree[node]===null) return;
  48
+      matches = matches.concat(walk(matcher, tree[node], tree, i));
45 49
     });
46 50
   }
47 51
   return matches;
@@ -49,13 +53,10 @@ function walk(matcher, tree, parent, index) {
49 53
 
50 54
 function analyze(matcher, source) {
51 55
   // treeish can be source string, file object (from asset.js) or ast
52  
-  if (source.mtime && !source.ast) {
53  
-    source.ast = parser.parse(source.source);
54  
-  }
55 56
   var tree;
56  
-  if (source.ast) {
57  
-    tree = source.ast;
58  
-  } else if (Array.isArray(source)) {
  57
+  if (file.isFile(source)) {
  58
+    tree = source.ast();
  59
+  } else if (typeof source == 'object') {
59 60
     tree = source;
60 61
   } else {
61 62
     tree = parser.parse(source);
61  lib/loadbuilder/asset.js
... ...
@@ -1,15 +1,17 @@
1 1
 var util     = require('./util'),
2 2
     analyzer = require('./analyzer'),
3  
-    fs       = require('fs'),
4 3
     path     = require('path'),
5 4
     jshint   = require('jshint').JSHINT,
6  
-    uglify   = require("uglify-js");
  5
+    file     = require('./file');
7 6
 
8  
-var USING      = [ 'call', [ 'name', 'using' ], null ];
9  
-var ARRAY_ARG = [ 'array', null ];
10  
-var STRING_ARG = [ 'string', null ];
11  
-var PROVIDE    = [ 'call', [ 'name', 'provide' ], null ];
12  
-var REQUIRE    = [ 'call', [ 'name', 'require' ], [ [ 'string', null] ] ];
  7
+var ARRAY_ARG = {
  8
+  type: "ArrayExpression",
  9
+  elements: null
  10
+};
  11
+var STRING_ARG = {
  12
+  type: "Literal",
  13
+  value: null
  14
+};
13 15
 
14 16
 var dependencyCache = {};
15 17
 var dependencyCacheLastUpdate = {};
@@ -20,10 +22,9 @@ function Script(id) {
20 22
 
21 23
 util.extend(Script.prototype, {
22 24
   dependencies: function() {
23  
-
24 25
     var usings, dependencies = [];
25 26
 
26  
-    usings = analyzer.analyze(USING, this.fromFile());
  27
+    usings = this.fromFile().usings();
27 28
 
28 29
     usings.forEach(function(call) {
29 30
       var args = call.values[0];
@@ -48,7 +49,6 @@ util.extend(Script.prototype, {
48 49
         }
49 50
       }, this);
50 51
     }, this);
51  
-
52 52
     return dependencies;
53 53
   },
54 54
   lint: function(options) {
@@ -60,20 +60,20 @@ util.extend(Script.prototype, {
60 60
       process.exit(1);
61 61
     }
62 62
   },
63  
-  toSource: function() {
64  
-    return this.deferWrapper(this.fromFile().source);
  63
+  ast: function() {
  64
+    return this.fromFile().ast();
65 65
   },
66  
-  preProcess: function(data) {
67  
-    return this.builder.preProcessor ? this.builder.preProcessor(data) : data;
  66
+  addTranslationMarkers: function(fnName) {
  67
+    return this.fromFile().addTranslationMarkers(fnName);
  68
+  },
  69
+  toSource: function() {
  70
+    return this.deferWrapper(this.fromFile().generate());
68 71
   },
69 72
   fromFile: function() {
70  
-    var fileInfo = fs.statSync(this.fullPath());
71  
-    if (!this.file || this.file.mtime != fileInfo.mtime.getTime()) {
72  
-      this.file = {
73  
-        mtime: fileInfo.mtime.getTime(),
74  
-        source: this.preProcess(fs.readFileSync(this.fullPath(), 'utf8'))
75  
-      };
  73
+    if (!this.file) {
  74
+      this.file = file(this.fullPath(), this.builder.preProcessor);
76 75
     }
  76
+    this.file.load();
77 77
     return this.file;
78 78
   },
79 79
   fullPath: function() {
@@ -116,7 +116,7 @@ util.extend(Module.prototype, {
116 116
     }
117 117
   },
118 118
   isCJS: function() {
119  
-    return !analyzer.analyze(PROVIDE, this.fromFile()).length;
  119
+    return !this.fromFile().provides().length;
120 120
   },
121 121
   amdWrappedSource: function() {
122 122
     var deps = ['module', 'require', 'exports'].concat(this.dependencies().map(function(d) { return d.id; })),
@@ -124,7 +124,7 @@ util.extend(Module.prototype, {
124 124
                    JSON.stringify(deps) + ",function(module, require, exports) {\n",
125 125
         postamble = "\n});"
126 126
 
127  
-    return preamble + this.fromFile().source + postamble;
  127
+    return preamble + this.fromFile().generate() + postamble;
128 128
   },
129 129
 
130 130
   dependencies: function() {
@@ -135,16 +135,16 @@ util.extend(Module.prototype, {
135 135
     }
136 136
   },
137 137
   dependenciesFromRequire: function() {
138  
-    var requires = analyzer.analyze(REQUIRE, this.fromFile());
  138
+    var requires = this.fromFile().requires();
139 139
 
140 140
     return requires.map(function(r) {
141  
-      var asset = this.builder.matchAsset(r.values[0], false);
  141
+      var asset = this.builder.matchAsset(r.values[0][0].value, false);
142 142
       return (asset.length==0) ? null : asset;
143 143
     }, this).filter(function(item){ return item!=null; });
144 144
   },
145 145
   addId: function() {
146  
-    var provides = analyzer.analyze(PROVIDE, this.fromFile()),
147  
-        tree = this.fromFile().ast,
  146
+    var provides = this.fromFile().provides(),
  147
+        tree = this.ast(),
148 148
         provide;
149 149
 
150 150
     if (provides.length > 0) {
@@ -152,11 +152,14 @@ util.extend(Module.prototype, {
152 152
 
153 153
        // TODO make this nice - maybe have a transform function?
154 154
       if (analyzer.match(STRING_ARG, provide.values[0][0]) == null) {
155  
-        provide.parent[provide.index][2].unshift(['string', this.id]);
  155
+        provide.parent.expression.arguments.unshift({
  156
+          type: "Literal",
  157
+          value: this.id
  158
+        });
  159
+        this.fromFile().taintAst();
156 160
       }
157 161
     }
158  
-
159  
-    return uglify.uglify.gen_code(tree, { beautify: true });
  162
+    return this.fromFile().generate();
160 163
   }
161 164
 });
162 165
 
71  lib/loadbuilder/builder.js
@@ -2,15 +2,23 @@ var util   = require('./util'),
2 2
     asset  = require('./asset'),
3 3
     path   = require('path'),
4 4
     fs     = require('fs'),
5  
-    uglify = require("uglify-js");
  5
+    uglify = require("uglify-js"),
  6
+    crypto = require('crypto'),
  7
+    mkdirp = require('mkdirp');
  8
+
  9
+function hashString(string) {
  10
+  var md5sum = crypto.createHash('md5');
  11
+  md5sum.update(string);
  12
+  return md5sum.digest('hex');
  13
+}
6 14
 
7 15
 function collect(excluded, assets, includeDependencies) {
8 16
   var collected = [];
9 17
 
10 18
   assets.forEach(function(asset) {
11 19
     if(!asset) {
12  
-      console.warn('Undefined asset in assets list');
13  
-      console.log(new Error().stack);
  20
+      this.warn('Undefined asset in assets list');
  21
+      this.log(new Error().stack);
14 22
       return;
15 23
     }
16 24
     var deps = [];
@@ -24,7 +32,7 @@ function collect(excluded, assets, includeDependencies) {
24 32
         collect(excluded, deps, includeDependencies)
25 33
       ).concat(asset);
26 34
     }
27  
-  });
  35
+  }, this);
28 36
 
29 37
   return collected;
30 38
 }
@@ -113,7 +121,6 @@ util.extend(Builder.prototype, {
113 121
   },
114 122
   mapAssets: function(assets) {
115 123
     var mapped = [];
116  
-
117 124
     for (var i=0, asset; asset = assets[i]; i++) {
118 125
       if (typeof asset == 'string') {
119 126
         asset = this.matchAsset(asset);
@@ -121,7 +128,6 @@ util.extend(Builder.prototype, {
121 128
 
122 129
       mapped.push(asset);
123 130
     }
124  
-
125 131
     return mapped;
126 132
   },
127 133
   lint: function(options) {
@@ -155,6 +161,10 @@ util.extend(Builder.prototype, {
155 161
   toSource: function() {
156 162
     var source = this.collectedAssets().map(function(a) {
157 163
       this.log('* ' + a.id);
  164
+      if (this.i18nFn && !a.i18n) {
  165
+        a.addTranslationMarkers(this.i18nFn);
  166
+        a.i18n = true;
  167
+      }
158 168
       return a.toSource();
159 169
     }, this).join('\n');
160 170
 
@@ -190,6 +200,55 @@ util.extend(Builder.prototype, {
190 200
   },
191 201
   collectedAssets: function() {
192 202
     return dedupe(collect(this.excludes, this.assets, this.options.includeDependencies));
  203
+  },
  204
+  publishi18n: function(folder, outputName, translations, cb){
  205
+    var bundle = this;
  206
+    // Collect the bundle dependencies and build
  207
+    this.addI18nMarkers('_').minify({ except: ['_', '$'] }).translate(translations).writei18n(folder, outputName, cb);
  208
+  },
  209
+  addI18nMarkers: function(underscore) {
  210
+    // replace _() strings with something that's easy to regex for
  211
+    this.i18nFn = underscore; // name of i18n function
  212
+    return this;
  213
+  },
  214
+  translate: function(translations) {
  215
+    this.translations = translations;
  216
+    return this;
  217
+  },
  218
+  writei18n: function(folder, fileName, success) {
  219
+    var manifest = this.manifest(),
  220
+        versions = {},
  221
+        source = this.toSource();
  222
+
  223
+    if (!this.i18nFn || !this.translations) {
  224
+      throw new Error('did not translate - check i18n function name and translation table');
  225
+    }
  226
+
  227
+    Object.keys(this.translations).forEach(function(langCode) {
  228
+      var fullPath = fileName.replace('<lang>', langCode);
  229
+      var langSrc = source.replace(/____i18n____(.*?)____\/i18n____/g, function(fullMatch, subMatch) {
  230
+        if (this.translations[langCode].hasOwnProperty(subMatch)) {
  231
+          console.log('matched for', langCode, this.translations[langCode][subMatch]);
  232
+          return this.translations[langCode][subMatch];
  233
+        }
  234
+        // revert to English if we have no string
  235
+        console.log('using english', langCode, subMatch);
  236
+        return subMatch;
  237
+      }.bind(this));
  238
+      var hash = hashString(langSrc);
  239
+      fullPath = fullPath.replace('<hash>', hash);
  240
+      versions[langCode] = fullPath;
  241
+
  242
+      fullPath = path.join(folder, langCode, fullPath);
  243
+      mkdirp.sync(path.dirname(fullPath));
  244
+      fs.writeFileSync(fullPath, langSrc, 'utf8');
  245
+    }, this);
  246
+
  247
+    success(manifest, versions);
  248
+
  249
+    this.log('> ' + fileName);
  250
+
  251
+    return this;
193 252
   }
194 253
 });
195 254
 
135  lib/loadbuilder/file.js
... ...
@@ -0,0 +1,135 @@
  1
+var util = require('./util'),
  2
+    fs = require('fs'),
  3
+    esprima = require('esprima'),
  4
+    escodegen= require('escodegen');
  5
+
  6
+var USING = {
  7
+  type: "CallExpression",
  8
+  callee: {
  9
+    type: "Identifier",
  10
+    name: "using"
  11
+  },
  12
+  arguments: null
  13
+};
  14
+var REQUIRE = {
  15
+  type: "CallExpression",
  16
+  callee: {
  17
+    type: "Identifier",
  18
+    name: "require"
  19
+  },
  20
+  arguments: null
  21
+};
  22
+var PROVIDE = {
  23
+  type: "CallExpression",
  24
+  callee: {
  25
+    type: "Identifier",
  26
+    name: "provide"
  27
+  },
  28
+  arguments: null
  29
+};
  30
+
  31
+var lbAnalyzer; // solution for circular ref
  32
+
  33
+var files = {};
  34
+
  35
+function File(fullPath, preProcessor) {
  36
+  this.fullPath = fullPath;
  37
+  this.preProcessor = preProcessor;
  38
+  this.derived = {};
  39
+  this.load();
  40
+}
  41
+
  42
+util.extend(File.prototype, {
  43
+  load: function() {
  44
+    var fileInfo = fs.statSync(this.fullPath),
  45
+        mtime = fileInfo.mtime.getTime();
  46
+    if (!this.source || this.mtime != mtime) {
  47
+      this.mtime = mtime;
  48
+      this.source = this.preProcess(fs.readFileSync(this.fullPath, 'utf8'));
  49
+      this.taint();
  50
+    }
  51
+  },
  52
+  taint: function() {
  53
+    this.derived = {};
  54
+  },
  55
+  taintAst: function() {
  56
+    delete this.derived.generated;
  57
+  },
  58
+  preProcess: function(data) {
  59
+    return this.preProcessor ? this.preProcessor(data) : data;
  60
+  },
  61
+  ast: function() {
  62
+    if (!this.derived.esprimaAst) {
  63
+      var ast = esprima.parse(this.source, {
  64
+        range: true,
  65
+        tokens: true,
  66
+        comment: true
  67
+      });
  68
+      ast = escodegen.attachComments(ast, ast.comments, ast.tokens);
  69
+      this.derived.esprimaAst = ast;
  70
+    }
  71
+    return this.derived.esprimaAst;
  72
+  },
  73
+  addTranslationMarkers: function(fnName) {
  74
+    if (!this.derived.i18nAdded) {
  75
+      var UNDERSCORE = {
  76
+            type: "CallExpression",
  77
+            callee: {
  78
+              type: "Identifier",
  79
+              name: fnName
  80
+            },
  81
+            arguments: null
  82
+          },
  83
+          tree = this.ast(),
  84
+          underscores = this.analyzer().analyze(UNDERSCORE, tree);
  85
+      // replace the underscore functions
  86
+      underscores.forEach(function(underscore) {
  87
+        var string = underscore.values[0];
  88
+        string[0].value = '____i18n____' + string[0].value + '____/i18n____';
  89
+        this.taintAst();
  90
+      }, this);
  91
+      this.derived.i18nAdded = true;
  92
+    }
  93
+  },
  94
+  generate: function(options) {
  95
+    if (!this.derived.generated) {
  96
+      options = options || {};
  97
+      var tree = this.ast();
  98
+      this.source = this.derived.generated = escodegen.generate(tree, util.extend({ comment: true }, options));
  99
+    }
  100
+    return this.derived.generated;
  101
+  },
  102
+  usings: function() {
  103
+    if (!this.derived.usings) {
  104
+      this.derived.usings = this.analyzer().analyze(USING, this.ast());
  105
+    }
  106
+    return this.derived.usings;
  107
+  },
  108
+  requires: function() {
  109
+    if (!this.derived.requires) {
  110
+      this.derived.requires = this.analyzer().analyze(REQUIRE, this.ast());
  111
+    }
  112
+    return this.derived.requires;
  113
+  },
  114
+  provides: function() {
  115
+    if (!this.derived.provides) {
  116
+      this.derived.provides = this.analyzer().analyze(PROVIDE, this.ast());
  117
+    }
  118
+    return this.derived.provides;
  119
+  },
  120
+  analyzer: function() {
  121
+    if (!lbAnalyzer) lbAnalyzer = require('./analyzer');
  122
+    return lbAnalyzer;
  123
+  }
  124
+});
  125
+
  126
+function file(fullPath, preProcessor) {
  127
+  if (files[fullPath]) return files[fullPath];
  128
+  return files[fullPath] = new File(fullPath, preProcessor);
  129
+}
  130
+
  131
+file.isFile = function(obj) {
  132
+  return obj instanceof File;
  133
+}
  134
+
  135
+module.exports = file;
7  package.json
... ...
@@ -1,6 +1,6 @@
1 1
 {
2 2
     "name": "loadbuilder",
3  
-    "version": "0.2.12",
  3
+    "version": "0.3.0",
4 4
     "description": "Combine and compress dependency chains created by Loadrunner",
5 5
     "contributors": [{ "name": "Dan Webb", "email": "dan@danwebb.net" }, { "name": "Kenneth Kufluk", "email": "kenneth@kufluk.com" }],
6 6
     "homepage": "https://github.com/danwrong/loadbuilder",
@@ -8,11 +8,14 @@
8 8
     "main" : "./lib/loadbuilder/builder",
9 9
     "engines": { "node": ">= 0.4.0" },
10 10
     "dependencies": {
  11
+      "esprima": "0.9.9",
  12
+      "escodegen": "0.0.4",
11 13
       "jshint": "0.5.9",
12 14
       "opts": "1.2.2",
13 15
       "uglify-js": "git://github.com/kennethkufluk/UglifyJS.git#loadbuilder",
14 16
       "colors": "0.6.0-1",
15  
-      "glob": "3.1.9"
  17
+      "glob": "3.1.9",
  18
+      "mkdirp": "0.3.0"
16 19
     },
17 20
     "devDependencies": {
18 21
       "expresso": ">=0.9.2"
77  test/analyzer.js
... ...
@@ -1,19 +1,34 @@
1 1
 var analyzer = require('loadbuilder/analyzer'),
2 2
     assert   = require('assert');
3 3
 
4  
-var tree = [1, 2, [3], [4, [5]], [5]], match, matches;
  4
+var tree = {
  5
+      a: 1,
  6
+      b: 2,
  7
+      c: [
  8
+        3,
  9
+        4,
  10
+        {
  11
+          d: 7
  12
+        }
  13
+      ],
  14
+      e: {
  15
+        f: 8
  16
+      },
  17
+      f: 9
  18
+    },
  19
+    match, matches;
5 20
 
6 21
 module.exports = {
7 22
   testMatchShouldReturnNullIfNoMatches: function() {
8  
-    match = analyzer.match(['not', 'here', 3556], tree);
  23
+    match = analyzer.match({ not: 'here' }, tree);
9 24
     assert.isNull(match);
10 25
   },
11 26
 
12 27
   testMatchShouldReturnArrayIfMatches: function() {
13  
-    match = analyzer.match([1, 2], tree);
  28
+    match = analyzer.match({ a: 1, b: 2 }, tree);
14 29
     assert.eql(match, []);
15 30
 
16  
-    match = analyzer.match([1, 2, [3]], tree);
  31
+    match = analyzer.match({ a: 1, b: 2, c: [ 3 ] }, tree);
17 32
     assert.eql(match, []);
18 33
 
19 34
     match = analyzer.match(tree, tree);
@@ -22,55 +37,59 @@ module.exports = {
22 37
 
23 38
   testMatchShouldReturnMatchedWildcardsInArray: function() {
24 39
 
25  
-    match = analyzer.match([null, 2], tree);
  40
+    match = analyzer.match({ a: null }, tree);
26 41
     assert.eql(match, [1]);
27 42
 
28  
-    match = analyzer.match([1, 2, [null]], tree);
29  
-    assert.eql(match, [3]);
  43
+    match = analyzer.match({
  44
+        a: 1,
  45
+        b: 2,
  46
+        c: null
  47
+      }, tree);
  48
+    assert.eql(match, [[3,4,{"d":7}]]);
30 49
 
31  
-    match = analyzer.match([null, 2, [null]], tree);
32  
-    assert.eql(match, [1, 3]);
33  
-  },
34  
-
35  
-  testMatchShouldMatchArraysWithWildcard: function() {
36  
-
37  
-    match = analyzer.match([1, 2, null], tree);
38  
-    assert.eql(match, [[3]]);
  50
+    match = analyzer.match({ a: null, b: null }, tree);
  51
+    assert.eql(match, [1, 2]);
39 52
   },
40 53
 
41 54
   testWalkShouldReturnArrayOfMatches: function() {
42  
-    matches = analyzer.walk([4], tree);
  55
+    matches = analyzer.walk({ f: 8 }, tree);
43 56
     assert.eql(matches, [
44 57
       { parent: tree, index: 3, values: [] }
45 58
     ]);
46 59
 
47  
-    matches = analyzer.walk([1, null], tree);
  60
+    matches = analyzer.walk({ a: 1, b: null }, tree);
48 61
     assert.eql(matches, [
49 62
       { parent: null, index: 0, values: [2] }
50 63
     ]);
51 64
 
52  
-    matches = analyzer.walk([4, [null]], tree);
  65
+    matches = analyzer.walk({ b: 2, c: [null] }, tree);
53 66
     assert.eql(matches, [
54  
-      { parent: tree, index: 3, values: [5] }
  67
+      { parent: null, index: 0, values: [3] }
55 68
     ]);
56 69
 
57  
-    matches = analyzer.walk([5], tree);
  70
+    matches = analyzer.walk({ f: null }, tree);
58 71
     assert.eql(matches, [
59  
-      { parent: tree[3], index: 1, values: [] },
60  
-      { parent: tree, index: 4, values: [] }
  72
+      { parent: null, index: 0, values: [9] },
  73
+      { parent: tree, index: 3, values: [8] }
61 74
     ]);
62 75
   },
63 76
 
64 77
   testAnalyzeShouldWalkJSSource: function() {
65 78
     var src = "function pow() { var thing = require('blah'); }";
66 79
 
67  
-    matches = analyzer.analyze(
68  
-                [ 'call',
69  
-                  [ 'name', 'require' ],
70  
-                  [
71  
-                    ['string', null]
72  
-                  ]
73  
-                ], src);
  80
+    matches = analyzer.analyze({
  81
+        "type": "CallExpression",
  82
+        "callee": {
  83
+            "type": "Identifier",
  84
+            "name": "require"
  85
+        },
  86
+        "arguments": [
  87
+            {
  88
+                "type": "Literal",
  89
+                "value": null
  90
+            }
  91
+        ]
  92
+    }, src);
74 93
 
75 94
     assert.eql(matches[0].values, ['blah']);
76 95
   }
13  test/asset.js
@@ -18,13 +18,12 @@ module.exports = {
18 18
     });
19 19
     assert.equal("deferred('fixtures/simple.js', function() {\nalert('hello world');\n});", a.toSource());
20 20
   },
21  
-  testShouldFindDependenciesForModule: function() {
  21
+  testShouldFindDependenciesForScript: function() {
22 22
     var a = new asset.Script('fixtures/dep1.js');
23 23
     a.builder = builder({
24 24
       docroot: __dirname
25 25
     });
26  
-
27  
-    assert.equal('dep1dep', a.dependencies()[0].id);
  26
+    assert.equal('fixtures/dep1dep.js', a.dependencies()[0].id);
28 27
   },
29 28
   testShouldAddNameToAnonModule: function() {
30 29
     var a = new asset.Module('anon');
@@ -33,7 +32,7 @@ module.exports = {
33 32
       path: '/modules'
34 33
     });
35 34
 
36  
-    assert.equal('provide("anon", function(exports) {\n    exports("hi");\n});', a.toSource());
  35
+    assert.equal("provide('anon', function (exports) {\n    exports('hi');\n});", a.toSource());
37 36
   },
38 37
   testShouldNotAddNameToNamedModule: function() {
39 38
     var a = new asset.Module('named');
@@ -42,7 +41,7 @@ module.exports = {
42 41
       path: '/modules'
43 42
     });
44 43
 
45  
-    assert.equal('provide("named", function(exports) {\n    exports("hi");\n});', a.toSource());
  44
+    assert.equal("/*! license */\nprovide('named', function (exports) {\n    exports('hi');\n});", a.toSource());
46 45
   },
47 46
   testShouldFindDependenciesForModule: function() {
48 47
     var a = new asset.Module('has_dep');
@@ -53,7 +52,7 @@ module.exports = {
53 52
 
54 53
     assert.equal('anon', a.dependencies()[0].id);
55 54
   },
56  
-  testShouldFindDependenciesForModule: function() {
  55
+  testShouldFindDependenciesForModule2: function() {
57 56
     var a = new asset.Module('common');
58 57
     a.builder = builder({
59 58
       docroot: __dirname,
@@ -71,6 +70,6 @@ module.exports = {
71 70
     });
72 71
 
73 72
     assert.equal('define("common",["module","require","exports","anon"],' +
74  
-                 'function(module, require, exports) {\nvar a = require("anon");\n});', a.toSource());
  73
+                 'function(module, require, exports) {\nvar a = require(\'anon\');\n});', a.toSource());
75 74
   }
76 75
 }
6  test/builder.js
@@ -30,7 +30,7 @@ module.exports = {
30 30
   testShouldBeAbleToExcludeALowLevelDep: function() {
31 31
     assert.equal(
32 32
       builder(opts).include('mod_with_dep').exclude('named').toSource(),
33  
-      "provide(\"mod_with_dep\", function(exports) {\n    using(\"named\", function() {\n        exports(3);\n    });\n});"
  33
+      "provide('mod_with_dep', function (exports) {\n    using('named', function () {\n        exports(3);\n    });\n});"
34 34
     );
35 35
   },
36 36
   testShouldCollectDependencies: function() {
@@ -69,7 +69,7 @@ module.exports = {
69 69
     var a = builder(opts).include('mod_with_dep'),
70 70
         result = builder(opts).include('mod_with_same_dep').exclude(a).toSource();
71 71
     assert.equal(
72  
-      "provide(\"mod_with_same_dep\", function(exports) {\n    using(\"named\", function() {\n        exports(3);\n    });\n});",
  72
+      "provide('mod_with_same_dep', function (exports) {\n    using('named', function () {\n        exports(3);\n    });\n});",
73 73
       result
74 74
     );
75 75
   },
@@ -90,7 +90,7 @@ module.exports = {
90 90
   },
91 91
   testShouldBeAbleToSuccessFullyLoadANamedModule: function() {
92 92
     assert.equal(
93  
-      "provide(\"named\", function(exports) {\n    exports(\"hi\");\n});",
  93
+      "/*! license */\nprovide('named', function (exports) {\n    exports('hi');\n});",
94 94
       builder(opts).include('named').toSource()
95 95
     );
96 96
   }
1  test/modules/named.js
... ...
@@ -1,3 +1,4 @@
  1
+/*! license */
1 2
 provide('named', function(exports) {
2 3
   exports('hi');
3 4
 });

0 notes on commit 4504353

Please sign in to comment.
Something went wrong with that request. Please try again.