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

Improve module expression parsing/printing #14980

Merged
merged 8 commits into from Sep 30, 2022
Merged
Expand Up @@ -11,5 +11,5 @@
"sourcesContent": [
"const m = module { export const foo = \"foo\" };\nmodule {\n foo;\n bar;\n};\nfoo(module {});"
],
"mappings": "AAAA,MAAMA,CAAC,GAAG;EAAS,OAAO,MAAMC,GAAG,GAAG,KAAK;AAAC,CAAC;AAC7C;EACEA,GAAG;EACHC,GAAG;AACL,CAAC;AACDD,GAAG,CAAC,SAAS,CAAC"
"mappings": "AAAA,MAAMA,CAAC,GAAG;EAAS,OAAO,MAAMC,GAAG,GAAG,KAAK;AAAC,CAAC;AAC7C;EACEA,GAAG;EACHC,GAAG;AACL,CAAC;AACDD,GAAG,CAAC,QAAQ,CAAC,CAAC"
Copy link
Contributor Author

@JLHwung JLHwung Sep 30, 2022

Choose a reason for hiding this comment

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

The source map is updated because we now generate two sections module{ and } and map them respectively for the empty module expression module{}. Before this PR we map module{} as module{}.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could optimize this in the future (directly or in one of @jridgewell's packages) by merging source map segments that are adjacent both in the input and in the output.

Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be technically difficult, but I'm not sure that's better. In the last PR I marked the sourcemap for every ";".

Copy link
Member

Choose a reason for hiding this comment

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

This has to be done in Babel, because the sourcemap packages will not know whether this marking is important or not. Eg, function foo() { return bar; }, we should generate a marking for bar and } (the } is required for Chrome's debug stepping). I can't make the source map package ignore this module {} case without also ignoring that case.

}