Move strip processing into AST helper logic

We already have to track these behaviors for the standalone parsing and rather than having two whitespace pruning implementations this moves all of the behavior into one place.

Fixes #852
This commit is contained in:
kpdecker
2014-08-23 17:44:20 -05:00
parent ccd803ff15
commit 84d646bb5d
4 changed files with 81 additions and 53 deletions
@@ -85,11 +85,6 @@ JavaScriptCompiler.prototype = {
opcode = opcodes[i];
this[opcode.opcode].apply(this, opcode.args);
// Reset the stripNext flag if it was not set by this operation.
if (opcode.opcode !== this.stripNext) {
this.stripNext = false;
}
}
// Flush any trailing content that might be pending.
@@ -280,27 +275,10 @@ JavaScriptCompiler.prototype = {
if (this.pendingContent) {
content = this.pendingContent + content;
}
if (this.stripNext) {
content = content.replace(/^\s+/, '');
}
this.pendingContent = content;
},
// [strip]
//
// On stack, before: ...
// On stack, after: ...
//
// Removes any trailing whitespace from the prior content node and flags
// the next operation for stripping if it is a content node.
strip: function() {
if (this.pendingContent) {
this.pendingContent = this.pendingContent.replace(/\s+$/, '');
}
this.stripNext = 'strip';
},
// [append]
//
// On stack, before: value, ...