Can the replacement occur on the AST instead of as a string?
b12f opened this issue · 1 comments
I know this would be a major refactoring, but the current replacing functionality breaks code that feels like it should work if coming from a webpack background:
replace({
values: {
ASSET_URL: JSON.stringify('http://my-asset-url/'),
},
}),
// Code being transformed
Vue.prototype.ASSET_URL = ASSET_URL;
Here, both the key and the value are being replaced, resulting in a syntax error further down the build line:
Vue.prototype.'http://my-asset-url/' = 'http://my-asset-url/';
It would make sense if only identifiers are replaced, the same way webpack.DefinePlugin
handles this issue.
If you feel like this would be a good change but need help implementing it, hit me up.
Hi @b12f,
I do agree that using the AST instead of string replacement could be a more correct/complete
solution and resolve issues like the above. We would need to do some research to see how we might implement this.
It could potentially introduce a breaking change for those expecting both parts to be replaced. Perhaps a separate key should be used instead of values
like identifiers
, or perhaps an option could be passed.
Would you be up for proposing a design for this? If so, can you open up an RFC type issue on the github.com/rollup/org mono-repo?
We are going through a process to migrate all rollup plugins there, and new development would need to occur there.
I am going to close the issue here, but rest assured I think this is a valid concern and would to address it over on the mono-repo.
Thanks!
Wes