mirror of
https://github.com/zotero/zotero.git
synced 2026-09-29 01:41:24 +00:00
Use native Promise.try(), fix Components.utils.import()
This commit is contained in:
parent
b62fd3aa04
commit
d5ec1ecc28
3 changed files with 13 additions and 4 deletions
|
|
@ -12,3 +12,6 @@ Zotero modifications:
|
|||
|
||||
Run:
|
||||
scripts/migrate-fx140/migrate.py <esmify|asyncify> [file_or_dir]
|
||||
|
||||
Special notes for esmify:
|
||||
- If the script you're running on is a window/XPCOM script, not an MJS/ESM, pass --imports
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ function doTranslate(inputFile, root) {
|
|||
'race',
|
||||
'reject',
|
||||
'resolve',
|
||||
'try',
|
||||
]))
|
||||
.forEach(path => {
|
||||
let callee = path.node.callee;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ const {
|
|||
|
||||
module.exports = function (fileInfo, api) {
|
||||
const { jscodeshift } = api;
|
||||
|
||||
// Cheap hack:
|
||||
// Zotero usually calls Components.utils.import(), not Cu.import().
|
||||
// Those are the same thing, but this script can't rewrite the former
|
||||
// to ChromeUtils.importESModule(), because it's unable to handle
|
||||
// changing the number of property accesses in the chain.
|
||||
// Just replace it in the text before parsing!
|
||||
fileInfo.source = fileInfo.source.replace(/Components\.utils\.import\(/g, 'Cu.import(');
|
||||
|
||||
const root = jscodeshift(fileInfo.source);
|
||||
doTranslate(fileInfo.path, jscodeshift, root);
|
||||
return root.toSource({ useTabs: true, lineTerminator: "\n" });
|
||||
|
|
@ -61,10 +70,6 @@ const importCalls = [
|
|||
from: ["Cu", "import"],
|
||||
to: ["ChromeUtils", "importESModule"],
|
||||
},
|
||||
{
|
||||
from: ["Components", "utils", "import"],
|
||||
to: ["ChromeUtils", "importESModule"],
|
||||
},
|
||||
{
|
||||
from: ["ChromeUtils", "import"],
|
||||
to: ["ChromeUtils", "importESModule"],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue