UNPKG

2.12 kBJavaScriptView Raw
1// @generated
2/**
3 * Copyright (c) 2013-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the root directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
9 *
10 *
11 * @fullSyntaxTransform
12 */
13
14'use strict';
15
16var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
17
18var path = require('path');
19
20function babelAdapter(Plugin, t, name, visitorsBuilder) {
21 if (Plugin == null) {
22 // Babel 6.
23 return visitorsBuilder(t);
24 }
25 // Babel 5.
26 var legacyT = _extends({}, t, {
27 nullLiteral: function nullLiteral() {
28 return t.literal(null);
29 },
30 valueToNode: function valueToNode(value) {
31 return t.literal(value);
32 },
33 objectProperty: function objectProperty(ident, value) {
34 return t.property('init', ident, value);
35 }
36 });
37
38 var visitors = visitorsBuilder(legacyT).visitor;
39 var legacyVisitors = {};
40 Object.keys(visitors).forEach(function (key) {
41 legacyVisitors[key] = function (node, parent, scope, state) {
42 var _this = this;
43
44 var compatPath = {
45 get: function get() {
46 return _this.get.apply(_this, arguments);
47 },
48 node: node,
49 parent: parent
50 };
51 var compatState = state.opts.compatState;
52 if (!compatState) {
53 var filename = state.opts.filename;
54 state.opts.compatState = compatState = {
55 file: {
56 code: state.code != null ? state.code : state.file.code,
57 opts: {
58 basename: path.basename(filename, path.extname(filename)),
59 filename: filename
60 }
61 },
62 isLegacyState: true
63 };
64 }
65 return visitors[key](compatPath, compatState);
66 };
67 });
68 return new Plugin(name, { visitor: legacyVisitors });
69}
70
71module.exports = babelAdapter;
\No newline at end of file