Merge pull request #753 from paulkaplan/provide-argument-ids

Provide argument id list with callers and procdef blocks
This commit is contained in:
Paul Kaplan 2017-11-03 09:48:37 -04:00 committed by GitHub
commit e2ac6947af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,18 @@ const parseProcedureArgMap = function (procCode) {
return argMap;
};
/**
* Generate a list of "argument IDs" for procdefs and caller mutations.
* IDs just end up being `input0`, `input1`, ... which is good enough.
* @param {string} procCode Scratch 2.0 procedure string.
* @return {Array.<string>} Array of argument id strings.
*/
const parseProcedureArgIds = function (procCode) {
return parseProcedureArgMap(procCode)
.map(arg => arg.inputName)
.filter(name => name); // Filter out unnamed inputs which are labels
};
/**
* Flatten a block tree into a block list.
* Children are temporarily stored on the `block.children` property.
@ -501,6 +513,7 @@ const parseBlock = function (sb2block, getVariableId) {
tagName: 'mutation',
proccode: procData[0], // e.g., "abc %n %b %s"
argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2']
argumentids: JSON.stringify(parseProcedureArgIds(procData[0])),
argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc']
warp: procData[3], // Warp mode, e.g., true/false.
children: []
@ -512,7 +525,8 @@ const parseBlock = function (sb2block, getVariableId) {
activeBlock.mutation = {
tagName: 'mutation',
children: [],
proccode: sb2block[1]
proccode: sb2block[1],
argumentids: JSON.stringify(parseProcedureArgIds(sb2block[1]))
};
} else if (oldOpcode === 'getParam') {
// Mutation for procedure parameter.