initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

3
node_modules/babel-preset-fbjs/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
__tests__
node_modules
npm-debug.log

46
node_modules/babel-preset-fbjs/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,46 @@
## [Unreleased]
## [2.1.4] - 2017-06-16
### Fixed
- `inline-requires` works with named imports and no longer leaks paths after use.
## [2.1.3] - 2017-06-08
### Fixed
- `inline-requires` will stop unintentionally using Flow declarations as bindings.
## [2.1.2] - 2017-05-02
### Fixed
- `inline-requires` works better with other transforms (eg 'babel-plugin-transform-es2015-modules-commonjs').
## [2.1.1] - 2017-04-26
### Fixed
- `inline-requires` transform properly handles identifiers within functions whose definitions appear earlier in the file than the require call.
## [2.1.0] - 2016-10-07
### Added
- Modules using `__DEV__` will have the declaration inlined for `.js.flow` file generation.
### Fixed
- `typeof` imports are properly rewritten.
## [2.0.0] - 2016-05-25
### Added
- More syntaxes are parsed for `.js.flow` file generation: `babel-plugin-syntax-class-properties` & `babel-plugin-syntax-jsx`
- More transforms are applied for ES2015 and React support: `babel-plugin-transform-es2015-function-name`, `babel-plugin-transform-react-display-name`, `babel-plugin-transform-react-jsx`
- New custom transform to convert `Object.assign` to `require('object-assign')`, ensuring the use of a ponyfill that checks for a spec-compliant `Object.assign`.
### Fixed
- Type imports are properly rewritten with the rewrite-modules transform.
## [1.0.0] - 2016-04-28
### Added
- Initial release as a separate module.

50
node_modules/babel-preset-fbjs/README.md generated vendored Normal file
View File

@@ -0,0 +1,50 @@
# babel-preset-fbjs
> Babel preset for Facebook projects.
## Install
```sh
$ npm install --save-dev babel-preset-fbjs
```
## Basic Usage
### Via `.babelrc`
**.babelrc**
```json
{
"presets": ["fbjs"]
}
```
### Via CLI
```sh
$ babel script.js --presets fbjs
```
### Via Node API
```javascript
require('babel-core').transform('code', {
presets: ['fbjs']
});
```
## Advanced Usage
```javascript
require('babel-core').transform('code', {
presets: [
require('babel-preset-fbjs/configure')({
autoImport: true,
inlineRequires: false,
rewriteModules: {},
stripDEV: false
}
]
});
```

