Skip to content

Commit

Permalink
accommodate strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dchester committed Mar 27, 2016
1 parent ce415ed commit 3a14450
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
1 change: 1 addition & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var Context = require('./context');
var util = require('./util');
var mapper = require('module-async-mapper');
Expand Down
1 change: 1 addition & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var _async = require('async');

module.exports = function(async) {
Expand Down
15 changes: 11 additions & 4 deletions lib/require.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var packagePath = require('package-path');
var callsite = require('callsite');
var mapper = require('module-async-mapper');
Expand All @@ -23,10 +24,16 @@ module.exports = function(async) {
var key = require.resolve(file);
if (cache[key]) return cache[key];

var nonLocal = path.dirname(key) == '.';

try {
var pkg = require(path.join(packagePath.sync(key), 'package.json'));
/* jshint unused:false */
var version = pkg.version;
// don't traverse up we only have a filename
if (!nonLocal) {
var _path = packagePath.sync(key);
var pkg = require(path.join(packagePath.sync(key), 'package.json'));
/* jshint unused:false */
var version = pkg.version;
}
} catch (e) {}

version = version || '*';
Expand All @@ -40,7 +47,7 @@ module.exports = function(async) {
// restore the cache proper
require.cache[key] = _obj;

var _hints = mapper.loadHints(file, version) || {};
var _hints = nonLocal ? {} : mapper.loadHints(file, version) || {};
for (var k in hints) _hints[k] = hints[k];
obj = async.wrap(obj, { hints: _hints });
cache[key] = obj;
Expand Down
32 changes: 9 additions & 23 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use strict";
var callsite = require('callsite');

module.exports = {

keys: function(obj) {
Expand Down Expand Up @@ -49,33 +52,16 @@ module.exports = {

props.forEach(function(prop) {
if (obj[prop] != source[prop]) {
obj[prop] = source[prop];
try {
obj[prop] = source[prop];
} catch (e) {}
}
});
},

is_generator_caller: function() {

var generatorCaller;
var fn = this.is_generator_caller;

var gnode = require.extensions['.js'].name == 'gnodeJsExtensionCompiler';

// hack to discover whether we're in a gnode/regenerator-style generator
if (
gnode &&
fn.caller &&
fn.caller.caller &&
fn.caller.caller.caller &&
fn.caller.caller.caller.toString().match(/^function invoke[\s\S]*GenStateExecuting/m)
) {
generatorCaller = true;
}

if (fn.caller && fn.caller.caller && fn.caller.caller.constructor.name == 'GeneratorFunction') {
generatorCaller = true;
}

return generatorCaller;
var typeName = callsite()[3].getTypeName();
// accommodate nodes 4 and 0.12
return typeName == '[object Generator]' || typeName == 'GeneratorFunctionPrototype';
}
};
1 change: 1 addition & 0 deletions test/unit/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var assert = require('assert');
var fs = require('fs');
var async = require('../..');
Expand Down

0 comments on commit 3a14450

Please sign in to comment.