Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_catchUp(newlines, parent) {
if (newlines <= 0) return 0;
if (
// TODO: this will become unnecessary with future parsing udpates -- should remove
parent && parent.type === "SequenceExpression" ||
false) {
// TODO: check other contexts
// TODO: preserve indentation for escaped newlines
this.push({type: tt.whitespace, value: {code: repeating("\\\n", newlines)}})
} else {
let first = true;
for (let i = newlines; i > 0; i--) {
this.newline(!first);
first = false;
}
}
return newlines;
}
export default function indentNode(node, patcher, levels=1) {
if (levels === 0) {
return;
}
let source = patcher.original;
let range = trimmedNodeRange(node, source);
let offset = range[0];
let indent = repeat(determineIndent(source), levels);
while (offset < range[1]) {
patcher.insert(offset, indent);
offset = source.indexOf('\n', offset);
if (offset < 0) {
break;
}
while (source[offset] === '\n') {
// Skip empty lines.
offset += '\n'.length;
}
}
}
dump() {
let sep = repeating("-", 60);
console.log(sep);
let scope = this;
do {
console.log("#", scope.block.type);
for (let name in scope.bindings) {
let binding = scope.bindings[name];
console.log(" -", name, {
constant: binding.constant,
references: binding.references,
violations: binding.constantViolations.length,
kind: binding.kind
});
}
} while (scope = scope.parent);
console.log(sep);
}
getIndent() {
if (this.format.compact || this.format.concise) {
return "";
} else {
return repeating(this.format.indent.style, this._indent);
}
}
tt.tab.toCode = function(token, state) {
return token.value ? repeating(state.format.indent.indent, token.value) : "";
};
tt.indent.toCode = function() {