Can an AppleScript Script USE a JXA Script Library?

Can an AppleScript Script USE a JXA Script Library?

Whenever I try to USE a JXA script, in the Scripting Libraries folder, from an AppleScript, I get this error message on compile:

My simple code:


use myLib : script "LIB JXA"

-- OR --

use script "LIB JXA"

The same script file works fine when used in a JXA script:


-- this is actually JavaScript code --

var myLib = Library("LIB JXA")

And, I can USE an AppleScript Script Library from AppleScript without any problem:


use myLib : script "LIB AS"

I have found that I can use an AppleScript script as a script library called from JXA.
However, the reverse doesn’t appear to work.

Am I doing something, or is this a limitation of AppleScript?

I have searched extensively, and none of the Apple docs offer any info on this.

TIA for your help.

OK, to make it easy for everyone to test on their own machine, I’m providing the actual script files:


# ========  TEST AppleScript TO USE/CALL SCRIP LIBs ===========

use scripting additions -- not sure if this is always needed?

--- EXECUTE FUNCTION FROM AppleScript LIB ---
--		(this always works fine)

use myLibAS : script "JMichaelLibAS" -- AS Script Lib
myLibAS's helloAS("Called from an AppleScript")


--- EXECUTE FUNCTION FROM JXA LIB ---
--		(FAILS on Compile with:  "script doesn't seem to belong to AppleScript")
(*
use myLibJS : script "JMichaelLibJXA"		-- JXA Script Lib
myLibJS's helloJS("Called from AppleScript")
*)


// ======= JXA SCRIPT TO USE/CALL SCRIP LIBs ===========
//    (USE of both AS and JXA libs always works)


//--- EXECUTE FUNCTION FROM AppleScript LIB ---

var myLibAS = Library("JMichaelLibAS")
myLibAS.helloAS("CAlled from JXA")

//--- EXECUTE FUNCTION FROM JXA LIB ---

var myLibJS = Library("JMichaelLibJXA")
myLibJS.helloJS("CAlled from JXA")


## --- AppleScript SCRIPT LIB:  JMichaelLibAS ---

on helloAS(pMsg)
	display alert ("Hello from AS Lib: " & pMsg)
	
end helloAS


// --- JXA SCRIPT LIB:  JMichaelLibJXA.scpt ---

function helloJS(pMsg) {

	var app = Application.currentApplication()
	app.includeStandardAdditions = true
	
	app.displayAlert('From My JXA Lib:  ' + pMsg)

}

I don’t believe so, no.

An AppleScript .scpt file is compile code; JXA .scpt files are little more than text files, and AppleScript can’t do anything with them.