Skip to content

Commit

Permalink
Add originating function info to onLocalDeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
dapetcu21 authored and pablomayobre committed May 9, 2017
1 parent ac42a00 commit fdab913
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions luaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,15 +1317,15 @@
}

// Add identifier name to the current scope if it doesnt already exist.
function scopeIdentifierName(name) {
if (options.onLocalDeclaration) options.onLocalDeclaration(name);
function scopeIdentifierName(name, data) {
if (options.onLocalDeclaration) options.onLocalDeclaration(name, data);
if (-1 !== indexOf(scopes[scopeDepth], name)) return;
scopes[scopeDepth].push(name);
}

// Add identifier to the current scope
function scopeIdentifier(node) {
scopeIdentifierName(node.name);
function scopeIdentifier(node, data) {
scopeIdentifierName(node.name, data);
attachScope(node, true);
}

Expand Down Expand Up @@ -1838,6 +1838,8 @@
var parameters = [];
expect('(');

var parameterIndex = (name && name.indexer === ':') ? 1 : 0

// The declaration has arguments
if (!consume(')')) {
// Arguments are a comma separated list of identifiers, optionally ending
Expand All @@ -1846,7 +1848,10 @@
if (Identifier === token.type) {
var parameter = parseIdentifier();
// Function parameters are local.
if (options.scope) scopeIdentifier(parameter);
if (options.scope) scopeIdentifier(parameter, {
parameterOf: name,
parameterIndex: parameterIndex
});

parameters.push(parameter);

Expand Down Expand Up @@ -1897,7 +1902,10 @@
pushLocation(marker);
name = parseIdentifier();
base = finishNode(ast.memberExpression(base, ':', name));
if (options.scope) scopeIdentifierName('self');
if (options.scope) scopeIdentifierName('self', {
parameterOf: base,
parameterIndex: 0
});
}

return base;
Expand Down

0 comments on commit fdab913

Please sign in to comment.