{"size": 1319, "ext": "js", "max_stars_repo_path": "build-system/babel-plugins/babel-plugin-transform-amp-extension-call/index.js", "max_stars_repo_name": "lytics/amphtml", "max_stars_repo_stars_event_min_datetime": "2019-02-04T17:37:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T08:20:06.000Z", "max_issues_repo_path": "build-system/babel-plugins/babel-plugin-transform-amp-extension-call/index.js", "max_issues_repo_name": "lytics/amphtml", "max_issues_repo_issues_event_min_datetime": "2020-04-01T20:14:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-15T22:12:10.000Z", "max_forks_repo_path": "build-system/babel-plugins/babel-plugin-transform-amp-extension-call/index.js", "max_forks_repo_name": "lytics/amphtml", "max_forks_repo_forks_event_min_datetime": "2020-05-06T20:15:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T20:21:17.000Z"}
{"max_stars_count": 20, "max_issues_count": 28, "max_forks_count": 3, "avg_line_length": 31.4047619048, "max_line_length": 76, "alphanum_fraction": 0.6231993935}
/**
 * Copyright 2019 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.
 */

module.exports = function (babel) {
  const {types: t} = babel;
  return {
    name: 'transform-amp-extension-call',
    visitor: {
      CallExpression(path) {
        const {node} = path;
        const {callee} = node;
        if (
          t.isIdentifier(callee.object, {name: 'AMP'}) &&
          t.isIdentifier(callee.property, {name: 'extension'})
        ) {
          const func = node.arguments[node.arguments.length - 1];

          const IIFE = t.expressionStatement(
            t.callExpression(func, [
              t.memberExpression(t.identifier('self'), t.identifier('AMP')),
            ])
          );
          path.replaceWith(IIFE);
        }
      },
    },
  };
};