101
node_modules/babel-preset-fbjs/configure.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/* eslint-disable indent */
module.exports = function(options) {
options = Object.assign({
autoImport: true,
inlineRequires: process.env.NODE_ENV === 'test',
objectAssign: true,
rewriteModules: null, // {map: ?{[module: string]: string}, prefix: ?string}
stripDEV: false,
target: 'js',
}, options);
if (options.target !== 'js' && options.target !== 'flow') {
throw new Error('options.target must be one of "js" or "flow".');
}
// Always enable these. These will overlap with some transforms (which also
// enable the corresponding syntax, eg Flow), but these are the minimal
// additional syntaxes that need to be enabled so we can minimally transform
// to .js.flow files as well.
let presetSets = [
[
require('babel-plugin-syntax-class-properties'),
require('babel-plugin-syntax-flow'),
require('babel-plugin-syntax-jsx'),
require('babel-plugin-syntax-trailing-function-commas'),
require('babel-plugin-syntax-object-rest-spread'),
options.autoImport ? require('./plugins/auto-importer') : null,
options.rewriteModules ?
[require('./plugins/rewrite-modules'), options.rewriteModules || {}] :
null,
],
[
options.inlineRequires ? require('./plugins/inline-requires') : null,
options.stripDEV ? require('./plugins/dev-expression') : null,
]
];
// We only want to add declarations for flow transforms and not for js. So we
// have to do this separate from above.
if (options.target === 'flow') {
presetSets[0].push(require('./plugins/dev-declaration'));
}
// Enable everything else for js.
if (options.target === 'js') {
presetSets[0] = presetSets[0].concat([
require('babel-plugin-transform-es2015-template-literals'),
require('babel-plugin-transform-es2015-literals'),
require('babel-plugin-transform-es2015-function-name'),
require('babel-plugin-transform-es2015-arrow-functions'),
require('babel-plugin-transform-es2015-block-scoped-functions'),
require('babel-plugin-transform-class-properties'),
[require('babel-plugin-transform-es2015-classes'), {loose: true}],
require('babel-plugin-transform-es2015-object-super'),
require('babel-plugin-transform-es2015-shorthand-properties'),
require('babel-plugin-transform-es2015-computed-properties'),
require('babel-plugin-transform-es2015-for-of'),
require('babel-plugin-check-es2015-constants'),
[require('babel-plugin-transform-es2015-spread'), {loose: true}],
require('babel-plugin-transform-es2015-parameters'),
[require('babel-plugin-transform-es2015-destructuring'), {loose: true}],
require('babel-plugin-transform-es2015-block-scoping'),
require('babel-plugin-transform-es2015-modules-commonjs'),
require('babel-plugin-transform-es3-member-expression-literals'),
require('babel-plugin-transform-es3-property-literals'),
require('babel-plugin-transform-flow-strip-types'),
require('babel-plugin-transform-object-rest-spread'),
require('babel-plugin-transform-react-display-name'),
require('babel-plugin-transform-react-jsx'),
// Don't enable this plugin unless we're compiling JS, even if the option is true
options.objectAssign ? require('./plugins/object-assign') : null,
]);
}
// Use two passes to circumvent bug with auto-importer and inline-requires.
const passPresets = presetSets.map(function(plugins) {
return {
plugins: plugins.filter(function(plugin) {
return plugin != null;
}),
};
});
return {
passPerPreset: true,
presets: passPresets,
};
};

10
node_modules/babel-preset-fbjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
module.exports = require('./configure')({});

130
node_modules/babel-preset-fbjs/package.json generated vendored Normal file
View File

