| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,13 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Support `exports` as an alternative to `module.exports`. | ||
| 4 | + | ||
| 5 | + function Buffer() {}; | ||
| 6 | + | ||
| 7 | + exports.Buffer = Buffer; | ||
| 8 | + exports.fn1 = function fn1() {}; | ||
| 9 | + | ||
| 10 | + var fn2 = exports.fn2 = function() {}; | ||
| 11 | + | ||
| 12 | + function fn3() {}; | ||
| 13 | + exports.fn3 = fn3; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + { | ||
| 2 | + "exports.Buffer": "exports.js#L5", | ||
| 3 | + "exports.fn1": "exports.js#L8", | ||
| 4 | + "exports.fn2": "exports.js#L10", | ||
| 5 | + "exports.fn3": "exports.js#L12" | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,6 +61,7 @@ process.argv.slice(2).forEach((file) => { | |||
| 61 | 61 | ||
| 62 | 62 | // Scan for exports. | |
| 63 | 63 | const exported = { constructors: [], identifiers: [] }; | |
| 64 | + const indirect = {}; | ||
| 64 | 65 | program.forEach((statement) => { | |
| 65 | 66 | if (statement.type === 'ExpressionStatement') { | |
| 66 | 67 | const expr = statement.expression; | |
@@ -69,35 +70,52 @@ process.argv.slice(2).forEach((file) => { | |||
| 69 | 70 | let lhs = expr.left; | |
| 70 | 71 | if (expr.left.object.type === 'MemberExpression') lhs = lhs.object; | |
| 71 | 72 | if (lhs.type !== 'MemberExpression') return; | |
| 72 | - if (lhs.object.name !== 'module') return; | ||
| 73 | - if (lhs.property.name !== 'exports') return; | ||
| 74 | - | ||
| 75 | - let rhs = expr.right; | ||
| 76 | - while (rhs.type === 'AssignmentExpression') rhs = rhs.right; | ||
| 77 | - | ||
| 78 | - if (rhs.type === 'NewExpression') { | ||
| 79 | - exported.constructors.push(rhs.callee.name); | ||
| 80 | - } else if (rhs.type === 'ObjectExpression') { | ||
| 81 | - rhs.properties.forEach((property) => { | ||
| 82 | - if (property.value.type === 'Identifier') { | ||
| 83 | - exported.identifiers.push(property.value.name); | ||
| 84 | - if (/^[A-Z]/.test(property.value.name[0])) { | ||
| 85 | - exported.constructors.push(property.value.name); | ||
| 86 | - } | ||
| 73 | + if (lhs.object.name === 'exports') { | ||
| 74 | + const name = lhs.property.name; | ||
| 75 | + if (expr.right.type === 'FunctionExpression') { | ||
| 76 | + definition[`${basename}.${name}`] = | ||
| 77 | + `${link}#L${statement.loc.start.line}`; | ||
| 78 | + } else if (expr.right.type === 'Identifier') { | ||
| 79 | + if (expr.right.name === name) { | ||
| 80 | + indirect[name] = `${basename}.${name}`; | ||
| 87 | 81 | } | |
| 88 | - }); | ||
| 89 | - } else if (rhs.type === 'Identifier') { | ||
| 90 | - exported.identifiers.push(rhs.name); | ||
| 82 | + } else { | ||
| 83 | + exported.identifiers.push(name); | ||
| 84 | + } | ||
| 85 | + } else if (lhs.object.name === 'module') { | ||
| 86 | + if (lhs.property.name !== 'exports') return; | ||
| 87 | + | ||
| 88 | + let rhs = expr.right; | ||
| 89 | + while (rhs.type === 'AssignmentExpression') rhs = rhs.right; | ||
| 90 | + | ||
| 91 | + if (rhs.type === 'NewExpression') { | ||
| 92 | + exported.constructors.push(rhs.callee.name); | ||
| 93 | + } else if (rhs.type === 'ObjectExpression') { | ||
| 94 | + rhs.properties.forEach((property) => { | ||
| 95 | + if (property.value.type === 'Identifier') { | ||
| 96 | + exported.identifiers.push(property.value.name); | ||
| 97 | + if (/^[A-Z]/.test(property.value.name[0])) { | ||
| 98 | + exported.constructors.push(property.value.name); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + }); | ||
| 102 | + } else if (rhs.type === 'Identifier') { | ||
| 103 | + exported.identifiers.push(rhs.name); | ||
| 104 | + } | ||
| 91 | 105 | } | |
| 92 | 106 | } else if (statement.type === 'VariableDeclaration') { | |
| 93 | 107 | for (const decl of statement.declarations) { | |
| 94 | 108 | let init = decl.init; | |
| 95 | 109 | while (init && init.type === 'AssignmentExpression') init = init.left; | |
| 96 | 110 | if (!init || init.type !== 'MemberExpression') continue; | |
| 97 | - if (init.object.name !== 'module') continue; | ||
| 98 | - if (init.property.name !== 'exports') continue; | ||
| 99 | - exported.constructors.push(decl.id.name); | ||
| 100 | - definition[decl.id.name] = `${link}#L${statement.loc.start.line}`; | ||
| 111 | + if (init.object.name === 'exports') { | ||
| 112 | + definition[`${basename}.${init.property.name}`] = | ||
| 113 | + `${link}#L${statement.loc.start.line}`; | ||
| 114 | + } else if (init.object.name === 'module') { | ||
| 115 | + if (init.property.name !== 'exports') continue; | ||
| 116 | + exported.constructors.push(decl.id.name); | ||
| 117 | + definition[decl.id.name] = `${link}#L${statement.loc.start.line}`; | ||
| 118 | + } | ||
| 101 | 119 | } | |
| 102 | 120 | } | |
| 103 | 121 | }); | |
@@ -107,10 +125,8 @@ process.argv.slice(2).forEach((file) => { | |||
| 107 | 125 | // ClassName.foo = ...; | |
| 108 | 126 | // ClassName.prototype.foo = ...; | |
| 109 | 127 | // function Identifier(...) {...}; | |
| 110 | - // class Foo {...} | ||
| 128 | + // class Foo {...}; | ||
| 111 | 129 | // | |
| 112 | - const indirect = {}; | ||
| 113 | - | ||
| 114 | 130 | program.forEach((statement) => { | |
| 115 | 131 | if (statement.type === 'ExpressionStatement') { | |
| 116 | 132 | const expr = statement.expression; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments