diff --git a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/index.js b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/index.js index 1192d0ef019c..1c54ff43ebe7 100644 --- a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/index.js +++ b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/index.js @@ -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') { @@ -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)); + } + }, }, }; }; diff --git a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/input.js b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/input.js index d6bbdd24f835..c786dcaa90b7 100644 --- a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/input.js +++ b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/input.js @@ -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 {}; diff --git a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/output.js b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/output.js index 5e7f97a5f3db..94c0e9342ade 100644 --- a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/output.js +++ b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/no-transform/output.js @@ -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 {}; diff --git a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/input.js b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/input.js index 870914f57d7b..364f8cb0e49b 100644 --- a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/input.js +++ b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/input.js @@ -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) { diff --git a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/output.mjs b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/output.mjs index b5bc706e04c8..ee25e00a9867 100644 --- a/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/output.mjs +++ b/build-system/babel-plugins/babel-plugin-amp-mode-transformer/test/fixtures/transform-assertions/transform/output.mjs @@ -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) {