Commit Graph

22 Commits

Author SHA1 Message Date
Joey Parrish 606457488f fix: Add license header to generated externs
To comply with internal regulations, even our generated externs should
have a license header.  This prepends the header to all generated
externs.

Closes #2638

Change-Id: Idef8e7bff53363175aefa34274a8f71477e830fa
2020-06-09 16:19:55 -07:00
Joey Parrish 7e6a0f38ff fix: Correct license headers in misc. files
This corrects/normalizes license headers in misc. files, such as
config files, docs, build tools, tests, and externs.  This does not
affect the compiled output, and is only done for consistency.

Issue #2638

Change-Id: I9d8da2de55243b08d7df2b743aac73c6f15e858a
2020-06-09 16:13:56 -07:00
Joey Parrish a65ef9983b Remove partial exports, broken in new compiler
The old compiler would let us export a static method on a class
without exporting the whole class and its constructor.  The new
compiler silently ignores `@export` for any methods of a non-exported
class.

This means that for the latest Closure Compiler, we must export any
class with exported static methods.  In some cases, these are
non-utility classes with constructors we'd rather not export, but the
constructor is implicitly exported by exporting the class itself.

This was initially caught by the integration tests.  The error wasn't
especially helpful, so I added a try/catch to loadShaka that makes the
error more apparent:
  TypeError: Cannot read property 'registerParserByMime' of undefined

To make sure we do not make this mistake again, I've added a check to
the extern generator, which was already able to detect these types of
classes.  I don't know a compiler-based way to do it, since the
compiler silently ignores the export annotations in these cases.

Issue #2528

Change-Id: I797c75a8098b0bb3cf837588569f878253dec2cf
2020-04-30 17:30:36 +00:00
Joey Parrish 618e2486e4 Generate externs from partially exported classes
In v2.5, we had some classes which were not exported, but which had
certain individual methods which were exported.  This is still true in
v2.6, except that we're using ES6 classes everywhere instead of mostly
using .prototype.

The extern generator had support for exporting individual .prototype
methods, but not for exporting individual class methods (unless the
class itself was exported already).

This adds support in the extern generator for these "partially
exported" classes, to correct missing externs in preparation for the
v2.6 launch.

Change-Id: I17ef377980ce771d74fab78afe26aa36ba3cce90
2020-04-27 16:58:08 +00:00
Joey Parrish 07a171d28d Fix generated extern parameter formatting
The parameters for prototype methods and other function expressions
was already correct, but there was a lack of spaces between parameters
in class methods.

Change-Id: I3b77a36efc91d8a3648bf45da0f9b155d78e5da5
2020-04-22 20:17:20 +00:00
Jacob Trimble 011749e95f Standardize argument comments.
This changes the eslint rule to enforce a strict pattern for the
argument comments.  The comment must appear before the argument and
must be /* foo= */.  This still ignores line comments.

Change-Id: I3afb01c65e1088eda13facb3aeeaa7595a2f5aee
2020-01-06 19:40:52 +00:00
Joey Parrish 64896d70b0 Use shorter license header
This reflects changes in Google's policy on JavaScript license
headers, which should be smaller to avoid increasing the size of the
binary unnecessarily.

This also updates the company name from "Google, Inc" to "Google LLC".

Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
2019-11-22 18:18:36 +00:00
Jacob Trimble 0ac6c622c8 Fix using old Node versions.
Change-Id: I5a6098ffb1d2bb5477940e869fe7d1b03eae5c9e
2019-05-21 19:09:38 +00:00
Theodore Abshire f50f596965 Removed requirement for JSDoc for constructors
Previously, generateExterns required all methods to have JSDoc.
This made sense most of the time, but for an ES6 constructor not as
much. What the constructor does is kind of self-explanatory, and a JSDoc
along the lines of "/** Creates a Foo object. */" is a waste of space.

This changes generateExterns to not require a comment for such
constructors.

Change-Id: I12ae019934de9c020340baf0ca25f940d58d7d2f
2019-05-20 18:38:16 +00:00
Jacob Trimble 74918b90ec Convert networking files to ES6.
Issue #1157

Change-Id: Iae83b88881b351c97e8ec020625167f5f700f97e
2019-05-20 17:10:06 +00:00
Jacob Trimble 134bc260cd Use 'assert' module in generateExterns.
The 'assert' module will throw an error that will crash the script.
This ensures an error is caught instead of causing silent problems.

Change-Id: I47d54924bff3a83b9897fd84a85142e237f18da6
2019-05-20 16:03:54 +00:00
Joey Parrish ae4454b449 Update the extern generator for ES6 data classes
For classes which only contain a bunch of public, exported members set
in the constructor, the extern generator goes through some extra steps
to create externs for those.  This updates the generator to handle
these as they are converted to ES6.

Note that we currently have only three such classes:
 - shaka.util.Error
 - shaka.text.Cue
 - shaka.text.CueRegion

Issue #1157

