Why arrow function not working in Script Include - Tokyo?

Rahman3
Tera Expert

Hey guys,

I am exited about the Tokyo new Ecmascript features and playing with creating classes in Script Includes etc and over all it is good and promising. However, I have realised that arrow functions are not working inside a class in Script Include. Is everyone having this issue and reasons for it? Arrow functions are working inside the Business Rules though. See the following class that works great except the arror function! This arror function doesn't compile:

getInfo2 = () => `${this.name} is ${this.age} years old!`;

@Earl Duque @Andrew Barnes - AJB any ideas please?

This is really important as using other libraries code will have arrow functions and without it we are back to olden times 😉

let Person = class Person {
	
	//#isPrivate; // Private field not supported yet
	
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

	// This works!
    getInfo() {
        return `${this.name} is ${this.age} years old!`;
    }
	
	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

 

1 ACCEPTED SOLUTION

That is just a linter error, one can save the record with that error. However it seems in scopes the only way Script Includes are recognized and included into a context is if those contain the Class.create() instruction. And this was like this since forever, not linked with ES12.

All in all, after creating Script Include Person containing code

var Person = Class.create();

Person = class {

	//#isPrivate; // Private field not supported yet

	constructor(name, age) {
		this.name = name;
		this.age = age;
	}

	// This works!
	getInfo() {
		return `${this.name} is ${this.age} years old!`;
	}

	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

find_real_file.png

I can successfully run

var p = new Person('N1', 35);

gs.debug(p.getInfo2());

in Scripts - Background:

find_real_file.png

View solution in original post

7 REPLIES 7

The arrow function still not working for me, see the image below

 

find_real_file.png

That is just a linter error, one can save the record with that error. However it seems in scopes the only way Script Includes are recognized and included into a context is if those contain the Class.create() instruction. And this was like this since forever, not linked with ES12.

All in all, after creating Script Include Person containing code

var Person = Class.create();

Person = class {

	//#isPrivate; // Private field not supported yet

	constructor(name, age) {
		this.name = name;
		this.age = age;
	}

	// This works!
	getInfo() {
		return `${this.name} is ${this.age} years old!`;
	}

	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

find_real_file.png

I can successfully run

var p = new Person('N1', 35);

gs.debug(p.getInfo2());

in Scripts - Background:

find_real_file.png

This did not work for me. When running through the Script Background I get error. So that is why I created the let Person = class Person

 

I get this error when I remove let Person:

 

Evaluator.evaluateString() problem: com.glide.script.transpilation.SourceMapException: ECMAScript 2021 (ES12): More than 1 source inside the source map. Expected only 1. sourceMap={"version":3,"sources":["<anon>","<<jsx-config-pragma.js>>"],"sourcesContent":["class Person {\r\n\t\r\n\t//#isPrivate; // Private field not supported yet\r\n\t\r\n    constructor(name, age) {\r\n        this.name = name;\r\n        this.age = age;\r\n    }\r\n\r\n    getInfo() {\r\n        return `${this.name} is ${this.age} years old!`;\r\n    }\r\n}","React.createElement"],"names":["Person","name","age","getInfo"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAAA,IAAA,AAAMA,MAAM,iBCAR,ADAJ;;aAAMA,MAAM,CAIIC,IAAI,EAAEC,GAAG;;QACjB,IAAI,CAACD,IAAI,GAAGA,IAAI,CAAC;QACjB,IAAI,CAACC,GAAG,GAAGA,GAAG,CAAC;;;;YAGnBC,GAAO,EAAPA,SAAO;YATX,OASIA,SAAAA,OAAO,GAAG;gBACN,OAAO,AAAC,EAAA,CAAkB,MAAQ,CAAxB,IAAI,CAACF,IAAI,EAAC,MAAI,CAAW,CAAA,MAAW,CAApB,IAAI,CAACC,GAAG,EAAC,aAAW,CAAC,CAAC;aACnD;;;;CACJ,EAAA"}: 	com.glide.script.transpilation.ClosureSourceMapper.<init>(ClosureSourceMapper.java:54)
	com.glide.script.transpilation.ClosureSourceMapper.construct(ClosureSourceMapper.java:37)
	com.glide.script.transpilation.ClosureSourceMapper.constructUnchecked(ClosureSourceMapper.java:30)
	com.glide.script.InterpretedCompiler.interpret0(InterpretedCompiler.java:88)
	com.glide.script.InterpretedCompiler.compile0(InterpretedCompiler.java:56)
	com.glide.script.InterpretedCompiler.compile0(InterpretedCompiler.java:51)
	com.glide.script.Compiler.compile(Compiler.java:174)
	com.glide.script.InterpretedCompiler.interpret(InterpretedCompiler.java:46)
	com.glide.script.ScriptCompiler.getScript(ScriptCompiler.java:38)
	com.glide.script.ScriptEvaluator.getScript(ScriptEvaluator.java:409)
	com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:383)
	com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:204)
	com.glide.script.system.ASystemInclude.includeScript(ASystemInclude.java:200)
	com.glide.script.system.ASystemInclude.include(ASystemInclude.java:137)
	com.glide.script.AGlideRhinoScopeHandler.isScriptInclude(AGlideRhinoScopeHandler.java:46)
	com.glide.script.fencing.GlidePackageScopeHandler.found(GlidePackageScopeHandler.java:31)
	com.glide.script.ARhinoScope.get(ARhinoScope.java:82)
	com.glide.script.RhinoScope.get(RhinoScope.java:52)
	com.glide.script.PackageScope.get(PackageScope.java:41)
	org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:2097)
	org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1569)
	org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1562)
	org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1271)
	org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)
	org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:160)
	com.glide.caller.gen.null_null_script.call(Unknown Source)
	com.glide.script.ScriptCaller.call(ScriptCaller.java:18)
	org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
	org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:597)
	org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3573)
	org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:172)
	com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:392)
	com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:204)
	com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:133)
	com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:348)
	com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:240)
	com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:219)
	com.glide.processors.ScriptProcessor.evaluateScript0(ScriptProcessor.java:397)
	com.glide.processors.ScriptProcessor.lambda$evaluateScriptWithRecordingOption$0(ScriptProcessor.java:380)
	com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67)
	com.glide.processors.ScriptProcessor.evaluateScriptWithRecordingOption(ScriptProcessor.java:380)
	com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:360)
	com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:259)
	com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:217)
	com.glide.processors.AProcessor.runProcessor(AProcessor.java:613)
	com.glide.processors.AProcessor.processTransaction(AProcessor.java:275)
	com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:184)
	com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:172)
	com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:51)
	com.glide.sys.Transaction.run(Transaction.java:2502)
	com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:27)
	java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	java.base/java.lang.Thread.run(Thread.java:829)

Evaluator: com.glide.script.RhinoEcmaError: undefined is not a function. script : Line(1) column(0) ==> 1: var person = new x_290424_ec2021.Person("Roya", 11); 2: 3: gs.info(person.getInfo());