Skip to content

Commit a174ab3

Browse files
authored
fix: Clarify custom generator codelab instructions (#2102)
1 parent f642f46 commit a174ab3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

codelabs/custom_generator/custom_generator.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ Next, hook up the new generator with the sample app. First, remove the old code
212212

213213
```js
214214
// Remove these lines!
215-
import {generator} from './generators/javascript';
215+
import {forBlock} from './generators/javascript';
216216
import {javascriptGenerator} from 'blockly/javascript';
217217

218218
// Also remove this line! (further down)
219-
Object.assign(javascriptGenerator, generator);
219+
Object.assign(javascriptGenerator.forBlock, forBlock);
220220
```
221221

222222
Now import the new generator:
@@ -305,12 +305,12 @@ Operator precedence rules determine how the correct order of operations is maint
305305

306306
Since JSON does not allow values that are expressions, the code does not need to consider operator precedence for the generator being built in this codelab. The same value can be used everywhere a precedence value is required. Since parentheses never need to be added to the JSON, call this value `ATOMIC`.
307307

308-
Declare a new enum called `Order` and add the `ATOMIC` value:
308+
In `src/generators/json.js`, declare a new enum called `Order` and add the `ATOMIC` value:
309309

310310
```js
311311
const Order = {
312312
ATOMIC: 0,
313-
}
313+
};
314314
```
315315

316316
## Value block generators
@@ -326,6 +326,7 @@ The simplest block in this example is the `logic_null` block.
326326
![The null block simply returns "null".](./null_block.png)
327327

328328
No matter what, it generates the code `'null'`. Notice that this is a string, because all generated code is a string.
329+
Add the following code to `src/generators/json.js`:
329330

330331

331332
```js
@@ -518,7 +519,7 @@ Next, use `prefixLines` to add indentation at the beginning of each line:
518519

519520
```js
520521
const indentedValueString =
521-
generator.prefixLines(valueString, jsonGenerator.INDENT);
522+
generator.prefixLines(valueString, generator.INDENT);
522523
```
523524

524525
`INDENT` is a property on the generator. It defaults to two spaces, but language generators may override it to increase indent or change to tabs.

0 commit comments

Comments
 (0)