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

import xxx from '.' will be transpiled to the root file by mistake #7417

Closed
tangye1234 opened this issue May 19, 2023 · 7 comments · Fixed by #7655
Closed

import xxx from '.' will be transpiled to the root file by mistake #7417

tangye1234 opened this issue May 19, 2023 · 7 comments · Fixed by #7655
Assignees
Labels
Milestone

Comments

@tangye1234
Copy link

tangye1234 commented May 19, 2023

Describe the bug

After swc 1.3.52,the swc will transpile the path '.' by mistake.

Command: swc src -d dist

Expect: import x from '.' should be relative path index in the same source dir
Actual: import x from '.' will be compiled to the package root file by mistake

Notice. I have a path alias and jest profile.

Input code

// root index.js
require('./dist/index.js')

----------------------

// src/index.ts

async function main() {
  import('./lib/foo')
}

main()


// src/lib/index.ts

export default {}

----------------------

// src/lib/foo.ts

import o from '.'

export default function bar() {
  console.log(o)
}

Config

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "target": "es2022",
    "parser": {
      "dynamicImport": true,
      "syntax": "typescript",
      "tsx": false,
      "decorators": false
    },
    "baseUrl": ".",
    "paths": {
      "@/*": [ "src/*" ]
    }
  },
  "exclude": ["\\btest\\b"],
  "module": {
    "type": "commonjs"
  }
}

Playground link

No response

Expected behavior

// dist/lib/foo.js

const _ = /#PURE/ _interop_require_default(require("./index.js"));
...

Actual behavior

// dist/lib/foo.js

const _ = /#PURE/ _interop_require_default(require("../../index.js"));
...

Version

1.3.53+

Additional context

No response

@tangye1234
Copy link
Author

👌 1.3.52
❌ 1.3.53+

@kdy1 kdy1 added this to the Planned milestone May 20, 2023
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 May 20, 2023
@kdy1
Copy link
Member

kdy1 commented May 22, 2023

Do you know how tsc behave?

@tangye1234
Copy link
Author

Do you know how tsc behave?

I've tested tsc and it is OK.

@tangye1234
Copy link
Author

tangye1234 commented May 22, 2023

In my project, I get three snapshots for debugging
TSC:
image

SWC@latest
image

SWC@1.3.52
image

@kdy1
Copy link
Member

kdy1 commented Jul 13, 2023

I can't repro. Please see #7655

@kdy1
Copy link
Member

kdy1 commented Jul 13, 2023

I'll test again using the testing system of swc crate

kdy1 added a commit that referenced this issue Jul 13, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.70 Jul 18, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 17, 2023

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 Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants