Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

cannot create a new generator using typescript

52 views
Skip to first unread message

Bertrand Thelen

unread,
Nov 15, 2024, 11:12:50 AM11/15/24
to Blockly
Hi,

I just tried to create a new generator for our custom DSL. 
I first followed the "build a custom generator" lab but than tried to move to typescript in order to re-use the code from the existing generators.

After solving all the path or naming issue, I'm stuck with a few errors left on the diascript_generator.ts (pasted below).

Currently it's mostly a mix of the lua and the javascript generator with little to no modification but I can provide the files if needed.

In order to retrieve the variables real names, I suppose that I need the namesDb and given that the names modules (and others in the xxx_generator.ts files) are not exported, I cannot reach them.
The last error is not about a missing dependency but and is rather cryptic to me but I haven't investigated much on that side so far.

Am I doing something wrong? Should I follow another method for custom generators?

Thanks for any advice that could help me unlock that.

Regards,
Bertrand


error log:

Compiled with problems:
×
ERROR in ./src/generators/diascript/diascript_generator.ts 14:0-61
Module not found: Error: Package path ./core/inputs/input_types is not exported from package C:\Users\bet\diascriptTest\node_modules\blockly (see exports field in C:\Users\bet\diascriptTest\node_modules\blockly\package.json)
ERROR in ./src/generators/diascript/diascript_generator.ts 15:0-43
Module not found: Error: Package path ./core/names is not exported from package C:\Users\bet\diascriptTest\node_modules\blockly (see exports field in C:\Users\bet\diascriptTest\node_modules\blockly\package.json)
ERROR in ./src/generators/diascript/diascript_generator.ts 16:0-57
Module not found: Error: Package path ./core/utils/string is not exported from package C:\Users\bet\diascriptTest\node_modules\blockly (see exports field in C:\Users\bet\diascriptTest\node_modules\blockly\package.json)
ERROR in ./src/generators/diascript.ts (C:\Users\bet\diascriptTest\src\generators\diascript.ts) 35:38-54
[tsl] ERROR in C:\Users\bet\diascriptTest\src\generators\diascript.ts(35,39) TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ variables_get_dynamic: (block: Block, generator: DiascriptGenerator) => [string, Order]; variables_set_dynamic: (block: Block, generator: DiascriptGenerator) => string; ... 23 more ...; controls_ifelse: (block: Block, generator: DiascriptGenerator) => string; }'. No index signature with a parameter of type 'string' was found on type '{ variables_get_dynamic: (block: Block, generator: DiascriptGenerator) => [string, Order]; variables_set_dynamic: (block: Block, generator: DiascriptGenerator) => string; ... 23 more ...; controls_ifelse: (block: Block, generator: DiascriptGenerator) => string; }'.


Aaron Dodson

unread,
Nov 15, 2024, 3:51:38 PM11/15/24
to Blockly
Hi,

What do your import statements look like? Blockly core itself imports classes and functions by path, but for third parties, the expectation is that you just 

import * as Blockly from 'blockly/core';

once at the top of your file, and then reference types in your code by their fully-qualified name e.g. Blockly.utils.string, or Blockly.inputTypes.STATEMENT or the like. Let me know if that helps or if you're still running into issues!

- Aaron

Bertrand Thelen

unread,
Nov 18, 2024, 1:44:12 PM11/18/24
to Blockly
Was exactly that, thanks for the help
I was using:

```import type {Block} from 'blockly/core/block';
import {CodeGenerator} from 'blockly/core/generator';
import {inputTypes} from 'blockly/core/inputs/input_types';
import {Names, NameType} from 'blockly/core/names';```

and the likes. changing to the fully qualified name from Blockly solved all my issues.

Can't wait to continue to discover Blockly, pretty sure it will respond to a few needs we had for a long time!

Thank you,
Bertrand
Reply all
Reply to author
Forward
0 new messages