Skip to content

Commit 9f33674

Browse files
committed
[chore] some code comments
1 parent a2bf8a1 commit 9f33674

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/block.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { get_offsets, dedent_code } from './utils.js';
22

3-
// return a new block
3+
// create a new block to add code transformations to
44
export const new_block = () => ({ transformed_code: '', line_offsets: null, translations: new Map() });
55

66
// get translation info and include the processed scripts in this block's transformed_code
7+
// each translation consists of info about the original text range (range),
8+
// the difference after dedenting (dedent), line/length info about the text itself (offsets),
9+
// line/length info about the transformed code prior to adding the text (unoffsets) and the new
10+
// line count of the transformed code after adding the text (end). This information can be used
11+
// to map code back to its original position.
712
export const get_translation = (text, block, node, options = {}) => {
813
block.transformed_code += '\n';
914
const translation = { options, unoffsets: get_offsets(block.transformed_code) };

src/postprocess.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const transform_message = ({ transformed_code }, { unoffsets, dedent, offsets, r
1515
}
1616
}
1717
// shift position reference backward according to unoffsets
18+
// (aka: throw out the generated code lines prior to the original code)
1819
{
1920
const { length, lines, last } = unoffsets;
2021
if (message.line === lines) {
@@ -33,6 +34,7 @@ const transform_message = ({ transformed_code }, { unoffsets, dedent, offsets, r
3334
}
3435
}
3536
// adjust position reference according to the previous dedenting
37+
// (aka: re-add the stripped indentation)
3638
{
3739
const { offsets, total_offsets } = dedent;
3840
message.column += offsets[message.line - 1];
@@ -45,6 +47,7 @@ const transform_message = ({ transformed_code }, { unoffsets, dedent, offsets, r
4547
}
4648
}
4749
// shift position reference forward according to offsets
50+
// (aka: re-add the code that is originally prior to the code)
4851
{
4952
const { length, lines, last } = offsets;
5053
if (message.line === 1) {

0 commit comments

Comments
 (0)