-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement inter-module virtual global scope passing (#16800)
- This allows the `renamePrefixPrefix` option to actually work. - Passes the intermediate bundle info to the extension wrapper. - Renames modules so that they have the same names as production JS files. - Factors wrapper into common module shared between legacy and new compilation. - Removes the notion of the base bundle, because with that we need 2 wrappers in the main binary which is bad (e.g. for source maps). - This is also a code size win. Main binary now at 214K.
- Loading branch information
Showing
13 changed files
with
274 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ build | |
dist | ||
dist.3p | ||
dist.tools | ||
out | ||
examples | ||
third_party | ||
test/coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2018 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const {VERSION} = require('./internal-version'); | ||
|
||
// If there is a sync JS error during initial load, | ||
// at least try to unhide the body. | ||
exports.mainBinary = 'var global=self;self.AMP=self.AMP||[];' + | ||
'try{(function(_){<%= contents %>})(AMP._={})}catch(e){' + | ||
'setTimeout(function(){' + | ||
'var s=document.body.style;' + | ||
's.opacity=1;' + | ||
's.visibility="visible";' + | ||
's.animation="none";' + | ||
's.WebkitAnimation="none;"},1000);throw e};'; | ||
|
||
exports.extension = function(name, loadPriority, intermediateDeps) { | ||
let deps = ''; | ||
if (intermediateDeps) { | ||
deps = 'i:'; | ||
function quote(s) { | ||
return `"${s}"`; | ||
} | ||
if (intermediateDeps.length == 1) { | ||
deps += quote(intermediateDeps[0]); | ||
} else { | ||
deps += `[${intermediateDeps.map(quote).join(',')}]`; | ||
} | ||
deps += ','; | ||
} | ||
let priority = ''; | ||
if (loadPriority) { | ||
if (loadPriority != 'high') { | ||
throw new Error('Unsupported loadPriority: ' + loadPriority); | ||
} | ||
priority = 'p:"high",'; | ||
} | ||
return `(self.AMP=self.AMP||[]).push({n:"${name}",${priority}${deps}` + | ||
`v:"${VERSION}",f:(function(AMP,_){<%= contents %>\n})});`; | ||
}; | ||
|
||
exports.none = '<%= contents %>'; |
Oops, something went wrong.