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

feat: allow the dialog methods to take in extra parameters #8084

Merged
merged 4 commits into from
May 8, 2024

Conversation

BeksOmega
Copy link
Collaborator

@BeksOmega BeksOmega commented May 7, 2024

The basics

The details

Resolves

Fixes #7882

Proposed Changes

Makes it so the setX dialog methods assign directly to the property on the exported namespace tree instead of to an internal variable.

Reason for Changes

Fixes a problem for Scratch where they didn't have a good place for their dialog code to live.

Test Coverage

Added tests that assigned dialogmethods can take in extra parameters.

Documentation

This is pretty niche so I don't think it needs explicit documentation.

Additional Information

This doesn't have to go into v11, I just put it up against that in case it can be reviewed in time.

@BeksOmega BeksOmega requested a review from a team as a code owner May 7, 2024 20:47
@BeksOmega BeksOmega requested a review from NeilFraser May 7, 2024 20:47
@github-actions github-actions bot added PR: feature Adds a feature and removed PR: feature Adds a feature labels May 7, 2024
@BeksOmega BeksOmega merged commit 278006b into google:rc/v11.0.0 May 8, 2024
6 checks passed
@cpcallen
Copy link
Contributor

This PR is causing tests in blockly-samples repository to fail for typed-variable-modal—but seemingly only when I merge the master branch into rc/v11.0.0 (see google/blockly-samples#2348) and then link that against a locally-built version of Blockly from this repo's rc/v11.0.0 branch:

Error: Not implemented: window.alert
    at module.exports (webpack-internal:///./node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
    at Window.eval [as alert] (webpack-internal:///./node_modules/jsdom/lib/jsdom/browser/Window.js:864:7)
    at Object.alert$$module$build$src$core$dialog (webpack-internal:///../../../blockly/dist/blockly_compressed.js:575:605)
    at TypedVariableModal.onConfirm_ (webpack-internal:///./src/TypedVariableModal.js:205:56)

Linking to the commit before this PR landed prevents the test failures.
Running tests directly in the blockly-samples repository's rc/v11.0.0 branch also does not exhibit test failures.

@cpcallen
Copy link
Contributor

After discussing with @BeksOmega, our working theory was that the test failure was being caused by the call to sinon.stub() in the typed-variable-modal tests failing to successfully stub Blockly.dialog.alert now that that is export let alert = … rather than the previous export function alert(…).

Having looked at blockly_compressed.js, I can confirm that this does appear to be probable. Here is an extract from the compiled output for core/dialog.ts, rewriting for legibility:

var alert$$internal = (a,b) => {
  window.alert(a);
  b&&b()
},

module$build$src$core$dialog = {
  get alert(){ return alert$$internal },
  // ...
};

…where the object declared as module$build$src$core$dialog becomes Blockly.dialog.

In other words: Closure Compiler does correctly support export let, and does so by creating a get accessor method for the exported name. It will actually do this for export functions too, since function declarations are equivalent to var and thus also mutable—though it's clever enough to only emit get accessors for dynamic exports that are actually subject to subsequent assignment

It's possible in principle for such an accessor to be stubbed, but Sinon would have to use Object.defineProperty rather than a simple assignment, and it probably doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants