Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(generators): Migrate Dart generators to TypeScript #7646

Merged
merged 8 commits into from
Nov 14, 2023

Conversation

cpcallen
Copy link
Contributor

The basics

The details

Resolves

Part of #6828.

Proposed Changes

Migrate generators/dart/*.js and generators/dart.js to TypeScript.

Also make a few minor corrections to previously-migrated files in generators/javascript/ and generators/python/ for consistency (see commit d934aa1).

Reason for Changes

Finish TS migration.

Test Coverage

npm test passes. No changes to manual test procedures required.

Documentation

No changes to documentation yet, as there should be minimal changes to the generated code and no changes to the published typings (because during build we overwrite the generated .d.ts files with the ones from typings/).

Additional Information

It may be easier to review this commit-by-commit, as the final format commit make a lot of noisy changes.

Slightly simplify the implementation of getAdjusted, in part to
make it more readable.  Also improve its JSDoc comment.
First pass doing very mechanistic migration, not attempting to fix
all the resulting type errors.
This consists almost entirely of adding casts, so the code output
by tsc should be as similar as possible to the pre-migration .js
source files.
The migration of the JavaScript and Python generators
inadvertently introduced some inconsistencies in the code,
e.g.:

- Incorrect import ordering.
- Putting executable code before the initial comment line that
  most generator functions begin with, and/or deleting or
  replacing these comments.
  -  N.B. however that these inline comments should have been
     JSDocs; a task to convert them has been added to google#7600.
The way the generator functions are added to
dartGenerator.forBlock has been modified so that incorrect
generator function signatures will cause tsc to generate a type
error.
One block protected with // prettier-ignore to preserve careful
comment formatting.

Where there are repeated concatenations prettier has made a pretty
mess of things, but the correct fix is probably to use template
literals instead (rather than just locally disabling prettier).
This is one of the items in the to-do list in google#7600.
Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM!

generators/dart/dart_generator.ts Outdated Show resolved Hide resolved
generators/dart/loops.ts Show resolved Hide resolved
generators/dart/colour.ts Show resolved Hide resolved
generators/javascript/logic.ts Show resolved Hide resolved
@cpcallen
Copy link
Contributor Author

Fixed the one definite error. Please let me know if your other comments have been satisfactorily addressed (at least for the purposes of this PR).

@BeksOmega
Copy link
Collaborator

LGTM!

@cpcallen cpcallen merged commit 81b427f into google:develop Nov 14, 2023
6 checks passed
@cpcallen cpcallen deleted the refactor/6828/dart branch November 14, 2023 16:13
cpcallen added a commit to cpcallen/blockly that referenced this pull request Mar 15, 2024
In PRs google#7602, google#7616, google#7646, google#7647 and google#7654 the @Protected
access modifier on scrub_ was not transcribed to the new
typescript signature.

BREAKING CHANGE: This makes scrub_ protected again, which will
break any code attempting to access this method from outside
a CodeGenerator subclass.
cpcallen added a commit to cpcallen/blockly that referenced this pull request Mar 15, 2024
Fixes google#2156.

In PRs google#7602, google#7616, google#7646, google#7647 and google#7654 the @Protected
access modifier on scrub_ on the CodeGenerator subclasses
was not transcribed to the new typescript signature.  I was
going to re-add it, but this breaks some of the procedure
block generator functions which rely on it, and then
@BeksOmega pointed out that this might be one of the
CodeGenerator API functions which we had already decided
should be public—and lo and behold I found google#2156.

Per discussion amongst team, I am not renaming it to
scrub at this time.
cpcallen added a commit to cpcallen/blockly that referenced this pull request Mar 15, 2024
Fixes google#2156.

In PRs google#7602, google#7616, google#7646, google#7647 and google#7654 the @Protected
access modifier on scrub_ on the CodeGenerator subclasses
was not transcribed to the new typescript signature.  I was
going to re-add it, but this breaks some of the procedure
block generator functions which rely on it, and then
@BeksOmega pointed out that this might be one of the
CodeGenerator API functions which we had already decided
should be public—and lo and behold I found google#2156.

Per discussion amongst team, I am not renaming it to
scrub at this time.
cpcallen added a commit to cpcallen/blockly that referenced this pull request Mar 15, 2024
Fixes google#2156.

In PRs google#7602, google#7616, google#7646, google#7647 and google#7654 the @Protected
access modifier on scrub_ on the CodeGenerator subclasses
was not transcribed to the new typescript signature.  I was
going to re-add it, but this breaks some of the procedure
block generator functions which rely on it, and then
@BeksOmega pointed out that this might be one of the
CodeGenerator API functions which we had already decided
should be public—and lo and behold I found google#2156.

Per discussion amongst team, I am not renaming it to
scrub at this time.
cpcallen added a commit that referenced this pull request Mar 15, 2024
Fixes #2156.

In PRs #7602, #7616, #7646, #7647 and #7654 the @Protected
access modifier on scrub_ on the CodeGenerator subclasses
was not transcribed to the new typescript signature.  I was
going to re-add it, but this breaks some of the procedure
block generator functions which rely on it, and then
@BeksOmega pointed out that this might be one of the
CodeGenerator API functions which we had already decided
should be public—and lo and behold I found #2156.

Per discussion amongst team, I am not renaming it to
scrub at this time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants