Remove the closure used with the PostScriptToken class

This patch uses the same approach as used in lots of other parts of the code-base, which thus *slightly* reduces the size of this code.
This commit is contained in:
Jonas Jenwald 2021-07-24 13:05:46 +02:00
parent 81009d42cf
commit ebbbc973a5

View File

@ -109,22 +109,22 @@ const PostScriptTokenTypes = {
IFELSE: 5, IFELSE: 5,
}; };
const PostScriptToken = (function PostScriptTokenClosure() { class PostScriptToken {
const opCache = Object.create(null); static get opCache() {
return shadow(this, "opCache", Object.create(null));
}
// eslint-disable-next-line no-shadow
class PostScriptToken {
constructor(type, value) { constructor(type, value) {
this.type = type; this.type = type;
this.value = value; this.value = value;
} }
static getOperator(op) { static getOperator(op) {
const opValue = opCache[op]; const opValue = PostScriptToken.opCache[op];
if (opValue) { if (opValue) {
return opValue; return opValue;
} }
return (opCache[op] = new PostScriptToken( return (PostScriptToken.opCache[op] = new PostScriptToken(
PostScriptTokenTypes.OPERATOR, PostScriptTokenTypes.OPERATOR,
op op
)); ));
@ -161,9 +161,7 @@ const PostScriptToken = (function PostScriptTokenClosure() {
new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE") new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE")
); );
} }
} }
return PostScriptToken;
})();
class PostScriptLexer { class PostScriptLexer {
constructor(stream) { constructor(stream) {