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

fix: Rename Generator to CodeGenerator #6585

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
"jsdoc/check-param-names": ["off", {"checkDestructured": false}],
// Allow any text in the license tag. Other checks are not relevant.
"jsdoc/check-values": ["off"]

}
}]
}
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ All submissions, including submissions by project members, require review. We
use Github pull requests for this purpose.

### Browser compatibility
We care strongly about making Blockly work on all browsers. As of 2022 we
We care strongly about making Blockly work on all browsers. As of 2022 we
support Edge, Chrome, Safari, and Firefox. We will not accept changes that only
work on a subset of those browsers. You can check [caniuse.com](https://caniuse.com/)
work on a subset of those browsers. You can check [caniuse.com](https://caniuse.com/)
for compatibility information.

### The small print
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ updates:
- "PR: chore"
- "PR: dependencies"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/"
directory: "/"
target-branch: "develop"
schedule:
interval: "weekly"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag_module_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ name: Tag module cleanup

# Trigger on pull requests against goog_module branch only
# Uses pull_request_target to get write permissions so that it can write labels.
on:
on:
pull_request_target:
branches:
- goog_module

jobs:
tag-module-cleanup:

# Add the type: cleanup label
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
permissions:
contents: write # for peter-evans/create-pull-request to create branch
pull-requests: write # for peter-evans/create-pull-request to create a PR
runs-on: ubuntu-latest
runs-on: ubuntu-latest

steps:
- name: Check Out Blockly
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/base_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var goog = goog || {};
/**
* Reference to the global object. This is provided as 'root' by the
* UMD wrapper, but prefer globalThis if it is defined.
*
*
* https://www.ecma-international.org/ecma-262/9.0/index.html#sec-global-object
*
* @const
Expand Down
9 changes: 5 additions & 4 deletions core/blockly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {FlyoutButton} from './flyout_button.js';
import {HorizontalFlyout} from './flyout_horizontal.js';
import {FlyoutMetricsManager} from './flyout_metrics_manager.js';
import {VerticalFlyout} from './flyout_vertical.js';
import {Generator} from './generator.js';
import {CodeGenerator} from './generator.js';
import {Gesture} from './gesture.js';
import {Grid} from './grid.js';
import {Icon} from './icon.js';
Expand Down Expand Up @@ -567,12 +567,12 @@ WorkspaceCommentSvg.prototype.showContextMenu =
return;
}
const menuOptions = [];

if (this.isDeletable() && this.isMovable()) {
menuOptions.push(ContextMenu.commentDuplicateOption(this));
menuOptions.push(ContextMenu.commentDeleteOption(this));
}

ContextMenu.show(e, menuOptions, this.RTL);
};

Expand Down Expand Up @@ -663,7 +663,8 @@ export {FieldVariable};
export {Flyout};
export {FlyoutButton};
export {FlyoutMetricsManager};
export {Generator};
export {CodeGenerator};
export {CodeGenerator as Generator}; // Deprecated name, October 2022.
export {Gesture};
export {Grid};
export {HorizontalFlyout};
Expand Down
20 changes: 10 additions & 10 deletions core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @class
*/
import * as goog from '../closure/goog/goog.js';
goog.declareModuleId('Blockly.Generator');
goog.declareModuleId('Blockly.CodeGenerator');

import type {Block} from './block.js';
import * as common from './common.js';
Expand All @@ -24,14 +24,14 @@ import type {Workspace} from './workspace.js';
* Class for a code generator that translates the blocks into a language.
*
* @unrestricted
* @alias Blockly.Generator
* @alias Blockly.CodeGenerator
*/
export class Generator {
export class CodeGenerator {
name_: string;

/**
* This is used as a placeholder in functions defined using
* Generator.provideFunction_. It must not be legal code that could
* CodeGenerator.provideFunction_. It must not be legal code that could
* legitimately appear in a function definition (or comment), and it must
* not confuse the regular expression parser.
*/
Expand Down Expand Up @@ -205,7 +205,7 @@ export class Generator {
|[string, number] {
if (this.isInitialized === false) {
console.warn(
'Generator init was not called before blockToCode was called.');
'CodeGenerator init was not called before blockToCode was called.');
}
if (!block) {
return '';
Expand Down Expand Up @@ -414,7 +414,7 @@ export class Generator {
* "listRandom", not "random"). There is no danger of colliding with reserved
* words, or user-defined variable or procedure names.
*
* The code gets output when Generator.finish() is called.
* The code gets output when CodeGenerator.finish() is called.
*
* @param desiredName The desired name of the function (e.g. mathIsPrime).
* @param code A list of statements or one multi-line code string. Use ' '
Expand Down Expand Up @@ -514,23 +514,23 @@ export class Generator {
}
}

Object.defineProperties(Generator.prototype, {
Object.defineProperties(CodeGenerator.prototype, {
/**
* A database of variable names.
*
* @name Blockly.Generator.prototype.variableDB_
* @name Blockly.CodeGenerator.prototype.variableDB_
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
* @suppress {checkTypes}
*/
variableDB_: ({
/** @returns Name database. */
get(this: Generator): Names |
get(this: CodeGenerator): Names |
undefined {
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
return this.nameDB_;
},
/** @param nameDb New name database. */
set(this: Generator, nameDb: Names|undefined) {
set(this: CodeGenerator, nameDb: Names|undefined) {
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
this.nameDB_ = nameDb;
},
Expand Down
1 change: 0 additions & 1 deletion demos/blockfactory/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,3 @@ BlocklyDevTools.Analytics.sendQueued = function() {
// stub
this.LOG_TO_CONSOLE_ && console.log('Analytics.sendQueued');
};

4 changes: 2 additions & 2 deletions demos/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Code.renderContent = function() {

/**
* Attempt to generate the code and display it in the UI, pretty printed.
* @param generator {!Blockly.Generator} The generator to use.
* @param generator {!Blockly.CodeGenerator} The generator to use.
*/
Code.attemptCodeGeneration = function(generator) {
var content = document.getElementById('content_' + Code.selected);
Expand All @@ -388,7 +388,7 @@ Code.attemptCodeGeneration = function(generator) {

/**
* Check whether all blocks in use have generator functions.
* @param generator {!Blockly.Generator} The generator to use.
* @param generator {!Blockly.CodeGenerator} The generator to use.
*/
Code.checkAllGeneratorFunctionsDefined = function(generator) {
var blocks = Code.workspace.getAllBlocks(false);
Expand Down
4 changes: 2 additions & 2 deletions demos/mobile/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
29 changes: 14 additions & 15 deletions demos/mobile/ios/Blockly WebView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class ViewController: UIViewController, WKUIDelegate {
/// The name used to reference this iOS object when executing callbacks from the JS code.
/// If this value is changed, it should also be changed in the `CODE_GENERATOR_BRIDGE_JS` file.
fileprivate static let HOST_HTML = "Blockly/webview.html"

@IBOutlet weak var webView: WKWebView!

/// Additional setup after loading the UI NIB.
override func viewDidLoad() {
super.viewDidLoad()
webView.uiDelegate = self
// Do any additional setup after loading the view, typically from a nib.
loadWebContent()
}

/// Load the root HTML page into the webview.
func loadWebContent() {
if let htmlUrl = Bundle.main.url(forResource: "webview", withExtension: "html",
Expand All @@ -41,7 +41,7 @@ class ViewController: UIViewController, WKUIDelegate {
runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping () -> Void) {

let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let title = NSLocalizedString("OK", comment: "OK Button")
let ok = UIAlertAction(title: title, style: .default) { (action: UIAlertAction) -> Void in
Expand All @@ -51,25 +51,25 @@ class ViewController: UIViewController, WKUIDelegate {
present(alert, animated: true)
completionHandler()
}

/// Handle window.confirm() with a native dialog.
func webView(_ webView: WKWebView,
runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void) {

let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let closeAndHandle = { (okayed: Bool) in
alert.dismiss(animated: true, completion: nil)
completionHandler(okayed)
}

let okTitle = NSLocalizedString("OK", comment: "OK button title")
let ok = UIAlertAction(title: okTitle, style: .default) { (action: UIAlertAction) -> Void in
closeAndHandle(true)
}
alert.addAction(ok)

let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel button title")
let cancel = UIAlertAction(title: cancelTitle, style: .default) {
(action: UIAlertAction) -> Void in
Expand All @@ -78,34 +78,33 @@ class ViewController: UIViewController, WKUIDelegate {
alert.addAction(cancel)
present(alert, animated: true)
}

/// Handle window.prompt() with a native dialog.
func webView(_ webView: WKWebView,
runJavaScriptTextInputPanelWithPrompt prompt: String,
defaultText: String?,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (String?) -> Void) {

let alert = UIAlertController(title: prompt, message: nil, preferredStyle: .alert)

alert.addTextField { (textField) in
textField.text = defaultText
}

let okTitle = NSLocalizedString("OK", comment: "OK button title")
let okAction = UIAlertAction(title: okTitle, style: .default) { (_) in
let textInput = alert.textFields![0] as UITextField
completionHandler(textInput.text)
}
alert.addAction(okAction)

let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel button title")
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel) { (_) in
completionHandler(nil)
}
alert.addAction(cancelAction)

present(alert, animated: true)
}
}

10 changes: 5 additions & 5 deletions generators/dart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ goog.module('Blockly.Dart');
const Variables = goog.require('Blockly.Variables');
const stringUtils = goog.require('Blockly.utils.string');
const {Block} = goog.requireType('Blockly.Block');
const {Generator} = goog.require('Blockly.Generator');
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
const {Names, NameType} = goog.require('Blockly.Names');
const {Workspace} = goog.requireType('Blockly.Workspace');
const {inputTypes} = goog.require('Blockly.inputTypes');


/**
* Dart code generator.
* @type {!Generator}
* @type {!CodeGenerator}
*/
const Dart = new Generator('Dart');
const Dart = new CodeGenerator('Dart');

/**
* List of illegal variable names.
Expand Down Expand Up @@ -86,7 +86,7 @@ Dart.isInitialized = false;
* @param {!Workspace} workspace Workspace to generate code from.
*/
Dart.init = function(workspace) {
// Call Blockly.Generator's init.
// Call Blockly.CodeGenerator's init.
Object.getPrototypeOf(this).init.call(this);

if (!this.nameDB_) {
Expand Down Expand Up @@ -145,7 +145,7 @@ Dart.finish = function(code) {
definitions.push(def);
}
}
// Call Blockly.Generator's finish.
// Call Blockly.CodeGenerator's finish.
code = Object.getPrototypeOf(this).finish.call(this, code);
this.isInitialized = false;

Expand Down
10 changes: 5 additions & 5 deletions generators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ goog.module('Blockly.JavaScript');
const Variables = goog.require('Blockly.Variables');
const stringUtils = goog.require('Blockly.utils.string');
const {Block} = goog.requireType('Blockly.Block');
const {Generator} = goog.require('Blockly.Generator');
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
const {inputTypes} = goog.require('Blockly.inputTypes');
const {Names, NameType} = goog.require('Blockly.Names');
const {Workspace} = goog.requireType('Blockly.Workspace');


/**
* JavaScript code generator.
* @type {!Generator}
* @type {!CodeGenerator}
*/
const JavaScript = new Generator('JavaScript');
const JavaScript = new CodeGenerator('JavaScript');

/**
* List of illegal variable names.
Expand Down Expand Up @@ -127,7 +127,7 @@ JavaScript.isInitialized = false;
* @param {!Workspace} workspace Workspace to generate code from.
*/
JavaScript.init = function(workspace) {
// Call Blockly.Generator's init.
// Call Blockly.CodeGenerator's init.
Object.getPrototypeOf(this).init.call(this);

if (!this.nameDB_) {
Expand Down Expand Up @@ -169,7 +169,7 @@ JavaScript.init = function(workspace) {
JavaScript.finish = function(code) {
// Convert the definitions dictionary into a list.
const definitions = Object.values(this.definitions_);
// Call Blockly.Generator's finish.
// Call Blockly.CodeGenerator's finish.
code = Object.getPrototypeOf(this).finish.call(this, code);
this.isInitialized = false;

Expand Down