Reputation: 2137
I'm building a Google Docs plugin and I'm trying to pull a PDF from an external site to parse (for simple things like number of pages, text content, etc. that doesn't require visual rendering of the document). However, I've been having a lot of trouble integrating the Javascript library into my project.
I understand that I will have to do some manual work to remove some stuff that are the parts that are browser-dependent, like DOM rendering or network connections. However, the error here is completely unrelated.
I've tried manually copying all the source files into the project (changing the paths where required) and using a "built" library I found online (as just that one file in my project). However, I'm getting an odd syntax error whenever I save my project-
Missing name after . operator. (line 1120, file "pdf")
This is line 1120 in file "pdf":
if (typeof globalScope.Promise.prototype.catch !== 'function') {
This is a chunk of related code:
if (typeof globalScope.Promise.resolve !== 'function') {
globalScope.Promise.resolve = function (value) {
return new globalScope.Promise(function (resolve) { resolve(value); });
};
}
if (typeof globalScope.Promise.reject !== 'function') {
globalScope.Promise.reject = function (reason) {
return new globalScope.Promise(function (resolve, reject) {
reject(reason);
});
};
}
if (typeof globalScope.Promise.prototype.catch !== 'function') {
globalScope.Promise.prototype.catch = function (onReject) {
return globalScope.Promise.prototype.then(undefined, onReject);
};
}
return;
However, no syntax errors that I can see there.
So, real question:
Upvotes: 2
Views: 1833
Reputation: 4034
Because catch
is a JavaScript reserved word Apps Script is strict and blocks its use as a parameter.
Your code IS valid, just not strict mode friendly.
Use globalScope.Promise.prototype['catch']
instead.
Upvotes: 1