Enable the import/no-cycle ESLint plugin rule

Having cyclical imports is obviously not a good idea, and this ESLint plugin rule can help detect those; please see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md
This commit is contained in:
Jonas Jenwald 2023-06-02 14:41:27 +02:00
parent 605d9f492f
commit cf3a35e9da
22 changed files with 328 additions and 213 deletions

View File

@ -37,6 +37,7 @@
"import/extensions": ["error", "always", { "ignorePackages": true, }],
"import/first": "error",
"import/named": "error",
"import/no-cycle": "error",
"import/no-empty-named-blocks": "error",
"import/no-mutable-exports": "error",
"import/no-self-import": "error",

View File

@ -36,12 +36,10 @@ import {
$removeChild,
$setValue,
$text,
XFAAttribute,
XFAObjectArray,
XmlObject,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { BindItems, Field, Items, SetProperty, Text } from "./template.js";
import { createDataNode, searchNode } from "./som.js";
import { XFAAttribute, XFAObjectArray, XmlObject } from "./xfa_object.js";
import { NamespaceIds } from "./namespaces.js";
import { warn } from "../../shared/util.js";

View File

@ -23,12 +23,12 @@ import {
$onChild,
$resolvePrototypes,
$root,
XFAObject,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { NamespaceSetUp } from "./setup.js";
import { Template } from "./template.js";
import { UnknownNamespace } from "./unknown.js";
import { warn } from "../../shared/util.js";
import { XFAObject } from "./xfa_object.js";
class Root extends XFAObject {
constructor(ids) {

View File

@ -14,9 +14,8 @@
*/
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import { $content, $finalize } from "./symbol_utils.js";
import {
$content,
$finalize,
ContentObject,
IntegerObject,
Option01,

View File

@ -20,7 +20,7 @@ import {
$setValue,
$toString,
$uid,
} from "./xfa_object.js";
} from "./symbol_utils.js";
class DataHandler {
constructor(root, data) {

View File

@ -19,10 +19,9 @@ import {
$namespaceId,
$nodeName,
$onChild,
XFAObject,
XmlObject,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import { XFAObject, XmlObject } from "./xfa_object.js";
const DATASETS_NS_ID = NamespaceIds.datasets.id;

View File

@ -20,7 +20,7 @@ import {
$text,
$toHTML,
$toPages,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { Binder } from "./bind.js";
import { DataHandler } from "./data.js";
import { FontFinder } from "./fonts.js";

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { $globalData } from "./xfa_object.js";
import { $globalData } from "./symbol_utils.js";
import { stripQuotes } from "./utils.js";
import { warn } from "../../shared/util.js";

View File

@ -24,12 +24,12 @@ import {
$pushGlyphs,
$text,
$toStyle,
XFAObject,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { createValidAbsoluteUrl, warn } from "../../shared/util.js";
import { getMeasurement, stripQuotes } from "./utils.js";
import { selectFont } from "./fonts.js";
import { TextMeasure } from "./text.js";
import { XFAObject } from "./xfa_object.js";
function measureToString(m) {
if (typeof m === "string") {

View File

@ -20,7 +20,7 @@ import {
$getTemplateRoot,
$isSplittable,
$isThereMoreWidth,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { measureToString } from "./html_utils.js";
// Subform and ExclGroup have a layout so they share these functions.

View File

@ -24,7 +24,7 @@ import {
$onChild,
$onText,
$setId,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { XMLParserBase, XMLParserErrorCode } from "../xml_parser.js";
import { Builder } from "./builder.js";
import { warn } from "../../shared/util.js";

View File

@ -14,17 +14,11 @@
*/
import {
$appendChild,
$getChildren,
$getChildrenByClass,
$getChildrenByName,
$getParent,
$namespaceId,
XFAObject,
XFAObjectArray,
XmlObject,
} from "./xfa_object.js";
import { NamespaceIds } from "./namespaces.js";
} from "./symbol_utils.js";
import { warn } from "../../shared/util.js";
const namePattern = /^[^.[]+/;
@ -58,7 +52,6 @@ const shortcuts = new Map([
]);
const somCache = new WeakMap();
const NS_DATASETS = NamespaceIds.datasets.id;
function parseIndex(index) {
index = index.trim();
@ -193,7 +186,7 @@ function searchNode(
const { name, cacheName, operator, index } = parsed[i];
const nodes = [];
for (const node of root) {
if (!(node instanceof XFAObject)) {
if (!node.isXFAObject) {
continue;
}
@ -218,7 +211,7 @@ function searchNode(
break;
case operators.dotHash:
children = node[$getChildrenByClass](name);
if (children instanceof XFAObjectArray) {
if (children.isXFAObjectArray) {
children = children.children;
} else {
children = [children];
@ -265,20 +258,6 @@ function searchNode(
return root;
}
function createNodes(root, path) {
let node = null;
for (const { name, index } of path) {
for (let i = 0, ii = !isFinite(index) ? 0 : index; i <= ii; i++) {
const nsId = root[$namespaceId] === NS_DATASETS ? -1 : root[$namespaceId];
node = new XmlObject(nsId, name);
root[$appendChild](node);
}
root = node;
}
return node;
}
function createDataNode(root, container, expr) {
const parsed = parseExpression(expr);
if (!parsed) {
@ -302,7 +281,7 @@ function createDataNode(root, container, expr) {
const { name, operator, index } = parsed[i];
if (!isFinite(index)) {
parsed[i].index = 0;
return createNodes(root, parsed.slice(i));
return root.createNodes(parsed.slice(i));
}
let children;
@ -315,7 +294,7 @@ function createDataNode(root, container, expr) {
break;
case operators.dotHash:
children = root[$getChildrenByClass](name);
if (children instanceof XFAObjectArray) {
if (children.isXFAObjectArray) {
children = children.children;
} else {
children = [children];
@ -326,19 +305,19 @@ function createDataNode(root, container, expr) {
}
if (children.length === 0) {
return createNodes(root, parsed.slice(i));
return root.createNodes(parsed.slice(i));
}
if (index < children.length) {
const child = children[index];
if (!(child instanceof XFAObject)) {
if (!child.isXFAObject) {
warn(`XFA - Cannot create a node.`);
return null;
}
root = child;
} else {
parsed[i].index = index - children.length;
return createNodes(root, parsed.slice(i));
return root.createNodes(parsed.slice(i));
}
}
return null;

View File

@ -0,0 +1,156 @@
/* Copyright 2021 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// We use these symbols to avoid name conflict between tags
// and properties/methods names.
const $acceptWhitespace = Symbol();
const $addHTML = Symbol();
const $appendChild = Symbol();
const $childrenToHTML = Symbol();
const $clean = Symbol();
const $cleanPage = Symbol();
const $cleanup = Symbol();
const $clone = Symbol();
const $consumed = Symbol();
const $content = Symbol("content");
const $data = Symbol("data");
const $dump = Symbol();
const $extra = Symbol("extra");
const $finalize = Symbol();
const $flushHTML = Symbol();
const $getAttributeIt = Symbol();
const $getAttributes = Symbol();
const $getAvailableSpace = Symbol();
const $getChildrenByClass = Symbol();
const $getChildrenByName = Symbol();
const $getChildrenByNameIt = Symbol();
const $getDataValue = Symbol();
const $getExtra = Symbol();
const $getRealChildrenByNameIt = Symbol();
const $getChildren = Symbol();
const $getContainedChildren = Symbol();
const $getNextPage = Symbol();
const $getSubformParent = Symbol();
const $getParent = Symbol();
const $getTemplateRoot = Symbol();
const $globalData = Symbol();
const $hasSettableValue = Symbol();
const $ids = Symbol();
const $indexOf = Symbol();
const $insertAt = Symbol();
const $isCDATAXml = Symbol();
const $isBindable = Symbol();
const $isDataValue = Symbol();
const $isDescendent = Symbol();
const $isNsAgnostic = Symbol();
const $isSplittable = Symbol();
const $isThereMoreWidth = Symbol();
const $isTransparent = Symbol();
const $isUsable = Symbol();
const $lastAttribute = Symbol();
const $namespaceId = Symbol("namespaceId");
const $nodeName = Symbol("nodeName");
const $nsAttributes = Symbol();
const $onChild = Symbol();
const $onChildCheck = Symbol();
const $onText = Symbol();
const $pushGlyphs = Symbol();
const $popPara = Symbol();
const $pushPara = Symbol();
const $removeChild = Symbol();
const $root = Symbol("root");
const $resolvePrototypes = Symbol();
const $searchNode = Symbol();
const $setId = Symbol();
const $setSetAttributes = Symbol();
const $setValue = Symbol();
const $tabIndex = Symbol();
const $text = Symbol();
const $toPages = Symbol();
const $toHTML = Symbol();
const $toString = Symbol();
const $toStyle = Symbol();
const $uid = Symbol("uid");
export {
$acceptWhitespace,
$addHTML,
$appendChild,
$childrenToHTML,
$clean,
$cleanPage,
$cleanup,
$clone,
$consumed,
$content,
$data,
$dump,
$extra,
$finalize,
$flushHTML,
$getAttributeIt,
$getAttributes,
$getAvailableSpace,
$getChildren,
$getChildrenByClass,
$getChildrenByName,
$getChildrenByNameIt,
$getContainedChildren,
$getDataValue,
$getExtra,
$getNextPage,
$getParent,
$getRealChildrenByNameIt,
$getSubformParent,
$getTemplateRoot,
$globalData,
$hasSettableValue,
$ids,
$indexOf,
$insertAt,
$isBindable,
$isCDATAXml,
$isDataValue,
$isDescendent,
$isNsAgnostic,
$isSplittable,
$isThereMoreWidth,
$isTransparent,
$isUsable,
$lastAttribute,
$namespaceId,
$nodeName,
$nsAttributes,
$onChild,
$onChildCheck,
$onText,
$popPara,
$pushGlyphs,
$pushPara,
$removeChild,
$resolvePrototypes,
$root,
$searchNode,
$setId,
$setSetAttributes,
$setValue,
$tabIndex,
$text,
$toHTML,
$toPages,
$toString,
$toStyle,
$uid,
};

View File

@ -58,13 +58,7 @@ import {
$toPages,
$toStyle,
$uid,
ContentObject,
Option01,
OptionObject,
StringObject,
XFAObject,
XFAObjectArray,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
addHTML,
@ -88,6 +82,14 @@ import {
setPara,
toStyle,
} from "./html_utils.js";
import {
ContentObject,
Option01,
OptionObject,
StringObject,
XFAObject,
XFAObjectArray,
} from "./xfa_object.js";
import {
getBBox,
getColor,

View File

@ -14,13 +14,8 @@
*/
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
$namespaceId,
$nodeName,
$onChildCheck,
XFAObject,
XFAObjectArray,
} from "./xfa_object.js";
import { $namespaceId, $nodeName, $onChildCheck } from "./symbol_utils.js";
import { XFAObject, XFAObjectArray } from "./xfa_object.js";
const XDP_NS_ID = NamespaceIds.xdp.id;

View File

@ -13,83 +13,72 @@
* limitations under the License.
*/
import {
$acceptWhitespace,
$addHTML,
$appendChild,
$childrenToHTML,
$clean,
$cleanup,
$clone,
$consumed,
$content,
$dump,
$extra,
$finalize,
$flushHTML,
$getAttributeIt,
$getAttributes,
$getAvailableSpace,
$getChildren,
$getChildrenByClass,
$getChildrenByName,
$getChildrenByNameIt,
$getContainedChildren,
$getDataValue,
$getParent,
$getRealChildrenByNameIt,
$getSubformParent,
$getTemplateRoot,
$globalData,
$hasSettableValue,
$indexOf,
$insertAt,
$isBindable,
$isCDATAXml,
$isDataValue,
$isDescendent,
$isNsAgnostic,
$isSplittable,
$isThereMoreWidth,
$isTransparent,
$lastAttribute,
$namespaceId,
$nodeName,
$nsAttributes,
$onChild,
$onChildCheck,
$onText,
$popPara,
$pushPara,
$removeChild,
$resolvePrototypes,
$root,
$setId,
$setSetAttributes,
$setValue,
$text,
$toHTML,
$toString,
$toStyle,
$uid,
} from "./symbol_utils.js";
import { getInteger, getKeyword, HTMLResult } from "./utils.js";
import { shadow, utf8StringToString, warn } from "../../shared/util.js";
import { encodeToXmlString } from "../core_utils.js";
import { NamespaceIds } from "./namespaces.js";
import { searchNode } from "./som.js";
// We use these symbols to avoid name conflict between tags
// and properties/methods names.
const $acceptWhitespace = Symbol();
const $addHTML = Symbol();
const $appendChild = Symbol();
const $childrenToHTML = Symbol();
const $clean = Symbol();
const $cleanPage = Symbol();
const $cleanup = Symbol();
const $clone = Symbol();
const $consumed = Symbol();
const $content = Symbol("content");
const $data = Symbol("data");
const $dump = Symbol();
const $extra = Symbol("extra");
const $finalize = Symbol();
const $flushHTML = Symbol();
const $getAttributeIt = Symbol();
const $getAttributes = Symbol();
const $getAvailableSpace = Symbol();
const $getChildrenByClass = Symbol();
const $getChildrenByName = Symbol();
const $getChildrenByNameIt = Symbol();
const $getDataValue = Symbol();
const $getExtra = Symbol();
const $getRealChildrenByNameIt = Symbol();
const $getChildren = Symbol();
const $getContainedChildren = Symbol();
const $getNextPage = Symbol();
const $getSubformParent = Symbol();
const $getParent = Symbol();
const $getTemplateRoot = Symbol();
const $globalData = Symbol();
const $hasSettableValue = Symbol();
const $ids = Symbol();
const $indexOf = Symbol();
const $insertAt = Symbol();
const $isCDATAXml = Symbol();
const $isBindable = Symbol();
const $isDataValue = Symbol();
const $isDescendent = Symbol();
const $isNsAgnostic = Symbol();
const $isSplittable = Symbol();
const $isThereMoreWidth = Symbol();
const $isTransparent = Symbol();
const $isUsable = Symbol();
const $lastAttribute = Symbol();
const $namespaceId = Symbol("namespaceId");
const $nodeName = Symbol("nodeName");
const $nsAttributes = Symbol();
const $onChild = Symbol();
const $onChildCheck = Symbol();
const $onText = Symbol();
const $pushGlyphs = Symbol();
const $popPara = Symbol();
const $pushPara = Symbol();
const $removeChild = Symbol();
const $root = Symbol("root");
const $resolvePrototypes = Symbol();
const $searchNode = Symbol();
const $setId = Symbol();
const $setSetAttributes = Symbol();
const $setValue = Symbol();
const $tabIndex = Symbol();
const $text = Symbol();
const $toPages = Symbol();
const $toHTML = Symbol();
const $toString = Symbol();
const $toStyle = Symbol();
const $uid = Symbol("uid");
const _applyPrototype = Symbol();
const _attributes = Symbol();
const _attributeNames = Symbol();
@ -123,6 +112,29 @@ class XFAObject {
this[$globalData] = null;
}
get isXFAObject() {
return true;
}
get isXFAObjectArray() {
return false;
}
createNodes(path) {
let root = this,
node = null;
for (const { name, index } of path) {
for (let i = 0, ii = isFinite(index) ? index : 0; i <= ii; i++) {
const nsId =
root[$namespaceId] === NS_DATASETS ? -1 : root[$namespaceId];
node = new XmlObject(nsId, name);
root[$appendChild](node);
}
root = node;
}
return node;
}
[$onChild](child) {
if (!this[_hasChildren] || !this[$onChildCheck](child)) {
return false;
@ -715,6 +727,14 @@ class XFAObjectArray {
this[_children] = [];
}
get isXFAObject() {
return false;
}
get isXFAObjectArray() {
return true;
}
push(child) {
const len = this[_children].length;
if (len <= this[_max]) {
@ -1077,73 +1097,6 @@ class Option10 extends IntegerObject {
}
export {
$acceptWhitespace,
$addHTML,
$appendChild,
$childrenToHTML,
$clean,
$cleanPage,
$cleanup,
$clone,
$consumed,
$content,
$data,
$dump,
$extra,
$finalize,
$flushHTML,
$getAttributeIt,
$getAttributes,
$getAvailableSpace,
$getChildren,
$getChildrenByClass,
$getChildrenByName,
$getChildrenByNameIt,
$getContainedChildren,
$getDataValue,
$getExtra,
$getNextPage,
$getParent,
$getRealChildrenByNameIt,
$getSubformParent,
$getTemplateRoot,
$globalData,
$hasSettableValue,
$ids,
$indexOf,
$insertAt,
$isBindable,
$isCDATAXml,
$isDataValue,
$isDescendent,
$isNsAgnostic,
$isSplittable,
$isThereMoreWidth,
$isTransparent,
$isUsable,
$namespaceId,
$nodeName,
$nsAttributes,
$onChild,
$onChildCheck,
$onText,
$popPara,
$pushGlyphs,
$pushPara,
$removeChild,
$resolvePrototypes,
$root,
$searchNode,
$setId,
$setSetAttributes,
$setValue,
$tabIndex,
$text,
$toHTML,
$toPages,
$toString,
$toStyle,
$uid,
ContentObject,
IntegerObject,
Option01,

View File

@ -27,8 +27,7 @@ import {
$pushGlyphs,
$text,
$toHTML,
XmlObject,
} from "./xfa_object.js";
} from "./symbol_utils.js";
import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
import {
fixTextIndent,
@ -37,6 +36,7 @@ import {
setFontFamily,
} from "./html_utils.js";
import { getMeasurement, HTMLResult, stripQuotes } from "./utils.js";
import { XmlObject } from "./xfa_object.js";
const XHTML_NS_ID = NamespaceIds.xhtml.id;
const $richText = Symbol();

View File

@ -13,18 +13,19 @@
* limitations under the License.
*/
import {
FORMS_VERSION,
USERACTIVATION_CALLBACKID,
VIEWER_TYPE,
VIEWER_VARIATION,
VIEWER_VERSION,
} from "./app_utils.js";
import { Color } from "./color.js";
import { EventDispatcher } from "./event.js";
import { FullScreen } from "./fullscreen.js";
import { PDFObject } from "./pdf_object.js";
import { Thermometer } from "./thermometer.js";
const VIEWER_TYPE = "PDF.js";
const VIEWER_VARIATION = "Full";
const VIEWER_VERSION = 21.00720099;
const FORMS_VERSION = 21.00720099;
const USERACTIVATION_CALLBACKID = 0;
class App extends PDFObject {
constructor(data) {
super(data);
@ -654,4 +655,4 @@ class App extends PDFObject {
}
}
export { App, USERACTIVATION_CALLBACKID };
export { App };

View File

@ -0,0 +1,31 @@
/* Copyright 2020 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const VIEWER_TYPE = "PDF.js";
const VIEWER_VARIATION = "Full";
const VIEWER_VERSION = 21.00720099;
const FORMS_VERSION = 21.00720099;
const USERACTIVATION_CALLBACKID = 0;
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
export {
FORMS_VERSION,
USERACTIVATION_CALLBACKID,
USERACTIVATION_MAXTIME_VALIDITY,
VIEWER_TYPE,
VIEWER_VARIATION,
VIEWER_VERSION,
};

View File

@ -13,9 +13,10 @@
* limitations under the License.
*/
import { USERACTIVATION_CALLBACKID } from "./app.js";
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
import {
USERACTIVATION_CALLBACKID,
USERACTIVATION_MAXTIME_VALIDITY,
} from "./app_utils.js";
class Event {
constructor(data) {

View File

@ -19,7 +19,7 @@ import {
$getChildrenByClass,
$getChildrenByName,
$text,
} from "../../src/core/xfa/xfa_object.js";
} from "../../src/core/xfa/symbol_utils.js";
import { Binder } from "../../src/core/xfa/bind.js";
import { searchNode } from "../../src/core/xfa/som.js";
import { XFAParser } from "../../src/core/xfa/parser.js";

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { $uid } from "../../src/core/xfa/xfa_object.js";
import { $uid } from "../../src/core/xfa/symbol_utils.js";
import { DataHandler } from "../../src/core/xfa/data.js";
import { searchNode } from "../../src/core/xfa/som.js";
import { XFAParser } from "../../src/core/xfa/parser.js";