Skip to content

Commit

Permalink
Implement inter-module virtual global scope passing (#16800)
Browse files Browse the repository at this point in the history
- 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
cramforce committed Jul 18, 2018
1 parent 310a1bf commit 16c65fb
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 160 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build
dist
dist.3p
dist.tools
out
examples
third_party
test/coverage
Expand Down
3 changes: 2 additions & 1 deletion build-system/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ExtensionPayload() {}
/** @type {string} */
ExtensionPayload.prototype.n;

/** @type {function(!Object)} */
/** @type {function(!Object,!Object)} */
ExtensionPayload.prototype.f;

/** @type {string|undefined} */
Expand Down Expand Up @@ -99,6 +99,7 @@ window.AMP_TEST;
window.AMP_TEST_IFRAME;
window.AMP_TAG;
window.AMP = {};
window.AMP._ = {};

/** @constructor */
function AmpConfigType() {}
Expand Down
8 changes: 0 additions & 8 deletions build-system/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint "no-unused-vars": 0 */
/** @const {!Object} */
const process = {
env: {
'NODE_ENV': 'production',
},
};
55 changes: 55 additions & 0 deletions build-system/compile-wrappers.js
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 %>';
Loading

0 comments on commit 16c65fb

Please sign in to comment.