pxt-core 8.1.2 → 8.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4357,6 +4357,56 @@ ${output}</xml>`;
4357
4357
  }
4358
4358
  return undefined;
4359
4359
  }
4360
+ function getCallKey(statement) {
4361
+ const call = statement.expression;
4362
+ const callInfo = pxtc.pxtInfo(call).callInfo;
4363
+ const attributes = attrs(callInfo);
4364
+ if (attributes.blockAllowMultiple)
4365
+ return undefined;
4366
+ if (attributes.blockHandlerKey)
4367
+ return attributes.blockHandlerKey;
4368
+ const args = callInfo.args.filter(arg => !ts.isArrowFunction(arg) && !isFunctionExpression(arg)).map(arg => getArgKeyRecursive(arg)).join("$$");
4369
+ return attributes.blockId + "-" + args;
4370
+ }
4371
+ // custom function to get the key for an argument. we do this instead of simply calling getText() because this
4372
+ // handles whitespace and certain passthrough nodes like parenthesized expressions
4373
+ function getArgKeyRecursive(n) {
4374
+ if (!n)
4375
+ return "";
4376
+ switch (n.kind) {
4377
+ case SK.ParenthesizedExpression:
4378
+ case SK.AsExpression:
4379
+ return getArgKeyRecursive(n.expression);
4380
+ case SK.Identifier:
4381
+ return n.text;
4382
+ case SK.StringLiteral:
4383
+ case SK.FirstTemplateToken:
4384
+ case SK.NoSubstitutionTemplateLiteral:
4385
+ return `"${n.text}"`;
4386
+ case SK.NumericLiteral:
4387
+ return n.text;
4388
+ case SK.TrueKeyword:
4389
+ return "true";
4390
+ case SK.FalseKeyword:
4391
+ return "false";
4392
+ case SK.BinaryExpression:
4393
+ return `{${getArgKeyRecursive(n.left)}${n.operatorToken.getText()}${getArgKeyRecursive(n.right)}}`;
4394
+ case SK.PrefixUnaryExpression:
4395
+ return n.operator + getArgKeyRecursive(n.operand);
4396
+ case SK.PropertyAccessExpression:
4397
+ return getArgKeyRecursive(n.expression) + "." + getArgKeyRecursive(n.name);
4398
+ case SK.ArrayLiteralExpression:
4399
+ return `[${n.elements.map(e => getArgKeyRecursive(e))}]`;
4400
+ case SK.ElementAccessExpression:
4401
+ return `${n.expression}[${n.argumentExpression}]`;
4402
+ case SK.TaggedTemplateExpression:
4403
+ return `${getArgKeyRecursive(n.tag)}\`${n.template.getText()}\``;
4404
+ case SK.CallExpression:
4405
+ return `${getArgKeyRecursive(n.expression)}(${n.arguments.map(getArgKeyRecursive).join(",")})`;
4406
+ default:
4407
+ return n.getText();
4408
+ }
4409
+ }
4360
4410
  function countBlock() {
4361
4411
  emittedBlocks++;
4362
4412
  if (emittedBlocks > MAX_BLOCKS) {
@@ -4926,6 +4976,101 @@ ${output}</xml>`;
4926
4976
  }
4927
4977
  return undefined;
4928
4978
  }
4979
+ /**
4980
+ * We split up comments according to the following rules:
4981
+ * 1. If the comment is not top-level:
4982
+ * a. Combine it with all comments for the following statement
4983
+ * b. If there is no following statement in the current block, group it with the previous statement
4984
+ * c. If there are no statements inside the block, group it with the parent block
4985
+ * d. If trailing the same line as the statement, group it with the comments for that statement
4986
+ * 2. If the comment is top-level:
4987
+ * b. If the comment is followed by an empty line, it becomes a workspace comment
4988
+ * c. If the comment is followed by a multi-line comment, it becomes a workspace comment
4989
+ * a. If the comment is a single-line comment, combine it with the next single-line comment
4990
+ * d. If the comment is not followed with an empty line, group it with the next statement or event
4991
+ * e. All other comments are workspace comments
4992
+ *
4993
+ * The below function gathers any comments associated to the Node, and attaches them
4994
+ * to the StatementNode.
4995
+ */
4996
+ function getNodeComments(commented, stmt) {
4997
+ let comments = [];
4998
+ let current;
4999
+ for (let i = 0; i < commentMap.length; i++) {
5000
+ current = commentMap[i];
5001
+ if (!current.owner && current.start >= commented.pos && current.end <= commented.end) {
5002
+ current.owner = commented;
5003
+ current.ownerStatement = stmt;
5004
+ comments.push(current);
5005
+ }
5006
+ if (current.start > commented.end)
5007
+ break;
5008
+ }
5009
+ if (current && current.isTrailingComment) {
5010
+ const endLine = ts.getLineAndCharacterOfPosition(file, commented.end);
5011
+ const commentLine = ts.getLineAndCharacterOfPosition(file, current.start);
5012
+ if (endLine.line === commentLine.line) {
5013
+ // If the comment is trailing and on the same line as the statement, it probably belongs
5014
+ // to this statement. Remove it from any statement it's already assigned to and any workspace
5015
+ // comments
5016
+ if (current.ownerStatement) {
5017
+ current.ownerStatement.comment.splice(current.ownerStatement.comment.indexOf(current), 1);
5018
+ for (const wsComment of workspaceComments) {
5019
+ wsComment.comment.splice(wsComment.comment.indexOf(current), 1);
5020
+ }
5021
+ }
5022
+ current.owner = commented;
5023
+ current.ownerStatement = stmt;
5024
+ comments.push(current);
5025
+ }
5026
+ }
5027
+ if (comments.length) {
5028
+ const wsCommentRefs = [];
5029
+ if (isTopLevelComment(commented)) {
5030
+ let currentWorkspaceComment = [];
5031
+ const localWorkspaceComments = [];
5032
+ comments.forEach((comment, index) => {
5033
+ let beforeStatement = comment.owner && comment.start < comment.owner.getStart();
5034
+ if (comment.kind === CommentKind.MultiLine && beforeStatement) {
5035
+ if (currentWorkspaceComment.length) {
5036
+ localWorkspaceComments.push(currentWorkspaceComment);
5037
+ currentWorkspaceComment = [];
5038
+ }
5039
+ if (index != comments.length - 1) {
5040
+ localWorkspaceComments.push([comment]);
5041
+ return;
5042
+ }
5043
+ }
5044
+ currentWorkspaceComment.push(comment);
5045
+ if (comment.followedByEmptyLine && beforeStatement) {
5046
+ localWorkspaceComments.push(currentWorkspaceComment);
5047
+ currentWorkspaceComment = [];
5048
+ }
5049
+ });
5050
+ comments = currentWorkspaceComment;
5051
+ localWorkspaceComments.forEach(comment => {
5052
+ const refId = getCommentRef();
5053
+ wsCommentRefs.push(refId);
5054
+ workspaceComments.push({ comment, refId });
5055
+ });
5056
+ }
5057
+ // Attach comments to StatementNode
5058
+ if (stmt) {
5059
+ if (wsCommentRefs.length) {
5060
+ if (stmt.data)
5061
+ stmt.data += ";" + wsCommentRefs.join(";");
5062
+ else
5063
+ stmt.data = wsCommentRefs.join(";");
5064
+ }
5065
+ if (comments && comments.length) {
5066
+ if (stmt.comment)
5067
+ stmt.comment = stmt.comment.concat(comments);
5068
+ else
5069
+ stmt.comment = comments;
5070
+ }
5071
+ }
5072
+ }
5073
+ }
4929
5074
  function getStatementBlock(n, next, parent, asExpression = false, topLevel = false) {
4930
5075
  const node = n;
4931
5076
  let stmt;
@@ -5028,7 +5173,7 @@ ${output}</xml>`;
5028
5173
  }
5029
5174
  }
