Skip to content

Commit

Permalink
support "export X from Y" syntax of ES6 without importing X first (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored May 14, 2018
1 parent d823bdc commit d2f98f9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions e2e/flows/es6-link-files.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,59 @@ describe('es6 components with link files', function () {
});
});

describe('when a component uses link file to import multiple members with export (without import) syntax', () => {
let utilIndexFixture;
before(() => {
helper.setNewLocalAndRemoteScopes();
helper.importCompiler();
const isArrayFixture = "export default function isArray() { return 'got is-array'; };";
helper.createFile('utils', 'is-array.js', isArrayFixture);
helper.addComponent('utils/is-array.js');
const isStringFixture = "export default function isString() { return 'got is-string'; };";
helper.createFile('utils', 'is-string.js', isStringFixture);
helper.addComponent('utils/is-string.js');
utilIndexFixture = "export isArray from './is-array'; export isString from './is-string'; ";
helper.createFile('utils', 'index.js', utilIndexFixture);
const fooBarFixture =
"import { isString } from '../utils'; export default function foo() { return isString() + ' and got foo'; };";
helper.createComponentBarFoo(fooBarFixture);
helper.addComponentBarFoo();

helper.commitAllComponents();
helper.exportAllComponents();
});
describe('when the project cloned to somewhere else as AUTHORED', () => {
before(() => {
helper.mimicGitCloneLocalProject(false);
helper.addRemoteScope();
helper.importAllComponents(true);
});
it('should not override the original link file', () => {
const currentUtilIndex = fs.readFileSync(path.join(helper.localScopePath, 'utils', 'index.js'));
expect(currentUtilIndex.toString()).to.equal(utilIndexFixture);
});
});
describe('when importing the component', () => {
before(() => {
helper.reInitLocalScope();
helper.addRemoteScope();
helper.importComponent('bar/foo ');
});
it('should auto-generate a link file', () => {
const currentUtilIndex = fs.readFileSync(
path.join(helper.localScopePath, 'components', 'bar', 'foo', 'utils', 'index.js')
);
expect(currentUtilIndex.toString()).to.not.equal(utilIndexFixture);
});
it('should rewrite the relevant part of the link file', () => {
const appJsFixture = "const barFoo = require('./components/bar/foo'); console.log(barFoo.default());";
fs.outputFileSync(path.join(helper.localScopePath, 'app.js'), appJsFixture);
const result = helper.runCmd('node app.js');
expect(result.trim()).to.equal('got is-string and got foo');
});
});
});

describe('when a component uses link file to import members AND that link file is part of the component', () => {
let utilIndexFixture;
before(() => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"array-difference": "^0.0.1",
"async-exit-hook": "^2.0.1",
"babel-runtime": "^6.23.0",
"bit-javascript": "0.10.16",
"bit-javascript": "0.10.17-dev.1",
"buffer-from": "^0.1.1",
"chalk": "^2.1.0",
"chokidar": "^1.7.0",
Expand Down

0 comments on commit d2f98f9

Please sign in to comment.