Browse Source

Merge pull request #4140 from lofcz/feat-fix-empty-js-in-output

Fix empty scrips gen
pull/4144/head
Artur Arseniev 4 years ago
committed by GitHub
parent
commit
22f0ace34c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/code_manager/model/JsGenerator.js

17
src/code_manager/model/JsGenerator.js

@ -39,7 +39,7 @@ export default Backbone.Model.extend({
} }
} }
comps.each(function(model) { comps.each(function (model) {
code += this.mapModel(model); code += this.mapModel(model);
}, this); }, this);
@ -54,7 +54,20 @@ export default Backbone.Model.extend({
for (let type in this.mapJs) { for (let type in this.mapJs) {
const mapType = this.mapJs[type]; const mapType = this.mapJs[type];
if (!mapType.code) {
continue;
}
if (mapType.props) { if (mapType.props) {
function isFunctionEmpty(fn) {
const content = fn.toString().match(/\{([\s\S]*)\}/m)[1]; // content between first and last { }
return content.replace(/^\s*\/\/.*$/gm, '').trim().length === 0; // remove comments
}
if (isFunctionEmpty(mapType.code)) {
continue;
}
code += ` code += `
var props = ${JSON.stringify(mapType.props)}; var props = ${JSON.stringify(mapType.props)};
var ids = Object.keys(props).map(function(id) { return '#'+id }).join(','); var ids = Object.keys(props).map(function(id) { return '#'+id }).join(',');
@ -75,5 +88,5 @@ export default Backbone.Model.extend({
} }
return code; return code;
} },
}); });

Loading…
Cancel
Save