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.
*/
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';
/**
@ -159,13 +159,13 @@ export class CategoryMaskShaderContext extends MPImageShaderContext {
protected override setupShaders(): void {
super.setupShaders();
const gl = this.gl!;
this.backgroundTextureUniform = assertNotNull(
this.backgroundTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'backgroundTexture'),
'Uniform location');
this.colorMappingTextureUniform = assertNotNull(
this.colorMappingTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'colorMappingTexture'),
'Uniform location');
this.maskTextureUniform = assertNotNull(
this.maskTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'maskTexture'),
'Uniform location');
}

View File

@ -14,7 +14,7 @@
* 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';
/**
@ -60,13 +60,13 @@ export class ConfidenceMaskShaderContext extends MPImageShaderContext {
protected override setupShaders(): void {
super.setupShaders();
const gl = this.gl!;
this.defaultTextureUniform = assertNotNull(
this.defaultTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'defaultTexture'),
'Uniform location');
this.overlayTextureUniform = assertNotNull(
this.overlayTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'overlayTexture'),
'Uniform location');
this.maskTextureUniform = assertNotNull(
this.maskTextureUniform = assertExists(
gl.getUniformLocation(this.program!, 'maskTexture'),
'Uniform location');
}

View File

@ -14,7 +14,7 @@
* 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. */
const INSTANCE_COUNT_WARNING_THRESHOLD = 250;
@ -249,8 +249,8 @@ export class MPImage {
'is passed when iniitializing the image.');
}
if (!this.gl) {
this.gl = assertNotNull(
this.canvas.getContext('webgl2'),
this.gl = assertExists(
this.canvas.getContext('webgl2') as WebGL2RenderingContext,
'You cannot use a canvas that is already bound to a different ' +
'type of rendering context.');
}

View File

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

View File

@ -14,7 +14,7 @@
* 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';
/** 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.');
}
if (!this.gl) {
this.gl = assertNotNull(
this.canvas.getContext('webgl2'),
this.gl = assertExists(
this.canvas.getContext('webgl2') as WebGL2RenderingContext,
'You cannot use a canvas that is already bound to a different ' +
'type of rendering context.');
}

View File

@ -5,7 +5,7 @@
"devDependencies": {
"@bazel/jasmine": "^5.7.2",
"@bazel/rollup": "^5.7.1",
"@bazel/typescript": "^5.7.1",
"@bazel/typescript": "^5.8.1",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.1.0",
@ -20,6 +20,6 @@
"protobufjs-cli": "^1.0.2",
"rollup": "^2.3.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