[FireMonkey] import statement handling #333
-
Hi, I'm wondering how FireMonkey handles import statements, i.e. import { function } from 'script'; Do they work in user scripts? I've had issues with them recently, and have been working around this by using libraries that add themselves as a global object, but I would much prefer using imports if they work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
FireMonkey handles the injection of the script into the tab. From then on, everything, except GM API, is pure JavaScript. In the following code, where exactly is import { function } from 'script'; Normally, |
Beta Was this translation helpful? Give feedback.
-
I have discussed Normally, the JavaScript engine would get the module and then make it available to the JS code that imported it. That is not possible within userscript context since there is no process to get the the module. Module Import exampleModule app.js export {App};
class App {
static run() {
console.log('App.run called');
}
} Importer import {App} from './app.js';
App.run(); Mimic Module Import in userscript exampleNote: import/export cause error
Module // ==UserScript==
// @name Module
// @author erosman
// @version 1.0
// ==/UserScript==
// export {App}; // causes error
class App {
static run() {
console.log('App.run called');
}
} Importer // ==UserScript==
// @name Module Importer
// @match *://*.example.com/*
// @author erosman
// @version 1.0
// @require Module
// ==/UserScript==
// import {App} from './app.js'; // causes error
App.run(); // App.run called |
Beta Was this translation helpful? Give feedback.
I have discussed
import
in userscript context with Mozilla engineers.Normally, the JavaScript engine would get the module and then make it available to the JS code that imported it.
That is not possible within userscript context since there is no process to get the the module.
Module Import example
Module app.js
Importer
Mimic Module Import in userscript example
Note: import/export cause error
Module
// ==UserScript==