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

fix: Fix the problem that the inline sourcemap file reports an error … #7002

Merged
merged 2 commits into from Mar 6, 2023

Conversation

limerickgds
Copy link
Contributor

@limerickgds limerickgds commented Mar 2, 2023

…when inputSourceMap is set to true

Description: When I configure InputSourcemap to true in the project, swc can only handle sourcemapurl of file type, and if I set it to inline, swc can only handle inline, otherwise an error will be reported. I hope that swc can recognize the content of sourcemapurl instead of requiring me to decide what configuration should be set based on the content in source content.Similar to babel's processing method

BREAKING CHANGE: false

Related issue (if exists):

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2023

CLA assistant check
All committers have signed the CLA.

@limerickgds limerickgds force-pushed the fix/sourcemap-config branch 2 times, most recently from 197c732 to dd7c572 Compare March 5, 2023 09:34
@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

I'm not going to accept this PR, as there's InputSourceMap::Str("inline"). Use correct option.

@kdy1 kdy1 closed this Mar 6, 2023
@limerickgds
Copy link
Contributor Author

limerickgds commented Mar 6, 2023

@kdy1 when the sourcemapUrl of the source file is file, setting InputSourceMap::Str("inline") will report an error:
failed to parse inline source map url
Caused by:
relative URL without a base

At the same time, the setting of babel does not need to distinguish between true and inline, can we be more automated

@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

when the sourcemapUrl of the source file is file, setting InputSourceMap::Str("inline") will report an error

It's expected

@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

Why do you expect external source map to work when you give "inline" as the option?

@limerickgds
Copy link
Contributor Author

limerickgds commented Mar 6, 2023

Why do you expect external source map to work when you give "inline" as the option?

I just want to be able to automatically process "file" or "inline", instead of requiring me to analyze the file and choose a type to process. When I set InputSourceMap to true, it doesn't work, I followed what you said, using InputSourceMap::Str("inline") as well.
But I re-read the implementation, maybe I can resubmit a pr, you can review some

@jridgewell
Copy link
Contributor

jridgewell commented Mar 6, 2023

I agree with @limerickgds here. It's cumbersome to know beforehand whether the file has an inline or external source map without inspecting it. We shouldn't force the user to know that, it should just be a boolean "allow input maps" or "ignore input maps" and let SWC figure out whether it's inline or external. This is how Babel does it (technically, they also allow you to manually pass a SourceMap instance, too, but that a separate feature).

@kdy1 kdy1 reopened this Mar 6, 2023
@limerickgds
Copy link
Contributor Author

limerickgds commented Mar 6, 2023

@kdy1
I'm writing a build tool to compile modules from babel to swc. There will be two types of sourcemap files in the project code, one inline sourcemap and some .map files. When I use swc transform to run, I need to paser the file to analyze the sourcemap type of the file, and then set the swc option to compile, the performance will be relatively low. It turns out that when using babel, I don't need to make such a setting, just set it to true, and babel will automatically recognize sourcemapurl to deal with this kind of problem.

@jridgewell thank you for your understanding

crates/swc/src/lib.rs Outdated Show resolved Hide resolved
crates/swc/src/lib.rs Outdated Show resolved Hide resolved
crates/swc/src/lib.rs Outdated Show resolved Hide resolved
crates/swc/src/lib.rs Show resolved Hide resolved
@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

Sorry, I didn't know that babel supports both on true.
@jridgewell Thank you!

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

swc-bump:

  • swc

@limerickgds
Copy link
Contributor Author

limerickgds commented Mar 6, 2023

Sorry, I didn't know that babel supports both on true. @jridgewell Thank you!

@kdy1 https://babeljs.io/docs/options#inputsourcemap This is the babel configuration. There is no need to support inline, I did not completely cancel the swc configuration option. Because this is a breaking change, this is left to you to decide, okay?

@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

Yes, I know and I don't want to make a breaking change at the moment, and even if it's the case, it should be another PR.

@jridgewell
Copy link
Contributor

I think for the time being, just treating the two options as equivalent and supporting both inline and external for both is the right decision.

@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

It sounds good

@kdy1 kdy1 added this to the Planned milestone Mar 6, 2023
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Can you address #7002 (comment) too?

@limerickgds
Copy link
Contributor Author

limerickgds commented Mar 6, 2023

Can you address #7002 (comment) too?

My understanding is that inputSourcemap setting true and "inline" should be the same processing flow, right?
If this is the meaning, I agree, so that the branch will not increase the complexity.

@kdy1
Copy link
Member

kdy1 commented Mar 6, 2023

Yes, exactly

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Please revert the lockfile and preset-env data

crates/swc_ecma_preset_env/data/core-js-compat/data.json Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thank you!


@kdy1 kdy1 enabled auto-merge (squash) March 6, 2023 04:24
@kdy1 kdy1 merged commit da5367b into swc-project:main Mar 6, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.38 Mar 6, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants