babel-plugin-ember-modules-api-polyfill
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "babel-plugin-ember-modules-api-polyfill", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Polyfill for Ember JS API.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -6,2 +6,12 @@ 'use strict'; | ||
function isBlacklisted(blacklist, importPath, exportName) { | ||
if (Array.isArray(blacklist)) { | ||
return blacklist.indexOf(importPath) > -1; | ||
} else { | ||
let blacklistedExports = blacklist[importPath]; | ||
return blacklistedExports.indexOf(exportName) > -1; | ||
} | ||
} | ||
module.exports = function(babel) { | ||
@@ -35,5 +45,6 @@ const t = babel.types; | ||
let replacements = []; | ||
let removals = []; | ||
let importPath = node.source.value; | ||
if (!reverseMapping[importPath] || blacklist.indexOf(importPath) > -1) { | ||
if (!reverseMapping[importPath]) { | ||
// not a module provided by emberjs/rfcs#176 | ||
@@ -48,3 +59,4 @@ // so we have nothing to do here | ||
// Iterate all the specifiers and attempt to locate their mapping | ||
node.specifiers.forEach(specifier => { | ||
path.get('specifiers').forEach(specifierPath => { | ||
let specifier = specifierPath.node; | ||
let importName; | ||
@@ -74,2 +86,6 @@ | ||
if (isBlacklisted(blacklist, importPath, importName)) { | ||
return; | ||
} | ||
// Extract the global mapping | ||
@@ -83,2 +99,4 @@ const global = mapping[importName]; | ||
removals.push(specifierPath); | ||
// Repalce the node with a new `var name = Ember.something` | ||
@@ -95,4 +113,7 @@ replacements.push( | ||
if (replacements.length > 0) { | ||
if (removals.length === node.specifiers.length) { | ||
path.replaceWithMultiple(replacements); | ||
} else if (replacements.length > 0) { | ||
removals.forEach(specifierPath => specifierPath.remove()); | ||
path.insertAfter(replacements); | ||
} | ||
@@ -99,0 +120,0 @@ }, |
@@ -91,2 +91,16 @@ 'use strict'; | ||
// Ensure unknown exports are not removed | ||
describe(`unknown imports from known module`, () => { | ||
it(`allows blacklisting import paths`, assert => { | ||
let input = `import { derp } from '@ember/object/computed';`; | ||
assert.throws(() => { | ||
transform(input, [ | ||
[Plugin], | ||
]); | ||
}, /@ember\/object\/computed does not have a derp import/); | ||
}); | ||
}); | ||
describe('options', () => { | ||
@@ -101,2 +115,11 @@ it(`allows blacklisting import paths`, assert => { | ||
}); | ||
it(`allows blacklisting specific named imports`, assert => { | ||
let input = `import { assert, inspect } from '@ember/debug';`; | ||
let actual = transform(input, [ | ||
[Plugin, { blacklist: { '@ember/debug': ['assert', 'warn', 'deprecate'] } }], | ||
]); | ||
assert.equal(actual, `import { assert } from '@ember/debug';\nvar inspect = Ember.inspect;`); | ||
}); | ||
}); |
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
74311
322