Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
refactor: use TS 4.5 const assertions
Browse files Browse the repository at this point in the history
TypeScript 4.5 supports const assertions in JSDoc comments. This allows
us to remove the `_c()` function, previously used as a workaround.
This should make the lexer very slightly faster and won't affect any
semantics.
  • Loading branch information
pastelmind committed Feb 8, 2022
1 parent 626da78 commit faf0d6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ReferenceToken,
tokenize,
} from "./lexer.js";
import { _c } from "./types.js";

/**
* @typedef {import("./int32.js").Int32} Int32
Expand Down Expand Up @@ -417,7 +416,7 @@ export class AstBinaryOp {
* @param {AstExpression} right Right side expression
*/
constructor(operator, left, right) {
this.type = _c("AstBinaryOp");
this.type = /** @type {const} */ ("AstBinaryOp");
this.operator = operator;
this.left = left;
this.right = right;
Expand All @@ -430,7 +429,7 @@ export class AstUnaryOp {
* @param {AstExpression} expression Expression to apply the operator
*/
constructor(operator, expression) {
this.type = _c("AstUnaryOp");
this.type = /** @type {const} */ ("AstUnaryOp");
this.operator = operator;
this.expression = expression;
}
Expand All @@ -443,7 +442,7 @@ export class AstConditional {
* @param {AstExpression} falseExpression Expression to evaluate if condition is false (zero)
*/
constructor(condition, trueExpression, falseExpression) {
this.type = _c("AstConditional");
this.type = /** @type {const} */ ("AstConditional");
this.condition = condition;
this.trueExpression = trueExpression;
this.falseExpression = falseExpression;
Expand All @@ -463,7 +462,7 @@ export class AstNumber extends AstIntegralExpression {
*/
constructor(value) {
super();
this.type = _c("AstNumber");
this.type = /** @type {const} */ ("AstNumber");
this.value = value;
}
}
Expand All @@ -474,7 +473,7 @@ export class AstIdentifier extends AstIntegralExpression {
*/
constructor(name) {
super();
this.type = _c("AstIdentifier");
this.type = /** @type {const} */ ("AstIdentifier");
this.name = name;
}
}
Expand All @@ -487,7 +486,7 @@ export class AstFunctionCall extends AstIntegralExpression {
*/
constructor(functionName, arg1, arg2) {
super();
this.type = _c("AstFunctionCall");
this.type = /** @type {const} */ ("AstFunctionCall");
this.functionName = functionName;
this.arg1 = arg1;
this.arg2 = arg2;
Expand All @@ -503,7 +502,7 @@ export class AstRefFunctionCall extends AstIntegralExpression {
*/
constructor(functionName, reference, code1, code2) {
super();
this.type = _c("AstRefFunctionCall");
this.type = /** @type {const} */ ("AstRefFunctionCall");
this.functionName = functionName;
this.reference = reference;
this.code1 = code1;
Expand Down
10 changes: 0 additions & 10 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@
* @template T, B
* @typedef {T & Branded<B>} Nominal
*/

/**
* Helper function for creating number and string literal types.
* @template {number | string} T
* @param {T} value
* @return {T}
*/
export function _c(value) {
return value;
}

0 comments on commit faf0d6c

Please sign in to comment.