Upgrade TypeScript to 5.3.3

PiperOrigin-RevId: 592599208
This commit is contained in:
Sebastian Schmidt 2023-12-20 10:36:21 -08:00 committed by Copybara-Service
parent 1a88e75a37
commit 7edcba9fc0
7 changed files with 925 additions and 893 deletions

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {assertNotNull, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context'; import {assertExists, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context';
import {ImageSource} from '../../../../web/graph_runner/graph_runner'; import {ImageSource} from '../../../../web/graph_runner/graph_runner';
/** /**
@ -159,13 +159,13 @@ export class CategoryMaskShaderContext extends MPImageShaderContext {
protected override setupShaders(): void { protected override setupShaders(): void {
super.setupShaders(); super.setupShaders();
const gl = this.gl!; const gl = this.gl!;
this.backgroundTextureUniform = assertNotNull( this.backgroundTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'backgroundTexture'), gl.getUniformLocation(this.program!, 'backgroundTexture'),
'Uniform location'); 'Uniform location');
this.colorMappingTextureUniform = assertNotNull( this.colorMappingTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'colorMappingTexture'), gl.getUniformLocation(this.program!, 'colorMappingTexture'),
'Uniform location'); 'Uniform location');
this.maskTextureUniform = assertNotNull( this.maskTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'maskTexture'), gl.getUniformLocation(this.program!, 'maskTexture'),
'Uniform location'); 'Uniform location');
} }

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {assertNotNull, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context'; import {assertExists, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context';
import {ImageSource} from '../../../../web/graph_runner/graph_runner'; import {ImageSource} from '../../../../web/graph_runner/graph_runner';
/** /**
@ -60,13 +60,13 @@ export class ConfidenceMaskShaderContext extends MPImageShaderContext {
protected override setupShaders(): void { protected override setupShaders(): void {
super.setupShaders(); super.setupShaders();
const gl = this.gl!; const gl = this.gl!;
this.defaultTextureUniform = assertNotNull( this.defaultTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'defaultTexture'), gl.getUniformLocation(this.program!, 'defaultTexture'),
'Uniform location'); 'Uniform location');
this.overlayTextureUniform = assertNotNull( this.overlayTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'overlayTexture'), gl.getUniformLocation(this.program!, 'overlayTexture'),
'Uniform location'); 'Uniform location');
this.maskTextureUniform = assertNotNull( this.maskTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'maskTexture'), gl.getUniformLocation(this.program!, 'maskTexture'),
'Uniform location'); 'Uniform location');
} }

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {assertNotNull, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context'; import {assertExists, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context';
/** Number of instances a user can keep alive before we raise a warning. */ /** Number of instances a user can keep alive before we raise a warning. */
const INSTANCE_COUNT_WARNING_THRESHOLD = 250; const INSTANCE_COUNT_WARNING_THRESHOLD = 250;
@ -249,8 +249,8 @@ export class MPImage {
'is passed when iniitializing the image.'); 'is passed when iniitializing the image.');
} }
if (!this.gl) { if (!this.gl) {
this.gl = assertNotNull( this.gl = assertExists(
this.canvas.getContext('webgl2'), this.canvas.getContext('webgl2') as WebGL2RenderingContext,
'You cannot use a canvas that is already bound to a different ' + 'You cannot use a canvas that is already bound to a different ' +
'type of rendering context.'); 'type of rendering context.');
} }

View File

