1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | 'use strict';
|
15 |
|
16 | var _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 |
|
18 | var path = require('path');
|
19 |
|
20 | function babelAdapter(Plugin, t, name, visitorsBuilder) {
|
21 | if (Plugin == null) {
|
22 |
|
23 | return visitorsBuilder(t);
|
24 | }
|
25 |
|
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 |
|
71 | module.exports = babelAdapter; |
\ | No newline at end of file |