turn inserted helper declarations into function declarations if possible
This commit is contained in:
parent
63b44a3e6e
commit
b30bdf2294
@ -232,14 +232,14 @@ class CodeGenerator {
|
||||
this.map.mark(node, "end");
|
||||
if (opts.after) opts.after();
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
|
||||
newline(false);
|
||||
|
||||
this.printTrailingComments(node, parent);
|
||||
} else {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
||||
}
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
}
|
||||
|
||||
printJoin(print, nodes, opts = {}) {
|
||||
|
||||
@ -370,13 +370,23 @@ export default class File {
|
||||
}
|
||||
|
||||
var ref = util.template("helper-" + name);
|
||||
ref._compact = true;
|
||||
|
||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
init: ref,
|
||||
unique: true
|
||||
});
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = true;
|
||||
ref._generated = true;
|
||||
ref.id = uid;
|
||||
ref.type = "FunctionDeclaration";
|
||||
this.path.unshiftContainer("body", ref);
|
||||
} else {
|
||||
ref._compact = true;
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
init: ref,
|
||||
unique: true
|
||||
});
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user