@@ -0,0 +1,130 @@
{
"_args": [
[
"babel-preset-fbjs@^2.1.2",
"/home/bernhard/freifunk-app/node_modules/fbjs-scripts"
]
],
"_from": "babel-preset-fbjs@>=2.1.2 <3.0.0",
"_id": "babel-preset-fbjs@2.1.4",
"_inCache": true,
"_installable": true,
"_location": "/babel-preset-fbjs",
"_nodeVersion": "7.9.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/babel-preset-fbjs-2.1.4.tgz_1497625813254_0.6485950043424964"
},
"_npmUser": {
"email": "briandavidvaughn@gmail.com",
"name": "brianvaughn"
},
"_npmVersion": "5.0.3",
"_phantomChildren": {},
"_requested": {
"name": "babel-preset-fbjs",
"raw": "babel-preset-fbjs@^2.1.2",
"rawSpec": "^2.1.2",
"scope": null,
"spec": ">=2.1.2 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/fbjs-scripts",
"/metro"
],
"_resolved": "https://registry.npmjs.org/babel-preset-fbjs/-/babel-preset-fbjs-2.1.4.tgz",
"_shasum": "22f358e6654073acf61e47a052a777d7bccf03af",
"_shrinkwrap": null,
"_spec": "babel-preset-fbjs@^2.1.2",
"_where": "/home/bernhard/freifunk-app/node_modules/fbjs-scripts",
"bugs": {
"url": "https://github.com/facebook/fbjs/issues"
},
"dependencies": {
"babel-plugin-check-es2015-constants": "^6.8.0",
"babel-plugin-syntax-class-properties": "^6.8.0",
"babel-plugin-syntax-flow": "^6.8.0",
"babel-plugin-syntax-jsx": "^6.8.0",
"babel-plugin-syntax-object-rest-spread": "^6.8.0",
"babel-plugin-syntax-trailing-function-commas": "^6.8.0",
"babel-plugin-transform-class-properties": "^6.8.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.8.0",
"babel-plugin-transform-es2015-block-scoping": "^6.8.0",
"babel-plugin-transform-es2015-classes": "^6.8.0",
"babel-plugin-transform-es2015-computed-properties": "^6.8.0",
"babel-plugin-transform-es2015-destructuring": "^6.8.0",
"babel-plugin-transform-es2015-for-of": "^6.8.0",
"babel-plugin-transform-es2015-function-name": "^6.8.0",
"babel-plugin-transform-es2015-literals": "^6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.8.0",
"babel-plugin-transform-es2015-object-super": "^6.8.0",
"babel-plugin-transform-es2015-parameters": "^6.8.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.8.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
"babel-plugin-transform-es3-property-literals": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-plugin-transform-react-display-name": "^6.8.0",
"babel-plugin-transform-react-jsx": "^6.8.0"
},
"description": "Babel preset for Facebook projects.",
"devDependencies": {
"babel-core": "^6.8.0",
"jest-cli": "^17.0.3"
},
"directories": {},
"dist": {
"integrity": "sha512-6XVQwlO26V5/0P9s2Eje8Epqkv/ihaMJ798+W98ktOA8fCn2IFM6wEi7CDW3fTbKFZ/8fDGvGZH01B6GSuNiWA==",
"shasum": "22f358e6654073acf61e47a052a777d7bccf03af",
"tarball": "https://registry.npmjs.org/babel-preset-fbjs/-/babel-preset-fbjs-2.1.4.tgz"
},
"homepage": "https://github.com/facebook/fbjs#readme",
"jest": {
"modulePathIgnorePatterns": [
"/node_modules/"
],
"rootDir": "",
"testPathDirs": [
"<rootDir>"
]
},
"license": "BSD-3-Clause",
"main": "index.js",
"maintainers": [
{
"name": "brianvaughn",
"email": "briandavidvaughn@gmail.com"
},
{
"name": "fb",
"email": "opensource+npm@fb.com"
},
{
"name": "spicyj",
"email": "ben@benalpert.com"
},
{
"name": "yungsters",
"email": "yungsters@gmail.com"
},
{
"name": "zpao",
"email": "paul@oshannessy.com"
}
],
"name": "babel-preset-fbjs",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/fbjs.git"
},
"scripts": {
"test": "NODE_ENV=test jest"
},
"version": "2.1.4"
}

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const MODULES = [
// Local Promise implementation.
'Promise',
];
/**
* Automatically imports a module if its identifier is in the AST.
*/
module.exports = function autoImporter(babel) {
const t = babel.types;
function isAppropriateModule(name, scope, state) {
const autoImported = state.autoImported;
return MODULES.indexOf(name) !== -1
&& !autoImported.hasOwnProperty(name)
&& !scope.hasBinding(name, /*skip globals*/true);
}
return {
pre: function() {
// Cache per file to avoid calling `scope.hasBinding` several
// times for the same module, which has already been auto-imported.
this.autoImported = {};
},
visitor: {
ReferencedIdentifier: function(path) {
const node = path.node;
const scope = path.scope;
if (!isAppropriateModule(node.name, scope, this)) {
return;
}
scope.getProgramParent().push({
id: t.identifier(node.name),
init: t.callExpression(
t.identifier('require'),
[t.stringLiteral(node.name)]
),
});
this.autoImported[node.name] = true;
},
},
};
};

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = function(babel) {
const t = babel.types;
// We can't construct an identifier with a type annotation all in 1 fell swoop
// so we have to create & mutate, then pass along.
const DEV_IDENTIFIER = t.identifier('__DEV__');
DEV_IDENTIFIER.typeAnnotation = t.typeAnnotation(t.booleanTypeAnnotation());
const DEV_DECLARATION = t.declareVariable(
DEV_IDENTIFIER
);
return {
pre() {
this.usesDEV = false;
},
visitor: {
Identifier: {
enter(path, file) {
this.usesDEV = this.usesDEV || path.isIdentifier({name: '__DEV__'});
},
},
Program: {
exit(path, file) {
if (!this.usesDEV) {
return;
}
// Add the declaration at the front of the body if we've used __DEV__.
path.node.body.unshift(DEV_DECLARATION);
},
},
},
};
};

