Skip to content

Commit

Permalink
Merge pull request #46 from enb-bem/fix/lang-sourcemap
Browse files Browse the repository at this point in the history
Append lang mock to the end of file to not make source map being invalid
  • Loading branch information
Andrew Abramov committed Dec 19, 2014
2 parents b363fad + adf3250 commit f42fc7b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/techs/mock-lang-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ module.exports = require('enb/lib/build-flow').create()
return vfs.read(source, 'utf8')
.then(function (content) {
var mock = [
'(function(global, bem_) {',
' if(bem_.I18N) return;',
' global.BEM = bem_;',
' var i18n = bem_.I18N = function(keyset, key) {',
' return key;',
' };',
' i18n.keyset = function() { return i18n }',
' i18n.key = function(key) { return key }',
' i18n.lang = function() { return }',
'})(this, typeof BEM === \'undefined\' ? {} : BEM);'
].join('\n');
'(function(global, bem_) {',
' if(bem_.I18N) return;',
' global.BEM = bem_;',
' var i18n = bem_.I18N = function(keyset, key) {',
' return key;',
' };',
' i18n.keyset = function() { return i18n }',
' i18n.key = function(key) { return key }',
' i18n.lang = function() { return }',
'})(this, typeof BEM === \'undefined\' ? {} : BEM);'
].join('\n'),
mapIndex = content.lastIndexOf('//# sourceMappingURL='),
map;

return [mock, content].join('\n');
// if there is a #sourceMappingURL pragma append
// the mock before it so the source map will be
// valid. We can't insert it in the beginning because
// source map locations will point to the wrong lines.
if (mapIndex !== -1) {
map = content.substring(mapIndex);
content = content.substring(0, mapIndex);
}

return [content, mock, map].join('\n');
});
})
.createTech();

0 comments on commit f42fc7b

Please sign in to comment.