Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spike] allow functions to be stripped from imports #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ module.exports = function(filteredImports) {
function referencesFilteredImport(identifier, filteredImports) {
for (var moduleName in filteredImports) {
var imports = filteredImports[moduleName];

//NOTE: GJ: just spiking something, mind your head
for (var i = 0; i < imports.length; i++) {
var methodName = imports[i]; //TODO: GJ: naming
if(methodName[0] === '.') {
if('.' + identifier.container.property.name === methodName) { //TODO : GJ: refactor
return true;
}
}

if (identifier.referencesImport(moduleName, imports[i])) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/ember-debug/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var _ember = require('ember');

_ember['default'].isEmpty(); //this should remain
_ember['default'].isEmpty(); //this should remain
11 changes: 11 additions & 0 deletions test/fixtures/ember-debug/fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Em from 'ember';
import Ember from 'ember';

Em.assert('this will be stripped');
Em.debug('this will also be stripped');

Ember.assert('this will be stripped');
Ember.debug('this also will be stripped');

Em.isEmpty(); //this should remain
Ember.isEmpty(); //this should remain
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function testFixture(name, options) {
plugins: [filterImports(options)]
});

assert.strictEqual(result.code, expected);
assert.strictEqual(result.code.trim(), expected.trim());
});
}

Expand All @@ -31,4 +31,8 @@ describe('babel-plugin-filter-imports', function() {
testFixture('partial-filter-1', { assert: ['default'], cloud: ['default'] });
testFixture('partial-filter-2', { assert: ['a', 'c'] });
testFixture('partial-filter-3', { assert: ['a', 'c'] });

//NOTE: GJ: this is just an experiment, the actual API changes may be different
// this will strip `Ember.assert` and `Ember.debug` function calls
testFixture('ember-debug', { ember: ['.assert', '.debug'] });
});