requirejs-rails 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # v0.5.1
2
+
3
+ - This is a quick turn to fix an issue that could trigger an Anonymous mismatched define() error from require.js and/or r.js.
4
+
5
+ The preferred way to use the helper tag is now with an argument, like
6
+ so:
7
+
8
+ ```erb
9
+ <%= requirejs_include_tag "application" %>
10
+ ```
11
+
12
+ This usage ensures that the above helper will correctly generate a
13
+ data-main attribute for the script tag. The requirejs_include_tag
14
+ helper still works without an argument, and won't generate data-main
15
+ in that case.
16
+
17
+ Thanks to Andrew de Andrade for the catch.
18
+
1
19
  # v0.5.0
2
20
 
3
21
  - Precompilation via `rake assets:precompile` is now implemented.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- requirejs-rails (0.5.1)
4
+ requirejs-rails (0.5.2)
5
5
  railties (~> 3.1.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -21,7 +21,7 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
21
21
  <html>
22
22
  <head>
23
23
  <title>Frobnitz Online</title>
24
- <%= stylesheet_link_tag "application" %>
24
+ <%= stylesheet_link_tag "application" %>
25
25
  <%= requirejs_include_tag "application" %>
26
26
  <%= csrf_meta_tags %>
27
27
  <meta charset="utf-8">
data/bin/r.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license r.js 1.0.2+ 20111207 10:15pm Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
2
+ * @license r.js 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3
3
  * Available via the MIT or new BSD license.
4
4
  * see: http://github.com/jrburke/requirejs for details
5
5
  */
@@ -20,7 +20,7 @@ var requirejs, require, define;
20
20
 
21
21
  var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
22
22
  nodeDefine, exists, reqMain, loadedOptimizedLib,
23
- version = '1.0.2+ 20111207 10:15pm',
23
+ version = '1.0.3',
24
24
  jsSuffixRegExp = /\.js$/,
25
25
  commandOption = '',
26
26
  //Used by jslib/rhino/args.js
@@ -101,7 +101,7 @@ var requirejs, require, define;
101
101
  }
102
102
 
103
103
  /** vim: et:ts=4:sw=4:sts=4
104
- * @license RequireJS 1.0.2 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
104
+ * @license RequireJS 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
105
105
  * Available via the MIT or new BSD license.
106
106
  * see: http://github.com/jrburke/requirejs for details
107
107
  */
@@ -113,7 +113,7 @@ var requirejs, require, define;
113
113
 
114
114
  (function () {
115
115
  //Change this version number for each release.
116
- var version = "1.0.2",
116
+ var version = "1.0.3",
117
117
  commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
118
118
  cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
119
119
  currDirRegExp = /^\.\//,
@@ -1423,11 +1423,6 @@ var requirejs, require, define;
1423
1423
  } : null]);
1424
1424
  }
1425
1425
 
1426
- //If a global jQuery is defined, check for it. Need to do it here
1427
- //instead of main() since stock jQuery does not register as
1428
- //a module via define.
1429
- jQueryCheck();
1430
-
1431
1426
  //Doing this scriptCount decrement branching because sync envs
1432
1427
  //need to decrement after resume, otherwise it looks like
1433
1428
  //loading is complete after the first dependency is fetched.
@@ -2041,10 +2036,6 @@ var requirejs, require, define;
2041
2036
  //global queue, assign them to this context.
2042
2037
  ctx.takeGlobalQueue();
2043
2038
 
2044
- //Allow for jQuery to be loaded/already in the page, and if jQuery 1.4.3,
2045
- //make sure to hold onto it for readyWait triggering.
2046
- ctx.jQueryCheck();
2047
-
2048
2039
  if (!ctx.scriptCount) {
2049
2040
  ctx.resume();
2050
2041
  }
