Skip to content

fix(pluginutils): keep for(const..) out of scope #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 9, 2020
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
11 changes: 7 additions & 4 deletions packages/pluginutils/src/attachScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc
if (node.type === 'VariableDeclaration') {
const { kind } = node;
const isBlockDeclaration = blockDeclarations[kind];

node.declarations.forEach((declaration: Node) => {
scope.addDeclaration(declaration, isBlockDeclaration, true);
});
// don't add const/let declarations in the body of a for loop #113
const parentType = parent ? parent.type : '';
if (!(isBlockDeclaration && /ForOfStatement/.test(parentType))) {
node.declarations.forEach((declaration: Node) => {
scope.addDeclaration(declaration, isBlockDeclaration, true);
});
}
}

let newScope: AttachedScope | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/pluginutils/src/createFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const createFilter: CreateFilter = function createFilter(include?, exclude?, opt
const pattern = getMatcherString(id, resolutionBase);
const fn = mm.matcher(pattern, { dot: true });
const result = fn(what);

return result;
}
};
Expand Down