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. |
sapphi-red
left a comment
There was a problem hiding this comment.
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\ncorrectly:What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).