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

resolveImportMeta hook implement #1010

Open
underfin opened this issue Apr 30, 2024 · 1 comment
Open

resolveImportMeta hook implement #1010

underfin opened this issue Apr 30, 2024 · 1 comment

Comments

@underfin
Copy link
Contributor

The resolveImportMeta hook gives a way to allows to customize import.meta and import.meta.someProperty, see here
https://rollupjs.org/plugin-development/#resolveimportmeta. Here has a example for it.

function importMetaUrlCurrentModulePlugin() {
	return {
		name: 'import-meta-url-current-module',
		resolveImportMeta(property, { moduleId }) {
			if (property === 'url') {
				return `'${pathToFileURL(moduleId).href}'`;
			}
			if (property == null) {
				return `{url:'${pathToFileURL(moduleId).href}'}`;
			}
			return null;
		}
	};
}

The hook will return string code to replace original import.meta.xx. Because the rolldown using Ast to codegen. It is difficult to implement it, it need to the oxc has some ways create ast from string, we could using parse at now. If you has good ideas, please let me know.

@hyf0
Copy link
Member

hyf0 commented Apr 30, 2024

It seems to be just a short-cut of transform hook. We could support it natively, since we would have transform step in the future for DCE and variables replacement.

However, supporting this requires us to call JsCallback while transforming. I intend not to and wonder if there are other solutions/workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants