Skip to content

Fixed referencing named function expressions#671

Merged
Perryvw merged 3 commits intomasterfrom
bugfix/named-function-expression
Jul 18, 2019
Merged

Fixed referencing named function expressions#671
Perryvw merged 3 commits intomasterfrom
bugfix/named-function-expression

Conversation

@tomblind
Copy link
Copy Markdown
Collaborator

fixes #669

const y = function x() {
    x();
}

=>

local y
y = (function()
    local function x(self)
        x(_G)
    end
    return x
end)()

const symbol = this.checker.getSymbolAtLocation(node.name);
if (symbol) {
const symbolId = this.symbolIds.get(symbol);
if (symbolId && scope.referencedSymbols.has(symbolId)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (symbolId && scope.referencedSymbols.has(symbolId)) {
if (symbolId !== undefined && scope.referencedSymbols.has(symbolId)) {

It can't happen in practice, since genSymbolIdCounter always starts from 1, but I think it's better to keep things safe when checking numbers and strings.

We probably should enable strict-boolean-expressions after we'll migrate to eslint.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'm definitely in favor of enabling strict-boolean-expressions.

@Perryvw Perryvw merged commit 9376ea5 into master Jul 18, 2019
@Perryvw Perryvw deleted the bugfix/named-function-expression branch July 18, 2019 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function expressions can have names. This is not accounted for

3 participants