Skip to content
This repository was archived by the owner on Apr 16, 2019. It is now read-only.

improving detection for cjs. fixes issue #9 #10

Merged
merged 2 commits into from
Mar 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ function extract(src) {
});
throw new Error('Common JS script detected');
};
context.module = {
exports: Object.create(null)
};
context.exports = context.module.exports;
context.exports = Object.create(null);
context.module = context;


// executing the JavaScript source into a new context to avoid leaking
Expand All @@ -98,11 +96,10 @@ function extract(src) {
}
} finally {
// very dummy detection process for CommonJS modules
if (typeof context.module.exports === 'function' ||
typeof context.exports === 'function' ||
Object.keys(context.module.exports).length > 0 ||
if (typeof context.exports === 'function' ||
typeof context.exports === 'string' ||
typeof context.exports === 'number' ||
Object.keys(context.exports).length > 0 ||
Object.getPrototypeOf(context.module.exports) ||
Object.getPrototypeOf(context.exports)) {
mods.push({type: 'cjs'});
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cjs-export-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2;
1 change: 1 addition & 0 deletions test/fixtures/cjs-export-regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = new RegExp('abc');
1 change: 1 addition & 0 deletions test/fixtures/cjs-export-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports = 'something';