Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Snippets
  • Sign up now
  • Login
  • Sign in / Register
  • scion scion
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • SCION-SCXMLSCION-SCXML
  • scionscion
  • Issues
  • #25
Closed
Open
Issue created Aug 02, 2021 by Korel@Korel

registerCustomActionTags exception regarding function name

Hello,
My friend and I were trying to figure out how to add custom actions (which is also discussed in https://gitter.im/SCION-SCXML/Lobby). First of all, thank you very much for the guidance given in gitter! After following the examples, we have encountered a "SyntaxError: Unexpected token" exception. After some research, I was able to fix it with a hack. I'll provide code samples and the way I temporarily fixed it below. I'm using node 10.24.0, packages installed with npm 7.19.0:

"@scion-scxml/core": "^2.6.24",
"@scion-scxml/scxml": "^4.3.27"

Example code (Index.js):

const scxml = require("@scion-scxml/scxml");
const core = require("@scion-scxml/core");

let doc1 = `
<scxml initial="s0" version="1.0" xmlns="http://www.w3.org/2005/07/scxml" xmlns:test="http://example.com">
  <state id="s0">
      <onentry>
        <log expr="'Entry'" label="info"/>
        <test:me  />
        <send event="e0"/>
      </onentry>
      <transition target="final" event="e0">
      </transition>
  </state>
  <final id="final">
      <onentry>
          <log expr="'Reached final'" label="info"/>
      </onentry>
  </final>
</scxml>
`;

let action = {
  "http://example.com": {
    me: function (action, builder) {
      return `this.log("It works!!")`;
    },
  },
};

scxml.registerCustomActionTags(action);

scxml.documentStringToModel("", doc1, function (err, model) {
  if (err) throw err;
  model.prepare(function (err, fnModel) {
    if (err) throw err;
    //instantiate the interpreter
    var sc = new core.Statechart(fnModel);
    //start the interpreter
    sc.start();
  });
});

The exception we were getting is: exception

I figured, I should somehow fixed the function name to make it valid again. Therefore my fix was modifying scjson-to-module.js line 200

if(action.$type.startsWith("{"))
      action.$type = action.$type.replace(/[{\+\-\[\]\.: }/]/g, '_')

change

With this, I was able to get it to work. There might be a better or more elegant solutions (I have also not polished the regex).

endresult

I'm sorry if I have not followed any correct convention during the issue. Thank you!

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking