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

Cjs2esm #3879

Closed
wants to merge 3 commits into from
Closed

Cjs2esm #3879

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
root: true,
extends: ['scratch', 'scratch/es6'],
env: {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Cast = require('../util/cast');
import Cast from "../util/cast";

class Scratch3ControlBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -203,4 +203,4 @@ class Scratch3ControlBlocks {
}
}

module.exports = Scratch3ControlBlocks;
export default Scratch3ControlBlocks;
6 changes: 3 additions & 3 deletions src/blocks/scratch3_core_example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const BlockType = require('../extension-support/block-type');
const ArgumentType = require('../extension-support/argument-type');
import BlockType from "../extension-support/block-type";
import ArgumentType from "../extension-support/argument-type";

/* eslint-disable-next-line max-len */
const blockIconURI = 'data:image/svg+xml,%3Csvg id="rotate-counter-clockwise" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%233d79cc;%7D.cls-2%7Bfill:%23fff;%7D%3C/style%3E%3C/defs%3E%3Ctitle%3Erotate-counter-clockwise%3C/title%3E%3Cpath class="cls-1" d="M22.68,12.2a1.6,1.6,0,0,1-1.27.63H13.72a1.59,1.59,0,0,1-1.16-2.58l1.12-1.41a4.82,4.82,0,0,0-3.14-.77,4.31,4.31,0,0,0-2,.8,4.25,4.25,0,0,0-1.34,1.73,5.06,5.06,0,0,0,.54,4.62A5.58,5.58,0,0,0,12,17.74h0a2.26,2.26,0,0,1-.16,4.52A10.25,10.25,0,0,1,3.74,18,10.14,10.14,0,0,1,2.25,8.78,9.7,9.7,0,0,1,5.08,4.64,9.92,9.92,0,0,1,9.66,2.5a10.66,10.66,0,0,1,7.72,1.68l1.08-1.35a1.57,1.57,0,0,1,1.24-.6,1.6,1.6,0,0,1,1.54,1.21l1.7,7.37A1.57,1.57,0,0,1,22.68,12.2Z"/%3E%3Cpath class="cls-2" d="M21.38,11.83H13.77a.59.59,0,0,1-.43-1l1.75-2.19a5.9,5.9,0,0,0-4.7-1.58,5.07,5.07,0,0,0-4.11,3.17A6,6,0,0,0,7,15.77a6.51,6.51,0,0,0,5,2.92,1.31,1.31,0,0,1-.08,2.62,9.3,9.3,0,0,1-7.35-3.82A9.16,9.16,0,0,1,3.17,9.12,8.51,8.51,0,0,1,5.71,5.4,8.76,8.76,0,0,1,9.82,3.48a9.71,9.71,0,0,1,7.75,2.07l1.67-2.1a.59.59,0,0,1,1,.21L22,11.08A.59.59,0,0,1,21.38,11.83Z"/%3E%3C/svg%3E';
Expand Down Expand Up @@ -66,4 +66,4 @@ class Scratch3CoreExample {

}

module.exports = Scratch3CoreExample;
export default Scratch3CoreExample;
4 changes: 2 additions & 2 deletions src/blocks/scratch3_data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Cast = require('../util/cast');
import Cast from "../util/cast";

class Scratch3DataBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -254,4 +254,4 @@ class Scratch3DataBlocks {
}
}

module.exports = Scratch3DataBlocks;
export default Scratch3DataBlocks;
4 changes: 2 additions & 2 deletions src/blocks/scratch3_event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Cast = require('../util/cast');
import Cast from "../util/cast";

class Scratch3EventBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -134,4 +134,4 @@ class Scratch3EventBlocks {
}
}

module.exports = Scratch3EventBlocks;
export default Scratch3EventBlocks;
16 changes: 8 additions & 8 deletions src/blocks/scratch3_looks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Cast = require('../util/cast');
const Clone = require('../util/clone');
const RenderedTarget = require('../sprites/rendered-target');
const uid = require('../util/uid');
const StageLayering = require('../engine/stage-layering');
const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
const MathUtil = require('../util/math-util');
import Cast from "../util/cast";
import Clone from "../util/clone";
import RenderedTarget from "../sprites/rendered-target";
import uid from "../util/uid";
import StageLayering from "../engine/stage-layering";
import getMonitorIdForBlockWithArgs from "../util/get-monitor-id";
import MathUtil from "../util/math-util";

/**
* @typedef {object} BubbleState - the bubble state associated with a particular target.
Expand Down Expand Up @@ -609,4 +609,4 @@ class Scratch3LooksBlocks {
}
}

module.exports = Scratch3LooksBlocks;
export default Scratch3LooksBlocks;
8 changes: 4 additions & 4 deletions src/blocks/scratch3_motion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Cast = require('../util/cast');
const MathUtil = require('../util/math-util');
const Timer = require('../util/timer');
import Cast from "../util/cast";
import MathUtil from "../util/math-util";
import Timer from "../util/timer";

class Scratch3MotionBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -285,4 +285,4 @@ class Scratch3MotionBlocks {
}
}

module.exports = Scratch3MotionBlocks;
export default Scratch3MotionBlocks;
6 changes: 3 additions & 3 deletions src/blocks/scratch3_operators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Cast = require('../util/cast.js');
const MathUtil = require('../util/math-util.js');
import Cast from "../util/cast.js";
import MathUtil from "../util/math-util.js";

class Scratch3OperatorsBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -151,4 +151,4 @@ class Scratch3OperatorsBlocks {
}
}

module.exports = Scratch3OperatorsBlocks;
export default Scratch3OperatorsBlocks;
2 changes: 1 addition & 1 deletion src/blocks/scratch3_procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ class Scratch3ProcedureBlocks {
}
}

module.exports = Scratch3ProcedureBlocks;
export default Scratch3ProcedureBlocks;
8 changes: 4 additions & 4 deletions src/blocks/scratch3_sensing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Cast = require('../util/cast');
const Timer = require('../util/timer');
const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
import Cast from "../util/cast";
import Timer from "../util/timer";
import getMonitorIdForBlockWithArgs from "../util/get-monitor-id";

class Scratch3SensingBlocks {
constructor (runtime) {
Expand Down Expand Up @@ -333,4 +333,4 @@ class Scratch3SensingBlocks {
}
}

module.exports = Scratch3SensingBlocks;
export default Scratch3SensingBlocks;
8 changes: 4 additions & 4 deletions src/blocks/scratch3_sound.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const MathUtil = require('../util/math-util');
const Cast = require('../util/cast');
const Clone = require('../util/clone');
import MathUtil from "../util/math-util";
import Cast from "../util/cast";
import Clone from "../util/clone";

/**
* Occluded boolean value to make its use more understandable.
Expand Down Expand Up @@ -347,4 +347,4 @@ class Scratch3SoundBlocks {
}
}

module.exports = Scratch3SoundBlocks;
export default Scratch3SoundBlocks;
7 changes: 3 additions & 4 deletions src/dispatch/central-dispatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const SharedDispatch = require('./shared-dispatch');

const log = require('../util/log');
import SharedDispatch from "./shared-dispatch";
import log from "../util/log";

/**
* This class serves as the central broker for message dispatch. It expects to operate on the main thread / Window and
Expand Down Expand Up @@ -138,4 +137,4 @@ class CentralDispatch extends SharedDispatch {
}
}

module.exports = new CentralDispatch();
export default new CentralDispatch();
4 changes: 2 additions & 2 deletions src/dispatch/shared-dispatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const log = require('../util/log');
import log from "../util/log";

/**
* @typedef {object} DispatchCallMessage - a message to the dispatch system representing a service method call
Expand Down Expand Up @@ -230,4 +230,4 @@ class SharedDispatch {
}
}

module.exports = SharedDispatch;
export default SharedDispatch;
7 changes: 3 additions & 4 deletions src/dispatch/worker-dispatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const SharedDispatch = require('./shared-dispatch');

const log = require('../util/log');
import SharedDispatch from "./shared-dispatch";
import log from "../util/log";

/**
* This class provides a Worker with the means to participate in the message dispatch system managed by CentralDispatch.
Expand Down Expand Up @@ -107,4 +106,4 @@ class WorkerDispatch extends SharedDispatch {
}
}

module.exports = new WorkerDispatch();
export default new WorkerDispatch();
8 changes: 4 additions & 4 deletions src/engine/adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mutationAdapter = require('./mutation-adapter');
const html = require('htmlparser2');
const uid = require('../util/uid');
import mutationAdapter from "./mutation-adapter";
import html from "htmlparser2";
import uid from "../util/uid";

/**
* Convert and an individual block DOM to the representation tree.
Expand Down Expand Up @@ -173,4 +173,4 @@ const adapter = function (e) {
return domToBlocks(html.parseDOM(e.xml.outerHTML, {decodeEntities: true}));
};

module.exports = adapter;
export default adapter;
6 changes: 3 additions & 3 deletions src/engine/block-utility.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Thread = require('./thread');
const Timer = require('../util/timer');
import Thread from "./thread";
import Timer from "../util/timer";

/**
* @fileoverview
Expand Down Expand Up @@ -237,4 +237,4 @@ class BlockUtility {
}
}

module.exports = BlockUtility;
export default BlockUtility;
23 changes: 12 additions & 11 deletions src/engine/blocks-execute-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
* caching execute information.
*/

/**
* A private method shared with execute to build an object containing the block
* information execute needs and that is reset when other cached Blocks info is
* reset.
* @param {Blocks} blocks Blocks containing the expected blockId
* @param {string} blockId blockId for the desired execute cache
*/
exports.getCached = function () {
throw new Error('blocks.js has not initialized BlocksExecuteCache');
export default {
/**
* A private method shared with execute to build an object containing the block
* information execute needs and that is reset when other cached Blocks info is
* reset.
* @param {Blocks} blocks Blocks containing the expected blockId
* @param {string} blockId blockId for the desired execute cache
*/
getCached() {
throw new Error("blocks.js has not initialized BlocksExecuteCache");
}
};

// Call after the default throwing getCached is assigned for Blocks to replace.
require('./blocks');
import "./blocks";
29 changes: 15 additions & 14 deletions src/engine/blocks-runtime-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ class RuntimeScriptCache {
}
}

