Skip to content
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

Imported functions improperly scoped #578

Closed
chinedufn opened this issue Jan 10, 2020 · 1 comment · Fixed by #579
Closed

Imported functions improperly scoped #578

chinedufn opened this issue Jan 10, 2020 · 1 comment · Fixed by #579
Assignees
Milestone

Comments

@chinedufn
Copy link

chinedufn commented Jan 10, 2020

The Problem

Say we have a file that looks like this

import { myFunction } from "./dep.js"

class SomeClass {
  constructor(properties) {
    this.props = properties;
  }
  call () {
    const {myFunction} = this.props
    if (myFunction) {
      myFunction()
    } else {
      console.log('DID NOT WORK!')
    }
  }
}

let instance = new SomeClass({
  myFunction: () => {
    console.log('CORRECT FUNCTION CALLED')
  }
});

instance.call()

If you compile this script with babel everything works as expected.

If you compile and run with SWC - you'll see whatever was in dep.js

It seems like functions that are imported are not properly scoped with functions of the same name that are closer in scope to where they're being called.

To Reproduce

git clone https://github.com/tailwind/swc-issue-578
cd swc-issue-578
npm install
npm run babel # Works as expected
npm run swc # Does not work as expected
@kdy1 kdy1 added this to the v1.1.13 milestone Jan 11, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Jan 11, 2020
@kdy1 kdy1 self-assigned this Jan 11, 2020
bors bot pushed a commit that referenced this issue Jan 11, 2020
swc_ecma_transform:
 - handle a class method in child scope (Fixes #578)
kdy1 added a commit to kdy1/swc that referenced this issue Jan 11, 2020
@kdy1 kdy1 closed this as completed in #579 Jan 11, 2020
kdy1 added a commit that referenced this issue Jan 11, 2020
swc_ecma_transform:
 - handle a class method in child scope (#578)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 28, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants