diff --git a/.prettierignore b/.prettierignore index 30db2098f393..ed10501eaf3e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -69,7 +69,7 @@ toolkit/components/backgroundtasks/defaults # A mainly-imported file, that we don't want to format, but want to keep an eye # on with the other imported files. -toolkit/components/formautofill/CreditCardRuleset.sys.mjs +toolkit/components/formautofill/shared/CreditCardRuleset.sys.mjs ############################################################################## # The list below is copied from .eslintignore. Prettier doesn't currently diff --git a/browser/extensions/formautofill/test/browser/browser_fathom_cc.js b/browser/extensions/formautofill/test/browser/browser_fathom_cc.js index 92ab1363e24b..83a27453d175 100644 --- a/browser/extensions/formautofill/test/browser/browser_fathom_cc.js +++ b/browser/extensions/formautofill/test/browser/browser_fathom_cc.js @@ -2,7 +2,7 @@ * By default this test only tests 1 sample. This is to avoid publishing all samples we have * to the codebase. If you update the Fathom CC model, please follow the instruction below * and run the test. Doing this makes sure the optimized (Native implementation) CC fathom model produces - * exactly the same result as the non-optimized model (JS implementation, See CreditCardRuleset.jsm). + * exactly the same result as the non-optimized model (JS implementation, See CreditCardRuleset.sys.mjs). * * To test this: * 1. Run the test setup script (fathom/test-setup.sh) to download all samples to the local @@ -102,7 +102,7 @@ async function run_test(path, dirs) { } // This value should sync with the number of supported types in - // CreditCardRuleset.jsm (See `get types()` in `this.creditCardRulesets`). + // CreditCardRuleset.sys.mjs (See `get types()` in `this.creditCardRulesets`). const EXPECTED_NUM_OF_CONFIDENCE = 2; for (let i = 0; i < eligibleFields.length; i++) { if ( diff --git a/toolkit/components/formautofill/FormAutofillHeuristics.sys.mjs b/toolkit/components/formautofill/FormAutofillHeuristics.sys.mjs index b1a5ca82a6a6..16d2f5d8547f 100644 --- a/toolkit/components/formautofill/FormAutofillHeuristics.sys.mjs +++ b/toolkit/components/formautofill/FormAutofillHeuristics.sys.mjs @@ -16,7 +16,7 @@ ChromeUtils.defineESModuleGetters(lazy, { CreditCard: "resource://gre/modules/CreditCard.sys.mjs", FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs", LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs", - creditCardRulesets: "resource://autofill/CreditCardRuleset.sys.mjs", + creditCardRulesets: "resource://gre/modules/shared/CreditCardRuleset.sys.mjs", }); XPCOMUtils.defineLazyGetter(lazy, "log", () => diff --git a/toolkit/components/formautofill/moz.build b/toolkit/components/formautofill/moz.build index eecd443f43e1..da065704fb77 100644 --- a/toolkit/components/formautofill/moz.build +++ b/toolkit/components/formautofill/moz.build @@ -10,6 +10,7 @@ with Files("**"): BUG_COMPONENT = ("Toolkit", "Form Autofill") EXTRA_JS_MODULES.shared += [ + "shared/CreditCardRuleset.sys.mjs", "shared/FormAutofillNameUtils.sys.mjs", "shared/FormAutofillUtils.sys.mjs", "shared/LabelUtils.sys.mjs", diff --git a/toolkit/components/formautofill/CreditCardRuleset.sys.mjs b/toolkit/components/formautofill/shared/CreditCardRuleset.sys.mjs similarity index 98% rename from toolkit/components/formautofill/CreditCardRuleset.sys.mjs rename to toolkit/components/formautofill/shared/CreditCardRuleset.sys.mjs index 61a9b51e9a12..0ac5d2b8fd60 100644 --- a/toolkit/components/formautofill/CreditCardRuleset.sys.mjs +++ b/toolkit/components/formautofill/shared/CreditCardRuleset.sys.mjs @@ -19,8 +19,6 @@ * CODE UNIQUE TO PRODUCTION--NOT IN THE TRAINING REPOSITORY: */ -import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; - import { element as clickedElement, out, @@ -29,18 +27,14 @@ import { score, type, } from "resource://gre/modules/third_party/fathom/fathom.mjs"; +import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; +import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs"; import { CreditCard, NETWORK_NAMES, } from "resource://gre/modules/CreditCard.sys.mjs"; - -const lazy = {}; - -ChromeUtils.defineESModuleGetters(lazy, { - FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs" , - FormLikeFactory: "resource://gre/modules/FormLikeFactory.sys.mjs", - LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs", -}); +import { FormLikeFactory } from "resource://gre/modules/FormLikeFactory.sys.mjs"; +import { LabelUtils } from "resource://gre/modules/shared/LabelUtils.sys.mjs"; /** * Callthrough abstraction to allow .getAutocompleteInfo() to be mocked out @@ -351,9 +345,9 @@ function autocompleteStringMatches(element, ccString) { } function getFillableFormElements(element) { - const formLike = lazy.FormLikeFactory.createFromField(element); + const formLike = FormLikeFactory.createFromField(element); return Array.from(formLike.elements).filter(el => - lazy.FormAutofillUtils.isCreditCardOrAddressFieldType(el) + FormAutofillUtils.isCreditCardOrAddressFieldType(el) ); } @@ -405,9 +399,9 @@ function idOrNameMatchRegExp(element, regExp) { function getElementLabels(element) { return { *[Symbol.iterator]() { - const labels = lazy.LabelUtils.findLabelElements(element); + const labels = LabelUtils.findLabelElements(element); for (let label of labels) { - yield* lazy.LabelUtils.extractLabelStrings(label); + yield* LabelUtils.extractLabelStrings(label); } }, }; @@ -1210,3 +1204,5 @@ export var creditCardRulesets = { }; creditCardRulesets.init(); + +export default creditCardRulesets;