mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-09-12 15:54:08 +07:00
Improve code quality and write tests
This commit is contained in:
34
node_modules/babel-plugin-dynamic-import-node/lib/index.js
generated
vendored
Normal file
34
node_modules/babel-plugin-dynamic-import-node/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
exports["default"] = function (api) {
|
||||
var transformImport = (0, _utils.createDynamicImportTransform)(api);
|
||||
return {
|
||||
// NOTE: Once we drop support for Babel <= v6 we should
|
||||
// update this to import from @babel/plugin-syntax-dynamic-import.
|
||||
// https://www.npmjs.com/package/@babel/plugin-syntax-dynamic-import
|
||||
manipulateOptions: function () {
|
||||
function manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push('dynamicImport');
|
||||
}
|
||||
|
||||
return manipulateOptions;
|
||||
}(),
|
||||
visitor: {
|
||||
Import: function () {
|
||||
function Import(path) {
|
||||
transformImport(this, path);
|
||||
}
|
||||
|
||||
return Import;
|
||||
}()
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
module.exports = exports["default"];
|
53
node_modules/babel-plugin-dynamic-import-node/lib/utils.js
generated
vendored
Normal file
53
node_modules/babel-plugin-dynamic-import-node/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getImportSource = getImportSource;
|
||||
exports.createDynamicImportTransform = createDynamicImportTransform;
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function getImportSource(t, callNode) {
|
||||
var importArguments = callNode.arguments;
|
||||
|
||||
var _importArguments = _slicedToArray(importArguments, 1),
|
||||
importPath = _importArguments[0];
|
||||
|
||||
var isString = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
|
||||
|
||||
if (isString) {
|
||||
t.removeComments(importPath);
|
||||
return importPath;
|
||||
}
|
||||
|
||||
return t.templateLiteral([t.templateElement({
|
||||
raw: '',
|
||||
cooked: ''
|
||||
}), t.templateElement({
|
||||
raw: '',
|
||||
cooked: ''
|
||||
}, true)], importArguments);
|
||||
}
|
||||
|
||||
function createDynamicImportTransform(_ref) {
|
||||
var template = _ref.template,
|
||||
t = _ref.types;
|
||||
var buildImport = template('Promise.resolve().then(() => MODULE)');
|
||||
return function (context, path) {
|
||||
var requireCall = t.callExpression(t.identifier('require'), [getImportSource(t, path.parent)]);
|
||||
var _context$opts$noInter = context.opts.noInterop,
|
||||
noInterop = _context$opts$noInter === undefined ? false : _context$opts$noInter;
|
||||
var MODULE = noInterop === true ? requireCall : t.callExpression(context.addHelper('interopRequireWildcard'), [requireCall]);
|
||||
var newImport = buildImport({
|
||||
MODULE: MODULE
|
||||
});
|
||||
path.parentPath.replaceWith(newImport);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user