babel-plugin-fake-import-specifiers
Advanced tools
Comparing version 1.1.3 to 2.0.0
{ | ||
"name": "babel-plugin-fake-import-specifiers", | ||
"version": "1.1.3", | ||
"version": "2.0.0", | ||
"description": "Allow importing pieces while only exporting the whole object", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "eslint-mocha --eslint-args=\"src test/*.js\"", | ||
"test": "mocha", | ||
"posttest": "npm run lint", | ||
"prelint": "eslint --version", | ||
@@ -27,9 +28,11 @@ "lint": "eslint src test/*.js", | ||
"babel": "^5.0.0", | ||
"chai": "^3.0.0", | ||
"eslint": "^3.0.0", | ||
"eslint-mocha": "0.2.2", | ||
"mocha": "^3.0.0" | ||
"chai": "^4.0.0", | ||
"eslint": "^5.0.0", | ||
"eslint-config-sane": "^0.6.0", | ||
"eslint-plugin-prefer-let": "^1.0.1", | ||
"fixture-skipper": "^2.0.0", | ||
"mocha": "^5.0.4" | ||
}, | ||
"engines": { | ||
"node": ">= 4" | ||
"node": ">= 6" | ||
}, | ||
@@ -36,0 +39,0 @@ "greenkeeper": { |
'use strict'; | ||
function convertDasherizedToCamelized(str) { | ||
return str.split('-').reduce(function(str, chunk) { | ||
return str.split('-').reduce((str, chunk) => { | ||
if (str === '') { | ||
@@ -14,22 +14,22 @@ str = chunk; | ||
module.exports = function(babel) { | ||
var Plugin = babel.Plugin; | ||
var t = babel.types; | ||
module.exports = function FakeImportSpecifiers({ | ||
Plugin, | ||
types: t | ||
}) { | ||
let sourcesToFake; | ||
let defaultSpecifierLookup; | ||
let newIdentifierLookup; | ||
var sourcesToFake; | ||
var defaultSpecifierLookup; | ||
var newIdentifierLookup; | ||
var visitor = { | ||
ImportDeclaration: function(node, parent, scope) { | ||
var value = node.source.value; | ||
var sourceMinusOne; | ||
var dasherizedPackageName; | ||
if (sourcesToFake.indexOf(value) === -1) { | ||
let visitor = { | ||
ImportDeclaration(node, parent, scope) { | ||
let { value } = node.source; | ||
let sourceMinusOne; | ||
let dasherizedPackageName; | ||
if (!sourcesToFake.includes(value)) { | ||
// try to match a partial import | ||
// ex: source = 'my-lib' | ||
// import aPackage from 'my-lib/a-package'; | ||
var lastSlashIndex = value.lastIndexOf('/'); | ||
let lastSlashIndex = value.lastIndexOf('/'); | ||
sourceMinusOne = value.substr(0, lastSlashIndex); | ||
if (sourcesToFake.indexOf(sourceMinusOne) === -1) { | ||
if (!sourcesToFake.includes(sourceMinusOne)) { | ||
return; | ||
@@ -40,7 +40,7 @@ } | ||
var defaultSpecifierIndentifier; | ||
var defaultSpecifier; | ||
var specifiers = node.specifiers; | ||
let defaultSpecifierIndentifier; | ||
let defaultSpecifier; | ||
let { specifiers } = node; | ||
for (var i in specifiers) { | ||
for (let i in specifiers) { | ||
if (!Object.prototype.hasOwnProperty.call(specifiers, i)) { | ||
@@ -50,3 +50,3 @@ continue; | ||
var specifier = specifiers[i]; | ||
let specifier = specifiers[i]; | ||
if (t.isImportDefaultSpecifier(specifier)) { | ||
@@ -68,3 +68,3 @@ defaultSpecifierIndentifier = specifier.local; | ||
var hasSpecifiers; | ||
let hasSpecifiers; | ||
@@ -79,4 +79,4 @@ function addSpecifierToLookup(name) { | ||
var oldName = defaultSpecifierIndentifier.name; | ||
var name = convertDasherizedToCamelized(dasherizedPackageName); | ||
let oldName = defaultSpecifierIndentifier.name; | ||
let name = convertDasherizedToCamelized(dasherizedPackageName); | ||
newIdentifierLookup[oldName] = name; | ||
@@ -88,3 +88,3 @@ | ||
} else { | ||
specifiers.forEach(function(specifier) { | ||
specifiers.forEach(specifier => { | ||
if (!t.isImportSpecifier(specifier)) { | ||
@@ -106,4 +106,4 @@ return; | ||
}, | ||
CallExpression: function(node) { | ||
var callee = node.callee; | ||
CallExpression(node) { | ||
let { callee } = node; | ||
if (callee.type !== 'Identifier') { | ||
@@ -113,4 +113,4 @@ return; | ||
var name = callee.name; | ||
var defaultSpecifierIndentifier = defaultSpecifierLookup[name]; | ||
let { name } = callee; | ||
let defaultSpecifierIndentifier = defaultSpecifierLookup[name]; | ||
if (!defaultSpecifierIndentifier) { | ||
@@ -120,3 +120,3 @@ return; | ||
var newIdentifier = newIdentifierLookup[name]; | ||
let newIdentifier = newIdentifierLookup[name]; | ||
if (newIdentifier) { | ||
@@ -136,3 +136,3 @@ name = newIdentifier; | ||
}, | ||
Program: function(node, parent, scope, file) { | ||
Program(node, parent, scope, file) { | ||
sourcesToFake = file.opts.extra['fake-import-specifiers'] || []; | ||
@@ -145,4 +145,4 @@ defaultSpecifierLookup = Object.create(null); | ||
return new Plugin('babel-plugin-fake-import-specifiers', { | ||
visitor: visitor | ||
visitor | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117
6812
7