View File

@@ -0,0 +1,131 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = function(babel) {
var t = babel.types;
var SEEN_SYMBOL = Symbol();
var DEV_EXPRESSION = t.binaryExpression(
'!==',
t.memberExpression(
t.memberExpression(
t.identifier('process'),
t.identifier('env'),
false
),
t.identifier('NODE_ENV'),
false
),
t.stringLiteral('production')
);
return {
visitor: {
Identifier: {
enter: function(path) {
// Do nothing when testing
if (process.env.NODE_ENV === 'test') {
return;
}
// replace __DEV__ with process.env.NODE_ENV !== 'production'
if (path.isIdentifier({name: '__DEV__'})) {
path.replaceWith(DEV_EXPRESSION);
}
},
},
CallExpression: {
exit: function(path) {
var node = path.node;
// Do nothing when testing
if (process.env.NODE_ENV === 'test') {
return;
}
// Ignore if it's already been processed
if (node[SEEN_SYMBOL]) {
return;
}
if (path.get('callee').isIdentifier({name: 'invariant'})) {
// Turns this code:
//
// invariant(condition, argument, argument);
//
// into this:
//
// if (!condition) {
// if ("production" !== process.env.NODE_ENV) {
// invariant(false, argument, argument);
// } else {
// invariant(false);
// }
// }
//
// Specifically this does 2 things:
// 1. Checks the condition first, preventing an extra function call.
// 2. Adds an environment check so that verbose error messages aren't
// shipped to production.
// The generated code is longer than the original code but will dead
// code removal in a minifier will strip that out.
var condition = node.arguments[0];
var devInvariant = t.callExpression(
node.callee,
[t.booleanLiteral(false)].concat(node.arguments.slice(1))
);
devInvariant[SEEN_SYMBOL] = true;
var prodInvariant = t.callExpression(
node.callee,
[t.booleanLiteral(false)]
);
prodInvariant[SEEN_SYMBOL] = true;
path.replaceWith(t.ifStatement(
t.unaryExpression('!', condition),
t.blockStatement([
t.ifStatement(
DEV_EXPRESSION,
t.blockStatement([
t.expressionStatement(devInvariant),
]),
t.blockStatement([
t.expressionStatement(prodInvariant),
])
),
])
));
} else if (path.get('callee').isIdentifier({name: 'warning'})) {
// Turns this code:
//
// warning(condition, argument, argument);
//
// into this:
//
// if ("production" !== process.env.NODE_ENV) {
// warning(condition, argument, argument);
// }
//
// The goal is to strip out warning calls entirely in production. We
// don't need the same optimizations for conditions that we use for
// invariant because we don't care about an extra call in __DEV__
node[SEEN_SYMBOL] = true;
path.replaceWith(t.ifStatement(
DEV_EXPRESSION,
t.blockStatement([
t.expressionStatement(
node
),
])
));
}
},
},
},
};
};

View File

