1 | import { Block } from 'decaffeinate-parser/dist/nodes';
|
2 | import NodePatcher from './NodePatcher';
|
3 | import { PatcherContext } from './types';
|
4 | export default class SharedBlockPatcher extends NodePatcher {
|
5 | node: Block;
|
6 | statements: Array<NodePatcher>;
|
7 | shouldPatchInline: boolean | null;
|
8 | constructor(patcherContext: PatcherContext, statements: Array<NodePatcher>);
|
9 | /**
|
10 | * Insert statements somewhere in this block.
|
11 | */
|
12 | insertStatementsAtIndex(statements: Array<string>, index: number): void;
|
13 | /**
|
14 | * Insert a statement before the current block. Since blocks can be patched in
|
15 | * a number of ways, this needs to handle a few cases:
|
16 | * - If it's completely inline, we don't deal with any indentation and just
|
17 | * put a semicolon-separated statement before the start.
|
18 | * - If it's a normal non-inline block, we insert the statement beforehand
|
19 | * with the given indentation. However, `this.outerStart` is the first
|
20 | * non-whitespace character of the first line, so it's already indented, so
|
21 | * if we want to add a line with *less* indentation, it's a lot more tricky.
|
22 | * We handle this by walking backward to the previous newline and inserting
|
23 | * a new line from there. This allows the prepended line to have whatever
|
24 | * indentation level we want.
|
25 | * - In some cases, such as nontrivial loop expressions with an inline body,
|
26 | * the source CoffeeScript is inline, but we want the result to be
|
27 | * non-inline, so we need to be a lot more careful. The normal non-inline
|
28 | * strategy won't work because there's no newline to walk back to in the
|
29 | * source CoffeeScript, so the strategy is to instead always insert at
|
30 | * `this.outerStart`. That means that the indentation for the actual body
|
31 | * needs to be done later, just before the body itself is patched. See the
|
32 | * uses of shouldConvertInlineBodyToNonInline in LoopPatcher for an example.
|
33 | */
|
34 | insertLineBefore(statement: string, indent?: string): void;
|
35 | insertLineAfter(statement: string, indent: string): void;
|
36 | /**
|
37 | * Gets whether this patcher's block is inline (on the same line as the node
|
38 | * that contains it) or not.
|
39 | */
|
40 | inline(): boolean;
|
41 | }
|