motion
Version:
motion - moving development forward
84 lines (60 loc) • 2 kB
JavaScript
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _bundler = require('../bundler');
var _bundler2 = _interopRequireDefault(_bundler);
var _cache = require('../cache');
var _cache2 = _interopRequireDefault(_cache);
var _opts = require('../opts');
var _opts2 = _interopRequireDefault(_opts);
var _libHelpers = require('./lib/helpers');
var _libFns = require('../lib/fns');
var viewMatcher = /^view\s+([\.A-Za-z_0-9]*)\s*\{/;
var views = [];
var Scanner = {
pre: function pre(filePath, source, next) {
var inView = false;
var viewNames = [];
source = source.split("\n").map(function (line, index) {
var result = line;
var view = result.match(viewMatcher);
if (view && view.length) {
inView = true;
viewNames.push(result.split(' ')[1]);
}
var JSXstart = inView && line.charAt(2) == '<' && line.charAt(3) != '/';
if (JSXstart) result = ';' + result.substr(1);
if (inView && line.charAt(0) == '}') inView = false;
return result;
}).join("\n");
// TODO move this into babel
if (filePath) {
_cache2['default'].add(filePath);
_cache2['default'].setViews(filePath, viewNames);
}
next(source);
}
};
exports.Scanner = Scanner;
function compile(type) {
return _libHelpers.through.obj(function (file, enc, next) {
var _this = this;
if (file.isNull()) {
next(null, file);
return;
}
try {
var res = Scanner[type](file.path, file.contents.toString(), function (source) {
var fileProps = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
file.contents = new Buffer(source || '');
// add fileprops coming from compilers
Object.assign(file, fileProps);
_this.push(file);
next();
});
} catch (err) {
this.emit('error', err);
next();
}
});
}
exports['default'] = compile;