5030
5175
  if (!skipComments) {
5031
- getComments(parent || node);
5176
+ getNodeComments(parent || node, stmt);
5032
5177
  }
5033
5178
  return stmt;
5034
5179
  function getNext() {
@@ -5037,97 +5182,6 @@ ${output}</xml>`;
5037
5182
  }
5038
5183
  return undefined;
5039
5184
  }
5040
- /**
5041
- * We split up comments according to the following rules:
5042
- * 1. If the comment is not top-level:
5043
- * a. Combine it with all comments for the following statement
5044
- * b. If there is no following statement in the current block, group it with the previous statement
5045
- * c. If there are no statements inside the block, group it with the parent block
5046
- * d. If trailing the same line as the statement, group it with the comments for that statement
5047
- * 2. If the comment is top-level:
5048
- * b. If the comment is followed by an empty line, it becomes a workspace comment
5049
- * c. If the comment is followed by a multi-line comment, it becomes a workspace comment
5050
- * a. If the comment is a single-line comment, combine it with the next single-line comment
5051
- * d. If the comment is not followed with an empty line, group it with the next statement or event
5052
- * e. All other comments are workspace comments
5053
- */
5054
- function getComments(commented) {
5055
- let comments = [];
5056
- let current;
5057
- for (let i = 0; i < commentMap.length; i++) {
5058
- current = commentMap[i];
5059
- if (!current.owner && current.start >= commented.pos && current.end <= commented.end) {
5060
- current.owner = commented;
5061
- current.ownerStatement = stmt;
5062
- comments.push(current);
5063
- }
5064
- if (current.start > commented.end)
5065
- break;
5066
- }
5067
- if (current && current.isTrailingComment) {
5068
- const endLine = ts.getLineAndCharacterOfPosition(file, commented.end);
5069
- const commentLine = ts.getLineAndCharacterOfPosition(file, current.start);
5070
- if (endLine.line === commentLine.line) {
5071
- // If the comment is trailing and on the same line as the statement, it probably belongs
5072
- // to this statement. Remove it from any statement it's already assigned to and any workspace
5073
- // comments
5074
- if (current.ownerStatement) {
5075
- current.ownerStatement.comment.splice(current.ownerStatement.comment.indexOf(current), 1);
5076
- for (const wsComment of workspaceComments) {
5077
- wsComment.comment.splice(wsComment.comment.indexOf(current), 1);
5078
- }
5079
- }
5080
- current.owner = commented;
5081
- current.ownerStatement = stmt;
5082
- comments.push(current);
5083
- }
5084
- }
5085
- if (comments.length) {
5086
- const wsCommentRefs = [];
5087
- if (isTopLevelComment(commented)) {
5088
- let currentWorkspaceComment = [];
5089
- const localWorkspaceComments = [];
5090
- comments.forEach((comment, index) => {
5091
- let beforeStatement = comment.owner && comment.start < comment.owner.getStart();
5092
- if (comment.kind === CommentKind.MultiLine && beforeStatement) {
5093
- if (currentWorkspaceComment.length) {
5094
- localWorkspaceComments.push(currentWorkspaceComment);
5095
- currentWorkspaceComment = [];
5096
- }
5097
- if (index != comments.length - 1) {
5098
- localWorkspaceComments.push([comment]);
5099
- return;
5100
- }
5101
- }
5102
- currentWorkspaceComment.push(comment);
5103
- if (comment.followedByEmptyLine && beforeStatement) {
5104
- localWorkspaceComments.push(currentWorkspaceComment);
5105
- currentWorkspaceComment = [];
5106
- }
5107
- });
5108
- comments = currentWorkspaceComment;
5109
- localWorkspaceComments.forEach(comment => {
5110
- const refId = getCommentRef();
5111
- wsCommentRefs.push(refId);
5112
- workspaceComments.push({ comment, refId });
5113
- });
5114
- }
5115
- if (stmt) {
5116
- if (wsCommentRefs.length) {
5117
- if (stmt.data)
5118
- stmt.data += ";" + wsCommentRefs.join(";");
5119
- else
5120
- stmt.data = wsCommentRefs.join(";");
5121
- }
5122
- if (comments && comments.length) {
5123
- if (stmt.comment)
5124
- stmt.comment = stmt.comment.concat(comments);
5125
- else
5126
- stmt.comment = comments;
5127
- }
5128
- }
5129
- }
5130
- }
5131
5185
  }
5132
5186
  function getTypeScriptStatementBlock(node, prefix, err) {
5133
5187
  if (options.errorOnGreyBlocks)
@@ -5894,15 +5948,29 @@ ${output}</xml>`;
5894
5948
  blockStatements.unshift(statement);
5895
5949
  }
