Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types annotations #12102

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 104 additions & 47 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var GH_PAGES_DIR = BUILD_DIR + "gh-pages/";
var SRC_DIR = "src/";
var LIB_DIR = BUILD_DIR + "lib/";
var DIST_DIR = BUILD_DIR + "dist/";
var TYPES_BUILD_DIR = BUILD_DIR + "types/";
var COMMON_WEB_FILES = ["web/images/*.{png,svg,gif,cur}", "web/debugger.js"];
var MOZCENTRAL_DIFF_FILE = "mozcentral.diff";

Expand Down Expand Up @@ -1141,6 +1142,21 @@ gulp.task("jsdoc", function (done) {
});
});

gulp.task("types", function (done) {
console.log("### Generating typescript definitions using tsc");
var args = [
"target ES2020",
"allowJS",
"declaration",
`outDir ${TYPES_BUILD_DIR}`,
"strict",
"esModuleInterop",
"forceConsistentCasingInFileNames",
"emitDeclarationOnly",
].join(" --");
exec(`node_modules/.bin/tsc --${args} src/pdf.js`, done);
});

function buildLib(defines, dir) {
// When we create a bundle, webpack is run on the source and it will replace
// require with __webpack_require__. When we want to use the real require,
Expand Down Expand Up @@ -1336,6 +1352,42 @@ gulp.task(
})
);

gulp.task(
"typestest",
gulp.series(
"testing-pre",
"generic",
"types",

function () {
var packageJsonSrc = packageBowerJson()[0];
var TYPESTEST_DIR = BUILD_DIR + "typestest/";

return merge([
packageJsonSrc.pipe(gulp.dest(TYPESTEST_DIR)),
gulp
.src([
GENERIC_DIR + "build/pdf.js",
GENERIC_DIR + "build/pdf.worker.js",
SRC_DIR + "pdf.worker.entry.js",
])
.pipe(gulp.dest(TYPESTEST_DIR + "build/")),
gulp
.src(TYPES_BUILD_DIR + "**/**")
.pipe(gulp.dest(TYPESTEST_DIR + "build/")),
]);
},
Comment on lines +1362 to +1379
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, defining this inline isn't really helping readability of the overall task, and it really ought to be moved into a helper function/task (e.g. typestest-pre) similar to what's done in other parts of the gulpfile.

function (done) {
exec(`node_modules/.bin/tsc -p test/types`, function (err, stdout) {
if (err !== null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just be if (err) {, right?

console.log("couldn't compile typescript test: " + stdout);
}
done(err);
});
}
)
);

gulp.task("baseline", function (done) {
console.log();
console.log("### Creating baseline environment");
Expand Down Expand Up @@ -1576,6 +1628,52 @@ gulp.task(
)
);

function packageBowerJson() {
var VERSION = getVersionJSON().version;
var DIST_NAME = "pdfjs-dist";
var DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library.";
var DIST_KEYWORDS = ["Mozilla", "pdf", "pdf.js"];
var DIST_HOMEPAGE = "http://mozilla.github.io/pdf.js/";
var DIST_BUGS_URL = "https://github.com/mozilla/pdf.js/issues";
var DIST_LICENSE = "Apache-2.0";
var npmManifest = {
name: DIST_NAME,
version: VERSION,
main: "build/pdf.js",
types: "build/pdf.d.ts",
description: DIST_DESCRIPTION,
keywords: DIST_KEYWORDS,
homepage: DIST_HOMEPAGE,
bugs: DIST_BUGS_URL,
license: DIST_LICENSE,
browser: {
canvas: false,
fs: false,
http: false,
https: false,
url: false,
zlib: false,
},
format: "amd", // to not allow system.js to choose 'cjs'
repository: {
type: "git",
url: DIST_REPO_URL,
},
};
var bowerManifest = {
name: DIST_NAME,
version: VERSION,
main: ["build/pdf.js", "build/pdf.worker.js"],
ignore: [],
keywords: DIST_KEYWORDS,
};

return [
createStringSource("package.json", JSON.stringify(npmManifest, null, 2)),
createStringSource("bower.json", JSON.stringify(bowerManifest, null, 2)),
];
}

gulp.task(
"dist-pre",
gulp.series(
Expand All @@ -1586,9 +1684,8 @@ gulp.task(
"image_decoders",
"lib",
"minified",
"types",
function () {
var VERSION = getVersionJSON().version;

console.log();
console.log("### Cloning baseline distribution");

Expand All @@ -1601,50 +1698,7 @@ gulp.task(
rimraf.sync(path.join(DIST_DIR, "*"));

// Rebuilding manifests
var DIST_NAME = "pdfjs-dist";
var DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library.";
var DIST_KEYWORDS = ["Mozilla", "pdf", "pdf.js"];
var DIST_HOMEPAGE = "http://mozilla.github.io/pdf.js/";
var DIST_BUGS_URL = "https://github.com/mozilla/pdf.js/issues";
var DIST_LICENSE = "Apache-2.0";
var npmManifest = {
name: DIST_NAME,
version: VERSION,
main: "build/pdf.js",
description: DIST_DESCRIPTION,
keywords: DIST_KEYWORDS,
homepage: DIST_HOMEPAGE,
bugs: DIST_BUGS_URL,
license: DIST_LICENSE,
browser: {
canvas: false,
fs: false,
http: false,
https: false,
url: false,
zlib: false,
},
format: "amd", // to not allow system.js to choose 'cjs'
repository: {
type: "git",
url: DIST_REPO_URL,
},
};
var packageJsonSrc = createStringSource(
"package.json",
JSON.stringify(npmManifest, null, 2)
);
var bowerManifest = {
name: DIST_NAME,
version: VERSION,
main: ["build/pdf.js", "build/pdf.worker.js"],
ignore: [],
keywords: DIST_KEYWORDS,
};
var bowerJsonSrc = createStringSource(
"bower.json",
JSON.stringify(bowerManifest, null, 2)
);
var [packageJsonSrc, bowerJsonSrc] = packageBowerJson();

return merge([
packageJsonSrc.pipe(gulp.dest(DIST_DIR)),
Expand Down Expand Up @@ -1698,6 +1752,9 @@ gulp.task(
gulp
.src(LIB_DIR + "**/*", { base: LIB_DIR })
.pipe(gulp.dest(DIST_DIR + "lib/")),
gulp
.src(TYPES_BUILD_DIR + "**/**")
.pipe(gulp.dest(DIST_DIR + "build/")),
]);
}
)
Expand Down Expand Up @@ -1847,7 +1904,7 @@ gulp.task("externaltest", function (done) {
gulp.task(
"npm-test",
gulp.series(
gulp.parallel("lint", "externaltest", "unittestcli"),
gulp.parallel("lint", "externaltest", "unittestcli", "typestest"),
"lint-chromium"
)
);
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"terser": "^4.8.0",
"through2": "^3.0.2",
"ttest": "^2.1.1",
"typescript": "^3.9.7",
"typogr": "^0.6.8",
"vinyl": "^2.2.0",
"vinyl-fs": "^3.0.3",
Expand Down
3 changes: 3 additions & 0 deletions src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* limitations under the License.
*/

/**
* Key/value storage for annotation data in forms.
*/
class AnnotationStorage {
constructor() {
this._storage = {};
Expand Down
Loading