Skip to content

Commit

Permalink
insert import on every file
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamBrodzinski committed Oct 27, 2015
1 parent a501719 commit 7cd1edd
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
25 changes: 13 additions & 12 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,26 @@ module.exports = function(file, fileName) {
}
});

lines.unshift("import Immutable from 'seamless-immutable';");

// f
// de-dent module methods
if (state.hasModule) {
lines = lines.map(function(line) {
if (line.match('RS_MODULE_LINE')) {
return "import Immutable from 'seamless-immutable'";
}
else {
// if first two lines are blank de-dent module internals
if (line[0] && !line[1].trim() && line[1] && !line[1].trim()) {
return line.slice(2);
} else {
return line;
}
var firstCharEmpty = line[0] && !line[0].trim();
var secondCharEmpty = line[1] && !line[1].trim();

if (firstCharEmpty && secondCharEmpty) {
return line.slice(2);
} else {
return line;
}
return line;
});
}

lines = lines.filter(function(line) {
return ! line.match('RS_REMOVE_LINE');
})

// return transformed lines
return lines.join('\n');
};
2 changes: 1 addition & 1 deletion lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ module.exports = {

state.hasModule = true;
var lline;
var newLine = line.replace(/^\s*defmodule\s+([\w$]+)\s+do\s*$/, 'RS_MODULE_LINE');
var newLine = line.replace(/^\s*defmodule\s+([\w$]+)\s+do\s*$/, 'RS_REMOVE_LINE');

// ** side effect, removes last 'end'
for (var i=1, n=lines.length; i < n; i++) {
Expand Down
1 change: 1 addition & 0 deletions test/examples/aliases.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Immutable from 'seamless-immutable';
// this is a single line comment

//#
Expand Down
1 change: 1 addition & 0 deletions test/examples/functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Immutable from 'seamless-immutable';
// compiles to eq. JavaScript, this example does not
// include the module syntax: `defmodule` as that is
// a separate transform (see test/examples/module.rs)
Expand Down
1 change: 1 addition & 0 deletions test/examples/immutable.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Immutable from 'seamless-immutable';
// const arr = Immutable([1, 2, 3]);
const arr = Immutable([1, 2, 3])
const arr = Immutable([1, {foo: 1}, [2,[3]] , 3])
Expand Down
2 changes: 1 addition & 1 deletion test/examples/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Immutable from 'seamless-immutable'
import Immutable from 'seamless-immutable';
export function add(a, b) {
return a + b
}
Expand Down
1 change: 1 addition & 0 deletions test/examples/pipe_operator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Immutable from 'seamless-immutable';
// single line pipes not finished
const bar = _.chain(Immutable([1, 2, 3])).pipesCall(Enum.uppcase).value();

Expand Down
1 change: 1 addition & 0 deletions test/examples/sample.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Immutable from 'seamless-immutable';
// auto declared constants
const bar = 2

Expand Down

0 comments on commit 7cd1edd

Please sign in to comment.