@@ -0,0 +1,158 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* This transform inlines top-level require(...) aliases with to enable lazy
* loading of dependencies.
*
* Continuing with the example above, this replaces all references to `Foo` in
* the module to `require('ModuleFoo')`.
*/
module.exports = function fbjsInlineRequiresTransform(babel) {
var t = babel.types;
function buildRequireCall(name, inlineRequiredDependencyMap) {
var call = t.callExpression(
t.identifier('require'),
[t.stringLiteral(inlineRequiredDependencyMap.get(name))]
);
call.new = true;
return call;
}
function inlineRequire(path, inlineRequiredDependencyMap, identifierToPathsMap) {
var node = path.node;
if (path.isReferenced()) {
path.replaceWith(buildRequireCall(node.name, inlineRequiredDependencyMap));
var paths = identifierToPathsMap.get(node.name);
if (paths) {
paths.delete(path);
}
}
}
return {
visitor: {
Program(_, state) {
/**
* Map of require(...) aliases to module names.
*
* `Foo` is an alias for `require('ModuleFoo')` in the following example:
* var Foo = require('ModuleFoo');
*/
state.inlineRequiredDependencyMap = new Map();
/**
* Map of variable names that have not yet been inlined.
* We track them in case we later remove their require()s,
* In which case we have to come back and update them.
*/
state.identifierToPathsMap = new Map();
},
/**
* Collect top-level require(...) aliases.
*/
CallExpression: function(path, state) {
var node = path.node;
if (isTopLevelRequireAlias(path)) {
var varName = path.parent.id.name;
var moduleName = node.arguments[0].value;
var inlineRequiredDependencyMap = state.inlineRequiredDependencyMap;
var identifierToPathsMap = state.identifierToPathsMap;
inlineRequiredDependencyMap.set(varName, moduleName);
// If we removed require() statements for variables we've already seen,
// We need to do a second pass on this program to replace them with require().
var maybePaths = identifierToPathsMap.get(varName);
if (maybePaths) {
maybePaths.forEach(path =>
inlineRequire(path, inlineRequiredDependencyMap, identifierToPathsMap));
maybePaths.delete(varName);
}
// Remove the declaration.
path.parentPath.parentPath.remove();
// And the associated binding in the scope.
path.scope.removeBinding(varName);
}
},
/**
* Inline require(...) aliases.
*/
Identifier: function(path, state) {
var node = path.node;
var parent = path.parent;
var scope = path.scope;
var identifierToPathsMap = state.identifierToPathsMap;
if (!shouldInlineRequire(node, scope, state.inlineRequiredDependencyMap)) {
// Monitor this name in case we later remove its require().
// This won't happen often but if it does we need to come back and update here.
var paths = identifierToPathsMap.get(node.name);
if (paths) {
paths.add(path);
} else {
identifierToPathsMap.set(node.name, new Set([path]));
}
return;
}
if (
parent.type === 'AssignmentExpression' &&
path.isBindingIdentifier() &&
!scope.bindingIdentifierEquals(node.name, node)
) {
throw new Error(
'Cannot assign to a require(...) alias, ' + node.name +
'. Line: ' + node.loc.start.line + '.'
);
}
inlineRequire(path, state.inlineRequiredDependencyMap, identifierToPathsMap);
},
},
};
};
function isTopLevelRequireAlias(path) {
return (
isRequireCall(path.node) &&
path.parent.type === 'VariableDeclarator' &&
path.parent.id.type === 'Identifier' &&
path.parentPath.parent.type === 'VariableDeclaration' &&
path.parentPath.parent.declarations.length === 1 &&
path.parentPath.parentPath.parent.type === 'Program'
);
}
function shouldInlineRequire(node, scope, inlineRequiredDependencyMap) {
return (
inlineRequiredDependencyMap.has(node.name) &&
!scope.hasBinding(node.name, true /* noGlobals */)
);
}
function isRequireCall(node) {
return (
!node.new &&
node.type === 'CallExpression' &&
node.callee.type === 'Identifier' &&
node.callee.name === 'require' &&
node['arguments'].length === 1 &&
node['arguments'][0].type === 'StringLiteral'
);
}

View File