@@ -2375,7 +2366,7 @@ define('node/file', ['fs', 'path'], function (fs, path) {
2375
2366
 
2376
2367
  function mkDir(dir) {
2377
2368
  if (!exists(dir)) {
2378
- fs.mkdirSync(dir, 0777);
2369
+ fs.mkdirSync(dir, 511);
2379
2370
  }
2380
2371
  }
2381
2372
 
@@ -2536,6 +2527,13 @@ define('node/file', ['fs', 'path'], function (fs, path) {
2536
2527
  return true; //Boolean
2537
2528
  },
2538
2529
 
2530
+ /**
2531
+ * Renames a file. May fail if "to" already exists or is on another drive.
2532
+ */
2533
+ renameFile: function (from, to) {
2534
+ return fs.renameSync(from, to);
2535
+ },
2536
+
2539
2537
  /**
2540
2538
  * Reads a *text* file.
2541
2539
  */
@@ -2772,6 +2770,13 @@ define('rhino/file', function () {
2772
2770
  return true; //Boolean
2773
2771
  },
2774
2772
 
2773
+ /**
2774
+ * Renames a file. May fail if "to" already exists or is on another drive.
2775
+ */
2776
+ renameFile: function (from, to) {
2777
+ return (new java.io.File(from)).renameTo((new java.io.File(to)));
2778
+ },
2779
+
2775
2780
  readFile: function (/*String*/path, /*String?*/encoding) {
2776
2781
  //A file read function that can deal with BOMs
2777
2782
  encoding = encoding || "utf-8";
@@ -3262,9 +3267,9 @@ function parse_js_number(num) {
3262
3267
 
3263
3268
  function JS_Parse_Error(message, line, col, pos) {
3264
3269
  this.message = message;
3265
- this.line = line;
3266
- this.col = col;
3267
- this.pos = pos;
3270
+ this.line = line + 1;
3271
+ this.col = col + 1;
3272
+ this.pos = pos + 1;
3268
3273
  this.stack = new Error().stack;
3269
3274
  };
3270
3275
 
@@ -3334,12 +3339,13 @@ function tokenizer($TEXT) {
3334
3339
  (type == "keyword" && HOP(KEYWORDS_BEFORE_EXPRESSION, value)) ||
3335
3340
  (type == "punc" && HOP(PUNC_BEFORE_EXPRESSION, value)));
3336
3341
  var ret = {
3337
- type : type,
3338
- value : value,
3339
- line : S.tokline,
3340
- col : S.tokcol,
3341
- pos : S.tokpos,
3342
- nlb : S.newline_before
3342
+ type : type,
3343
+ value : value,
3344
+ line : S.tokline,
3345
+ col : S.tokcol,
3346
+ pos : S.tokpos,
3347
+ endpos : S.pos,
3348
+ nlb : S.newline_before
3343
3349
  };
3344
3350
  if (!is_comment) {
3345
3351
  ret.comments_before = S.comments_before;
@@ -3476,8 +3482,7 @@ function tokenizer($TEXT) {
3476
3482
  next();
3477
3483
  return with_eof_error("Unterminated multiline comment", function(){
3478
3484
  var i = find("*/", true),
3479
- text = S.text.substring(S.pos, i),
3480
- tok = token("comment2", text, true);
3485
+ text = S.text.substring(S.pos, i);
3481
3486
  S.pos = i + 2;
3482
3487
  S.line += text.split("\n").length - 1;
3483
3488
  S.newline_before = text.indexOf("\n") >= 0;
@@ -3489,7 +3494,7 @@ function tokenizer($TEXT) {
3489
3494
  warn("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer.");
3490
3495
  }
3491
3496
 
3492
- return tok;
3497
+ return token("comment2", text, true);
3493
3498
  });
3494
3499
  };
3495
3500
 
@@ -3940,7 +3945,7 @@ function parse($TEXT, exigent_mode, embed_tokens) {
3940
3945
  return as("for-in", init, lhs, obj, in_loop(statement));
3941
3946
  };
3942
3947
 
3943
- var function_ = maybe_embed_tokens(function(in_statement) {
3948
+ var function_ = function(in_statement) {
3944
3949
  var name = is("name") ? prog1(S.token.value, next) : null;
3945
3950
  if (in_statement && !name)
3946
3951
  unexpected();
@@ -3968,7 +3973,7 @@ function parse($TEXT, exigent_mode, embed_tokens) {
3968
3973
  S.in_loop = loop;
3969
3974
  return a;
3970
3975
  })());
3971
- });
3976
+ };
3972
3977
 
3973
3978
  function if_() {
3974
3979
  var cond = parenthesised(), body = statement(), belse;
@@ -4316,7 +4321,7 @@ function characters(str) {
4316
4321
 
4317
4322
  function member(name, array) {
4318
4323
  for (var i = array.length; --i >= 0;)
4319
- if (array[i] === name)
4324
+ if (array[i] == name)
4320
4325
  return true;
4321
4326
  return false;
4322
4327
  };
@@ -4377,11 +4382,21 @@ function ast_squeeze_more(ast) {
4377
4382
  "function": _lambda,
4378
4383
  "defun": _lambda,
4379
4384
  "new": function(ctor, args) {
4380
- if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) {
4381
- if (args.length != 1) {
4382
- return [ "array", args ];
4383
- } else {
4384
- return walk([ "call", [ "name", "Array" ], args ]);
4385
+ if (ctor[0] == "name") {
4386
+ if (ctor[1] == "Array" && !scope.has("Array")) {
4387
+ if (args.length != 1) {
4388
+ return [ "array", args ];
4389
+ } else {
4390
+ return walk([ "call", [ "name", "Array" ], args ]);
4391
+ }
4392
+ } else if (ctor[1] == "Object" && !scope.has("Object")) {
4393
+ if (!args.length) {
4394
+ return [ "object", [] ];
4395
+ } else {
4396
+ return walk([ "call", [ "name", "Object" ], args ]);
4397
+ }
4398
+ } else if ((ctor[1] == "RegExp" || ctor[1] == "Function" || ctor[1] == "Error") && !scope.has(ctor[1])) {
4399
+ return walk([ "call", [ "name", ctor[1] ], args]);
4385
4400
  }
4386
4401
  }
4387
4402
  },
@@ -4390,8 +4405,16 @@ function ast_squeeze_more(ast) {
4390
4405
  // foo.toString() ==> foo+""
4391
4406
  return [ "binary", "+", expr[1], [ "string", "" ]];
4392
4407
  }
4393
- if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
4394
- return [ "array", args ];
4408
+ if (expr[0] == "name") {
4409
+ if (expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
4410
+ return [ "array", args ];
4411
+ }
4412
+ if (expr[1] == "Object" && !args.length && !scope.has("Object")) {
4413
+ return [ "object", [] ];
4414
+ }
4415
+ if (expr[1] == "String" && !scope.has("String")) {
4416
+ return [ "binary", "+", args[0], [ "string", "" ]];
4417
+ }
4395
4418
  }
4396
4419
  }
4397
4420
  }, function() {
@@ -4788,6 +4811,7 @@ function ast_add_scope(ast) {
4788
4811
 
4789
4812
  function with_new_scope(cont) {
4790
4813
  current_scope = new Scope(current_scope);
4814
+ current_scope.labels = new Scope();
4791
4815
  var ret = current_scope.body = cont();
4792
4816
  ret.scope = current_scope;
4793
4817
  current_scope = current_scope.parent;
@@ -4820,14 +4844,19 @@ function ast_add_scope(ast) {
4820
4844
  };
4821
4845
  };
4822
4846
 
4847
+ function _breacont(label) {
4848
+ if (label)
4849
+ current_scope.labels.refs[label] = true;
4850
+ };
4851
+
4823
4852
  return with_new_scope(function(){
4824
4853
  // process AST
4825
4854
  var ret = w.with_walkers({
4826
4855
  "function": _lambda,
4827
4856
  "defun": _lambda,
4828
- "label": function(name, stat) { define(name, "label") },
4829
- "break": function(label) { if (label) reference(label) },
4830
- "continue": function(label) { if (label) reference(label) },
4857
+ "label": function(name, stat) { current_scope.labels.define(name) },
4858
+ "break": _breacont,
4859
+ "continue": _breacont,
4831
4860
  "with": function(expr, block) {
4832
4861
  for (var s = current_scope; s; s = s.parent)
4833
4862
  s.uses_with = true;
@@ -4913,15 +4942,18 @@ function ast_mangle(ast, options) {
4913
4942
  };
4914
4943
 
4915
4944
  function _lambda(name, args, body) {
4916
- var is_defun = this[0] == "defun", extra;
4917
- if (name) {
4918
- if (is_defun) name = get_mangled(name);
4919
- else {
4920
- extra = {};
4921
- if (!(scope.uses_eval || scope.uses_with))
4922
- name = extra[name] = scope.next_mangled();
4923
- else
4924
- extra[name] = name;
4945
+ if (!options.no_functions) {
4946
+ var is_defun = this[0] == "defun", extra;
4947
+ if (name) {
4948
+ if (is_defun) name = get_mangled(name);
4949
+ else if (body.scope.references(name)) {
4950
+ extra = {};
4951
+ if (!(scope.uses_eval || scope.uses_with))
4952
+ name = extra[name] = scope.next_mangled();
4953
+ else
4954
+ extra[name] = name;
4955
+ }
4956
+ else name = null;
4925
4957
  }
4926
4958
  }
4927
4959
  body = with_scope(body.scope, function(){
@@ -4952,6 +4984,10 @@ function ast_mangle(ast, options) {
4952
4984
  }) ];
4953
4985
  };
4954
4986
 
4987
+ function _breacont(label) {
4988
+ if (label) return [ this[0], scope.labels.get_mangled(label) ];
4989
+ };
4990
+
4955
4991
  return w.with_walkers({
4956
4992
  "function": _lambda,
4957
4993
  "defun": function() {
@@ -4966,9 +5002,16 @@ function ast_mangle(ast, options) {
4966
5002
  }
4967
5003
  return ast;
4968
5004
  },
4969
- "label": function(label, stat) { return [ this[0], get_mangled(label), walk(stat) ] },
4970
- "break": function(label) { if (label) return [ this[0], get_mangled(label) ] },
4971
- "continue": function(label) { if (label) return [ this[0], get_mangled(label) ] },
5005
+ "label": function(label, stat) {
5006
+ if (scope.labels.refs[label]) return [
5007
+ this[0],
5008
+ scope.labels.get_mangled(label, true),
5009
+ walk(stat)
5010
+ ];
5011
+ return walk(stat);
5012
+ },
5013
+ "break": _breacont,
5014
+ "continue": _breacont,
4972
5015
  "var": _vardefs,
4973
5016
  "const": _vardefs,
4974
5017
  "name": function(name) {
@@ -5382,7 +5425,7 @@ function ast_squeeze(ast, options) {
5382
5425
  keep_comps : true
5383
5426
  });
5384
5427
 
5385
- var w = ast_walker(), walk = w.walk, scope;
5428
+ var w = ast_walker(), walk = w.walk;
5386
5429
 
5387
5430
  function negate(c) {
5388
5431
  var not_c = [ "unary-prefix", "!", c ];
@@ -5434,15 +5477,6 @@ function ast_squeeze(ast, options) {
5434
5477
  }, make_real_conditional);
5435
5478
  };
5436
5479
 
5437
- function with_scope(s, cont) {
5438
- var _scope = scope;
5439
- scope = s;
5440
- var ret = cont();
5441
- ret.scope = s;
5442
- scope = _scope;
5443
- return ret;
5444
- };
5445
-
5446
5480
  function rmblock(block) {
5447
5481
  if (block != null && block[0] == "block" && block[1]) {
5448
5482
  if (block[1].length == 1)
@@ -5454,14 +5488,7 @@ function ast_squeeze(ast, options) {
5454
5488
  };
5455
5489
 
5456
5490
  function _lambda(name, args, body) {
5457
- var is_defun = this[0] == "defun";
5458
- body = with_scope(body.scope, function(){
5459
- var ret = tighten(body, "lambda");
5460
- if (!is_defun && name && !scope.references(name))
5461
- name = null;
5462
- return ret;
5463
- });
5464
- return [ this[0], name, args, body ];
5491
+ return [ this[0], name, args, tighten(body, "lambda") ];
5465
5492
  };
5466
5493
 
5467
5494
  // this function does a few things:
@@ -5675,9 +5702,7 @@ function ast_squeeze(ast, options) {
5675
5702
  },
5676
5703
  "if": make_if,
5677
5704
  "toplevel": function(body) {
5678
- return [ "toplevel", with_scope(this.scope, function(){
5679
- return tighten(body);
5680
- }) ];
5705
+ return [ "toplevel", tighten(body) ];
5681
5706
  },
5682
5707
  "switch": function(expr, body) {
5683
5708
  var last = body.length - 1;
@@ -5752,7 +5777,6 @@ function ast_squeeze(ast, options) {
5752
5777
  }, function() {
5753
5778
  for (var i = 0; i < 2; ++i) {
5754
5779
  ast = prepare_ifs(ast);
5755
- ast = ast_add_scope(ast);
5756
5780
  ast = walk(ast);
5757
5781
  }
5758
5782
  return ast;
@@ -5824,7 +5848,7 @@ function gen_code(ast, options) {
5824
5848
  function encode_string(str) {
5825
5849
  var ret = make_string(str, options.ascii_only);
5826
5850
  if (options.inline_script)
5827
- ret = ret.replace(/<\x2fscript([>/\t\n\f\r ])/gi, "<\\/script$1");
5851
+ ret = ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi, "<\\/script$1");
5828
5852
  return ret;
5829
5853
  };
5830
5854
 
@@ -6405,8 +6429,7 @@ exports.MAP = MAP;
6405
6429
  // keep this last!
6406
6430
  exports.ast_squeeze_more = require("./squeeze-more").ast_squeeze_more;
6407
6431
 
6408
- });
6409
- define('uglifyjs/index', ["require", "exports", "module", "./parse-js", "./process"], function(require, exports, module) {
6432
+ });define('uglifyjs/index', ["require", "exports", "module", "./parse-js", "./process"], function(require, exports, module) {
6410
6433
 
6411
6434
  //convienence function(src, [options]);
6412
6435
  function uglify(orig_code, options){
@@ -6648,6 +6671,15 @@ define('parse', ['uglifyjs/index'], function (uglify) {
6648
6671
  if (result) {
6649
6672
  result += '\n';
6650
6673
  }
6674
+
6675
+ //If this is the main module for this file, combine any
6676
+ //"anonymous" dependencies (could come from a nested require
6677
+ //call) with this module.
6678
+ if (moduleCall.name === moduleName) {
6679
+ moduleCall.deps = moduleCall.deps.concat(moduleDeps);
6680
+ moduleDeps = [];
6681
+ }
6682
+
6651
6683
  depString = moduleCall.deps.length ? '["' + moduleCall.deps.join('","') + '"]' : '[]';
6652
6684
  result += 'define("' + moduleCall.name + '",' + depString + ');';
6653
6685
  }
@@ -7047,7 +7079,9 @@ define('pragma', ['parse', 'logger'], function (parse, logger) {
7047
7079
  apiDefRegExp: /var requirejs, require, define;/,
7048
7080
  defineCheckRegExp: /typeof\s+define\s*===\s*["']function["']\s*&&\s*define\s*\.\s*amd/g,
7049
7081
  defineJQueryRegExp: /typeof\s+define\s*===\s*["']function["']\s*&&\s*define\s*\.\s*amd\s*&&\s*define\s*\.\s*amd\s*\.\s*jQuery/g,
7082
+ defineHasRegExp: /typeof\s+define\s*==(=)?\s*['"]function['"]\s*&&\s*typeof\s+define\.amd\s*==(=)?\s*['"]object['"]\s*&&\s*define\.amd/g,
7050
7083
  defineTernaryRegExp: /typeof\s+define\s*===\s*['"]function["']\s*&&\s*define\s*\.\s*amd\s*\?\s*define/,
7084
+ amdefineRegExp: /if\s*\(\s*typeof define\s*\!==\s*'function'\s*\)\s*\{\s*[^\{\}]+amdefine[^\{\}]+\}/g,
7051
7085
 
7052
7086
  removeStrict: function (contents, config) {
7053
7087
  return config.useStrict ? contents : contents.replace(pragma.useStrictRegExp, '');
@@ -7058,14 +7092,17 @@ define('pragma', ['parse', 'logger'], function (parse, logger) {
7058
7092
  //Namespace require/define calls
7059
7093
  fileContents = fileContents.replace(pragma.nsRegExp, '$1' + ns + '.$2(');
7060
7094
 
7061
-
7062
7095
  //Namespace define ternary use:
7063
7096
  fileContents = fileContents.replace(pragma.defineTernaryRegExp,
7064
7097
  "typeof " + ns + ".define === 'function' && " + ns + ".define.amd ? " + ns + ".define");
7065
7098
 
7066
7099
  //Namespace define jquery use:
7067
7100
  fileContents = fileContents.replace(pragma.defineJQueryRegExp,
7068
- "typeof " + ns + ".define === 'function' && " + ns + ".define.amd && " + ns + ".define.jQuery");
7101
+ "typeof " + ns + ".define === 'function' && " + ns + ".define.amd && " + ns + ".define.amd.jQuery");
7102
+
7103
+ //Namespace has.js define use:
7104
+ fileContents = fileContents.replace(pragma.defineHasRegExp,
7105
+ "typeof " + ns + ".define === 'function' && typeof " + ns + ".define.amd === 'object' && " + ns + ".define.amd");
7069
7106
 
7070
7107
  //Namespace define checks.
7071
7108
  //Do this one last, since it is a subset of the more specific
@@ -7238,6 +7275,9 @@ define('pragma', ['parse', 'logger'], function (parse, logger) {
7238
7275
  }
7239
7276
  }
7240
7277
 
7278
+ //Strip amdefine use for node-shared modules.
7279
+ fileContents = fileContents.replace(pragma.amdefineRegExp, '');
7280
+
7241
7281
  //Do namespacing
7242
7282
  if (onLifecycleName === 'OnSave' && config.namespace) {
7243
7283
  fileContents = pragma.namespace(fileContents, config.namespace, onLifecycleName);
@@ -7533,14 +7573,16 @@ function (lang, logger, envOptimize, file, parse,
7533
7573
  '" not found for this environment');
7534
7574
  }
7535
7575
 
7536
- //Pull out any license comments for prepending after optimization.
7537
- optimize.licenseCommentRegExp.lastIndex = 0;
7538
- while ((match = optimize.licenseCommentRegExp.exec(fileContents))) {
7539
- comment = match[0];
7540
- //Only keep the comments if they are license comments.
7541
- if (comment.indexOf('@license') !== -1 ||
7542
- comment.indexOf('/*!') === 0) {
7543
- licenseContents += comment + '\n';
7576
+ if (config.preserveLicenseComments) {
7577
+ //Pull out any license comments for prepending after optimization.
7578
+ optimize.licenseCommentRegExp.lastIndex = 0;
7579
+ while ((match = optimize.licenseCommentRegExp.exec(fileContents))) {
7580
+ comment = match[0];
7581
+ //Only keep the comments if they are license comments.
7582
+ if (comment.indexOf('@license') !== -1 ||
7583
+ comment.indexOf('/*!') === 0) {
7584
+ licenseContents += comment + '\n';
7585
+ }
7544
7586
  }
7545
7587
  }
7546
7588
 
@@ -7620,19 +7662,18 @@ function (lang, logger, envOptimize, file, parse,
7620
7662
  uglify: function (fileName, fileContents, keepLines, config) {
7621
7663
  var parser = uglify.parser,
7622
7664
  processor = uglify.uglify,
7623
- ast, genCodeConfig;
7665
+ ast;
7624
7666
 
7625
7667
  config = config || {};
7626
- genCodeConfig = config.gen_codeOptions || keepLines;
7627
7668
 
7628
7669
  logger.trace("Uglifying file: " + fileName);
7629
7670
 
7630
7671
  try {
7631
- ast = parser.parse(fileContents, config.strict_semicolons);
7632
- ast = processor.ast_mangle(ast, config.do_toplevel);
7633
- ast = processor.ast_squeeze(ast, config.ast_squeezeOptions);
7672
+ ast = parser.parse(fileContents, config);
7673
+ ast = processor.ast_mangle(ast, config);
7674
+ ast = processor.ast_squeeze(ast, config);
7634
7675
 
7635
- fileContents = processor.gen_code(ast, genCodeConfig);
7676
+ fileContents = processor.gen_code(ast, config);
7636
7677
  } catch (e) {
7637
7678
  logger.error('Cannot uglify file: ' + fileName + '. Skipping it. Error is:\n' + e.toString());
7638
7679
  }
@@ -8107,6 +8148,7 @@ function (lang, logger, file, parse, optimize, pragma,
8107
8148
  isBuild: true,
8108
8149
  optimizeAllPluginResources: false,
8109
8150
  findNestedDependencies: false,
8151
+ preserveLicenseComments: true,
8110
8152
  //By default, all files/directories are copied, unless
8111
8153
  //they match this regexp, by default just excludes .folders
8112
8154
  dirExclusionRegExp: file.dirExclusionRegExp
@@ -8393,9 +8435,22 @@ function (lang, logger, file, parse, optimize, pragma,
8393
8435
 
8394
8436
  //Flatten them and collect the build output for each module.
8395
8437
  builtModule = build.flattenModule(module, module.layer, config);
8396
- file.saveUtf8File(module._buildPath, builtModule.text);
8438
+
8439
+ //Save it to a temp file for now, in case there are other layers that
8440
+ //contain optimized content that should not be included in later
8441
+ //layer optimizations. See issue #56.
8442
+ file.saveUtf8File(module._buildPath + '-temp', builtModule.text);
8397
8443
  buildFileContents += builtModule.buildText;
8398
8444
  });
8445
+
8446
+ //Now move the build layers to their final position.
8447
+ modules.forEach(function (module) {
8448
+ var finalPath = module._buildPath;
8449
+ if (file.exists(finalPath)) {
8450
+ file.deleteFile(finalPath);
8451
+ }
8452
+ file.renameFile(finalPath + '-temp', finalPath);
8453
+ });
8399
8454
  }
8400
8455
 
8401
8456
  //Do other optimizations.
@@ -8507,6 +8562,26 @@ function (lang, logger, file, parse, optimize, pragma,
8507
8562
  result[prop][name] = value;
8508
8563
  }
8509
8564
 
8565
+ //Used by convertArrayToObject to convert some things from prop.name=value
8566
+ //to a prop: { name: value}
8567
+ build.dotProps = [
8568
+ 'paths.',
8569
+ 'wrap.',
8570
+ 'pragmas.',
8571
+ 'pragmasOnSave.',
8572
+ 'has.',
8573
+ 'hasOnSave.',
8574
+ 'wrap.',
8575
+ 'uglify.',
8576
+ 'closure.'
8577
+ ];
8578
+
8579
+ build.hasDotPropMatch = function (prop) {
8580
+ return build.dotProps.some(function (dotProp) {
8581
+ return prop.indexOf(dotProp) === 0;
8582
+ });
8583
+ };
8584
+
8510
8585
  /**
8511
8586
  * Converts an array that has String members of "name=value"
8512
8587
  * into an object, where the properties on the object are the names in the array.
@@ -8543,7 +8618,7 @@ function (lang, logger, file, parse, optimize, pragma,
8543
8618
  value = value.split(",");
8544
8619
  }
8545
8620
 
8546
- if (prop.indexOf("paths.") === 0 || prop.indexOf("wrap.") === 0) {
8621
+ if (build.hasDotPropMatch(prop)) {
8547
8622
  stringDotToObj(result, prop.split('.')[0], prop, value);
8548
8623
  } else {
8549
8624
  result[prop] = value;
@@ -8736,9 +8811,9 @@ function (lang, logger, file, parse, optimize, pragma,
8736
8811
  //Set file.fileExclusionRegExp if desired
8737
8812
  if ('fileExclusionRegExp' in config) {
8738
8813
  if (typeof config.fileExclusionRegExp === "string") {
8739
- file.exclusionRegExp = new RegExp(config.fileExclusionRegExp);
8814
+ file.exclusionRegExp = new RegExp(config.fileExclusionRegExp);
8740
8815
  } else {
8741
- file.exclusionRegExp = config.fileExclusionRegExp;
8816
+ file.exclusionRegExp = config.fileExclusionRegExp;
8742
8817
  }
8743
8818
  } else if ('dirExclusionRegExp' in config) {
8744
8819
  //Set file.dirExclusionRegExp if desired, this is the old
@@ -8978,7 +9053,9 @@ function (lang, logger, file, parse, optimize, pragma,
8978
9053
  return match;
8979
9054
  }
8980
9055
 
8981
- if (layer) {
9056
+ //Only mark this module as having a name if not a named module,
9057
+ //or if a named module and the name matches expectations.
9058
+ if (layer && (!namedModule || namedModule === moduleName)) {
8982
9059
  layer.modulesWithNames[moduleName] = true;
8983
9060
  }
8984
9061
 
@@ -9000,7 +9077,7 @@ function (lang, logger, file, parse, optimize, pragma,
9000
9077
  }
9001
9078
  }
9002
9079
 
9003
- return start + namespace + "define('" + moduleName + "'," +
9080
+ return start + namespace + "define('" + (namedModule || moduleName) + "'," +
9004
9081
  (deps ? ('[' + deps.toString() + '],') : '') +
9005
9082
  (namedModule ? namedFuncStart.replace(build.leadingCommaRegExp, '') : suffix);
9006
9083
  });
@@ -1,5 +1,5 @@
1
1
  module Requirejs
2
2
  module Rails
3
- VERSION = "0.5.1"
3
+ VERSION = "0.5.2"
4
4
  end
5
5
  end
@@ -13,7 +13,7 @@ class RequirejsRailsTest < ActiveSupport::TestCase
13
13
  test "require.js version" do
14
14
  require_js = Pathname.new(__FILE__+'/../../vendor/assets/javascripts/require.js').cleanpath.read
15
15
  context = ExecJS.compile(require_js)
16
- assert_equal "1.0.2", context.eval("require.version")
16
+ assert_equal "1.0.3", context.eval("require.version")
17
17
  end
18
18
  end
19
19
 
@@ -1,5 +1,5 @@
1
1
  /** vim: et:ts=4:sw=4:sts=4
2
- * @license RequireJS 1.0.2 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
2
+ * @license RequireJS 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3
3
  * Available via the MIT or new BSD license.
4
4
  * see: http://github.com/jrburke/requirejs for details
5
5
  */
@@ -11,7 +11,7 @@
11
11
  var requirejs, require, define;
12
12
  (function () {
13
13
  //Change this version number for each release.
14
- var version = "1.0.2",
14
+ var version = "1.0.3",
15
15
  commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
16
16
  cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
17
17
  currDirRegExp = /^\.\//,
@@ -1321,11 +1321,6 @@ var requirejs, require, define;
1321
1321
  } : null]);
1322
1322
  }
1323
1323
 
1324
- //If a global jQuery is defined, check for it. Need to do it here
1325
- //instead of main() since stock jQuery does not register as
1326
- //a module via define.
1327
- jQueryCheck();
1328
-
1329
1324
  //Doing this scriptCount decrement branching because sync envs
1330
1325
  //need to decrement after resume, otherwise it looks like
1331
1326
  //loading is complete after the first dependency is fetched.
@@ -1939,10 +1934,6 @@ var requirejs, require, define;
1939
1934
  //global queue, assign them to this context.
1940
1935
  ctx.takeGlobalQueue();
1941
1936
 
1942
- //Allow for jQuery to be loaded/already in the page, and if jQuery 1.4.3,
1943
- //make sure to hold onto it for readyWait triggering.
1944
- ctx.jQueryCheck();
1945
-
1946
1937
  if (!ctx.scriptCount) {
1947
1938
  ctx.resume();
1948
1939
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requirejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000 Z
12
+ date: 2011-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70364520699460 !ruby/object:Gem::Requirement
16
+ requirement: &70284287973680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70364520699460
24
+ version_requirements: *70284287973680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70364520698260 !ruby/object:Gem::Requirement
27
+ requirement: &70284287973100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70364520698260
35
+ version_requirements: *70284287973100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70364520696860 !ruby/object:Gem::Requirement
38
+ requirement: &70284287972560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70364520696860
46
+ version_requirements: *70284287972560
47
47
  description: This gem provides RequireJS support for your Rails 3 application.
48
48
  email:
49
49
  - whitley@bangpath.org
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: -660159137027217743
125
+ hash: -2856611743431953633
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: -660159137027217743
134
+ hash: -2856611743431953633
135
135
  requirements:
136
136
  - node.js is required for 'rake assets:precompile', used to run the r.js build
137
137
  - If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17).