babel-plugin-ember-modules-api-polyfill
Advanced tools
Comparing version 2.1.0 to 2.2.0
# Changelog | ||
## v2.2.0 (2017-10-27) | ||
#### :bug: Bug Fix | ||
* [#31](https://github.com/ember-cli/babel-plugin-ember-modules-api-polyfill/pull/31) Allow `export { computed } from '@ember/object'` to work. ([@Turbo87](https://github.com/Turbo87)) | ||
* [#30](https://github.com/ember-cli/babel-plugin-ember-modules-api-polyfill/pull/30) Fix confusing "missing import" warning. ([@Turbo87](https://github.com/Turbo87)) | ||
#### Committers: 1 | ||
- Tobias Bieniek ([Turbo87](https://github.com/Turbo87)) | ||
## v2.1.0 (2017-10-03) | ||
@@ -11,2 +21,3 @@ | ||
## v2.0.1 (2017-08-29) | ||
@@ -13,0 +24,0 @@ |
{ | ||
"name": "babel-plugin-ember-modules-api-polyfill", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Polyfill for Ember JS API.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -113,3 +113,3 @@ 'use strict'; | ||
if (!global) { | ||
throw path.buildCodeFrameError(`${importPath} does not have a ${importName} import`); | ||
throw path.buildCodeFrameError(`${importPath} does not have a ${importName} export`); | ||
} | ||
@@ -138,2 +138,92 @@ | ||
}, | ||
ExportNamedDeclaration(path, state) { | ||
let blacklist = (state.opts && state.opts.blacklist) || []; | ||
let node = path.node; | ||
if (!node.source) { | ||
return; | ||
} | ||
let replacements = []; | ||
let removals = []; | ||
let specifiers = path.get('specifiers'); | ||
let importPath = node.source.value; | ||
// This is the mapping to use for the import statement | ||
const mapping = reverseMapping[importPath]; | ||
// Only walk specifiers if this is a module we have a mapping for | ||
if (mapping) { | ||
// Iterate all the specifiers and attempt to locate their mapping | ||
specifiers.forEach(specifierPath => { | ||
let specifier = specifierPath.node; | ||
// exported is the name of the module being export, | ||
// e.g. `foo` in `export { computed as foo } from '@ember/object';` | ||
const exported = specifier.exported; | ||
// local is the original name of the module, this is usually the same | ||
// as the exported value, unless the module is aliased | ||
const local = specifier.local; | ||
// We only care about the ExportSpecifier | ||
if (specifier.type !== 'ExportSpecifier') { | ||
return; | ||
} | ||
// Determine the import name, either default or named | ||
let importName = local.name; | ||
if (isBlacklisted(blacklist, importPath, importName)) { | ||
return; | ||
} | ||
// Extract the global mapping | ||
const global = mapping[importName]; | ||
// Ensure the module being imported exists | ||
if (!global) { | ||
throw path.buildCodeFrameError(`${importPath} does not have a ${importName} export`); | ||
} | ||
removals.push(specifierPath); | ||
// Repalce the node with a new `var name = Ember.something` | ||
replacements.push( | ||
t.exportNamedDeclaration( | ||
t.variableDeclaration('var', [ | ||
t.variableDeclarator( | ||
exported, | ||
t.memberExpression(t.identifier('Ember'), t.identifier(global)) | ||
), | ||
]), | ||
[], | ||
null | ||
) | ||
); | ||
}); | ||
} | ||
if (removals.length > 0 && removals.length === node.specifiers.length) { | ||
path.replaceWithMultiple(replacements); | ||
} else if (replacements.length > 0) { | ||
removals.forEach(specifierPath => specifierPath.remove()); | ||
path.insertAfter(replacements); | ||
} | ||
}, | ||
ExportAllDeclaration(path) { | ||
let node = path.node; | ||
let importPath = node.source.value; | ||
// This is the mapping to use for the import statement | ||
const mapping = reverseMapping[importPath]; | ||
// Only walk specifiers if this is a module we have a mapping for | ||
if (mapping) { | ||
throw path.buildCodeFrameError(`Wildcard exports from ${importPath} are currently not possible`); | ||
} | ||
}, | ||
}, | ||
@@ -140,0 +230,0 @@ }; |
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
102653
12
470