@@ -0,0 +1,52 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = function autoImporter(babel) {
const t = babel.types;
function getAssignIdent(path, file, state) {
if (!state.id) {
state.id = path.scope.generateUidIdentifier('assign');
path.scope.getProgramParent().push({
id: state.id,
init: t.callExpression(
t.identifier('require'),
[t.stringLiteral('object-assign')]
),
});
}
return state.id;
}
return {
pre: function() {
// map from module to generated identifier
this.id = null;
},
visitor: {
CallExpression: function(path, file) {
if (path.get('callee').matchesPattern('Object.assign')) {
// generate identifier and require if it hasn't been already
var id = getAssignIdent(path, file, this);
path.node.callee = id;
}
},
MemberExpression: function(path, file) {
if (path.matchesPattern('Object.assign')) {
var id = getAssignIdent(path, file, this);
path.replaceWith(id);
}
},
},
};
};

View File

@@ -0,0 +1,152 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* Rewrites module string literals according to the `map` and `prefix` options.
* This allows other npm packages to be published and used directly without
* being a part of the same build.
*/
function mapModule(state, module) {
var moduleMap = state.opts.map || {};
if (moduleMap.hasOwnProperty(module)) {
return moduleMap[module];
}
// Jest understands the haste module system, so leave modules intact.
if (process.env.NODE_ENV !== 'test') {
var modulePrefix = state.opts.prefix;
if (modulePrefix == null) {
modulePrefix = './';
}
return modulePrefix + module;
}
return null;
}
var jestMethods = [
'dontMock',
'genMockFromModule',
'mock',
'setMock',
'unmock',
];
function isJestProperty(t, property) {
return t.isIdentifier(property) && jestMethods.indexOf(property.name) !== -1;
}
module.exports = function(babel) {
var t = babel.types;
/**
* Transforms `require('Foo')` and `require.requireActual('Foo')`.
*/
function transformRequireCall(path, state) {
var calleePath = path.get('callee');
if (
!t.isIdentifier(calleePath.node, {name: 'require'}) &&
!(
t.isMemberExpression(calleePath.node) &&
t.isIdentifier(calleePath.node.object, {name: 'require'}) &&
t.isIdentifier(calleePath.node.property, {name: 'requireActual'})
)
) {
return;
}
var args = path.get('arguments');
if (!args.length) {
return;
}
var moduleArg = args[0];
if (moduleArg.node.type === 'StringLiteral') {
var module = mapModule(state, moduleArg.node.value);
if (module) {
moduleArg.replaceWith(t.stringLiteral(module));
}
}
}
/**
* Transforms `import type Bar from 'foo'`
*/
function transformTypeImport(path, state) {
var source = path.get('source');
if (source.type === 'StringLiteral') {
var module = mapModule(state, source.node.value);
if (module) {
source.replaceWith(t.stringLiteral(module));
}
}
}
/**
* Transforms either individual or chained calls to `jest.dontMock('Foo')`,
* `jest.mock('Foo')`, and `jest.genMockFromModule('Foo')`.
*/
function transformJestHelper(path, state) {
var calleePath = path.get('callee');
var args = path.get('arguments');
if (!args.length) {
return;
}
var moduleArg = args[0];
if (
moduleArg.node.type === 'StringLiteral' &&
calleePath.node &&
isJestProperty(t, calleePath.node.property)
) {
var module = mapModule(state, moduleArg.node.value);
if (module) {
moduleArg.replaceWith(t.stringLiteral(module));
}
}
}
const jestIdentifier = {
Identifier(path) {
if (path.node.name === 'jest') {
this.isJest = true;
}
},
};
function transformJestCall(path, state) {
let params = {isJest: false};
path.traverse(jestIdentifier, params);
if (params.isJest) {
transformJestHelper(path, state);
}
}
return {
visitor: {
CallExpression: {
exit(path, state) {
if (path.node.seen) {
return;
}
transformRequireCall(path, state);
transformJestCall(path, state);
path.node.seen = true;
},
},
ImportDeclaration: {
exit(path, state) {
let importKind = path.node.importKind;
if (importKind === 'type' || importKind === 'typeof') {
transformTypeImport(path, state);
}
}
}
},
};
};