5896
5950
  }
5897
- eventStatements.map(n => getStatementBlock(n, undefined, undefined, false, topLevel)).forEach(emitStatementNode);
5951
+ const compiledEvents = [];
5952
+ const keyMap = {};
5953
+ for (const statement of eventStatements) {
5954
+ const key = statement.kind === SK.FunctionDeclaration ? undefined : getCallKey(statement);
5955
+ if (key && keyMap[key]) {
5956
+ // Pass false for topLevel to force a grey block
5957
+ compiledEvents.push(getStatementBlock(statement, undefined, undefined, false, false));
5958
+ }
5959
+ else {
5960
+ keyMap[key] = true;
5961
+ compiledEvents.push(getStatementBlock(statement, undefined, undefined, false, topLevel));
5962
+ }
5963
+ }
5964
+ compiledEvents.forEach(emitStatementNode);
5898
5965
  if (blockStatements.length) {
5899
5966
  // wrap statement in "on start" if top level
5900
- const stmtNode = blockStatements.shift();
5901
- const stmt = getStatementBlock(stmtNode, blockStatements, parent, false, topLevel);
5967
+ const blockNode = blockStatements.shift();
5968
+ const stmt = getStatementBlock(blockNode, blockStatements, parent, false, topLevel);
5902
5969
  if (emitOnStart) {
5903
5970
  // Preserve any variable edeclarations that were never used
5904
- let current = stmt;
5905
- let currentNode = stmtNode;
5971
+ // stmt and blockNode will not yet align if there was an auto-declared variable.
5972
+ let currentStmtNode = stmt;
5973
+ let currentBlockNode = blockNode;
5906
5974
  autoDeclarations.forEach(([name, node]) => {
5907
5975
  if (varUsages[name] === ReferenceType.InBlocksOnly) {
5908
5976
  return;
@@ -5916,17 +5984,21 @@ ${output}</xml>`;
5916
5984
  v = getTypeScriptStatementBlock(node, "let ");
5917
5985
  }
5918
5986
  else {
5919
- v = getVariableSetOrChangeBlock(stmtNode, node.name, node.initializer, false, true);
5987
+ v = getVariableSetOrChangeBlock(blockNode, node.name, node.initializer, false, true);
5920
5988
  }
5921
- v.next = current;
5922
- current = v;
5923
- currentNode = node;
5989
+ // Auto-declared variables were not previously inserted into the stmt linked-list.
5990
+ // Insert auto-declared 'v' as the currentStmtNode.
5991
+ v.next = currentStmtNode;
5992
+ currentStmtNode = v;
5993
+ currentBlockNode = node;
5994
+ // Attach to currentStmtNode any associated comments
5995
+ getNodeComments(currentBlockNode.parent, currentStmtNode);
5924
5996
  });
5925
- if (current) {
5926
- const r = mkStmt(ts.pxtc.ON_START_TYPE, currentNode);
5997
+ if (currentStmtNode) {
5998
+ const r = mkStmt(ts.pxtc.ON_START_TYPE, currentBlockNode);
5927
5999
  r.handlers = [{
5928
6000
  name: "HANDLER",
5929
- statement: current
6001
+ statement: currentStmtNode
5930
6002
  }];
5931
6003
  return r;
5932
6004
  }
package/built/pxtlib.js CHANGED
@@ -5688,7 +5688,9 @@ var pxt;
5688
5688
  const height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
5689
5689
  const left = ((width / 2) - (popUpWidth / 2)) + winLeft;
5690
5690
  const top = ((height / 2) - (popUpHeight / 2)) + winTop;
5691
- const popupWindow = window.open(url, title, "width=" + popUpWidth + ", height=" + popUpHeight + ", top=" + top + ", left=" + left);
5691
+ const features = "width=" + popUpWidth + ", height=" + popUpHeight + ", top=" + top + ", left=" + left;
5692
+ // Current CEF version does not like when features parameter is passed and just immediately rejects.
5693
+ const popupWindow = window.open(url, title, !pxt.BrowserUtils.isIpcRenderer() ? features : undefined);
5692
5694
  if (popupWindow.focus) {
5693
5695
  popupWindow.focus();
5694
5696
  }
@@ -5696,7 +5698,7 @@ var pxt;
5696
5698
  }
5697
5699
  catch (e) {
5698
5700
  // Error opening popup
5699
- pxt.tickEvent('pxt.popupError', { url: url, msg: e.message });
5701
+ pxt.tickEvent('pxt.popupError', { msg: e.message });
5700
5702
  return null;
5701
5703
  }
5702
5704
  }
@@ -8698,11 +8700,16 @@ var pxt;
8698
8700
  docs.prepTemplate = prepTemplate;
8699
8701
  function setupRenderer(renderer) {
8700
8702
  renderer.image = function (href, title, text) {
8703
+ const endpointName = "makecode-lucas-testing-makecodetempmediaservice-usea";
8701
8704
  if (href.startsWith("youtube:")) {
8702
8705
  let out = '<div class="tutorial-video-embed"><iframe src="https://www.youtube.com/embed/' + href.split(":").pop()
8703
8706
  + '" title="' + title + '" frameborder="0" ' + 'allowFullScreen ' + 'allow="autoplay; picture-in-picture"></iframe></div>';
8704
8707
  return out;
8705
8708
  }
8709
+ else if (href.startsWith("azuremedia:")) {
8710
+ let out = `<div class="tutorial-video-embed"><video class="ams-embed" controls src="https://${endpointName}.streaming.media.azure.net/` + href.split(":").pop() + '/manifest(format=mpd-time-cmaf)" /></div>';
8711
+ return out;
8712
+ }
8706
8713
  else {
8707
8714
  let out = '<img class="ui image" src="' + href + '" alt="' + text + '"';
8708
8715
  if (title) {
package/built/pxtsim.js CHANGED
@@ -6295,6 +6295,7 @@ var pxsim;
6295
6295
  }
6296
6296
  }
6297
6297
  createFrame(url) {
6298
+ var _a;
6298
6299
  const wrapper = document.createElement("div");
6299
6300
  wrapper.className = `simframe ui embed`;
6300
6301
  const frame = document.createElement('iframe');
@@ -6309,7 +6310,7 @@ var pxsim;
6309
6310
  frame.frameBorder = "0";
6310
6311
  frame.dataset['runid'] = this.runId;
6311
6312
  frame.dataset['origin'] = new URL(furl).origin || "*";
6312
- if (this._runOptions.autofocus)
6313
+ if ((_a = this._runOptions) === null || _a === void 0 ? void 0 : _a.autofocus)
6313
6314
  frame.setAttribute("autofocus", "true");
6314
6315
  wrapper.appendChild(frame);
6315
6316
  const i = document.createElement("i");