@ -32,9 +32,9 @@ const FRAGMENT_SHADER = `
} }
`; `;
/** Helper to assert that `value` is not null. */ /** Helper to assert that `value` is not null or undefined. */
export function assertNotNull<T>(value: T|null, msg: string): T { export function assertExists<T>(value: T, msg: string): NonNullable<T> {
if (value === null) { if (!value) {
throw new Error(`Unable to obtain required WebGL resource: ${msg}`); throw new Error(`Unable to obtain required WebGL resource: ${msg}`);
} }
return value; return value;
@ -105,7 +105,7 @@ export class MPImageShaderContext {
private compileShader(source: string, type: number): WebGLShader { private compileShader(source: string, type: number): WebGLShader {
const gl = this.gl!; const gl = this.gl!;
const shader = const shader =
assertNotNull(gl.createShader(type), 'Failed to create WebGL shader'); assertExists(gl.createShader(type), 'Failed to create WebGL shader');
gl.shaderSource(shader, source); gl.shaderSource(shader, source);
gl.compileShader(shader); gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
@ -119,7 +119,7 @@ export class MPImageShaderContext {
protected setupShaders(): void { protected setupShaders(): void {
const gl = this.gl!; const gl = this.gl!;
this.program = this.program =
assertNotNull(gl.createProgram()!, 'Failed to create WebGL program'); assertExists(gl.createProgram()!, 'Failed to create WebGL program');
this.vertexShader = this.vertexShader =
this.compileShader(this.getVertexShader(), gl.VERTEX_SHADER); this.compileShader(this.getVertexShader(), gl.VERTEX_SHADER);
@ -144,11 +144,11 @@ export class MPImageShaderContext {
private createBuffers(flipVertically: boolean): MPImageShaderBuffers { private createBuffers(flipVertically: boolean): MPImageShaderBuffers {
const gl = this.gl!; const gl = this.gl!;
const vertexArrayObject = const vertexArrayObject =
assertNotNull(gl.createVertexArray(), 'Failed to create vertex array'); assertExists(gl.createVertexArray(), 'Failed to create vertex array');
gl.bindVertexArray(vertexArrayObject); gl.bindVertexArray(vertexArrayObject);
const vertexBuffer = const vertexBuffer =
assertNotNull(gl.createBuffer(), 'Failed to create buffer'); assertExists(gl.createBuffer(), 'Failed to create buffer');
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.enableVertexAttribArray(this.aVertex!); gl.enableVertexAttribArray(this.aVertex!);
gl.vertexAttribPointer(this.aVertex!, 2, gl.FLOAT, false, 0, 0); gl.vertexAttribPointer(this.aVertex!, 2, gl.FLOAT, false, 0, 0);
@ -157,7 +157,7 @@ export class MPImageShaderContext {
gl.STATIC_DRAW); gl.STATIC_DRAW);
const textureBuffer = const textureBuffer =
assertNotNull(gl.createBuffer(), 'Failed to create buffer'); assertExists(gl.createBuffer(), 'Failed to create buffer');
gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer); gl.bindBuffer(gl.ARRAY_BUFFER, textureBuffer);
gl.enableVertexAttribArray(this.aTex!); gl.enableVertexAttribArray(this.aTex!);
gl.vertexAttribPointer(this.aTex!, 2, gl.FLOAT, false, 0, 0); gl.vertexAttribPointer(this.aTex!, 2, gl.FLOAT, false, 0, 0);
@ -232,7 +232,7 @@ export class MPImageShaderContext {
WebGLTexture { WebGLTexture {
this.maybeInitGL(gl); this.maybeInitGL(gl);
const texture = const texture =
assertNotNull(gl.createTexture(), 'Failed to create texture'); assertExists(gl.createTexture(), 'Failed to create texture');
gl.bindTexture(gl.TEXTURE_2D, texture); gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri( gl.texParameteri(
gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapping ?? gl.CLAMP_TO_EDGE); gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapping ?? gl.CLAMP_TO_EDGE);
@ -252,7 +252,7 @@ export class MPImageShaderContext {
this.maybeInitGL(gl); this.maybeInitGL(gl);
if (!this.framebuffer) { if (!this.framebuffer) {
this.framebuffer = this.framebuffer =
assertNotNull(gl.createFramebuffer(), 'Failed to create framebuffe.'); assertExists(gl.createFramebuffer(), 'Failed to create framebuffe.');
} }
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer); gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
gl.framebufferTexture2D( gl.framebufferTexture2D(

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {assertNotNull, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context'; import {assertExists, MPImageShaderContext} from '../../../../tasks/web/vision/core/image_shader_context';
import {isIOS} from '../../../../web/graph_runner/platform_utils'; import {isIOS} from '../../../../web/graph_runner/platform_utils';
/** Number of instances a user can keep alive before we raise a warning. */ /** Number of instances a user can keep alive before we raise a warning. */
@ -270,8 +270,8 @@ export class MPMask {
'is passed when initializing the image.'); 'is passed when initializing the image.');
} }
if (!this.gl) { if (!this.gl) {
this.gl = assertNotNull( this.gl = assertExists(
this.canvas.getContext('webgl2'), this.canvas.getContext('webgl2') as WebGL2RenderingContext,
'You cannot use a canvas that is already bound to a different ' + 'You cannot use a canvas that is already bound to a different ' +
'type of rendering context.'); 'type of rendering context.');
} }

View File

@ -5,7 +5,7 @@
"devDependencies": { "devDependencies": {
"@bazel/jasmine": "^5.7.2", "@bazel/jasmine": "^5.7.2",
"@bazel/rollup": "^5.7.1", "@bazel/rollup": "^5.7.1",
"@bazel/typescript": "^5.7.1", "@bazel/typescript": "^5.8.1",
"@rollup/plugin-commonjs": "^23.0.2", "@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.1.0", "@rollup/plugin-terser": "^0.1.0",
@ -20,6 +20,6 @@
"protobufjs-cli": "^1.0.2", "protobufjs-cli": "^1.0.2",
"rollup": "^2.3.0", "rollup": "^2.3.0",
"ts-protoc-gen": "^0.15.0", "ts-protoc-gen": "^0.15.0",
"typescript": "^4.8.4" "typescript": "^5.3.3"
} }
} }

1766
yarn.lock

File diff suppressed because it is too large Load Diff