Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
properties: true,
wildcard: false
}, opts)
var state = {
undeclared: {},
undeclaredProps: {},
identifiers: opts.identifiers,
properties: opts.properties,
wildcard: opts.wildcard
}
// Parse if `src` is not already an AST.
var ast = typeof src === 'object' && src !== null && typeof src.type === 'string'
? src
: acorn.parse(src)
var parents = []
dash(ast, {
enter: function (node, parent) {
if (parent) parents.push(parent)
var visit = scopeVisitor[node.type]
if (visit) visit(node, state, parents)
},
leave: function (node, parent) {
var visit = bindingVisitor[node.type]
if (visit) visit(node, state, parents)
if (parent) parents.pop()
}
})
return {
function parse (src, opts) {
if (!opts) opts = {};
var acornOpts = {
ranges: defined(opts.ranges, opts.range),
locations: defined(opts.locations, opts.loc),
allowReserved: defined(opts.allowReserved, true),
allowImportExportEverywhere: defined(opts.allowImportExportEverywhere, false)
};
// Use acorn-node's defaults for the rest.
if (opts.ecmaVersion != null) acornOpts.ecmaVersion = opts.ecmaVersion;
if (opts.sourceType != null) acornOpts.sourceType = opts.sourceType;
if (opts.allowHashBang != null) acornOpts.allowHashBang = opts.allowHashBang;
if (opts.allowReturnOutsideFunction != null) acornOpts.allowReturnOutsideFunction = opts.allowReturnOutsideFunction;
return acorn.parse(src, acornOpts);
}
function onwrite (row, enc, cb) {
if (mayContainSplitRequire(row.source)) {
var ast = acorn.parse(row.source)
row.transformable = transformAst(row.source, { ast: ast })
detectSplitRequireCalls(ast, function (node) {
if (node.parent.type === 'CallExpression' && node.parent.callee === node) {
processSplitRequire(row, node.parent)
}
}, function (node) {
// Mark the thing we imported as the runtime row.
var importPath = getStringValue(node.arguments[0])
runtimeId = row.deps[importPath]
if (rowsById[runtimeId]) {
runtimeRow = rowsById[runtimeId]
}
})
}
if (runtimeId && String(row.id) === String(runtimeId)) {
module.exports = function (src) {
// If src is a Buffer, esprima will just stringify it, so we beat them to
// the punch. This avoids the problem where we're using esprima's range
// indexes -- which are meant for a UTF-16 string -- in a buffer that
// contains UTF-8 encoded text.
if (typeof src !== 'string') {
src = String(src);
}
var ast = parse(src, { range: true });
ast.body = ast.body.filter(function(node) {
return node.type !== 'EmptyStatement';
});
if (ast.body.length !== 1) return;
if (ast.body[0].type !== 'ExpressionStatement') return;
if (ast.body[0].expression.type === 'UnaryExpression') {
var body = ast.body[0].expression.argument;
} else if (ast.body[0].expression.type === 'AssignmentExpression') {
var body = ast.body[0].expression.right;
} else {
var body = ast.body[0].expression;
}
if (body.type !== 'CallExpression') return;
function onend (cb) {
if (!mayContainSplitRequire(source)) {
cb()
return
}
if (this.listenerCount('dep') === 0) {
throw new Error('split-require requires browserify v16 or up')
}
var self = this
var ast = acorn.parse(source)
detectSplitRequireCalls(ast, function (node) {
if (node.parent.type === 'CallExpression') {
var arg = node.parent.arguments[0]
self.emit('dep', arg.value)
}
})
cb()
}
}
function parse (src, opts) {
if (!opts) opts = {}
return aparse(src, opts);
}
function parse (src, opts) {
if (!opts) opts = {};
return acorn.parse(src, {
ecmaVersion: defined(opts.ecmaVersion, 9),
sourceType: defined(opts.sourceType, 'script'),
ranges: defined(opts.ranges, opts.range),
locations: defined(opts.locations, opts.loc),
allowReserved: defined(opts.allowReserved, true),
allowReturnOutsideFunction: defined(
opts.allowReturnOutsideFunction, true
),
allowImportExportEverywhere: defined(
opts.allowImportExportEverywhere, true
),
allowHashBang: defined(opts.allowHashBang, true)
});
}