Change-Id: I8041998b2bdca0e6f44dcc6f897eb3c660b3424f
2019-05-16 22:46:25 +00:00
Theodore Abshire 2636b4ea0a Made error for lack of block comment more helpful.
Change-Id: I23d4d1d50c152b2602dce92a486bce04888550cb
2019-05-16 16:26:32 +00:00
Joey Parrish e9aca65efb Replace forEach with for-of loops in generateExterns
Issue #1157

Change-Id: I6590827b82f459a926536b916a2d2e01a89135ed
2019-05-16 00:45:01 +00:00
Joey Parrish 42b40bd3da Require NodeJS v8+ and NPM v5+
This updates our build requirements to NodeJS v8+ and NPM v5+, both
released in 2017.

This also clarifies our support for Python 3 (not well-documented
before) to the version we are using on Debian, v3.5.

Requiring NodeJS v8+ means our node tools (like our extern generator)
no longer need shims for compatibility.  This allows us to drop the
"es6-shim" and "array-includes" modules.

In NPM v5+, the "prepublish" script has been deprecated, and replaced
with "prepublishOnly" (which is what we want) and "prepare" (the old
behavior we had to work around).  This allows us to drop the
"in-publish" module.

Change-Id: Ied189c76a58fe981c12d41155b834f2d6ea73bbd
2019-05-15 20:32:34 +00:00
Joey Parrish 2fdbc07dda Update generateExterns to ES6
This updates build/generateExterns.js to use ES6 syntax and comply
with linter rules in eslint.  It also adds this to the list of things
checked with that linter.

Issue #1157

Change-Id: I5d7fecc9375b8e97db529dd2c5efb74276a9acfb
2019-05-15 16:33:20 +00:00
Sandra Lokshina 6b1ca2d229 Initial release of Shaka Player UI
Other contributors:
 - @joeyparrish
 - @michellezhuogg
 - @TheModMaker
 - @theodab
 - @vaage

Change-Id: If6df33d9ab5035d1ead4402004f7de37ee8470f4
2018-11-16 14:40:37 -08:00
Joey Parrish fd0449d8f7 Re-enable some disabled style rules
This re-enables the following style rules:
  - "block-spacing"
  - "brace-style"
  - "comma-dangle"
  - "comma-spacing"
  - "new-cap"
  - "no-multi-spaces"
  - "no-multiple-empty-lines"
  - "one-var"
  - "padded-blocks"
  - "prefer-rest-params"

Change-Id: I15d616e8d5b88b273ded6128b4f9ad86bdb26bd1
2018-07-09 19:44:56 +00:00
Joey Parrish 1cf27b9064 Fix support for startTime of 0
During a recent refactor, startTime || null got introduced.
This would not only use null as a default, but would also convert 0
into null, which changes the meaning of 0 from "exactly timestamp 0"
to "default start position" (which is non-zero for live streams).

This fix adds a regression test that fails without the fix.

Change-Id: I01e1628df9d141697fdb7d9fb5e77a16ac3dab5b
2018-05-10 18:08:17 +00:00
Joey Parrish b15d4d3f4e Add support for generating externs for ES6 classes
This is necessary to allow the exporting of AbortableOperation.

Change-Id: Id343fe147b0ec5c1f653a679bb6472c222b2c59a
2018-04-05 22:03:11 +00:00
Joey Parrish 3a91c466cf Pull interface exports from constructors
Generated externs should include member assignments from constructors.
Without them, the generated externs may not appear to implement the
full interface.  The alternative is to re-declare these members on the
prototype, but that is more difficult to maintain.  Instead, the
extern generator can convert them for us.

Example code:

/** @interface @exportInterface */
FooLike = function() {};

/** @exportInterface @type {number} */
FooLike.prototype.bar;

/** @constructor @export @implements {FooLike} */
Foo = function() {
  /** @override @exportInterface */
  this.bar = 10;
};

Example externs:

/** @interface */
FooLike = function() {};

/** @type {number} */
FooLike.prototype.bar;

/**
 * @constructor @implements {FooLike}
 */
Foo = function() {}

/**
 * @override
 */
Foo.prototype.bar;

Change-Id: I435ba1800d5eefbf68c27851d6454c1a572cc6f6
2017-09-26 17:57:47 +00:00
Joey Parrish 8ba088a38f Generate externs automatically
We were not able to get our externs generated by the Closure compiler.
There were many issues with the Closure-generated externs, including
the order of the externs and the replacement of record types and enums
with their underlying types.

We made a few attempts to patch the compiler, but could not get our
patches accepted upstream.

This change introduces a new script to generate our externs from
scratch.  It uses a JavaScript parser called 'esprima'.

Some interfaces need to be exported to the generated externs, but are
not actually attached to the namespace by the compiler.  For this, we
introduce a new annotation.  These are the currently-supported export
annotations:

 - @export: truly exported (attached to namespace) by the compiler
 - @expose: truly exposed (not renamed) by the compiler
 - @exportDoc: considered part of the exports in the docs
 - @exportInterface: considered part of the exports in generated externs

These annotations are now documented in docs/design/export.md

Change-Id: I33bf7384889c14c9edb0fa5f11caa7c4f4d79af6
2017-02-01 11:42:16 -08:00