/**
* Get an array of scripts from a block container prefiltered to match opcode.
* @param {Blocks} container - Container of blocks
* @param {string} opcode - Opcode to filter top blocks by
*/
exports.getScripts = function () {
throw new Error('blocks.js has not initialized BlocksRuntimeCache');
export default {
/**
* Get an array of scripts from a block container prefiltered to match opcode.
* @param {Blocks} container - Container of blocks
* @param {string} opcode - Opcode to filter top blocks by
*/
getScripts() {
throw new Error("blocks.js has not initialized BlocksRuntimeCache");
},
/**
* Exposed RuntimeScriptCache class used by integration in blocks.js.
* @private
*/
_RuntimeScriptCache: RuntimeScriptCache
};

/**
* Exposed RuntimeScriptCache class used by integration in blocks.js.
* @private
*/
exports._RuntimeScriptCache = RuntimeScriptCache;

require('./blocks');
import "./blocks";
24 changes: 12 additions & 12 deletions src/engine/blocks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const adapter = require('./adapter');
const mutationAdapter = require('./mutation-adapter');
const xmlEscape = require('../util/xml-escape');
const MonitorRecord = require('./monitor-record');
const Clone = require('../util/clone');
const {Map} = require('immutable');
const BlocksExecuteCache = require('./blocks-execute-cache');
const BlocksRuntimeCache = require('./blocks-runtime-cache');
const log = require('../util/log');
const Variable = require('./variable');
const getMonitorIdForBlockWithArgs = require('../util/get-monitor-id');
import adapter from "./adapter";
import mutationAdapter from "./mutation-adapter";
import xmlEscape from "../util/xml-escape";
import MonitorRecord from "./monitor-record";
import Clone from "../util/clone";
import { Map } from "immutable";
import BlocksExecuteCache from "./blocks-execute-cache";
import BlocksRuntimeCache from "./blocks-runtime-cache";
import log from "../util/log";
import Variable from "./variable";
import getMonitorIdForBlockWithArgs from "../util/get-monitor-id";

/**
* @fileoverview
Expand Down Expand Up @@ -1295,4 +1295,4 @@ BlocksRuntimeCache.getScripts = function (blocks, opcode) {
return scripts;
};

module.exports = Blocks;
export default Blocks;
11 changes: 3 additions & 8 deletions src/engine/comment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* @fileoverview
* Object representing a Scratch Comment (block or workspace).
*/

const uid = require('../util/uid');
const xmlEscape = require('../util/xml-escape');
import uid from "../util/uid";
import xmlEscape from "../util/xml-escape";

class Comment {
/**
Expand Down Expand Up @@ -53,4 +48,4 @@ class Comment {

}

module.exports = Comment;
export default Comment;
14 changes: 7 additions & 7 deletions src/engine/execute.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const BlockUtility = require('./block-utility');
const BlocksExecuteCache = require('./blocks-execute-cache');
const log = require('../util/log');
const Thread = require('./thread');
const {Map} = require('immutable');
const cast = require('../util/cast');
import BlockUtility from "./block-utility";
import BlocksExecuteCache from "./blocks-execute-cache";
import log from "../util/log";
import Thread from "./thread";
import { Map } from "immutable";
import cast from "../util/cast";

/**
* Single BlockUtility instance reused by execute for every pritimive ran.
Expand Down Expand Up @@ -577,4 +577,4 @@ const execute = function (sequencer, thread) {
}
};

module.exports = execute;
export default execute;
4 changes: 2 additions & 2 deletions src/engine/monitor-record.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {Record} = require('immutable');
import { Record } from "immutable";

const MonitorRecord = Record({
id: null, // Block Id
Expand All @@ -20,4 +20,4 @@ const MonitorRecord = Record({
visible: true
});

module.exports = MonitorRecord;
export default MonitorRecord;
6 changes: 3 additions & 3 deletions src/engine/mutation-adapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const html = require('htmlparser2');
const decodeHtml = require('decode-html');
import html from "htmlparser2";
import decodeHtml from "decode-html";

/**
* Convert a part of a mutation DOM to a mutation VM object, recursively.
Expand Down Expand Up @@ -45,4 +45,4 @@ const mutationAdpater = function (mutation) {
return mutatorTagToObject(mutationParsed);
};

module.exports = mutationAdpater;
export default mutationAdpater;
2 changes: 1 addition & 1 deletion src/engine/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ Profiler.START = START;
*/
Profiler.STOP = STOP;

module.exports = Profiler;
export default Profiler;
Loading