Skip to content

Commit

Permalink
babel: teach amp mode transformer about #core/mode (#35477)
Browse files Browse the repository at this point in the history
* babel: teach amp mode transformer about #core/mode

* jridgewell babel feedback
  • Loading branch information
samouri committed Aug 3, 2021
1 parent 60eba27 commit a6893a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
Expand Up @@ -51,7 +51,7 @@ module.exports = function ({types: t}) {
const {node} = path;
const {object: obj, property} = node;
const {callee} = obj;
const {INTERNAL_RUNTIME_VERSION} = this.opts;
const {INTERNAL_RUNTIME_VERSION: version} = this.opts;

if (callee && callee.name === 'getMode') {
if (property.name === 'test' || property.name === 'localDev') {
Expand All @@ -61,10 +61,16 @@ module.exports = function ({types: t}) {
} else if (property.name === 'minified') {
path.replaceWith(t.booleanLiteral(true));
} else if (property.name === 'version') {
path.replaceWith(t.stringLiteral(INTERNAL_RUNTIME_VERSION));
path.replaceWith(t.stringLiteral(version));
}
}
},
CallExpression(path) {
const {INTERNAL_RUNTIME_VERSION: version} = this.opts;
if (path.get('callee').referencesImport('#core/mode', 'version')) {
path.replaceWith(t.stringLiteral(version));
}
},
},
};
};
Expand Up @@ -18,6 +18,7 @@ const test = getMode().test;
const localDev = getMode().localDev;
const minified = getMode().minified;
const development = getMode().development;
const namespaceVersion = mode.version();

function getMode() {
return {};
Expand Down
Expand Up @@ -17,6 +17,7 @@ const test = getMode().test;
const localDev = getMode().localDev;
const minified = getMode().minified;
const development = getMode().development;
const namespaceVersion = mode.version();

function getMode() {
return {};
Expand Down
Expand Up @@ -15,12 +15,14 @@
*/

import { getMode } from '../../../../../../../src/mode';
import * as mode from '#core/mode';

const test = getMode().test;
const localDev = getMode().localDev;
const minified = getMode().minified;
const development = getMode().development;
const version = getMode().version;
const namespaceVersion = mode.version();

function foo() {
if (getMode().development == false) {
Expand Down
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/
import { getMode } from '../../../../../../../src/mode';
import * as mode from '#core/mode';
const test = false;
const localDev = false;
const minified = true;
const development = false;
const version = "$internalRuntimeVersion$";
const namespaceVersion = "$internalRuntimeVersion$";

function foo() {
if (false == false) {
Expand Down

0 comments on commit a6893a0

Please sign in to comment.