Use remapping to remap minified sourcemap into source code#37238
Use remapping to remap minified sourcemap into source code#37238jridgewell merged 11 commits intoampproject:mainfrom
Conversation
samouri
left a comment
There was a problem hiding this comment.
Given we believe this to be a terser bug, lets file an issue
|
Testing this out locally, and I don't think this solves the issue. After doing more digging, I think I know the culprit of incorrect identifiers.
Potential fixes:
|
|
Discussed potential solution with @jridgewell. Conclusion was to get each sourcemap separately. Then apply remapping to them all. Babel will produces 100s of sourcemaps, esbuild 1, and terser 1. Remapping can handle collating all of them. We can remove this complication once esbuild supports outputting sourcemaps with names. |
|
Hey @erwinmombay! These files were changed: Hey @rsimha! These files were changed: |
f95639c to
bac4002
Compare
jridgewell
left a comment
There was a problem hiding this comment.
Ready for review.
| return; | ||
| } | ||
| key.replaceWith(t.identifier(`${name}AMP_PRIVATE_`)); | ||
| key.replaceWith(t.inherits(t.identifier(`${name}AMP_PRIVATE_`), node)); |
There was a problem hiding this comment.
When we replaced the node, it forgets what the original name is. We have to use t.inherits to pass the data from the original Identifier to the new Identifier.
| transformPromise.then((contents) => fs.outputFile(filepath, contents)); | ||
|
|
||
| const filepath = path.join(this.cacheDir, this.key_(hash)); | ||
| transformPromise.then((contents) => fs.outputJson(filepath, contents)); |
There was a problem hiding this comment.
This changes TransformCache to use JSON so that we can persist both the transformed code and the sourcemap in the cache directory.
Some build targets have directory parts in the `destFilename` as well as the `destDir`. We need the full dest directory path for remapping to work.
samouri
left a comment
There was a problem hiding this comment.
Nice work! I tested the fix, and sourcemaps lgtm. I checked both the names field as well as manually looked at the mapping in a visualizer.
| } | ||
|
|
||
| if (!name.endsWith('_')) { | ||
| if (!name.endsWith('_') || name === '__proto__') { |
There was a problem hiding this comment.
FMI: how did you find the proto bug? Also how isn't this breaking prod? I'm assuming we only set proto to null ever?
There was a problem hiding this comment.
I saw it in the names list as __proto___AMP_PRIVATE_
build-system/babel-plugins/babel-plugin-transform-rename-privates/index.js
Show resolved
Hide resolved
| /** | ||
| * Used to cache babel transforms done by esbuild. | ||
| * @const {TransformCache} | ||
| * @type {TransformCache<!CacheMessageDef>} |
There was a problem hiding this comment.
We no longer need the !, since TS assumes nonnullable (this isn't checked via closure)
| * @type {TransformCache<!CacheMessageDef>} | |
| * @type {TransformCache<CacheMessageDef>} |
There was a problem hiding this comment.
one more thing! pretty sure you can add @readonly for variables meant to be const (docs)
There was a problem hiding this comment.
Due to rebase issue, I'm going to fix this in a followup PR.
There was a problem hiding this comment.
@readonly didn't actually work for me when I tested it out. Maybe only for class props
…nce-attr-to-hero-img * 'main' of github.com:ampproject/amphtml: (525 commits) mathml storybook: supply missing component definition. (#37326) storybook: Iframe --> BentoIframe (#37327) 🖍 [Story system layer] New ad badge (#37311) 🐛 [amp story] Replay/next page button bug fix (#37316) 🚀 [Story performance] Remove affiliate links (#37280) Compiler: Add amp-carousel-0.1 to the builder map (#37308) ⏪ [Story system layer] Audio icon disappears when story has background audio (#37314) 🚀 [Story performance] Remove story access (#37281) Fix remapping esbuild output on Windows (#37312) 🐛 adds in correct weight for amp-story-product-tag text (#37188) typechecking carousel: remove shame files (#37213) Use remapping to remap minified sourcemap into source code (#37238) SwG Release 0.1.22.199 (#37310) 🐛 Adds microsoft-edge protocol (#34168) Sync for validator cpp engine and cpp htmlparser (#37292) ✨ amp-story-shopping Updated currency with product price and correct Localized currency (#37249) ✨[Smartadserver ad extension] Implement support for Fast Fetch (#36991) Remove client-side-experiments-config.json from this repo (#37304) 🚮 Remove closure compiler logic from build-system. (#37296) 🌐 Added RTL ordering i18n for amp story shopping tag (#37252) ...
For some reason, Terser is using the already changed property names instead of the original names (which exist inside the babel sourcemap). Instead of letting Terser do the remapping, we'll use our
remappinglibrary to remap our minified output maps into real source code.