-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: not match \n when injecting esbuild helpers #8414
Conversation
Oh, good catch. This isn't a problem when not using a banner since the result is minified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change looks ok to me.
But the output might be slightly different from the expected output.
The comment will be inside the wrapper function instead of outside.
iife
const MyLib=function(){"use strict";var u=Object.defineProperty;var e=Object.getOwnPropertySymbols;var i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable;var c=(n,t,o)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,r=(n,t)=>{for(var o in t||(t={}))i.call(t,o)&&c(n,o,t[o]);if(e)for(var o of e(t))s.call(t,o)&&c(n,o,t[o]);return n};/*!
MayLib
*/function n(t){console.log(r({},"foo")),document.querySelector(t).textContent="It works"}return n}();
umd
(function(n,e){typeof exports=="object"&&typeof module<"u"?module.exports=e():typeof define=="function"&&define.amd?define(e):(n=typeof globalThis<"u"?globalThis:n||self,n.MyLib=e())})(this,function(){"use strict";var u=Object.defineProperty;var t=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable;var i=(n,e,o)=>e in n?u(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,f=(n,e)=>{for(var o in e||(e={}))d.call(e,o)&&i(n,o,e[o]);if(t)for(var o of t(e))s.call(e,o)&&i(n,o,e[o]);return n};/*!
MayLib
*/function n(e){console.log(f({},"foo")),document.querySelector(e).textContent="It works"}return n});
Also there are still some broken niche case. #8412 (comment)
Since it was producing invalid js before, I think it is still good to merge it.
Maybe we could detect the last |
I think it is difficult to cover all usecases by the current way using regex. without var MyLibrary = (function (exports) {
'use strict';
exports.foo = { ...'foo' }
return exports;
})({}); with var someValueInjected = Object.assign({}, { value: 'by rollup.banner' });
var MyLibrary = (function (exports) {
'use strict';
exports.foo = { ...'foo' }
return exports;
})({}); with var someValueInjected = Object.assign({}, { value: 'by rollup.banner' });
var u=Object.defineProperty;var i=Object.getOwnPropertySymbols;var a=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable;var n=(r,o,f)=>o in r?u(r,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[o]=f,t=(r,o)=>{for(var f in o||(o={}))a.call(o,f)&&n(r,f,o[f]);if(i)for(var f of i(o))c.call(o,f)&&n(r,f,o[f]);return r};var MyLibrary=function(r){"use strict";return r.foo=t({},"foo"),r}({}); without var u=Object.defineProperty;var i=Object.getOwnPropertySymbols;var a=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable;var n=(r,o,f)=>o in r?u(r,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[o]=f,t=(r,o)=>{for(var f in o||(o={}))a.call(o,f)&&n(r,f,o[f]);if(i)for(var f of i(o))c.call(o,f)&&n(r,f,o[f]);return r};var MyLibrary=function(r){"use strict";return r.foo=t({},"foo"),r}({}); IMHO, we should override |
You're right. Maybe we could cache the |
Description
fixes #8412
Additional context
A plugin like this could be used to workaround it.
But, I found that the key to the bug was not
rollupOptions.output.banner
, but\n
, the following code does not match\n
correctly:What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).