feat(build): Support TypeScript in core/ (#6220)

* fix(tests): Use tsc-compiled base.js to allow use of goog.js

The Closure Compiler complains if you try to feed it a file named
goog.js which is not in the same directory as the Closure Library's
base.js.  Since tsc will "compile" goog.js when it encounters an
"import ... from '.../goog.js'", it is necessary to also have tsc
"compile" base.js and base_minimal.js, so they will come from the
same directory.  This necessitates some updates to paths in

* docs(build): JSDoc update for JSCOMP_WARNING

* refactor(utils): Convert utils/deprecation.js to TypeScript

This was done manually for test/proving purposes and might need to
be corrected based on what MigranTS generated.

* chore(utils): Update utils/deprecation.ts from MigranTS output

This manually applies certain changes from BeksOmega's ts/migration2
branch, but notably:

- I did not apply the reordering of the doc comments at the top.
- I applied the deletion of types and @package from the JSDoc.
- I preserved the import goog and goog.declareModuleId lines.
- I have applied a whitespace change on line 37 which violates the
  styleguide; I want to figure out why clang-format is not fixing
  this.

* feat(build): clang-format .ts files

And fix formatting issues introduced by MigranTS in deprecation.ts.

* fix(build): Fix sources for advanced compilation test

I'm not sure why this didn't fail on my local machine previously;
perhaps it succeeded only because of leftover files and would have
failed if I'd run npm run clean.

* fix(build): Disable checkTypes diagnostic group

Unfortunately TSC doesn't output type information in a form
that Closure Compiler can understand, so the latter raises errors
for situations like omitting an optional parameter.

We may have to turn off more diagnostics in future, but for now
this is sufficient.

* chore(utils): Use @internal where we previously used @package

Per comments on PR #6220.

This requires that we disable the nonStandardJsDocs diagnostic.
This commit is contained in:
Christopher Allen
2022-06-16 18:49:24 +01:00
committed by GitHub
parent e6a0b0cb4d
commit 4070ffc419
5 changed files with 60 additions and 33 deletions

View File

@@ -15,27 +15,29 @@
* This method is not specific to Blockly.
* @namespace Blockly.utils.deprecation
*/
goog.module('Blockly.utils.deprecation');
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.utils.deprecation');
/**
* Warn developers that a function or property is deprecated.
* @param {string} name The name of the function or property.
* @param {string} deprecationDate The date of deprecation.
* @param name The name of the function or property.
* @param deprecationDate The date of deprecation.
* Prefer 'month yyyy' or 'quarter yyyy' format.
* @param {string} deletionDate The date of deletion, in the same format as the
* @param deletionDate The date of deletion, in the same format as the
* deprecation date.
* @param {string=} opt_use The name of a function or property to use instead,
* if any.
* @param opt_use The name of a function or property to use instead, if any.
* @alias Blockly.utils.deprecation.warn
* @package
* @internal
*/
const warn = function(name, deprecationDate, deletionDate, opt_use) {
export function warn(
name: string, deprecationDate: string, deletionDate: string,
opt_use?: string) {
let msg = name + ' was deprecated on ' + deprecationDate +
' and will be deleted on ' + deletionDate + '.';
if (opt_use) {
msg += '\nUse ' + opt_use + ' instead.';
}
console.warn(msg);
};
exports.warn = warn;
}