mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Merge pull request #19806 from Snuffleupagus/more-logical-assign
Add more logical assignment in the `src/` folder
This commit is contained in:
commit
e06b32c831
6 changed files with 33 additions and 65 deletions
|
@ -3488,8 +3488,8 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||
// always make the field value an array with zero, one or multiple items.
|
||||
if (typeof this.data.fieldValue === "string") {
|
||||
this.data.fieldValue = [this.data.fieldValue];
|
||||
} else if (!this.data.fieldValue) {
|
||||
this.data.fieldValue = [];
|
||||
} else {
|
||||
this.data.fieldValue ||= [];
|
||||
}
|
||||
} else {
|
||||
// The specs say that we should have an indices array only with
|
||||
|
|
|
@ -998,9 +998,7 @@ class Catalog {
|
|||
warn(`Bad value, for key "${key}", in ViewerPreferences: ${value}.`);
|
||||
continue;
|
||||
}
|
||||
if (!prefs) {
|
||||
prefs = Object.create(null);
|
||||
}
|
||||
prefs ??= Object.create(null);
|
||||
prefs[key] = prefValue;
|
||||
}
|
||||
return shadow(this, "viewerPreferences", prefs);
|
||||
|
@ -1042,9 +1040,7 @@ class Catalog {
|
|||
const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref);
|
||||
for (const [key, value] of nameTree.getAll()) {
|
||||
const fs = new FileSpec(value, this.xref);
|
||||
if (!attachments) {
|
||||
attachments = Object.create(null);
|
||||
}
|
||||
attachments ??= Object.create(null);
|
||||
attachments[stringToPDFString(key)] = fs.serializable;
|
||||
}
|
||||
}
|
||||
|
@ -1058,9 +1054,7 @@ class Catalog {
|
|||
if (obj instanceof Dict && obj.has("XFAImages")) {
|
||||
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
|
||||
for (const [key, value] of nameTree.getAll()) {
|
||||
if (!xfaImages) {
|
||||
xfaImages = new Dict(this.xref);
|
||||
}
|
||||
xfaImages ??= new Dict(this.xref);
|
||||
xfaImages.set(stringToPDFString(key), value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1532,9 +1532,7 @@ class PDFDocument {
|
|||
warn(`Bad value, for custom key "${key}", in Info: ${value}.`);
|
||||
continue;
|
||||
}
|
||||
if (!docInfo.Custom) {
|
||||
docInfo.Custom = Object.create(null);
|
||||
}
|
||||
docInfo.Custom ??= Object.create(null);
|
||||
docInfo.Custom[key] = customValue;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -91,9 +91,7 @@ class XFAParser extends XMLParserBase {
|
|||
}
|
||||
} else if (name.startsWith("xmlns:")) {
|
||||
const prefix = name.substring("xmlns:".length);
|
||||
if (!prefixes) {
|
||||
prefixes = [];
|
||||
}
|
||||
prefixes ??= [];
|
||||
prefixes.push({ prefix, value });
|
||||
} else {
|
||||
const i = name.indexOf(":");
|
||||
|
@ -102,10 +100,7 @@ class XFAParser extends XMLParserBase {
|
|||
} else {
|
||||
// Attributes can have their own namespace.
|
||||
// For example in data, we can have <foo xfa:dataNode="dataGroup"/>
|
||||
let nsAttrs = attributeObj[$nsAttributes];
|
||||
if (!nsAttrs) {
|
||||
nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
|
||||
}
|
||||
const nsAttrs = (attributeObj[$nsAttributes] ??= Object.create(null));
|
||||
const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
|
||||
const attrs = (nsAttrs[ns] ||= Object.create(null));
|
||||
attrs[attrName] = value;
|
||||
|
|
|
@ -2462,9 +2462,7 @@ class ExclGroup extends XFAObject {
|
|||
|
||||
setAccess(this, attributes.class);
|
||||
|
||||
if (!this[$extra]) {
|
||||
this[$extra] = Object.create(null);
|
||||
}
|
||||
this[$extra] ||= Object.create(null);
|
||||
|
||||
Object.assign(this[$extra], {
|
||||
children,
|
||||
|
@ -2953,9 +2951,7 @@ class Field extends XFAObject {
|
|||
}
|
||||
}
|
||||
|
||||
if (!ui.attributes.style) {
|
||||
ui.attributes.style = Object.create(null);
|
||||
}
|
||||
ui.attributes.style ||= Object.create(null);
|
||||
|
||||
let aElement = null;
|
||||
|
||||
|
@ -3048,9 +3044,7 @@ class Field extends XFAObject {
|
|||
caption.attributes.class[0] = "xfaCaptionForCheckButton";
|
||||
}
|
||||
|
||||
if (!ui.attributes.class) {
|
||||
ui.attributes.class = [];
|
||||
}
|
||||
ui.attributes.class ||= [];
|
||||
|
||||
ui.children.splice(0, 0, caption);
|
||||
|
||||
|
@ -4067,11 +4061,9 @@ class PageArea extends XFAObject {
|
|||
}
|
||||
|
||||
[$getNextPage]() {
|
||||
if (!this[$extra]) {
|
||||
this[$extra] = {
|
||||
numberOfUse: 0,
|
||||
};
|
||||
}
|
||||
this[$extra] ||= {
|
||||
numberOfUse: 0,
|
||||
};
|
||||
|
||||
const parent = this[$getParent]();
|
||||
if (parent.relation === "orderedOccurrence") {
|
||||
|
@ -4090,11 +4082,9 @@ class PageArea extends XFAObject {
|
|||
|
||||
[$toHTML]() {
|
||||
// TODO: incomplete.
|
||||
if (!this[$extra]) {
|
||||
this[$extra] = {
|
||||
numberOfUse: 1,
|
||||
};
|
||||
}
|
||||
this[$extra] ||= {
|
||||
numberOfUse: 1,
|
||||
};
|
||||
|
||||
const children = [];
|
||||
this[$extra].children = children;
|
||||
|
@ -4186,13 +4176,11 @@ class PageSet extends XFAObject {
|
|||
}
|
||||
|
||||
[$getNextPage]() {
|
||||
if (!this[$extra]) {
|
||||
this[$extra] = {
|
||||
numberOfUse: 1,
|
||||
pageIndex: -1,
|
||||
pageSetIndex: -1,
|
||||
};
|
||||
}
|
||||
this[$extra] ||= {
|
||||
numberOfUse: 1,
|
||||
pageIndex: -1,
|
||||
pageSetIndex: -1,
|
||||
};
|
||||
|
||||
if (this.relation === "orderedOccurrence") {
|
||||
if (this[$extra].pageIndex + 1 < this.pageArea.children.length) {
|
||||
|
@ -5067,9 +5055,7 @@ class Subform extends XFAObject {
|
|||
|
||||
setAccess(this, attributes.class);
|
||||
|
||||
if (!this[$extra]) {
|
||||
this[$extra] = Object.create(null);
|
||||
}
|
||||
this[$extra] ||= Object.create(null);
|
||||
|
||||
Object.assign(this[$extra], {
|
||||
children,
|
||||
|
@ -5495,9 +5481,7 @@ class Template extends XFAObject {
|
|||
}
|
||||
}
|
||||
|
||||
if (!pageArea) {
|
||||
pageArea = pageAreas[0];
|
||||
}
|
||||
pageArea ||= pageAreas[0];
|
||||
|
||||
pageArea[$extra] = {
|
||||
numberOfUse: 1,
|
||||
|
|
|
@ -202,18 +202,15 @@ class App extends PDFObject {
|
|||
}
|
||||
|
||||
get constants() {
|
||||
if (!this._constants) {
|
||||
this._constants = Object.freeze({
|
||||
align: Object.freeze({
|
||||
left: 0,
|
||||
center: 1,
|
||||
right: 2,
|
||||
top: 3,
|
||||
bottom: 4,
|
||||
}),
|
||||
});
|
||||
}
|
||||
return this._constants;
|
||||
return (this._constants ??= Object.freeze({
|
||||
align: Object.freeze({
|
||||
left: 0,
|
||||
center: 1,
|
||||
right: 2,
|
||||
top: 3,
|
||||
bottom: 4,
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
set constants(_) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue